diff --git a/src/main/java/com/glodblock/github/client/GuiExtendedFluidPatternTerminal.java b/src/main/java/com/glodblock/github/client/GuiExtendedFluidPatternTerminal.java index ffc9c55b0..5c5375b0b 100644 --- a/src/main/java/com/glodblock/github/client/GuiExtendedFluidPatternTerminal.java +++ b/src/main/java/com/glodblock/github/client/GuiExtendedFluidPatternTerminal.java @@ -15,13 +15,14 @@ import com.glodblock.github.client.container.ContainerExtendedFluidPatternTerminal; import com.glodblock.github.client.render.FluidRenderUtils; import com.glodblock.github.common.item.ItemFluidPacket; +import com.glodblock.github.integration.jei.FluidPacketTarget; import com.glodblock.github.inventory.GuiType; import com.glodblock.github.inventory.InventoryHandler; import com.glodblock.github.inventory.slot.SlotSingleItem; import com.glodblock.github.network.CPacketFluidPatternTermBtns; import com.glodblock.github.network.CPacketInventoryAction; import com.glodblock.github.util.Ae2ReflectClient; -import com.glodblock.github.util.ModAndClassUtil; +import mezz.jei.api.gui.IGhostIngredientHandler.Target; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.ClickType; @@ -29,6 +30,8 @@ import net.minecraft.item.ItemStack; import javax.annotation.Nonnull; +import java.util.ArrayList; +import java.util.List; public class GuiExtendedFluidPatternTerminal extends GuiExpandedProcessingPatternTerm { @@ -52,15 +55,13 @@ public GuiExtendedFluidPatternTerminal(InventoryPlayer inventoryPlayer, ITermina public void initGui() { super.initGui(); craftingStatusBtn = Ae2ReflectClient.getCraftingStatusButton(this); - if (!ModAndClassUtil.NEE) { - this.combineEnableBtn = new GuiFCImgButton( this.guiLeft + 74, this.guiTop + this.ySize - 153, "FORCE_COMBINE", "DO_COMBINE" ); - this.combineEnableBtn.setHalfSize( true ); - this.buttonList.add( this.combineEnableBtn ); - - this.combineDisableBtn = new GuiFCImgButton( this.guiLeft + 74, this.guiTop + this.ySize - 153, "NOT_COMBINE", "DONT_COMBINE" ); - this.combineDisableBtn.setHalfSize( true ); - this.buttonList.add( this.combineDisableBtn ); - } + this.combineEnableBtn = new GuiFCImgButton( this.guiLeft + 74, this.guiTop + this.ySize - 153, "FORCE_COMBINE", "DO_COMBINE" ); + this.combineEnableBtn.setHalfSize( true ); + this.buttonList.add( this.combineEnableBtn ); + + this.combineDisableBtn = new GuiFCImgButton( this.guiLeft + 74, this.guiTop + this.ySize - 153, "NOT_COMBINE", "DONT_COMBINE" ); + this.combineDisableBtn.setHalfSize( true ); + this.buttonList.add( this.combineDisableBtn ); this.fluidEnableBtn = new GuiFCImgButton( this.guiLeft + 74, this.guiTop + this.ySize - 143, "FLUID_FIRST", "FLUID" ); this.fluidEnableBtn.setHalfSize( true ); @@ -92,17 +93,15 @@ private boolean renderMEStyleSlot(Slot slot, @Nonnull ItemStack stack) { @Override public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) { - if (!ModAndClassUtil.NEE) { - if ( this.container.combine ) - { - this.combineEnableBtn.visible = true; - this.combineDisableBtn.visible = false; - } - else - { - this.combineEnableBtn.visible = false; - this.combineDisableBtn.visible = true; - } + if ( this.container.combine ) + { + this.combineEnableBtn.visible = true; + this.combineDisableBtn.visible = false; + } + else + { + this.combineEnableBtn.visible = false; + this.combineDisableBtn.visible = true; } if (this.container.fluidFirst) @@ -151,4 +150,21 @@ protected void handleMouseClick(Slot slot, int slotIdx, int mouseButton, ClickTy super.handleMouseClick(slot, slotIdx, mouseButton, clickType); } + @Override + public List> getPhantomTargets(Object ingredient) { + if (FluidPacketTarget.covertFluid(ingredient) != null) { + List> targets = new ArrayList<>(); + for (Slot slot : this.inventorySlots.inventorySlots) { + if (slot instanceof SlotFake) { + Target target = new FluidPacketTarget(getGuiLeft(), getGuiTop(), slot); + targets.add(target); + mapTargetSlot.putIfAbsent(target, slot); + } + } + return targets; + } else { + return super.getPhantomTargets(ingredient); + } + } + } diff --git a/src/main/java/com/glodblock/github/client/GuiFluidPatternTerminal.java b/src/main/java/com/glodblock/github/client/GuiFluidPatternTerminal.java index 743d42589..a544a7c36 100644 --- a/src/main/java/com/glodblock/github/client/GuiFluidPatternTerminal.java +++ b/src/main/java/com/glodblock/github/client/GuiFluidPatternTerminal.java @@ -3,7 +3,6 @@ import appeng.api.storage.ITerminalHost; import appeng.api.storage.data.IAEItemStack; import appeng.client.gui.implementations.GuiPatternTerm; -import appeng.client.gui.widgets.GuiImgButton; import appeng.client.gui.widgets.GuiTabButton; import appeng.client.render.StackSizeRenderer; import appeng.container.AEBaseContainer; @@ -16,6 +15,7 @@ import com.glodblock.github.client.container.ContainerFluidPatternTerminal; import com.glodblock.github.client.render.FluidRenderUtils; import com.glodblock.github.common.item.ItemFluidPacket; +import com.glodblock.github.integration.jei.FluidPacketTarget; import com.glodblock.github.inventory.GuiType; import com.glodblock.github.inventory.InventoryHandler; import com.glodblock.github.inventory.slot.SlotSingleItem; @@ -23,6 +23,7 @@ import com.glodblock.github.network.CPacketInventoryAction; import com.glodblock.github.util.Ae2ReflectClient; import com.glodblock.github.util.ModAndClassUtil; +import mezz.jei.api.gui.IGhostIngredientHandler.Target; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.ClickType; @@ -30,6 +31,8 @@ import net.minecraft.item.ItemStack; import javax.annotation.Nonnull; +import java.util.ArrayList; +import java.util.List; public class GuiFluidPatternTerminal extends GuiPatternTerm { @@ -72,7 +75,7 @@ public void initGui() { this.fluidDisableBtn.setHalfSize( true ); this.buttonList.add( this.fluidDisableBtn ); - this.craftingFluidBtn = new GuiFCImgButton(this.guiLeft + 110, this.guiTop + this.ySize - 32, "CRAFT_FLUID", "ENCODE"); + this.craftingFluidBtn = new GuiFCImgButton(this.guiLeft + 110, this.guiTop + this.ySize - 115, "CRAFT_FLUID", "ENCODE"); this.buttonList.add( this.craftingFluidBtn ); } @@ -164,4 +167,21 @@ protected void handleMouseClick(Slot slot, int slotIdx, int mouseButton, ClickTy super.handleMouseClick(slot, slotIdx, mouseButton, clickType); } + @Override + public List> getPhantomTargets(Object ingredient) { + if (!this.container.isCraftingMode() && FluidPacketTarget.covertFluid(ingredient) != null) { + List> targets = new ArrayList<>(); + for (Slot slot : this.inventorySlots.inventorySlots) { + if (slot instanceof SlotFake) { + Target target = new FluidPacketTarget(getGuiLeft(), getGuiTop(), slot); + targets.add(target); + mapTargetSlot.putIfAbsent(target, slot); + } + } + return targets; + } else { + return super.getPhantomTargets(ingredient); + } + } + } \ No newline at end of file diff --git a/src/main/java/com/glodblock/github/integration/jei/FluidPacketTarget.java b/src/main/java/com/glodblock/github/integration/jei/FluidPacketTarget.java new file mode 100644 index 000000000..2031898b5 --- /dev/null +++ b/src/main/java/com/glodblock/github/integration/jei/FluidPacketTarget.java @@ -0,0 +1,62 @@ +package com.glodblock.github.integration.jei; + +import appeng.api.storage.data.IAEItemStack; +import appeng.container.slot.SlotFake; +import appeng.core.sync.network.NetworkHandler; +import appeng.core.sync.packets.PacketInventoryAction; +import appeng.helpers.InventoryAction; +import com.glodblock.github.common.item.ItemFluidPacket; +import com.glodblock.github.util.Util; +import mezz.jei.api.gui.IGhostIngredientHandler; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +import javax.annotation.Nonnull; +import java.awt.*; +import java.io.IOException; + +public class FluidPacketTarget implements IGhostIngredientHandler.Target { + + private final int left; + private final int top; + private final Slot slot; + + public FluidPacketTarget(int guiLeft, int guiTop, Slot slot) { + this.left = guiLeft; + this.top = guiTop; + this.slot = slot; + } + + @Nonnull + @Override + public Rectangle getArea() { + return new Rectangle(left + slot.xPos, top + slot.yPos, 16, 16); + } + + @Override + public void accept(@Nonnull Object ingredient) { + FluidStack fluid = covertFluid(ingredient); + if (fluid == null) { + return; + } + IAEItemStack packet = ItemFluidPacket.newAeStack(fluid); + final PacketInventoryAction p; + try { + p = new PacketInventoryAction(InventoryAction.PLACE_JEI_GHOST_ITEM, (SlotFake) slot, packet); + NetworkHandler.instance().sendToServer(p); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static FluidStack covertFluid(Object ingredient) { + FluidStack fluid = null; + if (ingredient instanceof FluidStack) { + fluid = (FluidStack) ingredient; + } else if (ingredient instanceof ItemStack) { + fluid = Util.getFluidFromItem((ItemStack) ingredient); + } + return fluid; + } +}