Skip to content

Commit caf3334

Browse files
committed
Fix the crafting station input slots having both overlays at the same time
1 parent 4165a5a commit caf3334

File tree

6 files changed

+67
-56
lines changed

6 files changed

+67
-56
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package gregtech.api.util;
2+
3+
import com.cleanroommc.modularui.integration.jei.JeiGhostIngredientSlot;
4+
import com.cleanroommc.modularui.integration.jei.ModularUIJeiPlugin;
5+
6+
public class JEIUtil {
7+
8+
/**
9+
* Check if the player is currently hovering over a valid ingredient for this slot. <br/>
10+
* Will always return false is JEI is not installed.
11+
*/
12+
public static boolean hoveringOverIngredient(JeiGhostIngredientSlot<?> jeiGhostIngredientSlot) {
13+
if (!Mods.JustEnoughItems.isModLoaded()) return false;
14+
return ModularUIJeiPlugin.hoveringOverIngredient(jeiGhostIngredientSlot);
15+
}
16+
}

src/main/java/gregtech/client/utils/RenderUtil.java

Lines changed: 27 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package gregtech.client.utils;
22

33
import gregtech.api.gui.resources.TextureArea;
4-
import gregtech.api.util.Mods;
4+
import gregtech.api.util.JEIUtil;
55

