fix storage unit bugs with locking closes #2155
This commit is contained in:
parent
852cd1c496
commit
bcfb8d3b02
2 changed files with 20 additions and 3 deletions
|
@ -61,7 +61,8 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity
|
|||
protected RebornInventory<StorageUnitBaseBlockEntity> 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);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -50,6 +50,8 @@ public class GuiStorageUnit extends GuiBase<BuiltScreenHandler> {
|
|||
// 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<BuiltScreenHandler> {
|
|||
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);
|
||||
|
|
Loading…
Reference in a new issue