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
# Mod Properties
mod_version=2.0
mod_version=2.2
maven_group=systems.brn
archives_base_name=Server_storage

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

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