From 2a7227c906851521f95e9cf493cabdea44fc5eec Mon Sep 17 00:00:00 2001 From: telontelvarost Date: Tue, 30 Jul 2024 22:24:28 -0400 Subject: [PATCH] Prevent illegal slot transfers with scroll wheel which could cause dupes/non-vanilla behavior --- gradle.properties | 2 +- .../mixin/ContainerBaseMixin.java | 21 ++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/gradle.properties b/gradle.properties index 1ecc472..167d57e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,7 +9,7 @@ yarn_mappings=b1.7.3-build.2 loader_version=0.14.24-babric.1 # Mod Properties -mod_version=2.1.3 +mod_version=2.1.4 maven_group=com.github.telvarost archives_base_name=InventoryTweaks diff --git a/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java b/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java index 5abc2e3..1cab116 100644 --- a/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java +++ b/src/main/java/com/github/telvarost/inventorytweaks/mixin/ContainerBaseMixin.java @@ -3,9 +3,11 @@ import com.github.telvarost.inventorytweaks.Config; import net.minecraft.client.gui.screen.ScreenBase; import net.minecraft.client.gui.screen.container.ContainerBase; +import net.minecraft.container.Crafting; +import net.minecraft.container.Furnace; +import net.minecraft.entity.player.PlayerContainer; import net.minecraft.item.ItemInstance; import net.minecraft.container.slot.Slot; -import net.modificationstation.stationapi.api.network.ModdedPacketHandler; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.spongepowered.asm.mixin.Mixin; @@ -232,12 +234,29 @@ private void inventoryTweaks_mouseReleasedOrSlotChanged(int mouseX, int mouseY, slotStackAmount = slotItemToExamine.count; } + /** - Allow transfers if one or both of the slots are empty */ if ( (null != cursorStack) && (null != slotItemToExamine) ) { + /** - Prevent transfers if items in slots do not match */ transferAllowed = cursorStack.isDamageAndIDIdentical(slotItemToExamine); } + /** - Prevent illegal transfers that can cause bugs/dupes */ + if ( (slot.id == 0) && (container instanceof Crafting) + || (slot.id == 2) && (container instanceof Furnace) + || ( (container instanceof PlayerContainer) + && ( (slot.id == 0) + || (slot.id == 5) + || (slot.id == 6) + || (slot.id == 7) + || (slot.id == 8) + ) + ) + ) { + transferAllowed = false; + } + if (transferAllowed) { inventoryTweaks_scrollCursorSlotTransfer(numberOfTurns, cursorStackAmount, slotStackAmount, itemBeingTransfered); }