Refresh all screens when changing items

This commit is contained in:
Bruno Rybársky 2024-05-26 23:22:53 +02:00
parent 541f19dde6
commit 1d4b658400
3 changed files with 12 additions and 9 deletions

@ -8,7 +8,7 @@ yarn_mappings=1.20.6+build.3
loader_version=0.15.11 loader_version=0.15.11
# Mod Properties # Mod Properties
mod_version=2.0 mod_version=2.2
maven_group=systems.brn maven_group=systems.brn
archives_base_name=Server_storage archives_base_name=Server_storage

@ -67,6 +67,10 @@ public class StorageBlockEntity extends BlockEntity implements Inventory, SidedI
markDirty(); markDirty();
ConnectedChests chests = new ConnectedChests(world, this.pos, false); ConnectedChests chests = new ConnectedChests(world, this.pos, false);
chests.tryPutItemStack(stack); chests.tryPutItemStack(stack);
updateDisplays();
}
public void updateDisplays() {
for (StorageScreen screen : openStorageScreens) { for (StorageScreen screen : openStorageScreens) {
screen.updateDisplay(); screen.updateDisplay();
} }

@ -52,16 +52,15 @@ public class StorageScreen extends PagedGui {
@Override @Override
public void updateDisplay() { public void updateDisplay() {
this.chests = new ConnectedChests(world, pos, sortAlphabetically); this.chests = new ConnectedChests(world, pos, sortAlphabetically);
String title = "Storage: " + String title = chests.containerUsedSlots +
chests.containerUsedSlots + "u/" +
"/" +
chests.containerSlots + chests.containerSlots +
"(" + "t(" +
chests.containerFreeSlots + chests.containerFreeSlots +
" free)" + "f)" +
"[" + "[" +
chests.containerCount + chests.containerCount +
"]"; "c]";
setTitle(Text.of(title)); setTitle(Text.of(title));
super.updateDisplay(); super.updateDisplay();
@ -116,7 +115,7 @@ public class StorageScreen extends PagedGui {
if (canRemoveFromInventory(chests.inventory, noLoreStack) && insertCount > 0) { if (canRemoveFromInventory(chests.inventory, noLoreStack) && insertCount > 0) {
player.getInventory().insertStack(insertingStack.copy()); player.getInventory().insertStack(insertingStack.copy());
chests.removeItemStack(insertingStack); chests.removeItemStack(insertingStack);
updateDisplay(); blockEntity.updateDisplays();
} }
} }
} }
@ -128,7 +127,7 @@ public class StorageScreen extends PagedGui {
if (chests.tryPutItemStack(stack)) { if (chests.tryPutItemStack(stack)) {
removeFromInventory(player.getInventory(), stack, stack.getCount()); removeFromInventory(player.getInventory(), stack, stack.getCount());
} }
updateDisplay(); blockEntity.updateDisplays();
return super.insertItem(stack, startIndex, endIndex, fromLast); return super.insertItem(stack, startIndex, endIndex, fromLast);
} }