Skip to content

Commit 76868c0

Browse files
committed
chore: better track mutations to internal item stacks
for REI "quick craft" compat
1 parent 06944fb commit 76868c0

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

src/main/java/dev/galacticraft/machinelib/api/menu/ConfiguredMenu.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,16 @@ protected boolean moveItemStackTo(ItemStack stack, int startIndex, int endIndex,
333333
return super.moveItemStackTo(stack, startIndex, endIndex, reverse);
334334
}
335335

336+
@Override
337+
public void sendAllDataToRemote() {
338+
for (int i = 0; i < this.internalSlots; i++) {
339+
if (this.slots.get(i) instanceof StorageSlot storageSlot) {
340+
storageSlot.handleStackMutation();
341+
}
342+
}
343+
super.sendAllDataToRemote();
344+
}
345+
336346
/**
337347
* Cycles the I/O configuration of a machine face.
338348
*

src/main/java/dev/galacticraft/machinelib/impl/compat/vanilla/StorageSlot.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,18 @@ public boolean allowModification(Player player) {
8686
return this.watchedStack;
8787
}
8888

89+
@ApiStatus.Internal
90+
public void handleStackMutation() {
91+
if (this.watchedStack != null && this.watchModCount == this.slot.getModifications()
92+
&& (this.watchedStack.getCount() != this.slot.getAmount()
93+
|| !this.slot.getComponents().equals(this.watchedStack.getComponentsPatch())
94+
|| !Utils.itemsEqual(this.slot.getResource(), this.watchedStack.getItem()))) {
95+
this.set(this.watchedStack);
96+
this.watchModCount = this.slot.getModifications();
97+
this.setChanged();
98+
}
99+
}
100+
89101
@Override
90102
public boolean hasItem() {
91103
return !this.slot.isEmpty();
@@ -109,7 +121,6 @@ public void setChanged() {
109121
|| !this.slot.getComponents().equals(this.watchedStack.getComponentsPatch())
110122
|| !Utils.itemsEqual(this.slot.getResource(), this.watchedStack.getItem())
111123
) {
112-
if (true) throw new AssertionError();
113124
this.set(this.watchedStack);
114125
this.slot.markModified();
115126
}

0 commit comments

Comments
 (0)