Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow non-item slot to lookup recipe in jei #451

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/main/java/appeng/client/gui/AEGuiHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/appeng/client/gui/widgets/GuiCustomSlot.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -68,4 +69,9 @@ public boolean isSlotEnabled() {
return true;
}

@Override
public Object getIngredient() {
return null;
}

}
11 changes: 10 additions & 1 deletion src/main/java/appeng/client/me/SlotFluidME.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package appeng.container.interfaces;

import javax.annotation.Nullable;

public interface ISpecialSlotIngredient {

@Nullable
Object getIngredient();

}
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,9 @@ public boolean needAccept() {
return this.getFluidStack() == null;
}

@Override
public Object getIngredient() {
return this.getFluidStack() == null ? null : this.getFluidStack().getFluidStack();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,9 @@ public void slotClicked(ItemStack clickStack, final int mouseButton) {
}
}

@Override
public Object getIngredient() {
return this.getFluidStack() == null ? null : this.getFluidStack().getFluidStack();
}

}
Loading