From 0a7799a664c5319a9ea78f584cceb1d60a26037f Mon Sep 17 00:00:00 2001 From: Yang Xizhi <60341015+GlodBlock@users.noreply.github.com> Date: Tue, 18 Jun 2024 16:14:20 +0800 Subject: [PATCH] Allow looking up recipes in JEI with non-item slots (#451) --- .../java/appeng/client/gui/AEGuiHandler.java | 32 +++++++++++++++++++ .../client/gui/widgets/GuiCustomSlot.java | 8 ++++- .../java/appeng/client/me/SlotFluidME.java | 11 ++++++- .../interfaces/ISpecialSlotIngredient.java | 10 ++++++ .../client/gui/widgets/GuiFluidSlot.java | 5 +++ .../client/gui/widgets/GuiFluidTank.java | 5 +++ 6 files changed, 69 insertions(+), 2 deletions(-) create mode 100644 src/main/java/appeng/container/interfaces/ISpecialSlotIngredient.java diff --git a/src/main/java/appeng/client/gui/AEGuiHandler.java b/src/main/java/appeng/client/gui/AEGuiHandler.java index 89acf508776..414ef89439e 100644 --- a/src/main/java/appeng/client/gui/AEGuiHandler.java +++ b/src/main/java/appeng/client/gui/AEGuiHandler.java @@ -7,11 +7,15 @@ import appeng.client.gui.implementations.GuiExpandedProcessingPatternTerm; import appeng.client.gui.implementations.GuiPatternTerm; import appeng.client.gui.implementations.GuiUpgradeable; +import appeng.client.gui.widgets.GuiCustomSlot; import appeng.container.interfaces.IJEIGhostIngredients; +import appeng.container.interfaces.ISpecialSlotIngredient; import appeng.container.slot.IJEITargetSlot; import mezz.jei.api.gui.IAdvancedGuiHandler; import mezz.jei.api.gui.IGhostIngredientHandler; import net.minecraft.client.gui.GuiScreen; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.inventory.Slot; import org.lwjgl.input.Mouse; import javax.annotation.Nonnull; @@ -63,11 +67,39 @@ public Object getIngredientUnderMouse(@Nonnull AEBaseGui guiContainer, int mouse if (guiContainer instanceof GuiCraftAmount) { if (guiContainer.getSlotUnderMouse() != null) { result = guiContainer.getSlotUnderMouse().getStack(); + } else { + return null; } } + + if (result != null) { + return result; + } + + Slot slot = guiContainer.getSlotUnderMouse(); + if (slot instanceof ISpecialSlotIngredient ss) { + return ss.getIngredient(); + } + for (GuiCustomSlot customSlot : guiContainer.guiSlots) { + if (this.checkSlotArea(guiContainer, customSlot, mouseX, mouseY)) { + return customSlot.getIngredient(); + } + } + return result; } + private boolean checkSlotArea(GuiContainer gui, GuiCustomSlot slot, int mouseX, int mouseY) { + int i = gui.guiLeft; + int j = gui.guiTop; + mouseX = mouseX - i; + mouseY = mouseY - j; + return mouseX >= slot.xPos() - 1 && + mouseX < slot.xPos() + slot.getWidth() + 1 && + mouseY >= slot.yPos() - 1 && + mouseY < slot.yPos() + slot.getHeight() + 1; + } + private int getSlotidx(AEBaseGui guiContainer, int mouseX, int mouseY, int rows) { int guileft = guiContainer.getGuiLeft(); int guitop = guiContainer.getGuiTop(); diff --git a/src/main/java/appeng/client/gui/widgets/GuiCustomSlot.java b/src/main/java/appeng/client/gui/widgets/GuiCustomSlot.java index a3e2c3f3cd5..22939f47a9e 100644 --- a/src/main/java/appeng/client/gui/widgets/GuiCustomSlot.java +++ b/src/main/java/appeng/client/gui/widgets/GuiCustomSlot.java @@ -1,13 +1,14 @@ package appeng.client.gui.widgets; +import appeng.container.interfaces.ISpecialSlotIngredient; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; -public abstract class GuiCustomSlot extends Gui implements ITooltip { +public abstract class GuiCustomSlot extends Gui implements ITooltip, ISpecialSlotIngredient { protected final int x; protected final int y; protected final int id; @@ -68,4 +69,9 @@ public boolean isSlotEnabled() { return true; } + @Override + public Object getIngredient() { + return null; + } + } diff --git a/src/main/java/appeng/client/me/SlotFluidME.java b/src/main/java/appeng/client/me/SlotFluidME.java index 3c8be954d4b..2bbe4c2ab76 100644 --- a/src/main/java/appeng/client/me/SlotFluidME.java +++ b/src/main/java/appeng/client/me/SlotFluidME.java @@ -20,11 +20,13 @@ import appeng.api.storage.data.IAEFluidStack; +import appeng.container.interfaces.ISpecialSlotIngredient; import appeng.fluids.container.slots.IMEFluidSlot; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraftforge.items.SlotItemHandler; +import org.jetbrains.annotations.Nullable; import javax.annotation.Nonnull; @@ -34,7 +36,7 @@ * @version rv6 - 22/05/2018 * @since rv6 22/05/2018 */ -public class SlotFluidME extends SlotItemHandler implements IMEFluidSlot { +public class SlotFluidME extends SlotItemHandler implements IMEFluidSlot, ISpecialSlotIngredient { private final InternalFluidSlotME slot; @@ -95,4 +97,11 @@ public boolean isHere(final IInventory inv, final int slotIn) { public boolean canTakeStack(final EntityPlayer par1EntityPlayer) { return false; } + + @Nullable + @Override + public Object getIngredient() { + return this.getAEFluidStack() == null ? null : this.getAEFluidStack().getFluidStack(); + } + } diff --git a/src/main/java/appeng/container/interfaces/ISpecialSlotIngredient.java b/src/main/java/appeng/container/interfaces/ISpecialSlotIngredient.java new file mode 100644 index 00000000000..03ecb2a92fa --- /dev/null +++ b/src/main/java/appeng/container/interfaces/ISpecialSlotIngredient.java @@ -0,0 +1,10 @@ +package appeng.container.interfaces; + +import javax.annotation.Nullable; + +public interface ISpecialSlotIngredient { + + @Nullable + Object getIngredient(); + +} diff --git a/src/main/java/appeng/fluids/client/gui/widgets/GuiFluidSlot.java b/src/main/java/appeng/fluids/client/gui/widgets/GuiFluidSlot.java index 07afc6532c0..9239bbb1ee7 100644 --- a/src/main/java/appeng/fluids/client/gui/widgets/GuiFluidSlot.java +++ b/src/main/java/appeng/fluids/client/gui/widgets/GuiFluidSlot.java @@ -99,4 +99,9 @@ public boolean needAccept() { return this.getFluidStack() == null; } + @Override + public Object getIngredient() { + return this.getFluidStack() == null ? null : this.getFluidStack().getFluidStack(); + } + } diff --git a/src/main/java/appeng/fluids/client/gui/widgets/GuiFluidTank.java b/src/main/java/appeng/fluids/client/gui/widgets/GuiFluidTank.java index 31c271255e0..7dac31c383a 100644 --- a/src/main/java/appeng/fluids/client/gui/widgets/GuiFluidTank.java +++ b/src/main/java/appeng/fluids/client/gui/widgets/GuiFluidTank.java @@ -147,4 +147,9 @@ public void slotClicked(ItemStack clickStack, final int mouseButton) { } } + @Override + public Object getIngredient() { + return this.getFluidStack() == null ? null : this.getFluidStack().getFluidStack(); + } + }