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.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);
}
}

View File

@ -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));
}
}
}