Skip to content

Commit 7d5fd46

Browse files
Fix Composite- & Obscured inventory window notification
1 parent 2e0b07f commit 7d5fd46

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

invui/src/main/java/xyz/xenondevs/invui/inventory/CompositeInventory.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import xyz.xenondevs.invui.inventory.event.ItemPostUpdateEvent;
88
import xyz.xenondevs.invui.inventory.event.ItemPreUpdateEvent;
99
import xyz.xenondevs.invui.inventory.event.UpdateReason;
10+
import xyz.xenondevs.invui.window.AbstractWindow;
1011

1112
import java.util.Collection;
1213
import java.util.function.Consumer;
@@ -142,18 +143,29 @@ private Pair<Inventory, Integer> findInventory(int slot) {
142143

143144
@Override
144145
public void notifyWindows() {
145-
super.notifyWindows();
146146
for (Inventory inventory : inventories) {
147147
inventory.notifyWindows();
148148
}
149149
}
150150

151151
@Override
152152
public void notifyWindows(int slot) {
153-
Pair<Inventory, Integer> invSlot = findInventory(slot);
153+
var invSlot = findInventory(slot);
154154
invSlot.first().notifyWindows(invSlot.second());
155155
}
156156

157+
@Override
158+
public void addViewer(AbstractWindow viewer, int what, int how) {
159+
var invSlot = findInventory(what);
160+
invSlot.first().addViewer(viewer, invSlot.second(), how);
161+
}
162+
163+
@Override
164+
public void removeViewer(AbstractWindow viewer, int what, int how) {
165+
var invSlot = findInventory(what);
166+
invSlot.first().removeViewer(viewer, invSlot.second(), how);
167+
}
168+
157169
@Override
158170
public ItemPreUpdateEvent callPreUpdateEvent(@Nullable UpdateReason updateReason, int slot, @Nullable ItemStack previousItemStack, @Nullable ItemStack newItemStack) {
159171
var invSlot = findInventory(slot);

invui/src/main/java/xyz/xenondevs/invui/inventory/ObscuredInventory.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import xyz.xenondevs.invui.inventory.event.ItemPostUpdateEvent;
66
import xyz.xenondevs.invui.inventory.event.ItemPreUpdateEvent;
77
import xyz.xenondevs.invui.inventory.event.UpdateReason;
8+
import xyz.xenondevs.invui.window.AbstractWindow;
89

910
import java.util.ArrayList;
1011
import java.util.function.Consumer;
@@ -64,7 +65,7 @@ public int getMaxSlotStackSize(int slot) {
6465

6566
@Override
6667
public @Nullable ItemStack[] getItems() {
67-
ItemStack[] items = new ItemStack[slots.length];
68+
@Nullable ItemStack[] items = new ItemStack[slots.length];
6869
for (int i = 0; i < slots.length; i++) {
6970
items[i] = inventory.getItem(slots[i]);
7071
}
@@ -73,7 +74,7 @@ public int getMaxSlotStackSize(int slot) {
7374

7475
@Override
7576
public @Nullable ItemStack[] getUnsafeItems() {
76-
ItemStack[] items = new ItemStack[slots.length];
77+
@Nullable ItemStack[] items = new ItemStack[slots.length];
7778
for (int i = 0; i < slots.length; i++) {
7879
items[i] = inventory.getUnsafeItem(slots[i]);
7980
}
@@ -102,10 +103,24 @@ protected void setDirectBackingItem(int slot, @Nullable ItemStack itemStack) {
102103

103104
@Override
104105
public void notifyWindows() {
105-
super.notifyWindows();
106106
inventory.notifyWindows();
107107
}
108108

109+
@Override
110+
public void notifyWindows(int slot) {
111+
inventory.notifyWindows(slot);
112+
}
113+
114+
@Override
115+
public void addViewer(AbstractWindow viewer, int what, int how) {
116+
inventory.addViewer(viewer, what, how);
117+
}
118+
119+
@Override
120+
public void removeViewer(AbstractWindow viewer, int what, int how) {
121+
inventory.removeViewer(viewer, what, how);
122+
}
123+
109124
@Override
110125
public ItemPreUpdateEvent callPreUpdateEvent(@Nullable UpdateReason updateReason, int slot, @Nullable ItemStack previousItemStack, @Nullable ItemStack newItemStack) {
111126
return inventory.callPreUpdateEvent(updateReason, slots[slot], previousItemStack, newItemStack);

0 commit comments

Comments
 (0)