diff --git a/src/main/java/techreborn/blockentity/storage/item/StorageUnitBaseBlockEntity.java b/src/main/java/techreborn/blockentity/storage/item/StorageUnitBaseBlockEntity.java index d17ad1326..4cdd53850 100644 --- a/src/main/java/techreborn/blockentity/storage/item/StorageUnitBaseBlockEntity.java +++ b/src/main/java/techreborn/blockentity/storage/item/StorageUnitBaseBlockEntity.java @@ -61,7 +61,8 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity protected RebornInventory inventory; private int maxCapacity; - private boolean shouldUpdate = false; + private boolean shouldUpdate = true; + private int prevCount = -1; private ItemStack storeItemStack; @@ -118,6 +119,12 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity } } + // Update for locked item for clients + if(isLocked() && prevCount != this.getCurrentCapacity()){ + prevCount = this.getCurrentCapacity(); + syncWithAll(); + } + if (shouldUpdate) { inventory.setChanged(); @@ -421,12 +428,13 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity } public void setLocked(boolean value) { - // Only set lockedItem in response to user input if (isLocked() == value) { return; } + // Only set lockedItem in response to user input lockedItemStack = value ? getStoredStack().copy() : ItemStack.EMPTY; + syncWithAll(); } public boolean canModifyLocking() { @@ -448,9 +456,16 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity @Override public boolean isValid(int slot, ItemStack stack) { + if (slot == INPUT_SLOT && isLocked()) { + return ItemUtils.isItemEqual(lockedItemStack, stack, true, true); + } + + if (slot == INPUT_SLOT && !(isEmpty() || isSameType(stack))) { return false; } return super.isValid(slot, stack); } + + } diff --git a/src/main/java/techreborn/client/gui/GuiStorageUnit.java b/src/main/java/techreborn/client/gui/GuiStorageUnit.java index 275ebe733..11054c032 100644 --- a/src/main/java/techreborn/client/gui/GuiStorageUnit.java +++ b/src/main/java/techreborn/client/gui/GuiStorageUnit.java @@ -50,6 +50,8 @@ public class GuiStorageUnit extends GuiBase { // Draw slots drawSlot(matrixStack, 100, 53, layer); drawSlot(matrixStack, 140, 53, layer); + + builder.drawLockButton(matrixStack,this, 150, 4, mouseX, mouseY, layer, storageEntity.isLocked()); } @Override @@ -64,7 +66,7 @@ public class GuiStorageUnit extends GuiBase { textRenderer.draw(matrixStack, new TranslatableText("techreborn.tooltip.unit.empty"), 10, 20, 4210752); } else { textRenderer.draw(matrixStack, new TranslatableText("gui.techreborn.storage.store"), 10, 20, 4210752); - textRenderer.draw(matrixStack, storageEntity.getStoredStack().getName(), 10, 30, 4210752); + textRenderer.draw(matrixStack, storageEntity.getDisplayedStack().getName(), 10, 30, 4210752); textRenderer.draw(matrixStack, new TranslatableText("gui.techreborn.storage.amount"), 10, 50, 4210752); textRenderer.draw(matrixStack, String.valueOf(storageEntity.getCurrentCapacity()), 10, 60, 4210752);