Dupe fix!!!

This commit is contained in:
BallOfEnergy 2025-03-28 19:50:27 -05:00
parent fa6d2a4e56
commit aaff6b9b70
2 changed files with 23 additions and 6 deletions

View File

@ -2,6 +2,9 @@ package com.hbm.inventory;
import com.hbm.interfaces.NotableComments; 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.IInventory;
import net.minecraft.inventory.Slot; import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -33,4 +36,17 @@ public class SlotNonRetarded extends Slot {
public int getSlotStackLimit() { public int getSlotStackLimit() {
return Math.max(this.inventory.getInventoryStackLimit(), this.getHasStack() ? this.getStack().stackSize : 1); 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);
}
} }

View File

@ -1,5 +1,6 @@
package com.hbm.inventory.container; package com.hbm.inventory.container;
import com.hbm.inventory.SlotNonRetarded;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container; import net.minecraft.inventory.Container;
@ -61,12 +62,12 @@ public class ContainerBase extends Container {
public void playerInv(InventoryPlayer invPlayer, int playerInvX, int playerInvY, int playerHotbarY) { public void playerInv(InventoryPlayer invPlayer, int playerInvX, int playerInvY, int playerHotbarY) {
for(int i = 0; i < 3; i++) { for(int i = 0; i < 3; i++) {
for(int j = 0; j < 9; j++) { 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++) { 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));
} }
} }
@ -83,7 +84,7 @@ public class ContainerBase extends Container {
int slotSize = 18; int slotSize = 18;
for(int row = 0; row < rows; row++) { for(int row = 0; row < rows; row++) {
for(int col = 0; col < cols; col++) { 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));
} }
} }
} }