Skip to content

Commit e164f8e

Browse files
committed
improve jei ghost slot interaction
1 parent 4c8231e commit e164f8e

File tree

5 files changed

+56
-29
lines changed

5 files changed

+56
-29
lines changed

src/main/java/com/cleanroommc/modularui/core/mixins/late/jei/GuiEventHandlerMixin.java

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

33
import com.cleanroommc.modularui.api.IMuiScreen;
44

5-
import mezz.jei.gui.GuiEventHandler;
6-
7-
import mezz.jei.gui.GuiScreenHelper;
8-
95
import net.minecraftforge.client.event.GuiScreenEvent;
106

11-
import org.spongepowered.asm.mixin.Final;
7+
import mezz.jei.gui.GuiEventHandler;
128
import org.spongepowered.asm.mixin.Mixin;
13-
import org.spongepowered.asm.mixin.Shadow;
149
import org.spongepowered.asm.mixin.injection.At;
1510
import org.spongepowered.asm.mixin.injection.Inject;
1611
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
1712

1813
/**
19-
* Modifies JEI to not draw tooltips when the cursor has a mui draggable element or the mouse is inside an exclusion area.
14+
* Prevent JEI to draw any tooltips when the cursor has a mui draggable element.
2015
*/
2116
@Mixin(value = GuiEventHandler.class, remap = false)
2217
public class GuiEventHandlerMixin {
2318

24-
@Shadow
25-
@Final
26-
private GuiScreenHelper guiScreenHelper;
27-
2819
@Inject(method = "onDrawScreenEventPost", at = @At(value = "INVOKE", target = "Lmezz/jei/gui/overlay/IngredientListOverlay;drawTooltips(Lnet/minecraft/client/Minecraft;II)V"), cancellable = true)
2920
public void onDrawScreenEventPost(GuiScreenEvent.DrawScreenEvent.Post event, CallbackInfo ci) {
3021
if (event.getGui() instanceof IMuiScreen muiScreen && muiScreen.getScreen().getContext().hasDraggable()) {
31-
ci.cancel();
32-
return;
33-
}
34-
if (guiScreenHelper.isInGuiExclusionArea(event.getMouseX(), event.getMouseY())) {
35-
ci.cancel();
22+
ci.cancel(); // TODO fix JEI ghost dragging ingredient z layer
3623
}
3724
}
3825
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.cleanroommc.modularui.core.mixins.late.jei;
2+
3+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
4+
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
5+
import mezz.jei.gui.GuiScreenHelper;
6+
import mezz.jei.gui.overlay.IngredientGrid;
7+
import mezz.jei.gui.overlay.IngredientGridWithNavigation;
8+
import net.minecraft.client.Minecraft;
9+
import org.spongepowered.asm.mixin.Final;
10+
import org.spongepowered.asm.mixin.Mixin;
11+
import org.spongepowered.asm.mixin.Shadow;
12+
import org.spongepowered.asm.mixin.injection.At;
13+
14+
/**
15+
* Prevent JEI from displaying the "delete" tooltip when above exclusion zones
16+
*/
17+
@Mixin(value = IngredientGridWithNavigation.class, remap = false)
18+
public abstract class IngredientGridMixin {
19+
20+
@Shadow
21+
@Final
22+
private GuiScreenHelper guiScreenHelper;
23+
24+
@WrapOperation(method = "drawTooltips",
25+
at = @At(value = "INVOKE",
26+
target = "Lmezz/jei/gui/overlay/IngredientGrid;drawTooltips(Lnet/minecraft/client/Minecraft;II)V"))
27+
private void considerExclusions(IngredientGrid instance, Minecraft minecraft, int mouseX, int mouseY,
28+
Operation<Void> original) {
29+
if (!guiScreenHelper.isInGuiExclusionArea(mouseX, mouseY)) {
30+
original.call(instance, minecraft, mouseX, mouseY);
31+
}
32+
}
33+
}

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@
3030
import net.minecraftforge.fluids.FluidTank;
3131
import net.minecraftforge.fluids.IFluidTank;
3232
import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
33+
import net.minecraftforge.fluids.capability.IFluidHandlerItem;
34+
import net.minecraftforge.fluids.capability.IFluidTankProperties;
3335

36+
import mezz.jei.Internal;
3437
import org.jetbrains.annotations.NotNull;
3538
import org.jetbrains.annotations.Nullable;
3639
import org.lwjgl.input.Keyboard;
@@ -162,6 +165,7 @@ public void draw(ModularGuiContext context, WidgetTheme widgetTheme) {
162165

163166
@Override
164167
public void drawOverlay(ModularGuiContext context, WidgetTheme widgetTheme) {
168+
super.drawOverlay(context, widgetTheme);
165169
if (ModularUI.Mods.JEI.isLoaded() && (ModularUIJeiPlugin.draggingValidIngredient(this) || ModularUIJeiPlugin.hoveringOverIngredient(this))) {
166170
GlStateManager.colorMask(true, true, true, false);
167171
drawHighlight(getArea(), isHovering());
@@ -276,7 +280,7 @@ public FluidSlot syncHandler(FluidSlotSyncHandler syncHandler) {
276280
return this;
277281
}
278282

279-
/* === Jei ghost slot === */
283+
/* === Recipe viewer ghost slot === */
280284

281285
@Override
282286
public void setGhostIngredient(@NotNull FluidStack ingredient) {
@@ -287,7 +291,17 @@ public void setGhostIngredient(@NotNull FluidStack ingredient) {
287291

288292
@Override
289293
public @Nullable FluidStack castGhostIngredientIfValid(@NotNull Object ingredient) {
290-
return areAncestorsEnabled() && this.syncHandler.isPhantom() && ingredient instanceof FluidStack fluidStack ? fluidStack : null;
294+
if (!this.syncHandler.isPhantom() || !areAncestorsEnabled()) return null;
295+
if (ingredient instanceof FluidStack fluidStack) return fluidStack; // is fluid stack
296+
297+
// turn into an item and check if it contains exactly one fluid
298+
ItemStack stack = Internal.getIngredientRegistry().getIngredientHelper(ingredient).getCheatItemStack(ingredient);
299+
if (stack.isEmpty()) return null;
300+
IFluidHandlerItem fluidHandlerItem = stack.getCapability(CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null);
301+
if (fluidHandlerItem == null) return null;
302+
IFluidTankProperties[] fluidTanks = fluidHandlerItem.getTankProperties();
303+
if (fluidTanks.length != 1 || fluidTanks[0].getContents() == null) return null;
304+
return fluidTanks[0].getContents().copy();
291305
}
292306

293307
@Override

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

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,9 @@ public void setGhostIngredient(@NotNull ItemStack ingredient) {
7474

7575
@Override
7676
public @Nullable ItemStack castGhostIngredientIfValid(@NotNull Object ingredient) {
77-
if (areAncestorsEnabled() && this.syncHandler.isPhantom()) {
78-
if (ingredient instanceof EnchantmentData enchantmentData) {
79-
ingredient = Internal.getIngredientRegistry().getIngredientHelper(enchantmentData).getCheatItemStack(enchantmentData);
80-
}
81-
82-
if (ingredient instanceof ItemStack itemStack) {
83-
return this.syncHandler.isItemValid(itemStack) ? itemStack : null;
84-
}
85-
}
86-
87-
return null;
77+
if (!this.syncHandler.isPhantom() || !areAncestorsEnabled()) return null;
78+
ItemStack itemStack = Internal.getIngredientRegistry().getIngredientHelper(ingredient).getCheatItemStack(ingredient);
79+
return this.syncHandler.isItemValid(itemStack) ? itemStack : null;
8880
}
8981

9082
@Override

src/main/resources/mixin.modularui.jei.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"mixins": [
99
"GhostIngredientDragManagerAccessor",
1010
"GuiEventHandlerMixin",
11+
"IngredientGridMixin",
1112
"IngredientListOverlayAccessor"
1213
]
1314
}

0 commit comments

Comments
 (0)