From aaff6b9b704a2a9c3540e092631e9758252bc0a6 Mon Sep 17 00:00:00 2001 From: BallOfEnergy <66693744+ballofenergy1@users.noreply.github.com> Date: Fri, 28 Mar 2025 19:50:27 -0500 Subject: [PATCH] Dupe fix!!! --- .../com/hbm/inventory/SlotNonRetarded.java | 18 +++++++++++++++++- .../hbm/inventory/container/ContainerBase.java | 11 ++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/hbm/inventory/SlotNonRetarded.java b/src/main/java/com/hbm/inventory/SlotNonRetarded.java index 87c166277..61be0b9a1 100644 --- a/src/main/java/com/hbm/inventory/SlotNonRetarded.java +++ b/src/main/java/com/hbm/inventory/SlotNonRetarded.java @@ -2,6 +2,9 @@ package com.hbm.inventory; import com.hbm.interfaces.NotableComments; +import com.hbm.inventory.container.ContainerCrateBase; +import com.hbm.items.block.ItemBlockStorageCrate; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; @@ -24,7 +27,7 @@ public class SlotNonRetarded extends Slot { public boolean isItemValid(ItemStack stack) { return inventory.isItemValidForSlot(this.slotNumber, stack); } - + /** * Because if slots have higher stacksizes than the maximum allowed by the tile, the display just stops working. * Why was that necessary? Sure it's not intended but falsifying information isn't very cool. @@ -33,4 +36,17 @@ public class SlotNonRetarded extends Slot { public int getSlotStackLimit() { return Math.max(this.inventory.getInventoryStackLimit(), this.getHasStack() ? this.getStack().stackSize : 1); } + + /** + * This prevents the player from moving containers that are being held *at all*, fixing a decently big dupe. + * I hate that this has to be here but... It is what it is. + */ + @Override + public boolean canTakeStack(EntityPlayer player) { + if(player.inventory.currentItem == this.getSlotIndex() && // If this slot is the current held slot. + this.getStack() != null && this.getStack().getItem() instanceof ItemBlockStorageCrate && // If the slot contains a storage crate. + player.openContainer instanceof ContainerCrateBase) // If the player is currently inside a crate container. + return false; + return super.canTakeStack(player); + } } diff --git a/src/main/java/com/hbm/inventory/container/ContainerBase.java b/src/main/java/com/hbm/inventory/container/ContainerBase.java index 2dd45772b..bafd2442e 100644 --- a/src/main/java/com/hbm/inventory/container/ContainerBase.java +++ b/src/main/java/com/hbm/inventory/container/ContainerBase.java @@ -1,5 +1,6 @@ package com.hbm.inventory.container; +import com.hbm.inventory.SlotNonRetarded; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Container; @@ -12,7 +13,7 @@ import net.minecraft.item.ItemStack; * implementation, because I really needed to get the te from a container But * you should very much use this to kill the giant amount of boilerplate in * container classes - * + * * @author 70k **/ public class ContainerBase extends Container { @@ -61,12 +62,12 @@ public class ContainerBase extends Container { public void playerInv(InventoryPlayer invPlayer, int playerInvX, int playerInvY, int playerHotbarY) { for(int i = 0; i < 3; i++) { for(int j = 0; j < 9; j++) { - this.addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, playerInvX + j * 18, playerInvY + i * 18)); + this.addSlotToContainer(new SlotNonRetarded(invPlayer, j + i * 9 + 9, playerInvX + j * 18, playerInvY + i * 18)); } } for(int i = 0; i < 9; i++) { - this.addSlotToContainer(new Slot(invPlayer, i, playerInvX + i * 18, playerHotbarY)); + this.addSlotToContainer(new SlotNonRetarded(invPlayer, i, playerInvX + i * 18, playerHotbarY)); } } @@ -75,7 +76,7 @@ public class ContainerBase extends Container { // - Mellow, 1884 /** * Used to add several conventional inventory slots at a time - * + * * @param inv the inventory to add the slots to * @param from the slot index to start from */ @@ -83,7 +84,7 @@ public class ContainerBase extends Container { int slotSize = 18; for(int row = 0; row < rows; row++) { for(int col = 0; col < cols; col++) { - this.addSlotToContainer(new Slot(inv, col + row * cols + from, x + col * slotSize, y + row * slotSize)); + this.addSlotToContainer(new SlotNonRetarded(inv, col + row * cols + from, x + col * slotSize, y + row * slotSize)); } } }