From d8daf53f120047bf69f45a41cdf07418ea3e5d73 Mon Sep 17 00:00:00 2001 From: Zorbatron <46525467+Zorbatron@users.noreply.github.com> Date: Wed, 21 May 2025 18:06:16 -0400 Subject: [PATCH 01/11] Fix JEI green overlay appearing when in cheat mode Fix slot hover overlay in crafting station --- .../gregtech/client/utils/RenderUtil.java | 33 ++++++++++++++++--- .../common/mui/widget/GTFluidSlot.java | 9 ++--- .../widget/workbench/CraftingInputSlot.java | 7 +++- .../widget/workbench/CraftingOutputSlot.java | 5 +++ .../widget/workbench/RecipeMemorySlot.java | 5 +++ .../mixins/mui2/ModularUIJeiPluginMixin.java | 23 +++++++++++++ src/main/resources/mixins.gregtech.mui2.json | 3 +- 7 files changed, 71 insertions(+), 14 deletions(-) create mode 100644 src/main/java/gregtech/mixins/mui2/ModularUIJeiPluginMixin.java diff --git a/src/main/java/gregtech/client/utils/RenderUtil.java b/src/main/java/gregtech/client/utils/RenderUtil.java index e62f32d9c07..f6a0f5e1e95 100644 --- a/src/main/java/gregtech/client/utils/RenderUtil.java +++ b/src/main/java/gregtech/client/utils/RenderUtil.java @@ -29,8 +29,10 @@ import codechicken.lib.vec.Matrix4; import com.cleanroommc.modularui.api.MCHelper; import com.cleanroommc.modularui.api.widget.IWidget; +import com.cleanroommc.modularui.drawable.GuiDraw; import com.cleanroommc.modularui.integration.jei.JeiGhostIngredientSlot; import com.cleanroommc.modularui.integration.jei.ModularUIJeiPlugin; +import com.cleanroommc.modularui.theme.WidgetSlotTheme; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.lwjgl.opengl.GL11; @@ -716,14 +718,35 @@ public void put(int element, float @NotNull... data) { return getTextureMap().getMissingSprite(); } - public static void handleJeiGhostHighlight(IWidget slot) { - if (!Mods.JustEnoughItems.isModLoaded()) return; - if (!(slot instanceof JeiGhostIngredientSlotingredientSlot)) return; - if (ModularUIJeiPlugin.hasDraggingGhostIngredient() || - ModularUIJeiPlugin.hoveringOverIngredient(ingredientSlot)) { + /** + * Draws the green overlay when a valid ingredient for the slot is hovered over in JEI + * + * @param slot the slot to draw the overlay on + * @return true if the overlay was drawn, false if not + */ + @SuppressWarnings("BooleanMethodIsAlwaysInverted") + public static boolean handleJeiGhostHighlight(@NotNull IWidget slot) { + if (!Mods.JustEnoughItems.isModLoaded()) return false; + if (!(slot instanceof JeiGhostIngredientSlotingredientSlot)) return false; + + if (ModularUIJeiPlugin.hoveringOverIngredient(ingredientSlot)) { GlStateManager.colorMask(true, true, true, false); ingredientSlot.drawHighlight(slot.getArea(), slot.isHovering()); GlStateManager.colorMask(true, true, true, true); + return true; } + + return false; + } + + /** + * Draws the gray-ish overlay over a slot when moused over + * + * @param slot the slot on which to draw the overlay + */ + public static void handleSlotOverlay(@NotNull IWidget slot, @NotNull WidgetSlotTheme slotTheme) { + GlStateManager.colorMask(true, true, true, false); + GuiDraw.drawRect(1, 1, slot.getArea().w() - 2, slot.getArea().h() - 2, slotTheme.getSlotHoverColor()); + GlStateManager.colorMask(true, true, true, true); } } diff --git a/src/main/java/gregtech/common/mui/widget/GTFluidSlot.java b/src/main/java/gregtech/common/mui/widget/GTFluidSlot.java index bc9ba458098..19efc9fb615 100644 --- a/src/main/java/gregtech/common/mui/widget/GTFluidSlot.java +++ b/src/main/java/gregtech/common/mui/widget/GTFluidSlot.java @@ -8,7 +8,6 @@ import gregtech.client.utils.RenderUtil; import gregtech.client.utils.TooltipHelper; -import net.minecraft.client.renderer.GlStateManager; import net.minecraft.item.ItemStack; import net.minecraft.util.text.TextFormatting; import net.minecraftforge.fluids.FluidStack; @@ -133,13 +132,9 @@ public void draw(ModularGuiContext context, WidgetSlotTheme widgetTheme) { this.textRenderer.draw(amount); } - if (isHovering()) { - GlStateManager.colorMask(true, true, true, false); - GuiDraw.drawRect(1, 1, getArea().w() - 2, getArea().h() - 2, widgetTheme.getSlotHoverColor()); - GlStateManager.colorMask(true, true, true, true); + if (!RenderUtil.handleJeiGhostHighlight(this) && isHovering()) { + RenderUtil.handleSlotOverlay(this, widgetTheme); } - - RenderUtil.handleJeiGhostHighlight(this); } @Override diff --git a/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java b/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java index 0e883aa9bd6..1d4fec89065 100644 --- a/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java +++ b/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java @@ -16,6 +16,7 @@ import com.cleanroommc.modularui.network.NetworkUtils; import com.cleanroommc.modularui.screen.RichTooltip; import com.cleanroommc.modularui.screen.viewport.ModularGuiContext; +import com.cleanroommc.modularui.theme.WidgetSlotTheme; import com.cleanroommc.modularui.theme.WidgetTheme; import com.cleanroommc.modularui.value.sync.PanelSyncManager; import com.cleanroommc.modularui.value.sync.SyncHandler; @@ -110,7 +111,11 @@ public void draw(ModularGuiContext context, WidgetTheme widgetTheme) { RenderUtil.renderItem(itemstack, 1, 1, 16, 16); } - RenderUtil.handleJeiGhostHighlight(this); + if (!RenderUtil.handleJeiGhostHighlight(this) && isHovering()) { + if (widgetTheme instanceof WidgetSlotTheme slotTheme) { + RenderUtil.handleSlotOverlay(this, slotTheme); + } + } } @Override diff --git a/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java b/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java index db766fe50bf..fd6f01d9360 100644 --- a/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java +++ b/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java @@ -21,6 +21,7 @@ import com.cleanroommc.modularui.network.NetworkUtils; import com.cleanroommc.modularui.screen.RichTooltip; import com.cleanroommc.modularui.screen.viewport.ModularGuiContext; +import com.cleanroommc.modularui.theme.WidgetSlotTheme; import com.cleanroommc.modularui.theme.WidgetTheme; import com.cleanroommc.modularui.utils.MouseData; import com.cleanroommc.modularui.value.sync.IntSyncValue; @@ -75,6 +76,10 @@ public void draw(ModularGuiContext context, WidgetTheme widgetTheme) { if (itemstack.isEmpty()) return; RenderUtil.renderItem(itemstack, 1, 1, 16, 16); + + if (isHovering() && widgetTheme instanceof WidgetSlotTheme slotTheme) { + RenderUtil.handleSlotOverlay(this, slotTheme); + } } @Override diff --git a/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java b/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java index 2d24eea1d83..d74a3b23db3 100644 --- a/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java +++ b/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java @@ -13,6 +13,7 @@ import com.cleanroommc.modularui.integration.jei.JeiIngredientProvider; import com.cleanroommc.modularui.screen.RichTooltip; import com.cleanroommc.modularui.screen.viewport.ModularGuiContext; +import com.cleanroommc.modularui.theme.WidgetSlotTheme; import com.cleanroommc.modularui.theme.WidgetTheme; import com.cleanroommc.modularui.utils.MouseData; import com.cleanroommc.modularui.widget.Widget; @@ -59,6 +60,10 @@ public void draw(ModularGuiContext context, WidgetTheme widgetTheme) { GTGuiTextures.RECIPE_LOCK.draw(context, 10, 1, 8, 8, widgetTheme); GlStateManager.enableDepth(); } + + if (isHovering() && widgetTheme instanceof WidgetSlotTheme slotTheme) { + RenderUtil.handleSlotOverlay(this, slotTheme); + } } @Override diff --git a/src/main/java/gregtech/mixins/mui2/ModularUIJeiPluginMixin.java b/src/main/java/gregtech/mixins/mui2/ModularUIJeiPluginMixin.java new file mode 100644 index 00000000000..d6c8c4e1717 --- /dev/null +++ b/src/main/java/gregtech/mixins/mui2/ModularUIJeiPluginMixin.java @@ -0,0 +1,23 @@ +package gregtech.mixins.mui2; + +import com.cleanroommc.modularui.integration.jei.JeiGhostIngredientSlot; +import com.cleanroommc.modularui.integration.jei.ModularUIJeiPlugin; +import mezz.jei.config.Config; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(value = ModularUIJeiPlugin.class) +public class ModularUIJeiPluginMixin { + + // TODO: remove this mixin when the fix from Brachy makes it into a release we use + @Inject(method = "hoveringOverIngredient", at = @At(value = "HEAD"), remap = false, cancellable = true) + private static void cancelIfCheatsOn(JeiGhostIngredientSlot ingredientSlot, + CallbackInfoReturnable cir) { + if (Config.isCheatItemsEnabled()) { + cir.setReturnValue(false); + cir.cancel(); + } + } +} diff --git a/src/main/resources/mixins.gregtech.mui2.json b/src/main/resources/mixins.gregtech.mui2.json index f313fa2b32d..ee6b07445fd 100644 --- a/src/main/resources/mixins.gregtech.mui2.json +++ b/src/main/resources/mixins.gregtech.mui2.json @@ -11,7 +11,8 @@ "ModularPanelMixin" ], "client": [ - "LangKeyMixin" + "LangKeyMixin", + "ModularUIJeiPluginMixin" ], "server": [] } From c130b967f04ecfb5f3861c2c73bd538990d3d8c5 Mon Sep 17 00:00:00 2001 From: Zorbatron <46525467+Zorbatron@users.noreply.github.com> Date: Wed, 21 May 2025 18:08:08 -0400 Subject: [PATCH 02/11] Remove redundant cancel from mixin --- src/main/java/gregtech/mixins/mui2/ModularUIJeiPluginMixin.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/gregtech/mixins/mui2/ModularUIJeiPluginMixin.java b/src/main/java/gregtech/mixins/mui2/ModularUIJeiPluginMixin.java index d6c8c4e1717..2f0853cb4f1 100644 --- a/src/main/java/gregtech/mixins/mui2/ModularUIJeiPluginMixin.java +++ b/src/main/java/gregtech/mixins/mui2/ModularUIJeiPluginMixin.java @@ -17,7 +17,6 @@ private static void cancelIfCheatsOn(JeiGhostIngredientSlot ingredientSlot, CallbackInfoReturnable cir) { if (Config.isCheatItemsEnabled()) { cir.setReturnValue(false); - cir.cancel(); } } } From a8b879587c223588e3ef1f110c401459d39066f5 Mon Sep 17 00:00:00 2001 From: Zorbatron <46525467+Zorbatron@users.noreply.github.com> Date: Wed, 21 May 2025 20:15:17 -0400 Subject: [PATCH 03/11] Add combined method for both overlays --- .../gregtech/client/utils/RenderUtil.java | 25 +++++++++++++++---- .../common/mui/widget/GTFluidSlot.java | 4 +-- .../widget/workbench/CraftingInputSlot.java | 6 ++--- .../widget/workbench/CraftingOutputSlot.java | 2 +- .../widget/workbench/RecipeMemorySlot.java | 2 +- 5 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/main/java/gregtech/client/utils/RenderUtil.java b/src/main/java/gregtech/client/utils/RenderUtil.java index f6a0f5e1e95..85aa95b86ab 100644 --- a/src/main/java/gregtech/client/utils/RenderUtil.java +++ b/src/main/java/gregtech/client/utils/RenderUtil.java @@ -725,11 +725,13 @@ public void put(int element, float @NotNull... data) { * @return true if the overlay was drawn, false if not */ @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public static boolean handleJeiGhostHighlight(@NotNull IWidget slot) { + public static boolean handleJeiGhostOverlay(@NotNull IWidget slot) { if (!Mods.JustEnoughItems.isModLoaded()) return false; if (!(slot instanceof JeiGhostIngredientSlotingredientSlot)) return false; - if (ModularUIJeiPlugin.hoveringOverIngredient(ingredientSlot)) { + // TODO: replace the first condition with draggingValidIngredient once MUI PR 146 makes it into a release we use + if (ingredientSlot.castGhostIngredientIfValid(ModularUIJeiPlugin.getGhostDrag()) != null || + ModularUIJeiPlugin.hoveringOverIngredient(ingredientSlot)) { GlStateManager.colorMask(true, true, true, false); ingredientSlot.drawHighlight(slot.getArea(), slot.isHovering()); GlStateManager.colorMask(true, true, true, true); @@ -740,13 +742,26 @@ public static boolean handleJeiGhostHighlight(@NotNull IWidget slot) { } /** - * Draws the gray-ish overlay over a slot when moused over + * Draws a gray-ish overlay over the slot 1px inwards from each side. Intended for item slots. * - * @param slot the slot on which to draw the overlay + * @param slot the slot to draw the overlay above */ - public static void handleSlotOverlay(@NotNull IWidget slot, @NotNull WidgetSlotTheme slotTheme) { + public static void drawSlotOverlay(@NotNull IWidget slot, @NotNull WidgetSlotTheme slotTheme) { GlStateManager.colorMask(true, true, true, false); GuiDraw.drawRect(1, 1, slot.getArea().w() - 2, slot.getArea().h() - 2, slotTheme.getSlotHoverColor()); GlStateManager.colorMask(true, true, true, true); } + + /** + * Handles drawing the green JEI overlay when dragging an item, and if no item is being dragged, the overlay when + * mousing over the slot. + * + * @param slot the slot to draw the overlay above + * @param slotTheme the theme to get the slot overlay color from + */ + public static void handleSlotOverlays(@NotNull IWidget slot, @NotNull WidgetSlotTheme slotTheme) { + if (!handleJeiGhostOverlay(slot) && slot.isHovering()) { + drawSlotOverlay(slot, slotTheme); + } + } } diff --git a/src/main/java/gregtech/common/mui/widget/GTFluidSlot.java b/src/main/java/gregtech/common/mui/widget/GTFluidSlot.java index 19efc9fb615..2f34ab8dce2 100644 --- a/src/main/java/gregtech/common/mui/widget/GTFluidSlot.java +++ b/src/main/java/gregtech/common/mui/widget/GTFluidSlot.java @@ -132,9 +132,7 @@ public void draw(ModularGuiContext context, WidgetSlotTheme widgetTheme) { this.textRenderer.draw(amount); } - if (!RenderUtil.handleJeiGhostHighlight(this) && isHovering()) { - RenderUtil.handleSlotOverlay(this, widgetTheme); - } + RenderUtil.handleSlotOverlays(this, widgetTheme); } @Override diff --git a/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java b/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java index 1d4fec89065..571c8a10b6c 100644 --- a/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java +++ b/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java @@ -111,10 +111,8 @@ public void draw(ModularGuiContext context, WidgetTheme widgetTheme) { RenderUtil.renderItem(itemstack, 1, 1, 16, 16); } - if (!RenderUtil.handleJeiGhostHighlight(this) && isHovering()) { - if (widgetTheme instanceof WidgetSlotTheme slotTheme) { - RenderUtil.handleSlotOverlay(this, slotTheme); - } + if (widgetTheme instanceof WidgetSlotTheme slotTheme) { + RenderUtil.handleSlotOverlays(this, slotTheme); } } diff --git a/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java b/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java index fd6f01d9360..07668d3473b 100644 --- a/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java +++ b/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java @@ -78,7 +78,7 @@ public void draw(ModularGuiContext context, WidgetTheme widgetTheme) { RenderUtil.renderItem(itemstack, 1, 1, 16, 16); if (isHovering() && widgetTheme instanceof WidgetSlotTheme slotTheme) { - RenderUtil.handleSlotOverlay(this, slotTheme); + RenderUtil.drawSlotOverlay(this, slotTheme); } } diff --git a/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java b/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java index d74a3b23db3..022fe3473d1 100644 --- a/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java +++ b/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java @@ -62,7 +62,7 @@ public void draw(ModularGuiContext context, WidgetTheme widgetTheme) { } if (isHovering() && widgetTheme instanceof WidgetSlotTheme slotTheme) { - RenderUtil.handleSlotOverlay(this, slotTheme); + RenderUtil.drawSlotOverlay(this, slotTheme); } } From fe80e10eb6cfd34aab7ad0b8b9b24f1485f37906 Mon Sep 17 00:00:00 2001 From: Zorbatron <46525467+Zorbatron@users.noreply.github.com> Date: Wed, 21 May 2025 20:19:54 -0400 Subject: [PATCH 04/11] Move the overlay drawing to drawOverlay --- src/main/java/gregtech/common/mui/widget/GTFluidSlot.java | 8 +++++++- .../common/mui/widget/workbench/CraftingInputSlot.java | 4 ++++ .../common/mui/widget/workbench/CraftingOutputSlot.java | 4 ++++ .../common/mui/widget/workbench/RecipeMemorySlot.java | 4 ++++ 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/java/gregtech/common/mui/widget/GTFluidSlot.java b/src/main/java/gregtech/common/mui/widget/GTFluidSlot.java index 2f34ab8dce2..212d7704b8d 100644 --- a/src/main/java/gregtech/common/mui/widget/GTFluidSlot.java +++ b/src/main/java/gregtech/common/mui/widget/GTFluidSlot.java @@ -131,8 +131,14 @@ public void draw(ModularGuiContext context, WidgetSlotTheme widgetTheme) { this.textRenderer.setPos(0, 12); this.textRenderer.draw(amount); } + } - RenderUtil.handleSlotOverlays(this, widgetTheme); + @Override + public void drawOverlay(ModularGuiContext context, WidgetTheme widgetTheme) { + super.drawOverlay(context, widgetTheme); + if (widgetTheme instanceof WidgetSlotTheme slotTheme) { + RenderUtil.handleSlotOverlays(this, slotTheme); + } } @Override diff --git a/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java b/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java index 571c8a10b6c..62fa5c4c2c2 100644 --- a/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java +++ b/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java @@ -110,7 +110,11 @@ public void draw(ModularGuiContext context, WidgetTheme widgetTheme) { RenderUtil.renderItem(itemstack, 1, 1, 16, 16); } + } + @Override + public void drawOverlay(ModularGuiContext context, WidgetTheme widgetTheme) { + super.drawOverlay(context, widgetTheme); if (widgetTheme instanceof WidgetSlotTheme slotTheme) { RenderUtil.handleSlotOverlays(this, slotTheme); } diff --git a/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java b/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java index 07668d3473b..2212630f2b6 100644 --- a/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java +++ b/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java @@ -76,7 +76,11 @@ public void draw(ModularGuiContext context, WidgetTheme widgetTheme) { if (itemstack.isEmpty()) return; RenderUtil.renderItem(itemstack, 1, 1, 16, 16); + } + @Override + public void drawOverlay(ModularGuiContext context, WidgetTheme widgetTheme) { + super.drawOverlay(context, widgetTheme); if (isHovering() && widgetTheme instanceof WidgetSlotTheme slotTheme) { RenderUtil.drawSlotOverlay(this, slotTheme); } diff --git a/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java b/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java index 022fe3473d1..fce01073baf 100644 --- a/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java +++ b/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java @@ -60,7 +60,11 @@ public void draw(ModularGuiContext context, WidgetTheme widgetTheme) { GTGuiTextures.RECIPE_LOCK.draw(context, 10, 1, 8, 8, widgetTheme); GlStateManager.enableDepth(); } + } + @Override + public void drawOverlay(ModularGuiContext context, WidgetTheme widgetTheme) { + super.drawOverlay(context, widgetTheme); if (isHovering() && widgetTheme instanceof WidgetSlotTheme slotTheme) { RenderUtil.drawSlotOverlay(this, slotTheme); } From 5f74b289b1f749af10ff7e5b1586fe0ac0bb976a Mon Sep 17 00:00:00 2001 From: Zorbatron <46525467+Zorbatron@users.noreply.github.com> Date: Wed, 21 May 2025 21:14:40 -0400 Subject: [PATCH 05/11] Mixin into ItemSlot apply the same fixes as done in our GTFluidSlot --- .../gregtech/mixins/mui2/ItemSlotMixin.java | 63 +++++++++++++++++++ src/main/resources/mixins.gregtech.mui2.json | 3 +- 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/main/java/gregtech/mixins/mui2/ItemSlotMixin.java diff --git a/src/main/java/gregtech/mixins/mui2/ItemSlotMixin.java b/src/main/java/gregtech/mixins/mui2/ItemSlotMixin.java new file mode 100644 index 00000000000..ef5411e5c1b --- /dev/null +++ b/src/main/java/gregtech/mixins/mui2/ItemSlotMixin.java @@ -0,0 +1,63 @@ +package gregtech.mixins.mui2; + +import net.minecraft.enchantment.EnchantmentData; +import net.minecraft.item.ItemStack; + +import com.cleanroommc.modularui.integration.jei.ModularUIJeiPlugin; +import com.cleanroommc.modularui.value.sync.ItemSlotSH; +import com.cleanroommc.modularui.widgets.ItemSlot; +import mezz.jei.Internal; +import mezz.jei.gui.ghost.GhostIngredientDrag; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Debug; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Redirect; + +// TODO: remove once MUI PR 146 merges into a release we use +@Debug(export = true) +@Mixin(value = ItemSlot.class) +public abstract class ItemSlotMixin { + + @Shadow(remap = false) + private ItemSlotSH syncHandler; + + @Redirect(method = "draw", + at = @At(value = "INVOKE", + target = "Lcom/cleanroommc/modularui/integration/jei/ModularUIJeiPlugin;hasDraggingGhostIngredient()Z"), + remap = false) + private boolean onlyHighlightOnValidDrag() { + GhostIngredientDrag ingredientDrag = ModularUIJeiPlugin.getGhostDrag(); + if (ingredientDrag == null) return false; + Object ingredient = ingredientDrag.getIngredient(); + if (ingredient == null) return false; + return gregTech$castIfItemStack(ingredient) != null; + } + + /** + * @author Zorbatron + * @reason Add support for dragging enchanted books from JEI + */ + @Overwrite(remap = false) + public @Nullable ItemStack castGhostIngredientIfValid(@NotNull Object ingredient) { + return gregTech$castIfItemStack(ingredient); + } + + @Unique + private @Nullable ItemStack gregTech$castIfItemStack(Object ingredient) { + if (ingredient instanceof EnchantmentData enchantmentData) { + ingredient = Internal.getIngredientRegistry().getIngredientHelper(enchantmentData) + .getCheatItemStack(enchantmentData); + } + + if (ingredient instanceof ItemStack itemStack) { + return syncHandler.isItemValid(itemStack) ? itemStack : null; + } + + return null; + } +} diff --git a/src/main/resources/mixins.gregtech.mui2.json b/src/main/resources/mixins.gregtech.mui2.json index ee6b07445fd..2e9d82357e3 100644 --- a/src/main/resources/mixins.gregtech.mui2.json +++ b/src/main/resources/mixins.gregtech.mui2.json @@ -12,7 +12,8 @@ ], "client": [ "LangKeyMixin", - "ModularUIJeiPluginMixin" + "ModularUIJeiPluginMixin", + "ItemSlotMixin" ], "server": [] } From f657da427d5f6bf37a408c587ff6d4af3f18adf8 Mon Sep 17 00:00:00 2001 From: Zorbatron <46525467+Zorbatron@users.noreply.github.com> Date: Wed, 21 May 2025 21:25:05 -0400 Subject: [PATCH 06/11] Only use `hoveringOverIngredient` since it returns the same object during the drag --- src/main/java/gregtech/client/utils/RenderUtil.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/gregtech/client/utils/RenderUtil.java b/src/main/java/gregtech/client/utils/RenderUtil.java index 85aa95b86ab..9b1fd502a70 100644 --- a/src/main/java/gregtech/client/utils/RenderUtil.java +++ b/src/main/java/gregtech/client/utils/RenderUtil.java @@ -729,9 +729,7 @@ public static boolean handleJeiGhostOverlay(@NotNull IWidget slot) { if (!Mods.JustEnoughItems.isModLoaded()) return false; if (!(slot instanceof JeiGhostIngredientSlotingredientSlot)) return false; - // TODO: replace the first condition with draggingValidIngredient once MUI PR 146 makes it into a release we use - if (ingredientSlot.castGhostIngredientIfValid(ModularUIJeiPlugin.getGhostDrag()) != null || - ModularUIJeiPlugin.hoveringOverIngredient(ingredientSlot)) { + if (ModularUIJeiPlugin.hoveringOverIngredient(ingredientSlot)) { GlStateManager.colorMask(true, true, true, false); ingredientSlot.drawHighlight(slot.getArea(), slot.isHovering()); GlStateManager.colorMask(true, true, true, true); From 930a69f3e99bc3eddf0bcd46dd36e3694a65f281 Mon Sep 17 00:00:00 2001 From: Zorbatron <46525467+Zorbatron@users.noreply.github.com> Date: Mon, 30 Jun 2025 11:47:10 -0400 Subject: [PATCH 07/11] oops --- src/main/java/gregtech/common/mui/widget/GTFluidSlot.java | 8 +------- .../common/mui/widget/workbench/CraftingInputSlot.java | 4 ---- .../common/mui/widget/workbench/CraftingOutputSlot.java | 4 ---- .../common/mui/widget/workbench/RecipeMemorySlot.java | 4 ---- 4 files changed, 1 insertion(+), 19 deletions(-) diff --git a/src/main/java/gregtech/common/mui/widget/GTFluidSlot.java b/src/main/java/gregtech/common/mui/widget/GTFluidSlot.java index 212d7704b8d..2f34ab8dce2 100644 --- a/src/main/java/gregtech/common/mui/widget/GTFluidSlot.java +++ b/src/main/java/gregtech/common/mui/widget/GTFluidSlot.java @@ -131,14 +131,8 @@ public void draw(ModularGuiContext context, WidgetSlotTheme widgetTheme) { this.textRenderer.setPos(0, 12); this.textRenderer.draw(amount); } - } - @Override - public void drawOverlay(ModularGuiContext context, WidgetTheme widgetTheme) { - super.drawOverlay(context, widgetTheme); - if (widgetTheme instanceof WidgetSlotTheme slotTheme) { - RenderUtil.handleSlotOverlays(this, slotTheme); - } + RenderUtil.handleSlotOverlays(this, widgetTheme); } @Override diff --git a/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java b/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java index 62fa5c4c2c2..571c8a10b6c 100644 --- a/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java +++ b/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java @@ -110,11 +110,7 @@ public void draw(ModularGuiContext context, WidgetTheme widgetTheme) { RenderUtil.renderItem(itemstack, 1, 1, 16, 16); } - } - @Override - public void drawOverlay(ModularGuiContext context, WidgetTheme widgetTheme) { - super.drawOverlay(context, widgetTheme); if (widgetTheme instanceof WidgetSlotTheme slotTheme) { RenderUtil.handleSlotOverlays(this, slotTheme); } diff --git a/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java b/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java index 2212630f2b6..07668d3473b 100644 --- a/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java +++ b/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java @@ -76,11 +76,7 @@ public void draw(ModularGuiContext context, WidgetTheme widgetTheme) { if (itemstack.isEmpty()) return; RenderUtil.renderItem(itemstack, 1, 1, 16, 16); - } - @Override - public void drawOverlay(ModularGuiContext context, WidgetTheme widgetTheme) { - super.drawOverlay(context, widgetTheme); if (isHovering() && widgetTheme instanceof WidgetSlotTheme slotTheme) { RenderUtil.drawSlotOverlay(this, slotTheme); } diff --git a/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java b/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java index fce01073baf..022fe3473d1 100644 --- a/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java +++ b/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java @@ -60,11 +60,7 @@ public void draw(ModularGuiContext context, WidgetTheme widgetTheme) { GTGuiTextures.RECIPE_LOCK.draw(context, 10, 1, 8, 8, widgetTheme); GlStateManager.enableDepth(); } - } - @Override - public void drawOverlay(ModularGuiContext context, WidgetTheme widgetTheme) { - super.drawOverlay(context, widgetTheme); if (isHovering() && widgetTheme instanceof WidgetSlotTheme slotTheme) { RenderUtil.drawSlotOverlay(this, slotTheme); } From 4165a5a787e47ce1182df779e3c13850e01f733f Mon Sep 17 00:00:00 2001 From: Zorbatron <46525467+Zorbatron@users.noreply.github.com> Date: Mon, 25 Aug 2025 21:01:40 -0400 Subject: [PATCH 08/11] Fix certain slots not having an overlay due to the theme not being a `WidgetSlotTheme` --- .../java/gregtech/client/utils/RenderUtil.java | 17 +++++++++++------ .../gregtech/common/mui/widget/GTFluidSlot.java | 2 +- .../mui/widget/workbench/CraftingInputSlot.java | 5 +---- .../widget/workbench/CraftingOutputSlot.java | 7 +------ .../mui/widget/workbench/RecipeMemorySlot.java | 5 +---- 5 files changed, 15 insertions(+), 21 deletions(-) diff --git a/src/main/java/gregtech/client/utils/RenderUtil.java b/src/main/java/gregtech/client/utils/RenderUtil.java index 9b1fd502a70..45575302cd7 100644 --- a/src/main/java/gregtech/client/utils/RenderUtil.java +++ b/src/main/java/gregtech/client/utils/RenderUtil.java @@ -33,6 +33,8 @@ import com.cleanroommc.modularui.integration.jei.JeiGhostIngredientSlot; import com.cleanroommc.modularui.integration.jei.ModularUIJeiPlugin; import com.cleanroommc.modularui.theme.WidgetSlotTheme; +import com.cleanroommc.modularui.theme.WidgetTheme; +import com.cleanroommc.modularui.utils.Color; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.lwjgl.opengl.GL11; @@ -744,22 +746,25 @@ public static boolean handleJeiGhostOverlay(@NotNull IWidget slot) { * * @param slot the slot to draw the overlay above */ - public static void drawSlotOverlay(@NotNull IWidget slot, @NotNull WidgetSlotTheme slotTheme) { + public static void drawSlotOverlay(@NotNull IWidget slot, int overlayColor) { GlStateManager.colorMask(true, true, true, false); - GuiDraw.drawRect(1, 1, slot.getArea().w() - 2, slot.getArea().h() - 2, slotTheme.getSlotHoverColor()); + GuiDraw.drawRect(1, 1, slot.getArea().w() - 2, slot.getArea().h() - 2, overlayColor); GlStateManager.colorMask(true, true, true, true); } + private static final int defaultSlotHoverColor = Color.withAlpha(Color.WHITE.main, 0x60); + /** * Handles drawing the green JEI overlay when dragging an item, and if no item is being dragged, the overlay when * mousing over the slot. * - * @param slot the slot to draw the overlay above - * @param slotTheme the theme to get the slot overlay color from + * @param slot the slot to draw the overlay above + * @param widgetTheme the theme to attempt to get the slot overlay color from */ - public static void handleSlotOverlays(@NotNull IWidget slot, @NotNull WidgetSlotTheme slotTheme) { + public static void handleSlotOverlay(@NotNull IWidget slot, @NotNull WidgetTheme widgetTheme) { if (!handleJeiGhostOverlay(slot) && slot.isHovering()) { - drawSlotOverlay(slot, slotTheme); + drawSlotOverlay(slot, widgetTheme instanceof WidgetSlotTheme slotTheme ? slotTheme.getSlotHoverColor() : + defaultSlotHoverColor); } } } diff --git a/src/main/java/gregtech/common/mui/widget/GTFluidSlot.java b/src/main/java/gregtech/common/mui/widget/GTFluidSlot.java index 3319d3c77c6..aadf8cfdbee 100644 --- a/src/main/java/gregtech/common/mui/widget/GTFluidSlot.java +++ b/src/main/java/gregtech/common/mui/widget/GTFluidSlot.java @@ -115,7 +115,7 @@ public void draw(ModularGuiContext context, WidgetSlotTheme widgetTheme) { this.textRenderer.draw(amount); } - RenderUtil.handleSlotOverlays(this, widgetTheme); + RenderUtil.handleSlotOverlay(this, widgetTheme); } @Override diff --git a/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java b/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java index 571c8a10b6c..655a5c0bde2 100644 --- a/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java +++ b/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java @@ -16,7 +16,6 @@ import com.cleanroommc.modularui.network.NetworkUtils; import com.cleanroommc.modularui.screen.RichTooltip; import com.cleanroommc.modularui.screen.viewport.ModularGuiContext; -import com.cleanroommc.modularui.theme.WidgetSlotTheme; import com.cleanroommc.modularui.theme.WidgetTheme; import com.cleanroommc.modularui.value.sync.PanelSyncManager; import com.cleanroommc.modularui.value.sync.SyncHandler; @@ -111,9 +110,7 @@ public void draw(ModularGuiContext context, WidgetTheme widgetTheme) { RenderUtil.renderItem(itemstack, 1, 1, 16, 16); } - if (widgetTheme instanceof WidgetSlotTheme slotTheme) { - RenderUtil.handleSlotOverlays(this, slotTheme); - } + RenderUtil.handleSlotOverlay(this, widgetTheme); } @Override diff --git a/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java b/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java index 07668d3473b..efd566ed7f7 100644 --- a/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java +++ b/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java @@ -21,7 +21,6 @@ import com.cleanroommc.modularui.network.NetworkUtils; import com.cleanroommc.modularui.screen.RichTooltip; import com.cleanroommc.modularui.screen.viewport.ModularGuiContext; -import com.cleanroommc.modularui.theme.WidgetSlotTheme; import com.cleanroommc.modularui.theme.WidgetTheme; import com.cleanroommc.modularui.utils.MouseData; import com.cleanroommc.modularui.value.sync.IntSyncValue; @@ -74,12 +73,8 @@ public boolean isValidSyncHandler(SyncHandler syncHandler) { public void draw(ModularGuiContext context, WidgetTheme widgetTheme) { ItemStack itemstack = this.syncHandler.getOutputStack(); if (itemstack.isEmpty()) return; - RenderUtil.renderItem(itemstack, 1, 1, 16, 16); - - if (isHovering() && widgetTheme instanceof WidgetSlotTheme slotTheme) { - RenderUtil.drawSlotOverlay(this, slotTheme); - } + RenderUtil.handleSlotOverlay(this, widgetTheme); } @Override diff --git a/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java b/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java index 022fe3473d1..e9356199fa9 100644 --- a/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java +++ b/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java @@ -13,7 +13,6 @@ import com.cleanroommc.modularui.integration.jei.JeiIngredientProvider; import com.cleanroommc.modularui.screen.RichTooltip; import com.cleanroommc.modularui.screen.viewport.ModularGuiContext; -import com.cleanroommc.modularui.theme.WidgetSlotTheme; import com.cleanroommc.modularui.theme.WidgetTheme; import com.cleanroommc.modularui.utils.MouseData; import com.cleanroommc.modularui.widget.Widget; @@ -61,9 +60,7 @@ public void draw(ModularGuiContext context, WidgetTheme widgetTheme) { GlStateManager.enableDepth(); } - if (isHovering() && widgetTheme instanceof WidgetSlotTheme slotTheme) { - RenderUtil.drawSlotOverlay(this, slotTheme); - } + RenderUtil.handleSlotOverlay(this, widgetTheme); } @Override From caf3334ccc27aa1e502a27d81bb1ed83ad98c99a Mon Sep 17 00:00:00 2001 From: Zorbatron <46525467+Zorbatron@users.noreply.github.com> Date: Tue, 2 Sep 2025 16:05:18 -0400 Subject: [PATCH 09/11] Fix the crafting station input slots having both overlays at the same time --- src/main/java/gregtech/api/util/JEIUtil.java | 16 +++++ .../gregtech/client/utils/RenderUtil.java | 66 ++++++++----------- .../common/mui/widget/GTFluidSlot.java | 2 +- .../widget/workbench/CraftingInputSlot.java | 11 +++- .../widget/workbench/CraftingOutputSlot.java | 1 - .../widget/workbench/RecipeMemorySlot.java | 27 ++++---- 6 files changed, 67 insertions(+), 56 deletions(-) create mode 100644 src/main/java/gregtech/api/util/JEIUtil.java diff --git a/src/main/java/gregtech/api/util/JEIUtil.java b/src/main/java/gregtech/api/util/JEIUtil.java new file mode 100644 index 00000000000..8cb414716f1 --- /dev/null +++ b/src/main/java/gregtech/api/util/JEIUtil.java @@ -0,0 +1,16 @@ +package gregtech.api.util; + +import com.cleanroommc.modularui.integration.jei.JeiGhostIngredientSlot; +import com.cleanroommc.modularui.integration.jei.ModularUIJeiPlugin; + +public class JEIUtil { + + /** + * Check if the player is currently hovering over a valid ingredient for this slot.
+ * Will always return false is JEI is not installed. + */ + public static boolean hoveringOverIngredient(JeiGhostIngredientSlot jeiGhostIngredientSlot) { + if (!Mods.JustEnoughItems.isModLoaded()) return false; + return ModularUIJeiPlugin.hoveringOverIngredient(jeiGhostIngredientSlot); + } +} diff --git a/src/main/java/gregtech/client/utils/RenderUtil.java b/src/main/java/gregtech/client/utils/RenderUtil.java index 45575302cd7..8b93f3f54ee 100644 --- a/src/main/java/gregtech/client/utils/RenderUtil.java +++ b/src/main/java/gregtech/client/utils/RenderUtil.java @@ -1,7 +1,7 @@ package gregtech.client.utils; import gregtech.api.gui.resources.TextureArea; -import gregtech.api.util.Mods; +import gregtech.api.util.JEIUtil; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.FontRenderer; @@ -31,7 +31,6 @@ import com.cleanroommc.modularui.api.widget.IWidget; import com.cleanroommc.modularui.drawable.GuiDraw; import com.cleanroommc.modularui.integration.jei.JeiGhostIngredientSlot; -import com.cleanroommc.modularui.integration.jei.ModularUIJeiPlugin; import com.cleanroommc.modularui.theme.WidgetSlotTheme; import com.cleanroommc.modularui.theme.WidgetTheme; import com.cleanroommc.modularui.utils.Color; @@ -47,6 +46,7 @@ public class RenderUtil { private static final Deque scissorFrameStack = new ArrayDeque<>(); + public static final int defaultSlotHoverColor = Color.withAlpha(Color.WHITE.main, 0x60); public static void useScissor(int x, int y, int width, int height, Runnable codeBlock) { pushScissorFrame(x, y, width, height); @@ -720,51 +720,39 @@ public void put(int element, float @NotNull... data) { return getTextureMap().getMissingSprite(); } - /** - * Draws the green overlay when a valid ingredient for the slot is hovered over in JEI - * - * @param slot the slot to draw the overlay on - * @return true if the overlay was drawn, false if not - */ - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public static boolean handleJeiGhostOverlay(@NotNull IWidget slot) { - if (!Mods.JustEnoughItems.isModLoaded()) return false; - if (!(slot instanceof JeiGhostIngredientSlotingredientSlot)) return false; - - if (ModularUIJeiPlugin.hoveringOverIngredient(ingredientSlot)) { - GlStateManager.colorMask(true, true, true, false); - ingredientSlot.drawHighlight(slot.getArea(), slot.isHovering()); - GlStateManager.colorMask(true, true, true, true); - return true; - } - - return false; - } - - /** - * Draws a gray-ish overlay over the slot 1px inwards from each side. Intended for item slots. - * - * @param slot the slot to draw the overlay above - */ public static void drawSlotOverlay(@NotNull IWidget slot, int overlayColor) { GlStateManager.colorMask(true, true, true, false); GuiDraw.drawRect(1, 1, slot.getArea().w() - 2, slot.getArea().h() - 2, overlayColor); GlStateManager.colorMask(true, true, true, true); } - private static final int defaultSlotHoverColor = Color.withAlpha(Color.WHITE.main, 0x60); + public static void drawSlotOverlay(@NotNull IWidget slot, WidgetTheme widgetTheme) { + drawSlotOverlay(slot, widgetTheme instanceof WidgetSlotTheme slotTheme ? slotTheme.getSlotHoverColor() : + defaultSlotHoverColor); + } - /** - * Handles drawing the green JEI overlay when dragging an item, and if no item is being dragged, the overlay when - * mousing over the slot. - * - * @param slot the slot to draw the overlay above - * @param widgetTheme the theme to attempt to get the slot overlay color from - */ public static void handleSlotOverlay(@NotNull IWidget slot, @NotNull WidgetTheme widgetTheme) { - if (!handleJeiGhostOverlay(slot) && slot.isHovering()) { - drawSlotOverlay(slot, widgetTheme instanceof WidgetSlotTheme slotTheme ? slotTheme.getSlotHoverColor() : - defaultSlotHoverColor); + if (slot.isHovering()) { + drawSlotOverlay(slot, widgetTheme); } } + + public static < + T extends IWidget & JeiGhostIngredientSlot> void drawJEIGhostSlotOverlay(@NotNull T jeiGhostIngredientSlot) { + GlStateManager.colorMask(true, true, true, false); + jeiGhostIngredientSlot.drawHighlight(jeiGhostIngredientSlot.getArea(), jeiGhostIngredientSlot.isHovering()); + GlStateManager.colorMask(true, true, true, true); + } + + public static < + T extends IWidget & JeiGhostIngredientSlot> boolean handleJEIGhostSlotOverlay(@NotNull T jeiGhostIngredientSlot, + @NotNull WidgetTheme widgetTheme) { + if (JEIUtil.hoveringOverIngredient(jeiGhostIngredientSlot)) { + drawJEIGhostSlotOverlay(jeiGhostIngredientSlot); + return true; + } + + handleSlotOverlay(jeiGhostIngredientSlot, widgetTheme); + return false; + } } diff --git a/src/main/java/gregtech/common/mui/widget/GTFluidSlot.java b/src/main/java/gregtech/common/mui/widget/GTFluidSlot.java index aadf8cfdbee..ebf9175a8c4 100644 --- a/src/main/java/gregtech/common/mui/widget/GTFluidSlot.java +++ b/src/main/java/gregtech/common/mui/widget/GTFluidSlot.java @@ -115,7 +115,7 @@ public void draw(ModularGuiContext context, WidgetSlotTheme widgetTheme) { this.textRenderer.draw(amount); } - RenderUtil.handleSlotOverlay(this, widgetTheme); + RenderUtil.handleJEIGhostSlotOverlay(this, widgetTheme); } @Override diff --git a/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java b/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java index 655a5c0bde2..7b494f7b392 100644 --- a/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java +++ b/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java @@ -1,6 +1,7 @@ package gregtech.common.mui.widget.workbench; import gregtech.api.util.GTUtility; +import gregtech.api.util.JEIUtil; import gregtech.client.utils.RenderUtil; import gregtech.common.metatileentities.storage.CraftingRecipeLogic; @@ -102,15 +103,21 @@ public void onMouseDrag(int mouseButton, long timeSinceClick) { @Override public void draw(ModularGuiContext context, WidgetTheme widgetTheme) { ItemStack itemstack = this.syncHandler.getStack(); + boolean jeiIngredientBeingHovered = JEIUtil.hoveringOverIngredient(this); + if (!itemstack.isEmpty()) { - if (!this.hasIngredients) { + if (!jeiIngredientBeingHovered && !this.hasIngredients) { RenderUtil.renderRect(0, 0, 18, 18, 200, 0x80FF0000); } RenderUtil.renderItem(itemstack, 1, 1, 16, 16); } - RenderUtil.handleSlotOverlay(this, widgetTheme); + if (jeiIngredientBeingHovered) { + RenderUtil.drawJEIGhostSlotOverlay(this); + } else { + RenderUtil.handleSlotOverlay(this, widgetTheme); + } } @Override diff --git a/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java b/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java index efd566ed7f7..6576008a0c5 100644 --- a/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java +++ b/src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java @@ -72,7 +72,6 @@ public boolean isValidSyncHandler(SyncHandler syncHandler) { @Override public void draw(ModularGuiContext context, WidgetTheme widgetTheme) { ItemStack itemstack = this.syncHandler.getOutputStack(); - if (itemstack.isEmpty()) return; RenderUtil.renderItem(itemstack, 1, 1, 16, 16); RenderUtil.handleSlotOverlay(this, widgetTheme); } diff --git a/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java b/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java index e9356199fa9..b33d71ee40c 100644 --- a/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java +++ b/src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java @@ -45,19 +45,20 @@ public RecipeMemorySlot(CraftingRecipeMemory memory, int index) { @Override public void draw(ModularGuiContext context, WidgetTheme widgetTheme) { - ItemStack itemstack = this.memory.getRecipeOutputAtIndex(this.index); - if (itemstack.isEmpty()) return; - - int cachedCount = itemstack.getCount(); - itemstack.setCount(1); // required to not render the amount overlay - RenderUtil.renderItem(itemstack, 1, 1, 16, 16); - itemstack.setCount(cachedCount); - - // noinspection DataFlowIssue - if (this.memory.getRecipeAtIndex(this.index).isRecipeLocked()) { - GlStateManager.disableDepth(); - GTGuiTextures.RECIPE_LOCK.draw(context, 10, 1, 8, 8, widgetTheme); - GlStateManager.enableDepth(); + ItemStack itemStack = this.memory.getRecipeOutputAtIndex(this.index); + + if (!itemStack.isEmpty()) { + int cachedCount = itemStack.getCount(); + itemStack.setCount(1); // required to not render the amount overlay + RenderUtil.renderItem(itemStack, 1, 1, 16, 16); + itemStack.setCount(cachedCount); + + // noinspection DataFlowIssue + if (this.memory.getRecipeAtIndex(this.index).isRecipeLocked()) { + GlStateManager.disableDepth(); + GTGuiTextures.RECIPE_LOCK.draw(context, 10, 1, 8, 8, widgetTheme); + GlStateManager.enableDepth(); + } } RenderUtil.handleSlotOverlay(this, widgetTheme); From e3ce70dbc68706bb6738c4f287aae2045d9581fe Mon Sep 17 00:00:00 2001 From: Zorbatron <46525467+Zorbatron@users.noreply.github.com> Date: Tue, 2 Sep 2025 16:53:12 -0400 Subject: [PATCH 10/11] Fix being able to ghost drag when you shouldn't be able to --- src/main/java/gregtech/api/util/JEIUtil.java | 13 ++++++ .../widget/workbench/CraftingInputSlot.java | 1 + .../gregtech/mixins/mui2/ItemSlotMixin.java | 44 +++++-------------- 3 files changed, 26 insertions(+), 32 deletions(-) diff --git a/src/main/java/gregtech/api/util/JEIUtil.java b/src/main/java/gregtech/api/util/JEIUtil.java index 8cb414716f1..08077c0a462 100644 --- a/src/main/java/gregtech/api/util/JEIUtil.java +++ b/src/main/java/gregtech/api/util/JEIUtil.java @@ -1,7 +1,10 @@ package gregtech.api.util; +import net.minecraft.enchantment.EnchantmentData; + import com.cleanroommc.modularui.integration.jei.JeiGhostIngredientSlot; import com.cleanroommc.modularui.integration.jei.ModularUIJeiPlugin; +import mezz.jei.Internal; public class JEIUtil { @@ -13,4 +16,14 @@ public static boolean hoveringOverIngredient(JeiGhostIngredientSlot jeiGhostI if (!Mods.JustEnoughItems.isModLoaded()) return false; return ModularUIJeiPlugin.hoveringOverIngredient(jeiGhostIngredientSlot); } + + public static Object getBookStackIfEnchantment(Object ingredient) { + if (ingredient instanceof EnchantmentData enchantmentData) { + return Internal.getIngredientRegistry() + .getIngredientHelper(enchantmentData) + .getCheatItemStack(enchantmentData); + } + + return ingredient; + } } diff --git a/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java b/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java index 7b494f7b392..3c718d2e90c 100644 --- a/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java +++ b/src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java @@ -135,6 +135,7 @@ public void setGhostIngredient(@NotNull ItemStack ingredient) { @Override public @Nullable ItemStack castGhostIngredientIfValid(@NotNull Object ingredient) { + ingredient = JEIUtil.getBookStackIfEnchantment(ingredient); return areAncestorsEnabled() && ingredient instanceof ItemStack ? (ItemStack) ingredient : null; } diff --git a/src/main/java/gregtech/mixins/mui2/ItemSlotMixin.java b/src/main/java/gregtech/mixins/mui2/ItemSlotMixin.java index ef5411e5c1b..7c4326e3ff8 100644 --- a/src/main/java/gregtech/mixins/mui2/ItemSlotMixin.java +++ b/src/main/java/gregtech/mixins/mui2/ItemSlotMixin.java @@ -1,63 +1,43 @@ package gregtech.mixins.mui2; -import net.minecraft.enchantment.EnchantmentData; +import gregtech.api.util.JEIUtil; + import net.minecraft.item.ItemStack; import com.cleanroommc.modularui.integration.jei.ModularUIJeiPlugin; -import com.cleanroommc.modularui.value.sync.ItemSlotSH; import com.cleanroommc.modularui.widgets.ItemSlot; -import mezz.jei.Internal; +import com.llamalad7.mixinextras.injector.wrapmethod.WrapMethod; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; import mezz.jei.gui.ghost.GhostIngredientDrag; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Debug; import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; // TODO: remove once MUI PR 146 merges into a release we use @Debug(export = true) -@Mixin(value = ItemSlot.class) +@Mixin(value = ItemSlot.class, remap = false) public abstract class ItemSlotMixin { - @Shadow(remap = false) - private ItemSlotSH syncHandler; + @Shadow + public abstract @Nullable ItemStack castGhostIngredientIfValid(@NotNull Object ingredient); @Redirect(method = "draw", at = @At(value = "INVOKE", - target = "Lcom/cleanroommc/modularui/integration/jei/ModularUIJeiPlugin;hasDraggingGhostIngredient()Z"), - remap = false) + target = "Lcom/cleanroommc/modularui/integration/jei/ModularUIJeiPlugin;hasDraggingGhostIngredient()Z")) private boolean onlyHighlightOnValidDrag() { GhostIngredientDrag ingredientDrag = ModularUIJeiPlugin.getGhostDrag(); if (ingredientDrag == null) return false; Object ingredient = ingredientDrag.getIngredient(); if (ingredient == null) return false; - return gregTech$castIfItemStack(ingredient) != null; - } - - /** - * @author Zorbatron - * @reason Add support for dragging enchanted books from JEI - */ - @Overwrite(remap = false) - public @Nullable ItemStack castGhostIngredientIfValid(@NotNull Object ingredient) { - return gregTech$castIfItemStack(ingredient); + return castGhostIngredientIfValid(ingredient) != null; } - @Unique - private @Nullable ItemStack gregTech$castIfItemStack(Object ingredient) { - if (ingredient instanceof EnchantmentData enchantmentData) { - ingredient = Internal.getIngredientRegistry().getIngredientHelper(enchantmentData) - .getCheatItemStack(enchantmentData); - } - - if (ingredient instanceof ItemStack itemStack) { - return syncHandler.isItemValid(itemStack) ? itemStack : null; - } - - return null; + @WrapMethod(method = "castGhostIngredientIfValid(Ljava/lang/Object;)Lnet/minecraft/item/ItemStack;") + public @Nullable ItemStack addSupportForEnchantedBooks(Object ingredient, Operation original) { + return original.call(JEIUtil.getBookStackIfEnchantment(ingredient)); } } From de75335898c052196eba1eb5f346cf27ea82ab8c Mon Sep 17 00:00:00 2001 From: Zorbatron <46525467+Zorbatron@users.noreply.github.com> Date: Tue, 2 Sep 2025 22:55:28 -0400 Subject: [PATCH 11/11] Remove mixin debug annotation --- src/main/java/gregtech/mixins/mui2/ItemSlotMixin.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/gregtech/mixins/mui2/ItemSlotMixin.java b/src/main/java/gregtech/mixins/mui2/ItemSlotMixin.java index 7c4326e3ff8..1f7bddb0573 100644 --- a/src/main/java/gregtech/mixins/mui2/ItemSlotMixin.java +++ b/src/main/java/gregtech/mixins/mui2/ItemSlotMixin.java @@ -11,14 +11,12 @@ import mezz.jei.gui.ghost.GhostIngredientDrag; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.spongepowered.asm.mixin.Debug; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Redirect; // TODO: remove once MUI PR 146 merges into a release we use -@Debug(export = true) @Mixin(value = ItemSlot.class, remap = false) public abstract class ItemSlotMixin {