Skip to content

Commit 696828a

Browse files
committed
implement the fixes for phantom slots from mui2 master
this was a pain
1 parent 51da18b commit 696828a

File tree

7 files changed

+292
-1
lines changed

7 files changed

+292
-1
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package gregtech.api.mui;
2+
3+
import com.cleanroommc.modularui.api.widget.Interactable;
4+
import com.cleanroommc.modularui.screen.viewport.LocatedWidget;
5+
6+
// todo remove on next mui2 update
7+
// this can't be a true accessor because of illegal classloading
8+
public interface InputAccessor {
9+
10+
boolean held();
11+
12+
void held(boolean held);
13+
14+
void timeHeld(long a);
15+
16+
LocatedWidget lastPressed();
17+
18+
void lastPressed(LocatedWidget last);
19+
20+
void lastButton(int b);
21+
22+
void addInteractable(Interactable i);
23+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package gregtech.mixins.jei;
2+
3+
import mezz.jei.gui.ghost.GhostIngredientDragManager;
4+
import mezz.jei.gui.overlay.IngredientListOverlay;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.gen.Accessor;
7+
8+
// todo remove on next mui2 update
9+
@Mixin(value = IngredientListOverlay.class, remap = false)
10+
public interface DragManagerAccessor {
11+
12+
@Accessor("ghostIngredientDragManager")
13+
GhostIngredientDragManager getManager();
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package gregtech.mixins.jei;
2+
3+
import mezz.jei.gui.ghost.GhostIngredientDrag;
4+
import mezz.jei.gui.ghost.GhostIngredientDragManager;
5+
import org.spongepowered.asm.mixin.Mixin;
6+
import org.spongepowered.asm.mixin.gen.Accessor;
7+
8+
// todo remove on next mui2 update
9+
@Mixin(value = GhostIngredientDragManager.class, remap = false)
10+
public interface GhostDragAccessor {
11+
12+
@Accessor("ghostIngredientDrag")
13+
GhostIngredientDrag<?> getDrag();
14+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package gregtech.mixins.mui2;
2+
3+
import gregtech.api.mui.InputAccessor;
4+
5+
import com.cleanroommc.modularui.api.widget.Interactable;
6+
import com.cleanroommc.modularui.screen.viewport.LocatedWidget;
7+
import org.jetbrains.annotations.Nullable;
8+
import org.spongepowered.asm.mixin.Mixin;
9+
import org.spongepowered.asm.mixin.Shadow;
10+
11+
// todo remove on next mui2 update
12+
@Mixin(targets = "com.cleanroommc.modularui.screen.ModularPanel$Input", remap = false)
13+
public abstract class InputMixin implements InputAccessor {
14+
15+
@Shadow
16+
private boolean held;
17+
18+
@Shadow
19+
private long timeHeld;
20+
21+
@Shadow
22+
private @Nullable LocatedWidget lastPressed;
23+
24+
@Shadow
25+
private int lastButton;
26+
27+
@Shadow
28+
protected abstract void addAcceptedInteractable(Interactable interactable);
29+
30+
@Override
31+
public boolean held() {
32+
return this.held;
33+
}
34+
35+
@Override
36+
public void held(boolean held) {
37+
this.held = held;
38+
}
39+
40+
@Override
41+
public void timeHeld(long a) {
42+
timeHeld = a;
43+
}
44+
45+
@Override
46+
public LocatedWidget lastPressed() {
47+
return this.lastPressed;
48+
}
49+
50+
@Override
51+
public void lastPressed(LocatedWidget last) {
52+
this.lastPressed = last;
53+
}
54+
55+
@Override
56+
public void lastButton(int b) {
57+
this.lastButton = b;
58+
}
59+
60+
@Override
61+
public void addInteractable(Interactable i) {
62+
addAcceptedInteractable(i);
63+
}
64+
}
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
package gregtech.mixins.mui2;
2+
3+
import gregtech.api.mui.InputAccessor;
4+
import gregtech.api.util.Mods;
5+
import gregtech.integration.jei.JustEnoughItemsModule;
6+
import gregtech.mixins.jei.DragManagerAccessor;
7+
import gregtech.mixins.jei.GhostDragAccessor;
8+
9+
import net.minecraft.client.Minecraft;
10+
11+
import com.cleanroommc.modularui.api.layout.IViewport;
12+
import com.cleanroommc.modularui.api.widget.IFocusedWidget;
13+
import com.cleanroommc.modularui.api.widget.Interactable;
14+
import com.cleanroommc.modularui.integration.jei.JeiGhostIngredientSlot;
15+
import com.cleanroommc.modularui.screen.ModularPanel;
16+
import com.cleanroommc.modularui.screen.viewport.LocatedWidget;
17+
import com.cleanroommc.modularui.utils.ObjectList;
18+
import com.cleanroommc.modularui.widget.ParentWidget;
19+
import mezz.jei.gui.ghost.GhostIngredientDrag;
20+
import mezz.jei.gui.ghost.GhostIngredientDragManager;
21+
import org.jetbrains.annotations.NotNull;
22+
import org.spongepowered.asm.mixin.Final;
23+
import org.spongepowered.asm.mixin.Mixin;
24+
import org.spongepowered.asm.mixin.Overwrite;
25+
import org.spongepowered.asm.mixin.Shadow;
26+
import org.spongepowered.asm.mixin.Unique;
27+
28+
@Mixin(value = ModularPanel.class, remap = false)
29+
public abstract class ModularPanelMixin extends ParentWidget<ModularPanel> implements IViewport {
30+
31+
@Shadow
32+
@Final
33+
private ObjectList<LocatedWidget> hovering;
34+
35+
@Shadow
36+
public abstract boolean closeOnOutOfBoundsClick();
37+
38+
@Shadow
39+
public abstract void animateClose();
40+
41+
@Shadow
42+
@Final
43+
private @NotNull String name;
44+
@Unique
45+
InputAccessor gregTech$mouse = null;
46+
47+
/**
48+
* @author Ghzdude - GTCEu
49+
* @reason Implement fixes to phantom slot handling from Mui2 master
50+
*/
51+
// this looks really cursed in mixin.out, but it works
52+
@Overwrite
53+
private boolean lambda$onMousePressed$3(int mouseButton) {
54+
LocatedWidget pressed = LocatedWidget.EMPTY;
55+
boolean result = false;
56+
57+
if (gregTech$mouse == null) {
58+
// reflection because the type is a private inner class
59+
try {
60+
gregTech$mouse = (InputAccessor) ModularPanel.class.getDeclaredField("mouse").get(this);
61+
} catch (IllegalAccessException | NoSuchFieldException e) {
62+
throw new RuntimeException(e);
63+
}
64+
}
65+
66+
if (this.hovering.isEmpty()) {
67+
if (closeOnOutOfBoundsClick()) {
68+
animateClose();
69+
result = true;
70+
}
71+
} else {
72+
loop:
73+
for (LocatedWidget widget : this.hovering) {
74+
widget.applyMatrix(getContext());
75+
if (widget.getElement() instanceof JeiGhostIngredientSlot<?>ghostSlot &&
76+
Mods.JustEnoughItems.isModLoaded()) {
77+
GhostIngredientDrag<?> drag = gregTech$getGhostDrag();
78+
if (drag != null && gregTech$insertGhostIngredient(drag, ghostSlot)) {
79+
gregTech$stopDrag();
80+
pressed = LocatedWidget.EMPTY;
81+
result = true;
82+
widget.unapplyMatrix(getContext());
83+
break;
84+
}
85+
}
86+
if (widget.getElement() instanceof Interactable interactable) {
87+
switch (interactable.onMousePressed(mouseButton)) {
88+
case IGNORE:
89+
break;
90+
case ACCEPT: {
91+
if (!gregTech$mouse.held()) {
92+
gregTech$mouse.addInteractable(interactable);
93+
}
94+
pressed = widget;
95+
// result = false;
96+
break;
97+
}
98+
case STOP: {
99+
pressed = LocatedWidget.EMPTY;
100+
result = true;
101+
widget.unapplyMatrix(getContext());
102+
break loop;
103+
}
104+
case SUCCESS: {
105+
if (!gregTech$mouse.held()) {
106+
gregTech$mouse.addInteractable(interactable);
107+
}
108+
pressed = widget;
109+
result = true;
110+
widget.unapplyMatrix(getContext());
111+
break loop;
112+
}
113+
}
114+
}
115+
if (getContext().onHoveredClick(mouseButton, widget)) {
116+
pressed = LocatedWidget.EMPTY;
117+
result = true;
118+
widget.unapplyMatrix(getContext());
119+
break;
120+
}
121+
widget.unapplyMatrix(getContext());
122+
if (widget.getElement().canHover()) {
123+
result = true;
124+
break;
125+
}
126+
}
127+
}
128+
129+
if (result && pressed.getElement() instanceof IFocusedWidget) {
130+
getContext().focus(pressed);
131+
} else {
132+
getContext().removeFocus();
133+
}
134+
if (!gregTech$mouse.held()) {
135+
gregTech$mouse.lastPressed(pressed);
136+
if (gregTech$mouse.lastPressed().getElement() != null) {
137+
gregTech$mouse.timeHeld(Minecraft.getSystemTime());
138+
}
139+
gregTech$mouse.lastButton(mouseButton);
140+
gregTech$mouse.held(true);
141+
}
142+
return result;
143+
}
144+
145+
@Unique
146+
private static GhostIngredientDrag<?> gregTech$getGhostDrag() {
147+
GhostIngredientDragManager manager = ((DragManagerAccessor) JustEnoughItemsModule.jeiRuntime
148+
.getIngredientListOverlay()).getManager();
149+
return ((GhostDragAccessor) manager).getDrag();
150+
}
151+
152+
@Unique
153+
@SuppressWarnings("rawtypes")
154+
private static boolean gregTech$insertGhostIngredient(GhostIngredientDrag drag,
155+
JeiGhostIngredientSlot slot) {
156+
Object object = slot.castGhostIngredientIfValid(drag.getIngredient());
157+
if (object != null) {
158+
// noinspection unchecked
159+
slot.setGhostIngredient(object);
160+
return true;
161+
}
162+
return false;
163+
}
164+
165+
@Unique
166+
private static void gregTech$stopDrag() {
167+
GhostIngredientDragManager manager = ((DragManagerAccessor) JustEnoughItemsModule.jeiRuntime
168+
.getIngredientListOverlay()).getManager();
169+
manager.stopDrag();
170+
}
171+
}

src/main/resources/mixins.gregtech.jei.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"compatibilityLevel": "JAVA_8",
77
"mixins": [
88
"BasicRecipeTransferHandlerServerMixin",
9+
"DragManagerAccessor",
10+
"GhostDragAccessor",
911
"IngredientGridMixin",
1012
"JEITooltipMixin",
1113
"StackHelperMixin"

src/main/resources/mixins.gregtech.mui2.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
"injectors": {
88
"maxShiftBy": 10
99
},
10-
"mixins": [],
10+
"mixins": [
11+
"InputMixin",
12+
"ModularPanelMixin"
13+
],
1114
"client": [
1215
"LangKeyMixin"
1316
],

0 commit comments

Comments
 (0)