Skip to content

Commit f381f6b

Browse files
authored
Fix gather problem (#135)
1 parent 966ed51 commit f381f6b

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/main/java/com/cleanroommc/modularui/core/mixins/early/minecraft/GuiContainerMixin.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22

33
import com.cleanroommc.modularui.api.IMuiScreen;
44
import com.cleanroommc.modularui.screen.IClickableGuiContainer;
5+
import com.cleanroommc.modularui.widgets.slot.ModularSlot;
6+
import com.cleanroommc.modularui.widgets.slot.SlotGroup;
57

68
import net.minecraft.client.gui.inventory.GuiContainer;
9+
import net.minecraft.inventory.IInventory;
710
import net.minecraft.inventory.Slot;
811

912
import org.spongepowered.asm.lib.Opcodes;
@@ -13,6 +16,7 @@
1316
import org.spongepowered.asm.mixin.injection.At;
1417
import org.spongepowered.asm.mixin.injection.Inject;
1518
import org.spongepowered.asm.mixin.injection.ModifyVariable;
19+
import org.spongepowered.asm.mixin.injection.Redirect;
1620
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1721

1822
@Mixin(GuiContainer.class)
@@ -59,4 +63,17 @@ public void getSlot(int x, int y, CallbackInfoReturnable<Slot> cir) {
5963
protected boolean mouseClickedOnSlot(boolean flag1) {
6064
return false;
6165
}
66+
67+
@Redirect(
68+
method = "mouseMovedOrUp",
69+
at = @At(value = "FIELD", opcode = Opcodes.GETFIELD, target = "Lnet/minecraft/inventory/Slot;inventory:Lnet/minecraft/inventory/IInventory;")
70+
)
71+
private IInventory checkSlotGroup(Slot slot) {
72+
if (slot instanceof ModularSlot ms) {
73+
SlotGroup slotGroup = ms.getSlotGroup();
74+
if (slotGroup == null) return null;
75+
return slotGroup.getDummyInventoryForComparison();
76+
}
77+
return slot.inventory;
78+
}
6279
}

src/main/java/com/cleanroommc/modularui/widgets/slot/SlotGroup.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.cleanroommc.modularui.widgets.slot;
22

3+
import net.minecraft.inventory.IInventory;
4+
import net.minecraft.inventory.InventoryBasic;
35
import net.minecraft.inventory.Slot;
46

57
import org.jetbrains.annotations.ApiStatus;
@@ -27,6 +29,7 @@ public class SlotGroup {
2729
private final boolean allowShiftTransfer;
2830
private boolean allowSorting = true;
2931
private final boolean singleton;
32+
private final IInventory dummyInventory = new InventoryBasic("[Null]", true, 0);
3033

3134
/**
3235
* Creates a slot group that is only a single slot. Singleton groups don't need to be registered.
@@ -117,4 +120,9 @@ public SlotGroup setAllowSorting(boolean allowSorting) {
117120
this.allowSorting = allowSorting;
118121
return this;
119122
}
123+
124+
@ApiStatus.Internal
125+
public IInventory getDummyInventoryForComparison() {
126+
return dummyInventory;
127+
}
120128
}

0 commit comments

Comments
 (0)