Skip to content

Commit fe85c70

Browse files
authored
Fix various JEI ghost hovering/dragging issues (#146)
* Fix JEI dragging overlay not testing if the ingredient is valid during a drag. Fix FluidSlots not having any JEI dragging overlay * Make enchanted books work in phantom item slots * Use the correct methods * No need to check if cheats are enabled because a drag wouldn't be able to start in the first place if cheats are on
1 parent 75dfff3 commit fe85c70

File tree

4 files changed

+45
-9
lines changed

4 files changed

+45
-9
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@
22

33
import mezz.jei.gui.ghost.GhostIngredientDrag;
44
import mezz.jei.gui.ghost.GhostIngredientDragManager;
5+
import org.jetbrains.annotations.Nullable;
56
import org.spongepowered.asm.mixin.Mixin;
67
import org.spongepowered.asm.mixin.gen.Accessor;
78

89
@Mixin(value = GhostIngredientDragManager.class, remap = false)
910
public interface GhostIngredientDragManagerAccessor {
1011

1112
@Accessor
12-
GhostIngredientDrag<?> getGhostIngredientDrag();
13+
@Nullable GhostIngredientDrag<?> getGhostIngredientDrag();
1314

1415
@Accessor
15-
Object getHoveredIngredient();
16+
@Nullable Object getHoveredIngredient();
1617
}

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import mezz.jei.gui.ghost.GhostIngredientDrag;
1616
import mezz.jei.gui.ghost.GhostIngredientDragManager;
1717
import org.jetbrains.annotations.NotNull;
18+
import org.jetbrains.annotations.Nullable;
1819

1920
@JEIPlugin
2021
public class ModularUIJeiPlugin implements IModPlugin {
@@ -30,7 +31,7 @@ public void register(@NotNull IModRegistry registry) {
3031
}
3132

3233
@Override
33-
public void onRuntimeAvailable(IJeiRuntime jeiRuntime) {
34+
public void onRuntimeAvailable(@NotNull IJeiRuntime jeiRuntime) {
3435
ModularUIJeiPlugin.runtime = jeiRuntime;
3536
}
3637

@@ -49,10 +50,24 @@ public static boolean hoveringOverIngredient(JeiGhostIngredientSlot<?> ingredien
4950
return ingredientSlot.castGhostIngredientIfValid(hovered) != null;
5051
}
5152

53+
public static boolean draggingValidIngredient(JeiGhostIngredientSlot<?> ingredientSlot) {
54+
Object dragging = getDraggedObject();
55+
if (dragging == null) return false;
56+
return ingredientSlot.castGhostIngredientIfValid(dragging) != null;
57+
}
58+
59+
@Nullable
5260
public static GhostIngredientDrag<?> getGhostDrag() {
5361
return ((GhostIngredientDragManagerAccessor) getGhostDragManager()).getGhostIngredientDrag();
5462
}
5563

64+
@Nullable
65+
public static Object getDraggedObject() {
66+
GhostIngredientDrag<?> drag = getGhostDrag();
67+
return drag == null ? null : drag.getIngredient();
68+
}
69+
70+
@Nullable
5671
public static Object getHoverdObject() {
5772
return ((GhostIngredientDragManagerAccessor) getGhostDragManager()).getHoveredIngredient();
5873
}

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

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

3+
import com.cleanroommc.modularui.ModularUI;
34
import com.cleanroommc.modularui.api.ITheme;
45
import com.cleanroommc.modularui.api.drawable.IDrawable;
56
import com.cleanroommc.modularui.api.drawable.IKey;
@@ -8,6 +9,7 @@
89
import com.cleanroommc.modularui.drawable.text.TextRenderer;
910
import com.cleanroommc.modularui.integration.jei.JeiGhostIngredientSlot;
1011
import com.cleanroommc.modularui.integration.jei.JeiIngredientProvider;
12+
import com.cleanroommc.modularui.integration.jei.ModularUIJeiPlugin;
1113
import com.cleanroommc.modularui.screen.ModularScreen;
1214
import com.cleanroommc.modularui.screen.RichTooltip;
1315
import com.cleanroommc.modularui.screen.viewport.ModularGuiContext;
@@ -156,7 +158,15 @@ public void draw(ModularGuiContext context, WidgetTheme widgetTheme) {
156158
this.textRenderer.setPos((int) (this.contentOffsetX + 0.5f), (int) (getArea().height - 5.5f));
157159
this.textRenderer.draw(s);
158160
}
159-
if (isHovering()) {
161+
}
162+
163+
@Override
164+
public void drawOverlay(ModularGuiContext context, WidgetTheme widgetTheme) {
165+
if (ModularUI.Mods.JEI.isLoaded() && (ModularUIJeiPlugin.draggingValidIngredient(this) || ModularUIJeiPlugin.hoveringOverIngredient(this))) {
166+
GlStateManager.colorMask(true, true, true, false);
167+
drawHighlight(getArea(), isHovering());
168+
GlStateManager.colorMask(true, true, true, true);
169+
} else if (isHovering()) {
160170
GlStateManager.colorMask(true, true, true, false);
161171
GuiDraw.drawRect(1, 1, getArea().w() - 2, getArea().h() - 2, getSlotHoverColor());
162172
GlStateManager.colorMask(true, true, true, true);

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
import com.cleanroommc.modularui.value.sync.PhantomItemSlotSH;
99
import com.cleanroommc.modularui.value.sync.SyncHandler;
1010

11+
import mezz.jei.Internal;
12+
1113
import net.minecraft.client.renderer.GlStateManager;
1214

15+
import net.minecraft.enchantment.EnchantmentData;
1316
import net.minecraft.item.ItemStack;
1417

1518
import org.jetbrains.annotations.NotNull;
@@ -33,7 +36,7 @@ public boolean isValidSyncHandler(SyncHandler syncHandler) {
3336

3437
@Override
3538
protected void drawOverlay() {
36-
if (ModularUI.Mods.JEI.isLoaded() && (ModularUIJeiPlugin.hasDraggingGhostIngredient() || ModularUIJeiPlugin.hoveringOverIngredient(this))) {
39+
if (ModularUI.Mods.JEI.isLoaded() && (ModularUIJeiPlugin.draggingValidIngredient(this) || ModularUIJeiPlugin.hoveringOverIngredient(this))) {
3740
GlStateManager.colorMask(true, true, true, false);
3841
drawHighlight(getArea(), isHovering());
3942
GlStateManager.colorMask(true, true, true, true);
@@ -73,10 +76,17 @@ public void setGhostIngredient(@NotNull ItemStack ingredient) {
7376

7477
@Override
7578
public @Nullable ItemStack castGhostIngredientIfValid(@NotNull Object ingredient) {
76-
return areAncestorsEnabled() &&
77-
this.syncHandler.isPhantom() &&
78-
ingredient instanceof ItemStack itemStack &&
79-
this.syncHandler.isItemValid(itemStack) ? itemStack : null;
79+
if (areAncestorsEnabled() && this.syncHandler.isPhantom()) {
80+
if (ingredient instanceof EnchantmentData enchantmentData) {
81+
ingredient = Internal.getIngredientRegistry().getIngredientHelper(enchantmentData).getCheatItemStack(enchantmentData);
82+
}
83+
84+
if (ingredient instanceof ItemStack itemStack) {
85+
return this.syncHandler.isItemValid(itemStack) ? itemStack : null;
86+
}
87+
}
88+
89+
return null;
8090
}
8191

8292
@Override

0 commit comments

Comments
 (0)