Fixed Window not being set for Items of nested GUIs

This commit is contained in:
NichtStudioCode 2021-05-03 19:48:52 +02:00
parent dd80927b46
commit 01cff674f0

@ -77,14 +77,19 @@ public abstract class BaseWindow implements Window {
} }
} }
// tell the Item or VirtualInventory that it is being displayed in this Window if (element != null) {
if (element instanceof ItemSlotElement) { // tell the Item or VirtualInventory that it is being displayed in this Window
((ItemSlotElement) element).getItem().addWindow(this); SlotElement holdingElement = element.getHoldingElement();
} else if (element instanceof VISlotElement) { if (holdingElement instanceof ItemSlotElement) {
((VISlotElement) element).getVirtualInventory().addWindow(this); ((ItemSlotElement) holdingElement).getItem().addWindow(this);
} else if (holdingElement instanceof VISlotElement) {
((VISlotElement) holdingElement).getVirtualInventory().addWindow(this);
}
elementsDisplayed[index] = holdingElement;
} else {
elementsDisplayed[index] = null;
} }
elementsDisplayed[index] = element;
} }
} }
@ -101,7 +106,7 @@ public abstract class BaseWindow implements Window {
// get the GUI at that index and ask for permission to drag an Item there // get the GUI at that index and ask for permission to drag an Item there
Pair<GUI, Integer> pair = getGuiAt(rawSlot); Pair<GUI, Integer> pair = getGuiAt(rawSlot);
if (pair != null && pair.getFirst().handleItemDrag(updateReason, pair.getSecond(), currentStack, newItems.get(rawSlot))) { if (pair != null && pair.getFirst().handleItemDrag(updateReason, pair.getSecond(), currentStack, newItems.get(rawSlot))) {
// the drag was cancelled // the drag was cancelled
int currentAmount = currentStack == null ? 0 : currentStack.getAmount(); int currentAmount = currentStack == null ? 0 : currentStack.getAmount();
int newAmount = newItems.get(rawSlot).getAmount(); int newAmount = newItems.get(rawSlot).getAmount();