Skip to content

Commit

Permalink
jei fluid drag compact
Browse files Browse the repository at this point in the history
  • Loading branch information
GlodBlock committed Dec 19, 2022
1 parent 813b871 commit cbd8161
Show file tree
Hide file tree
Showing 3 changed files with 121 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@
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;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;

public class GuiExtendedFluidPatternTerminal extends GuiExpandedProcessingPatternTerm {

Expand All @@ -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 );
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -151,4 +150,21 @@ protected void handleMouseClick(Slot slot, int slotIdx, int mouseButton, ClickTy
super.handleMouseClick(slot, slotIdx, mouseButton, clickType);
}

@Override
public List<Target<?>> getPhantomTargets(Object ingredient) {
if (FluidPacketTarget.covertFluid(ingredient) != null) {
List<Target<?>> 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);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,20 +15,24 @@
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;
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;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;

import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;

public class GuiFluidPatternTerminal extends GuiPatternTerm {

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

Expand Down Expand Up @@ -164,4 +167,21 @@ protected void handleMouseClick(Slot slot, int slotIdx, int mouseButton, ClickTy
super.handleMouseClick(slot, slotIdx, mouseButton, clickType);
}

@Override
public List<Target<?>> getPhantomTargets(Object ingredient) {
if (!this.container.isCraftingMode() && FluidPacketTarget.covertFluid(ingredient) != null) {
List<Target<?>> 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);
}
}

}
Original file line number Diff line number Diff line change
@@ -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<Object> {

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;
}
}

0 comments on commit cbd8161

Please sign in to comment.