66
import net.minecraft.client.Minecraft;
77
import net.minecraft.client.gui.FontRenderer;
@@ -31,7 +31,6 @@
3131
import com.cleanroommc.modularui.api.widget.IWidget;
3232
import com.cleanroommc.modularui.drawable.GuiDraw;
3333
import com.cleanroommc.modularui.integration.jei.JeiGhostIngredientSlot;
34-
import com.cleanroommc.modularui.integration.jei.ModularUIJeiPlugin;
3534
import com.cleanroommc.modularui.theme.WidgetSlotTheme;
3635
import com.cleanroommc.modularui.theme.WidgetTheme;
3736
import com.cleanroommc.modularui.utils.Color;
@@ -47,6 +46,7 @@
4746
public class RenderUtil {
4847

4948
private static final Deque<int[]> scissorFrameStack = new ArrayDeque<>();
49+
public static final int defaultSlotHoverColor = Color.withAlpha(Color.WHITE.main, 0x60);
5050

5151
public static void useScissor(int x, int y, int width, int height, Runnable codeBlock) {
5252
pushScissorFrame(x, y, width, height);
@@ -720,51 +720,39 @@ public void put(int element, float @NotNull... data) {
720720
return getTextureMap().getMissingSprite();
721721
}
722722

723-
/**
724-
* Draws the green overlay when a valid ingredient for the slot is hovered over in JEI
725-
*
726-
* @param slot the slot to draw the overlay on
727-
* @return true if the overlay was drawn, false if not
728-
*/
729-
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
730-
public static boolean handleJeiGhostOverlay(@NotNull IWidget slot) {
731-
if (!Mods.JustEnoughItems.isModLoaded()) return false;
732-
if (!(slot instanceof JeiGhostIngredientSlot<?>ingredientSlot)) return false;
733-
734-
if (ModularUIJeiPlugin.hoveringOverIngredient(ingredientSlot)) {
735-
GlStateManager.colorMask(true, true, true, false);
736-
ingredientSlot.drawHighlight(slot.getArea(), slot.isHovering());
737-
GlStateManager.colorMask(true, true, true, true);
738-
return true;
739-
}
740-
741-
return false;
742-
}
743-
744-
/**
745-
* Draws a gray-ish overlay over the slot 1px inwards from each side. Intended for item slots.
746-
*
747-
* @param slot the slot to draw the overlay above
748-
*/
749723
public static void drawSlotOverlay(@NotNull IWidget slot, int overlayColor) {
750724
GlStateManager.colorMask(true, true, true, false);
751725
GuiDraw.drawRect(1, 1, slot.getArea().w() - 2, slot.getArea().h() - 2, overlayColor);
752726
GlStateManager.colorMask(true, true, true, true);
753727
}
754728

755-
private static final int defaultSlotHoverColor = Color.withAlpha(Color.WHITE.main, 0x60);
729+
public static void drawSlotOverlay(@NotNull IWidget slot, WidgetTheme widgetTheme) {
730+
drawSlotOverlay(slot, widgetTheme instanceof WidgetSlotTheme slotTheme ? slotTheme.getSlotHoverColor() :
731+
defaultSlotHoverColor);
732+
}
756733

757-
/**
758-
* Handles drawing the green JEI overlay when dragging an item, and if no item is being dragged, the overlay when
759-
* mousing over the slot.
760-
*
761-
* @param slot the slot to draw the overlay above
762-
* @param widgetTheme the theme to attempt to get the slot overlay color from
763-
*/
764734
public static void handleSlotOverlay(@NotNull IWidget slot, @NotNull WidgetTheme widgetTheme) {
765-
if (!handleJeiGhostOverlay(slot) && slot.isHovering()) {
766-
drawSlotOverlay(slot, widgetTheme instanceof WidgetSlotTheme slotTheme ? slotTheme.getSlotHoverColor() :
767-
defaultSlotHoverColor);
735+
if (slot.isHovering()) {
736+
drawSlotOverlay(slot, widgetTheme);
768737
}
769738
}
739+
740+
public static <
741+
T extends IWidget & JeiGhostIngredientSlot<?>> void drawJEIGhostSlotOverlay(@NotNull T jeiGhostIngredientSlot) {
742+
GlStateManager.colorMask(true, true, true, false);
743+
jeiGhostIngredientSlot.drawHighlight(jeiGhostIngredientSlot.getArea(), jeiGhostIngredientSlot.isHovering());
744+
GlStateManager.colorMask(true, true, true, true);
745+
}
746+
747+
public static <
748+
T extends IWidget & JeiGhostIngredientSlot<?>> boolean handleJEIGhostSlotOverlay(@NotNull T jeiGhostIngredientSlot,
749+
@NotNull WidgetTheme widgetTheme) {
750+
if (JEIUtil.hoveringOverIngredient(jeiGhostIngredientSlot)) {
751+
drawJEIGhostSlotOverlay(jeiGhostIngredientSlot);
752+
return true;
753+
}
754+
755+
handleSlotOverlay(jeiGhostIngredientSlot, widgetTheme);
756+
return false;
757+
}
770758
}

src/main/java/gregtech/common/mui/widget/GTFluidSlot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public void draw(ModularGuiContext context, WidgetSlotTheme widgetTheme) {
115115
this.textRenderer.draw(amount);
116116
}
117117

118-
RenderUtil.handleSlotOverlay(this, widgetTheme);
118+
RenderUtil.handleJEIGhostSlotOverlay(this, widgetTheme);
119119
}
120120

121121
@Override

src/main/java/gregtech/common/mui/widget/workbench/CraftingInputSlot.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package gregtech.common.mui.widget.workbench;
22

33
import gregtech.api.util.GTUtility;
4+
import gregtech.api.util.JEIUtil;
45
import gregtech.client.utils.RenderUtil;
56
import gregtech.common.metatileentities.storage.CraftingRecipeLogic;
67

@@ -102,15 +103,21 @@ public void onMouseDrag(int mouseButton, long timeSinceClick) {
102103
@Override
103104
public void draw(ModularGuiContext context, WidgetTheme widgetTheme) {
104105
ItemStack itemstack = this.syncHandler.getStack();
106+
boolean jeiIngredientBeingHovered = JEIUtil.hoveringOverIngredient(this);
107+
105108
if (!itemstack.isEmpty()) {
106-
if (!this.hasIngredients) {
109+
if (!jeiIngredientBeingHovered && !this.hasIngredients) {
107110
RenderUtil.renderRect(0, 0, 18, 18, 200, 0x80FF0000);
108111
}
109112

110113
RenderUtil.renderItem(itemstack, 1, 1, 16, 16);
111114
}
112115

113-
RenderUtil.handleSlotOverlay(this, widgetTheme);
116+
if (jeiIngredientBeingHovered) {
117+
RenderUtil.drawJEIGhostSlotOverlay(this);
118+
} else {
119+
RenderUtil.handleSlotOverlay(this, widgetTheme);
120+
}
114121
}
115122

116123
@Override

src/main/java/gregtech/common/mui/widget/workbench/CraftingOutputSlot.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ public boolean isValidSyncHandler(SyncHandler syncHandler) {
7272
@Override
7373
public void draw(ModularGuiContext context, WidgetTheme widgetTheme) {
7474
ItemStack itemstack = this.syncHandler.getOutputStack();
75-
if (itemstack.isEmpty()) return;
7675
RenderUtil.renderItem(itemstack, 1, 1, 16, 16);
7776
RenderUtil.handleSlotOverlay(this, widgetTheme);
7877
}

src/main/java/gregtech/common/mui/widget/workbench/RecipeMemorySlot.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,19 +45,20 @@ public RecipeMemorySlot(CraftingRecipeMemory memory, int index) {
4545

4646
@Override
4747
public void draw(ModularGuiContext context, WidgetTheme widgetTheme) {
48-
ItemStack itemstack = this.memory.getRecipeOutputAtIndex(this.index);
49-
if (itemstack.isEmpty()) return;
50-
51-
int cachedCount = itemstack.getCount();
52-
itemstack.setCount(1); // required to not render the amount overlay
53-
RenderUtil.renderItem(itemstack, 1, 1, 16, 16);
54-
itemstack.setCount(cachedCount);
55-
56-
// noinspection DataFlowIssue
57-
if (this.memory.getRecipeAtIndex(this.index).isRecipeLocked()) {
58-
GlStateManager.disableDepth();
59-
GTGuiTextures.RECIPE_LOCK.draw(context, 10, 1, 8, 8, widgetTheme);
60-
GlStateManager.enableDepth();
48+
ItemStack itemStack = this.memory.getRecipeOutputAtIndex(this.index);
49+
50+
if (!itemStack.isEmpty()) {
51+
int cachedCount = itemStack.getCount();
52+
itemStack.setCount(1); // required to not render the amount overlay
53+
RenderUtil.renderItem(itemStack, 1, 1, 16, 16);
54+
itemStack.setCount(cachedCount);
55+
56+
// noinspection DataFlowIssue
57+
if (this.memory.getRecipeAtIndex(this.index).isRecipeLocked()) {
58+
GlStateManager.disableDepth();
59+
GTGuiTextures.RECIPE_LOCK.draw(context, 10, 1, 8, 8, widgetTheme);
60+
GlStateManager.enableDepth();
61+
}
6162
}
6263

6364
RenderUtil.handleSlotOverlay(this, widgetTheme);

0 commit comments

Comments
 (0)