Skip to content

Commit b1e8013

Browse files
committed
fix some more phantom slot issues
1 parent 9eafc58 commit b1e8013

File tree

12 files changed

+159
-4
lines changed

12 files changed

+159
-4
lines changed

src/main/java/com/cleanroommc/modularui/ModularUI.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class ModularUI {
3636

3737
private static boolean blurLoaded = false;
3838
private static boolean sorterLoaded = false;
39+
private static boolean jeiLoaded = false;
3940

4041
static {
4142
// confirm mXparser license
@@ -46,6 +47,7 @@ public class ModularUI {
4647
public void preInit(FMLPreInitializationEvent event) {
4748
blurLoaded = Loader.isModLoaded("blur");
4849
sorterLoaded = Loader.isModLoaded(BOGO_SORT);
50+
jeiLoaded = Loader.isModLoaded("jei");
4951
proxy.preInit(event);
5052
}
5153

@@ -66,4 +68,8 @@ public static boolean isBlurLoaded() {
6668
public static boolean isSortModLoaded() {
6769
return sorterLoaded;
6870
}
71+
72+
public static boolean isJeiLoaded() {
73+
return jeiLoaded;
74+
}
6975
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.cleanroommc.modularui.core;
2+
3+
import com.google.common.collect.ImmutableList;
4+
5+
import net.minecraftforge.fml.common.Loader;
6+
7+
import zone.rong.mixinbooter.ILateMixinLoader;
8+
9+
import java.util.List;
10+
import java.util.stream.Collectors;
11+
12+
public class LateMixins implements ILateMixinLoader {
13+
14+
public static final List<String> modMixins = ImmutableList.of("jei");
15+
16+
@Override
17+
public List<String> getMixinConfigs() {
18+
return modMixins.stream().map(mod -> "mixin.modularui." + mod + ".json").collect(Collectors.toList());
19+
}
20+
21+
@Override
22+
public boolean shouldMixinConfigQueue(String mixinConfig) {
23+
String[] parts = mixinConfig.split("\\.");
24+
return parts.length != 4 || shouldEnableModMixin(parts[2]);
25+
}
26+
27+
public boolean shouldEnableModMixin(String mod) {
28+
return Loader.isModLoaded(mod);
29+
}
30+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.cleanroommc.modularui.core.mixin.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+
@Mixin(value = GhostIngredientDragManager.class, remap = false)
9+
public interface GhostIngredientDragManagerAccessor {
10+
11+
@Accessor
12+
GhostIngredientDrag<?> getGhostIngredientDrag();
13+
}

src/main/java/com/cleanroommc/modularui/core/mixin/jei/IngredientGridMixin.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public abstract class IngredientGridMixin {
2424
at = @At(value = "INVOKE",
2525
target = "Lmezz/jei/gui/overlay/IngredientGrid;drawTooltips(Lnet/minecraft/client/Minecraft;II)V"))
2626
private void considerExclusions(IngredientGrid instance, Minecraft minecraft, int mouseX, int mouseY, Operation<Void> original) {
27-
if (!guiScreenHelper.isInGuiExclusionArea(mouseX, mouseY))
27+
if (!guiScreenHelper.isInGuiExclusionArea(mouseX, mouseY)) {
2828
original.call(instance, minecraft, mouseX, mouseY);
29+
}
2930
}
3031
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.cleanroommc.modularui.core.mixin.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+
@Mixin(value = IngredientListOverlay.class, remap = false)
9+
public interface IngredientListOverlayAccessor {
10+
11+
@Accessor
12+
GhostIngredientDragManager getGhostIngredientDragManager();
13+
}

src/main/java/com/cleanroommc/modularui/integration/jei/JeiGhostIngredientSlot.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
package com.cleanroommc.modularui.integration.jei;
22

33
import com.cleanroommc.modularui.api.widget.IWidget;
4+
import com.cleanroommc.modularui.drawable.GuiDraw;
5+
import com.cleanroommc.modularui.utils.Color;
46
import com.cleanroommc.modularui.widget.Widget;
57

8+
import mezz.jei.gui.ghost.GhostIngredientDrag;
9+
610
import org.jetbrains.annotations.NotNull;
711
import org.jetbrains.annotations.Nullable;
812

13+
import java.awt.*;
14+
915
/**
1016
* An interface for compat with JEI's ghost slots.
1117
* Implement this on any {@link IWidget}.
@@ -34,4 +40,18 @@ public interface JeiGhostIngredientSlot<I> {
3440
*/
3541
@Nullable
3642
I castGhostIngredientIfValid(@NotNull Object ingredient);
43+
44+
default void drawHighlight(Rectangle area, boolean hovering) {
45+
int color = hovering ? Color.argb(76, 201, 25, 128) : Color.argb(19, 201, 10, 64);
46+
GuiDraw.drawRect(0, 0, area.width, area.height, color);
47+
}
48+
49+
static <T> boolean insertGhostIngredient(GhostIngredientDrag<?> drag, JeiGhostIngredientSlot<T> slot) {
50+
T t = slot.castGhostIngredientIfValid(drag.getIngredient());
51+
if (t != null) {
52+
slot.setGhostIngredient(t);
53+
return true;
54+
}
55+
return false;
56+
}
3757
}

src/main/java/com/cleanroommc/modularui/integration/jei/ModularUIHandler.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ public Object getIngredientUnderMouse(@NotNull T guiContainer, int mouseX, int m
6464
@Override
6565
public void onComplete() {}
6666

67+
@Override
68+
public boolean shouldHighlightTargets() {
69+
return false;
70+
}
71+
6772
@Nullable
6873
@Override
6974
public IGuiProperties apply(@NotNull T guiScreen) {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,46 @@
11
package com.cleanroommc.modularui.integration.jei;
22

3+
import com.cleanroommc.modularui.core.mixin.jei.GhostIngredientDragManagerAccessor;
4+
import com.cleanroommc.modularui.core.mixin.jei.IngredientListOverlayAccessor;
35
import com.cleanroommc.modularui.screen.GuiContainerWrapper;
46

7+
import mezz.jei.api.IJeiRuntime;
58
import mezz.jei.api.IModPlugin;
69
import mezz.jei.api.IModRegistry;
710
import mezz.jei.api.JEIPlugin;
811

12+
import mezz.jei.gui.ghost.GhostIngredientDrag;
13+
import mezz.jei.gui.ghost.GhostIngredientDragManager;
914
import org.jetbrains.annotations.NotNull;
1015

1116
@JEIPlugin
1217
public class ModularUIJeiPlugin implements IModPlugin {
1318

19+
private static IJeiRuntime runtime;
20+
1421
@Override
1522
public void register(@NotNull IModRegistry registry) {
1623
new ModularUIHandler<>(GuiContainerWrapper.class).register(registry);
1724
}
25+
26+
@Override
27+
public void onRuntimeAvailable(IJeiRuntime jeiRuntime) {
28+
ModularUIJeiPlugin.runtime = jeiRuntime;
29+
}
30+
31+
public static IJeiRuntime getRuntime() {
32+
return runtime;
33+
}
34+
35+
public static GhostIngredientDragManager getGhostDragManager() {
36+
return ((IngredientListOverlayAccessor) runtime.getIngredientListOverlay()).getGhostIngredientDragManager();
37+
}
38+
39+
public static GhostIngredientDrag<?> getGhostDrag() {
40+
return ((GhostIngredientDragManagerAccessor) getGhostDragManager()).getGhostIngredientDrag();
41+
}
42+
43+
public static boolean hasDraggingGhostIngredient() {
44+
return getGhostDrag() != null;
45+
}
1846
}

src/main/java/com/cleanroommc/modularui/screen/ModularPanel.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.cleanroommc.modularui.screen;
22

3+
import com.cleanroommc.modularui.ModularUI;
34
import com.cleanroommc.modularui.api.IPanelHandler;
45
import com.cleanroommc.modularui.api.ITheme;
56
import com.cleanroommc.modularui.api.drawable.IDrawable;
@@ -8,6 +9,8 @@
89
import com.cleanroommc.modularui.api.widget.IFocusedWidget;
910
import com.cleanroommc.modularui.api.widget.IWidget;
1011
import com.cleanroommc.modularui.api.widget.Interactable;
12+
import com.cleanroommc.modularui.integration.jei.JeiGhostIngredientSlot;
13+
import com.cleanroommc.modularui.integration.jei.ModularUIJeiPlugin;
1114
import com.cleanroommc.modularui.screen.viewport.ModularGuiContext;
1215
import com.cleanroommc.modularui.screen.viewport.GuiViewportStack;
1316
import com.cleanroommc.modularui.screen.viewport.LocatedWidget;
@@ -20,6 +23,8 @@
2023
import com.cleanroommc.modularui.widget.sizer.Area;
2124
import com.cleanroommc.modularui.widgets.SlotGroupWidget;
2225

26+
import mezz.jei.gui.ghost.GhostIngredientDrag;
27+
2328
import net.minecraft.client.Minecraft;
2429

2530
import org.jetbrains.annotations.ApiStatus;
@@ -299,6 +304,17 @@ public boolean onMousePressed(int mouseButton) {
299304
loop:
300305
for (LocatedWidget widget : this.hovering) {
301306
widget.applyMatrix(getContext());
307+
// try inserting ghost ingredient
308+
if (widget.getElement() instanceof JeiGhostIngredientSlot<?> ghostSlot && ModularUI.isJeiLoaded()) {
309+
GhostIngredientDrag<?> drag = ModularUIJeiPlugin.getGhostDrag();
310+
if (drag != null && JeiGhostIngredientSlot.insertGhostIngredient(drag, ghostSlot)) {
311+
ModularUIJeiPlugin.getGhostDragManager().stopDrag();
312+
pressed = LocatedWidget.EMPTY;
313+
result = true;
314+
widget.unapplyMatrix(getContext());
315+
break;
316+
}
317+
}
302318
// click widget and see how it reacts
303319
if (widget.getElement() instanceof Interactable interactable) {
304320
switch (interactable.onMousePressed(mouseButton)) {

src/main/java/com/cleanroommc/modularui/widgets/FluidSlot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ public void setGhostIngredient(@NotNull FluidStack ingredient) {
268268

269269
@Override
270270
public @Nullable FluidStack castGhostIngredientIfValid(@NotNull Object ingredient) {
271-
return this.syncHandler.isPhantom() && ingredient instanceof FluidStack fluidStack ? fluidStack : null;
271+
return areAncestorsEnabled() && this.syncHandler.isPhantom() && ingredient instanceof FluidStack fluidStack ? fluidStack : null;
272272
}
273273

274274
@Override

0 commit comments

Comments
 (0)