From 41180792e19efc16866acca169b1520e8a450633 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salom=C3=A3o?= Date: Mon, 12 Apr 2021 23:51:49 -0300 Subject: [PATCH 1/5] Cellworkbench acts weird missing bookmark dragging --- .../java/appeng/client/gui/AEBaseGui.java | 6 + .../java/appeng/client/gui/AEGuiHandler.java | 74 +++++++-- .../gui/implementations/GuiPatternTerm.java | 61 +++++++- .../gui/implementations/GuiUpgradeable.java | 148 +++++++++++++++++- .../interfaces/IJEIGhostIngredients.java | 18 +++ .../sync/packets/PacketInventoryAction.java | 127 ++++++++++++++- .../java/appeng/helpers/InventoryAction.java | 3 +- .../integration/modules/jei/JEIPlugin.java | 1 + 8 files changed, 422 insertions(+), 16 deletions(-) create mode 100644 src/main/java/appeng/container/interfaces/IJEIGhostIngredients.java diff --git a/src/main/java/appeng/client/gui/AEBaseGui.java b/src/main/java/appeng/client/gui/AEBaseGui.java index de1448f0a..6a7041886 100644 --- a/src/main/java/appeng/client/gui/AEBaseGui.java +++ b/src/main/java/appeng/client/gui/AEBaseGui.java @@ -106,6 +106,12 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain private Stopwatch dbl_clickTimer = Stopwatch.createStarted(); private ItemStack dbl_whichItem = ItemStack.EMPTY; private Slot bl_clicked; + + public List getGuiSlots() + { + return guiSlots; + } + protected final List guiSlots = new ArrayList<>(); public AEBaseGui( final Container container ) diff --git a/src/main/java/appeng/client/gui/AEGuiHandler.java b/src/main/java/appeng/client/gui/AEGuiHandler.java index 749ae4a85..22bc1a32e 100644 --- a/src/main/java/appeng/client/gui/AEGuiHandler.java +++ b/src/main/java/appeng/client/gui/AEGuiHandler.java @@ -2,24 +2,23 @@ package appeng.client.gui; import javax.annotation.Nullable; import appeng.api.storage.data.IAEItemStack; -import appeng.client.gui.implementations.GuiCraftAmount; -import appeng.client.gui.implementations.GuiCraftConfirm; -import appeng.client.gui.implementations.GuiCraftingCPU; -import appeng.client.gui.widgets.GuiCustomSlot; -import appeng.container.implementations.ContainerCraftAmount; +import appeng.client.gui.implementations.*; +import appeng.container.interfaces.IJEIGhostIngredients; +import appeng.container.slot.SlotFake; +import appeng.fluids.client.gui.*; +import appeng.fluids.client.gui.widgets.GuiFluidSlot; import mezz.jei.api.gui.IAdvancedGuiHandler; -import net.minecraft.client.renderer.RenderItem; -import net.minecraft.inventory.Slot; -import net.minecraft.item.ItemStack; +import mezz.jei.api.gui.IGhostIngredientHandler; +import net.minecraft.client.gui.GuiScreen; +import net.minecraftforge.fluids.FluidStack; import java.awt.*; import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.List; -public class AEGuiHandler implements IAdvancedGuiHandler +public class AEGuiHandler implements IAdvancedGuiHandler, IGhostIngredientHandler { @Override @@ -39,7 +38,7 @@ public class AEGuiHandler implements IAdvancedGuiHandler @Override public Object getIngredientUnderMouse( AEBaseGui guiContainer, int mouseX, int mouseY ) { - List visual = new ArrayList<>(); + List visual; int guiSlotIdx = 0; Object result = null; if( guiContainer instanceof GuiCraftConfirm ) @@ -94,4 +93,57 @@ public class AEGuiHandler implements IAdvancedGuiHandler if( guiSloty > ( rows - 1 ) || mouseY < guitop + yo ) return -1; return ( guiSloty * 3 ) + guiSlotx + ( currentScroll * 3 ); } + + @Override + public List> getTargets( AEBaseGui gui, I ingredient, boolean doStart ) + { + ArrayList> targets = new ArrayList<>(); + if( gui instanceof IJEIGhostIngredients ) + { + IJEIGhostIngredients g = (IJEIGhostIngredients) gui; + List> phantomTargets = g.getPhantomTargets( ingredient ); + targets.addAll( (List>) (Object) phantomTargets ); + } + if( doStart ) + { + if( GuiScreen.isShiftKeyDown() ) + { + if( gui instanceof GuiUpgradeable || gui instanceof GuiPatternTerm ) + { + IJEIGhostIngredients ghostGui = ( (IJEIGhostIngredients) gui ); + for( Target target : targets ) + { + if( ghostGui.getFakeSlotTargetMap().get( target ) instanceof SlotFake ) + { + if( ( (SlotFake) ghostGui.getFakeSlotTargetMap().get( target ) ).getStack().isEmpty() ) + { + target.accept( ingredient ); + break; + } + } + else if( ghostGui.getFakeSlotTargetMap().get( target ) instanceof GuiFluidSlot ) + { + if( ( (GuiFluidSlot) ghostGui.getFakeSlotTargetMap().get( target ) ).getFluidStack() == null ) + { + target.accept( ingredient ); + break; + } + } + } + } + } + } + return targets; + } + + @Override + public void onComplete(){ + } + + @Override + public boolean shouldHighlightTargets() + { + return true; + } + } diff --git a/src/main/java/appeng/client/gui/implementations/GuiPatternTerm.java b/src/main/java/appeng/client/gui/implementations/GuiPatternTerm.java index ffaa435b3..b61cee120 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiPatternTerm.java +++ b/src/main/java/appeng/client/gui/implementations/GuiPatternTerm.java @@ -19,11 +19,21 @@ package appeng.client.gui.implementations; +import java.awt.*; import java.io.IOException; +import java.util.*; +import java.util.List; +import appeng.container.interfaces.IJEIGhostIngredients; +import appeng.container.slot.SlotFake; +import appeng.core.sync.packets.PacketInventoryAction; +import appeng.helpers.InventoryAction; +import appeng.util.item.AEItemStack; +import mezz.jei.api.gui.IGhostIngredientHandler.Target; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.init.Blocks; +import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import appeng.api.config.ActionItems; @@ -40,7 +50,7 @@ import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketValueConfig; -public class GuiPatternTerm extends GuiMEMonitorable +public class GuiPatternTerm extends GuiMEMonitorable implements IJEIGhostIngredients { private static final String BACKGROUND_CRAFTING_MODE = "guis/pattern.png"; @@ -67,6 +77,7 @@ public class GuiPatternTerm extends GuiMEMonitorable private GuiImgButton divThreeBtn; private GuiImgButton minusOneBtn; private GuiImgButton maxCountBtn; + public Map,Object> mapTargetSlot = new HashMap<>(); public GuiPatternTerm( final InventoryPlayer inventoryPlayer, final ITerminalHost te ) { @@ -274,4 +285,52 @@ public class GuiPatternTerm extends GuiMEMonitorable s.yPos = s.getY() + this.ySize - 78 - offsetPlayerSide; } + + @Override + public List> getPhantomTargets(Object ingredient) { + if (!(ingredient instanceof ItemStack )) { + return Collections.emptyList(); + } + List> targets = new ArrayList<>(); + for( Slot slot : this.inventorySlots.inventorySlots ) + { + if( slot instanceof SlotFake ) + { + ItemStack itemStack = (ItemStack) ingredient; + Target target = new Target() + { + @Override + public Rectangle getArea() + { + return new Rectangle( getGuiLeft() + slot.xPos, getGuiTop() + slot.yPos, 16, 16 ); + } + + @Override + public void accept( Object ingredient ) + { + final PacketInventoryAction p; + try + { + p = new PacketInventoryAction( InventoryAction.PLACE_JEI_GHOST_ITEM, (SlotFake) slot, AEItemStack.fromItemStack( itemStack ) ); + NetworkHandler.instance().sendToServer( p ); + + } + catch( IOException e ) + { + e.printStackTrace(); + } + } + }; + targets.add( target ); + mapTargetSlot.putIfAbsent( target, slot ); + } + } + return targets; + } + + @Override + public Map, Object> getFakeSlotTargetMap() + { + return mapTargetSlot; + } } diff --git a/src/main/java/appeng/client/gui/implementations/GuiUpgradeable.java b/src/main/java/appeng/client/gui/implementations/GuiUpgradeable.java index c2cff22d3..7e6f7f5c3 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiUpgradeable.java +++ b/src/main/java/appeng/client/gui/implementations/GuiUpgradeable.java @@ -19,8 +19,29 @@ package appeng.client.gui.implementations; +import java.awt.*; import java.io.IOException; +import java.util.*; +import java.util.List; +import appeng.client.gui.widgets.GuiCustomSlot; +import appeng.container.interfaces.IJEIGhostIngredients; +import appeng.container.slot.SlotFake; +import appeng.core.sync.packets.PacketInventoryAction; +import appeng.fluids.client.gui.widgets.GuiFluidSlot; +import appeng.fluids.util.AEFluidStack; +import appeng.helpers.InventoryAction; +import appeng.util.item.AEItemStack; +import mezz.jei.api.gui.IGhostIngredientHandler.Target; +import net.minecraft.block.Block; +import net.minecraft.inventory.Slot; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fluids.BlockFluidBase; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidRegistry; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import org.lwjgl.input.Mouse; import net.minecraft.client.gui.GuiButton; @@ -43,9 +64,9 @@ import appeng.parts.automation.PartExportBus; import appeng.parts.automation.PartImportBus; -public class GuiUpgradeable extends AEBaseGui +public class GuiUpgradeable extends AEBaseGui implements IJEIGhostIngredients { - + private final Map,Object> mapTargetSlot = new HashMap<>(); protected final ContainerUpgradeable cvb; protected final IUpgradeableHost bc; @@ -200,4 +221,127 @@ public class GuiUpgradeable extends AEBaseGui NetworkHandler.instance().sendToServer( new PacketConfigButton( this.schedulingMode.getSetting(), backwards ) ); } } + + @Override + public List> getPhantomTargets(Object ingredient) + { + mapTargetSlot.clear(); + + FluidStack fluidStack = null; + ItemStack itemStack = ItemStack.EMPTY; + + if( ingredient instanceof ItemStack ) + { + itemStack = (ItemStack) ingredient; + + if( itemStack.hasCapability( CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null ) ) + { + fluidStack = ( itemStack.getCapability( CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null ).drain( Integer.MAX_VALUE, false ) ); + } + if( fluidStack == null ) + { + NBTTagCompound tagCompound = itemStack.getTagCompound(); + if( tagCompound != null && tagCompound.hasKey( "Fluid" ) ) + { + Fluid fluid = FluidRegistry.getFluid( tagCompound.getString( "Fluid" ) ); + fluidStack = new FluidStack( fluid, 1000 ); + } + } + if( fluidStack == null ) + { + Block maybeFluidBlock = Block.getBlockFromItem( itemStack.getItem() ); + if( Block.getBlockFromItem( itemStack.getItem() ) instanceof BlockFluidBase ) + { + Fluid fluid = ( (BlockFluidBase) maybeFluidBlock ).getFluid(); + fluidStack = new FluidStack( fluid, 1000 ); + } + } + } + else if( ingredient instanceof FluidStack ) + { + fluidStack = (FluidStack) ingredient; + } + + List> targets = new ArrayList<>(); + + if( !itemStack.isEmpty() ) + { + for( Slot slot : this.inventorySlots.inventorySlots ) + { + if( slot instanceof SlotFake ) + { + ItemStack finalItemStack = itemStack; + Target targetItem = new Target() + { + @Override + public Rectangle getArea() + { + return new Rectangle( getGuiLeft() + slot.xPos, getGuiTop() + slot.yPos, 16, 16 ); + } + + @Override + public void accept( Object ingredient ) + { + final PacketInventoryAction p; + try + { + p = new PacketInventoryAction( InventoryAction.PLACE_JEI_GHOST_ITEM, (SlotFake) slot, AEItemStack.fromItemStack( finalItemStack ) ); + NetworkHandler.instance().sendToServer( p ); + + } + catch( IOException e ) + { + e.printStackTrace(); + } + } + }; + targets.add( targetItem ); + mapTargetSlot.putIfAbsent( targetItem, slot ); + } + } + } + if( fluidStack != null ) + { + for( GuiCustomSlot guiCustomSlot : this.guiSlots ) + { + if( guiCustomSlot instanceof GuiFluidSlot ) + { + FluidStack finalFluidStack = fluidStack; + Target targetFluid = new Target() + { + @Override + public Rectangle getArea() + { + return new Rectangle( getGuiLeft() + guiCustomSlot.xPos(), getGuiTop() + guiCustomSlot.yPos(), 16, 16 ); + } + + @Override + public void accept( Object ingredient ) + { + final PacketInventoryAction p; + try + { + p = new PacketInventoryAction( InventoryAction.PLACE_JEI_GHOST_ITEM, (GuiFluidSlot) guiCustomSlot, AEFluidStack.fromFluidStack( finalFluidStack ) ); + NetworkHandler.instance().sendToServer( p ); + + } + catch( IOException e ) + { + e.printStackTrace(); + } + } + }; + targets.add( targetFluid ); + mapTargetSlot.putIfAbsent( targetFluid, guiCustomSlot ); + } + } + } + return targets; + } + + @Override + public Map, Object> getFakeSlotTargetMap() + { + return mapTargetSlot; + } } diff --git a/src/main/java/appeng/container/interfaces/IJEIGhostIngredients.java b/src/main/java/appeng/container/interfaces/IJEIGhostIngredients.java new file mode 100644 index 000000000..f70eb0630 --- /dev/null +++ b/src/main/java/appeng/container/interfaces/IJEIGhostIngredients.java @@ -0,0 +1,18 @@ +package appeng.container.interfaces; + +import mezz.jei.api.gui.IGhostIngredientHandler.Target; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + + +public interface IJEIGhostIngredients +{ + List> getPhantomTargets( Object ingredient ); + + default Map, Object> getFakeSlotTargetMap(){ + return new HashMap<>(); + } + +} \ No newline at end of file diff --git a/src/main/java/appeng/core/sync/packets/PacketInventoryAction.java b/src/main/java/appeng/core/sync/packets/PacketInventoryAction.java index 0bb0dc71f..3feeaf6df 100644 --- a/src/main/java/appeng/core/sync/packets/PacketInventoryAction.java +++ b/src/main/java/appeng/core/sync/packets/PacketInventoryAction.java @@ -21,9 +21,17 @@ package appeng.core.sync.packets; import java.io.IOException; +import appeng.api.storage.data.IAEFluidStack; +import appeng.client.gui.implementations.GuiUpgradeable; +import appeng.client.gui.widgets.GuiCustomSlot; +import appeng.container.slot.SlotFake; +import appeng.fluids.client.gui.GuiFluidInterface; +import appeng.fluids.client.gui.widgets.GuiFluidSlot; +import appeng.fluids.util.AEFluidStack; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; +import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; @@ -49,6 +57,7 @@ public class PacketInventoryAction extends AppEngPacket private final int slot; private final long id; private final IAEItemStack slotItem; + private final IAEFluidStack slotFluid; // automatic. public PacketInventoryAction( final ByteBuf stream ) throws IOException @@ -57,6 +66,8 @@ public class PacketInventoryAction extends AppEngPacket this.slot = stream.readInt(); this.id = stream.readLong(); final boolean hasItem = stream.readBoolean(); + final boolean hasFluid = stream.readBoolean(); + if( hasItem ) { this.slotItem = AEItemStack.fromPacket( stream ); @@ -65,12 +76,19 @@ public class PacketInventoryAction extends AppEngPacket { this.slotItem = null; } + if( hasFluid ) + { + this.slotFluid = AEFluidStack.fromPacket( stream ); + } + else + { + this.slotFluid = null; + } } // api public PacketInventoryAction( final InventoryAction action, final int slot, final IAEItemStack slotItem ) throws IOException { - if( Platform.isClient() ) { throw new IllegalStateException( "invalid packet, client cannot post inv actions with stacks." ); @@ -80,6 +98,7 @@ public class PacketInventoryAction extends AppEngPacket this.slot = slot; this.id = 0; this.slotItem = slotItem; + this.slotFluid = null; final ByteBuf data = Unpooled.buffer(); @@ -91,16 +110,88 @@ public class PacketInventoryAction extends AppEngPacket if( slotItem == null ) { data.writeBoolean( false ); + data.writeBoolean( false ); } else { data.writeBoolean( true ); + data.writeBoolean( false ); slotItem.writeToPacket( data ); } this.configureWrite( data ); } + public PacketInventoryAction( final InventoryAction action, final SlotFake slot, final IAEItemStack slotItem ) throws IOException + { + if( action != InventoryAction.PLACE_JEI_GHOST_ITEM ) + { + throw new IllegalStateException( "invalid packet, client cannot post inv actions with stacks." ); + } + + this.action = action; + this.slot = slot.slotNumber; + this.id = 0; + this.slotItem = slotItem; + this.slotFluid = null; + + final ByteBuf data = Unpooled.buffer(); + + data.writeInt( this.getPacketID() ); + data.writeInt( action.ordinal() ); + data.writeInt( slot.slotNumber ); + data.writeLong( this.id ); + + if( slotItem == null ) + { + data.writeBoolean( false ); + data.writeBoolean( false ); + } + else + { + data.writeBoolean( true ); + data.writeBoolean( false ); + slotItem.writeToPacket( data ); + } + + + this.configureWrite( data ); + } + + public PacketInventoryAction( final InventoryAction action, final GuiFluidSlot slot, final IAEFluidStack slotFluid ) throws IOException + { + if( action != InventoryAction.PLACE_JEI_GHOST_ITEM ) + { + throw new IllegalStateException( "invalid packet, client cannot post inv actions with stacks." ); + } + + this.action = action; + this.slot = slot.getId(); + this.id = 2; + this.slotFluid = slotFluid; + this.slotItem = null; + + final ByteBuf data = Unpooled.buffer(); + + data.writeInt( this.getPacketID() ); + data.writeInt( action.ordinal() ); + data.writeInt( slot.getId() ); + data.writeLong( this.id ); + data.writeBoolean( false ); + + if( slotFluid == null ) + { + data.writeBoolean( false ); + } + else + { + data.writeBoolean( true ); + slotFluid.writeToPacket( data ); + } + + this.configureWrite( data ); + } + // api public PacketInventoryAction( final InventoryAction action, final int slot, final long id ) { @@ -108,6 +199,7 @@ public class PacketInventoryAction extends AppEngPacket this.slot = slot; this.id = id; this.slotItem = null; + this.slotFluid = null; final ByteBuf data = Unpooled.buffer(); @@ -116,6 +208,7 @@ public class PacketInventoryAction extends AppEngPacket data.writeInt( slot ); data.writeLong( id ); data.writeBoolean( false ); + data.writeBoolean( false ); this.configureWrite( data ); } @@ -150,6 +243,38 @@ public class PacketInventoryAction extends AppEngPacket } } } + else if( this.action == InventoryAction.PLACE_JEI_GHOST_ITEM ) + { + if( sender.openContainer.inventorySlots.get( this.slot ) instanceof SlotFake ) + { + if( this.slotItem != null ) sender.openContainer.inventorySlots.get( this.slot ).putStack( this.slotItem.createItemStack() ); + else sender.openContainer.inventorySlots.get( this.slot ).putStack( ItemStack.EMPTY ); + } + if( Minecraft.getMinecraft().currentScreen instanceof GuiUpgradeable ) + { + GuiUpgradeable cs = ( (GuiUpgradeable) Minecraft.getMinecraft().currentScreen ); + if( cs.getGuiSlots().size() > 0 ) + { + GuiCustomSlot ct = cs.getGuiSlots().get( this.slot ); + if( this.slotFluid != null ) + { + if( ct instanceof GuiFluidSlot ) + { + GuiFluidSlot gfs = (GuiFluidSlot) ct; + gfs.setFluidStack( this.slotFluid ); + } + } + else + { + if( ct instanceof GuiFluidSlot ) + { + GuiFluidSlot gfs = (GuiFluidSlot) ct; + gfs.setFluidStack( null ); + } + } + } + } + } else { baseContainer.doAction( sender, this.action, this.slot, this.id ); diff --git a/src/main/java/appeng/helpers/InventoryAction.java b/src/main/java/appeng/helpers/InventoryAction.java index 697ea0b08..6c545e8c8 100644 --- a/src/main/java/appeng/helpers/InventoryAction.java +++ b/src/main/java/appeng/helpers/InventoryAction.java @@ -43,5 +43,6 @@ public enum InventoryAction ROLL_UP, ROLL_DOWN, AUTO_CRAFT, - PLACE_SINGLE + PLACE_SINGLE, + PLACE_JEI_GHOST_ITEM } diff --git a/src/main/java/appeng/integration/modules/jei/JEIPlugin.java b/src/main/java/appeng/integration/modules/jei/JEIPlugin.java index 50e048d50..50f98c693 100644 --- a/src/main/java/appeng/integration/modules/jei/JEIPlugin.java +++ b/src/main/java/appeng/integration/modules/jei/JEIPlugin.java @@ -97,6 +97,7 @@ public class JEIPlugin implements IModPlugin AEGuiHandler aeGuiHandler = new AEGuiHandler(); registry.addAdvancedGuiHandlers(aeGuiHandler); + registry.addGhostIngredientHandler( aeGuiHandler.getGuiContainerClass(), aeGuiHandler); } private void registerDescriptions( IDefinitions definitions, IModRegistry registry ) From f776b4d5484db4c728f7de64d8b8d1fc76d734d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salom=C3=A3o?= Date: Tue, 13 Apr 2021 12:33:52 -0300 Subject: [PATCH 2/5] wip --- .../gui/implementations/GuiUpgradeable.java | 2 +- .../appeng/container/slot/IJEITargetSlot.java | 4 + .../java/appeng/container/slot/SlotFake.java | 2 +- .../sync/packets/PacketInventoryAction.java | 82 ++++--------------- .../client/gui/widgets/GuiFluidSlot.java | 3 +- 5 files changed, 23 insertions(+), 70 deletions(-) create mode 100644 src/main/java/appeng/container/slot/IJEITargetSlot.java diff --git a/src/main/java/appeng/client/gui/implementations/GuiUpgradeable.java b/src/main/java/appeng/client/gui/implementations/GuiUpgradeable.java index 7e6f7f5c3..e77dab278 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiUpgradeable.java +++ b/src/main/java/appeng/client/gui/implementations/GuiUpgradeable.java @@ -321,7 +321,7 @@ public class GuiUpgradeable extends AEBaseGui implements IJEIGhostIngredients final PacketInventoryAction p; try { - p = new PacketInventoryAction( InventoryAction.PLACE_JEI_GHOST_ITEM, (GuiFluidSlot) guiCustomSlot, AEFluidStack.fromFluidStack( finalFluidStack ) ); + p = new PacketInventoryAction( InventoryAction.PLACE_JEI_GHOST_ITEM, (GuiFluidSlot) guiCustomSlot, AEItemStack.fromItemStack(AEFluidStack.fromFluidStack( finalFluidStack ).asItemStackRepresentation() )); NetworkHandler.instance().sendToServer( p ); } diff --git a/src/main/java/appeng/container/slot/IJEITargetSlot.java b/src/main/java/appeng/container/slot/IJEITargetSlot.java new file mode 100644 index 000000000..c6d0f0429 --- /dev/null +++ b/src/main/java/appeng/container/slot/IJEITargetSlot.java @@ -0,0 +1,4 @@ +package appeng.container.slot; + +public interface IJEITargetSlot { +} diff --git a/src/main/java/appeng/container/slot/SlotFake.java b/src/main/java/appeng/container/slot/SlotFake.java index 8abe0d2e9..96b0a2212 100644 --- a/src/main/java/appeng/container/slot/SlotFake.java +++ b/src/main/java/appeng/container/slot/SlotFake.java @@ -24,7 +24,7 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.items.IItemHandler; -public class SlotFake extends AppEngSlot +public class SlotFake extends AppEngSlot implements IJEITargetSlot { public SlotFake( final IItemHandler inv, final int idx, final int x, final int y ) diff --git a/src/main/java/appeng/core/sync/packets/PacketInventoryAction.java b/src/main/java/appeng/core/sync/packets/PacketInventoryAction.java index 3feeaf6df..88ad68e35 100644 --- a/src/main/java/appeng/core/sync/packets/PacketInventoryAction.java +++ b/src/main/java/appeng/core/sync/packets/PacketInventoryAction.java @@ -24,8 +24,8 @@ import java.io.IOException; import appeng.api.storage.data.IAEFluidStack; import appeng.client.gui.implementations.GuiUpgradeable; import appeng.client.gui.widgets.GuiCustomSlot; +import appeng.container.slot.IJEITargetSlot; import appeng.container.slot.SlotFake; -import appeng.fluids.client.gui.GuiFluidInterface; import appeng.fluids.client.gui.widgets.GuiFluidSlot; import appeng.fluids.util.AEFluidStack; import io.netty.buffer.ByteBuf; @@ -48,6 +48,7 @@ import appeng.core.sync.network.INetworkInfo; import appeng.helpers.InventoryAction; import appeng.util.Platform; import appeng.util.item.AEItemStack; +import net.minecraftforge.fluids.FluidStack; public class PacketInventoryAction extends AppEngPacket @@ -57,7 +58,6 @@ public class PacketInventoryAction extends AppEngPacket private final int slot; private final long id; private final IAEItemStack slotItem; - private final IAEFluidStack slotFluid; // automatic. public PacketInventoryAction( final ByteBuf stream ) throws IOException @@ -66,7 +66,6 @@ public class PacketInventoryAction extends AppEngPacket this.slot = stream.readInt(); this.id = stream.readLong(); final boolean hasItem = stream.readBoolean(); - final boolean hasFluid = stream.readBoolean(); if( hasItem ) { @@ -76,14 +75,6 @@ public class PacketInventoryAction extends AppEngPacket { this.slotItem = null; } - if( hasFluid ) - { - this.slotFluid = AEFluidStack.fromPacket( stream ); - } - else - { - this.slotFluid = null; - } } // api @@ -98,7 +89,6 @@ public class PacketInventoryAction extends AppEngPacket this.slot = slot; this.id = 0; this.slotItem = slotItem; - this.slotFluid = null; final ByteBuf data = Unpooled.buffer(); @@ -110,19 +100,17 @@ public class PacketInventoryAction extends AppEngPacket if( slotItem == null ) { data.writeBoolean( false ); - data.writeBoolean( false ); } else { data.writeBoolean( true ); - data.writeBoolean( false ); slotItem.writeToPacket( data ); } this.configureWrite( data ); } - public PacketInventoryAction( final InventoryAction action, final SlotFake slot, final IAEItemStack slotItem ) throws IOException + public PacketInventoryAction(final InventoryAction action, final IJEITargetSlot slot, final IAEItemStack slotItem ) throws IOException { if( action != InventoryAction.PLACE_JEI_GHOST_ITEM ) { @@ -130,65 +118,29 @@ public class PacketInventoryAction extends AppEngPacket } this.action = action; - this.slot = slot.slotNumber; + if (slot instanceof SlotFake) + this.slot = ((SlotFake) slot).slotNumber; + else this.slot = ((GuiFluidSlot) slot).getId(); this.id = 0; this.slotItem = slotItem; - this.slotFluid = null; final ByteBuf data = Unpooled.buffer(); data.writeInt( this.getPacketID() ); data.writeInt( action.ordinal() ); - data.writeInt( slot.slotNumber ); + data.writeInt( this.slot ); data.writeLong( this.id ); if( slotItem == null ) { data.writeBoolean( false ); - data.writeBoolean( false ); } else { data.writeBoolean( true ); - data.writeBoolean( false ); slotItem.writeToPacket( data ); } - - this.configureWrite( data ); - } - - public PacketInventoryAction( final InventoryAction action, final GuiFluidSlot slot, final IAEFluidStack slotFluid ) throws IOException - { - if( action != InventoryAction.PLACE_JEI_GHOST_ITEM ) - { - throw new IllegalStateException( "invalid packet, client cannot post inv actions with stacks." ); - } - - this.action = action; - this.slot = slot.getId(); - this.id = 2; - this.slotFluid = slotFluid; - this.slotItem = null; - - final ByteBuf data = Unpooled.buffer(); - - data.writeInt( this.getPacketID() ); - data.writeInt( action.ordinal() ); - data.writeInt( slot.getId() ); - data.writeLong( this.id ); - data.writeBoolean( false ); - - if( slotFluid == null ) - { - data.writeBoolean( false ); - } - else - { - data.writeBoolean( true ); - slotFluid.writeToPacket( data ); - } - this.configureWrite( data ); } @@ -199,7 +151,6 @@ public class PacketInventoryAction extends AppEngPacket this.slot = slot; this.id = id; this.slotItem = null; - this.slotFluid = null; final ByteBuf data = Unpooled.buffer(); @@ -208,7 +159,6 @@ public class PacketInventoryAction extends AppEngPacket data.writeInt( slot ); data.writeLong( id ); data.writeBoolean( false ); - data.writeBoolean( false ); this.configureWrite( data ); } @@ -247,7 +197,7 @@ public class PacketInventoryAction extends AppEngPacket { if( sender.openContainer.inventorySlots.get( this.slot ) instanceof SlotFake ) { - if( this.slotItem != null ) sender.openContainer.inventorySlots.get( this.slot ).putStack( this.slotItem.createItemStack() ); + if( this.slotItem != null ) sender.openContainer.inventorySlots.get( this.slot ).putStack( this.slotItem.asItemStackRepresentation() ); else sender.openContainer.inventorySlots.get( this.slot ).putStack( ItemStack.EMPTY ); } if( Minecraft.getMinecraft().currentScreen instanceof GuiUpgradeable ) @@ -256,21 +206,19 @@ public class PacketInventoryAction extends AppEngPacket if( cs.getGuiSlots().size() > 0 ) { GuiCustomSlot ct = cs.getGuiSlots().get( this.slot ); - if( this.slotFluid != null ) + GuiFluidSlot gfs = (GuiFluidSlot) ct; + if( this.slotItem != null ) { - if( ct instanceof GuiFluidSlot ) + IAEFluidStack aefs = AEFluidStack.fromNBT(this.slotItem.getDefinition().getTagCompound()); + if (aefs != null) { - GuiFluidSlot gfs = (GuiFluidSlot) ct; - gfs.setFluidStack( this.slotFluid ); + FluidStack fluid = aefs.getFluidStack(); + gfs.setFluidStack(AEFluidStack.fromFluidStack(fluid)); } } else { - if( ct instanceof GuiFluidSlot ) - { - GuiFluidSlot gfs = (GuiFluidSlot) ct; - gfs.setFluidStack( null ); - } + gfs.setFluidStack( null ); } } } 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 7b1f7c1d5..d0e432a08 100644 --- a/src/main/java/appeng/fluids/client/gui/widgets/GuiFluidSlot.java +++ b/src/main/java/appeng/fluids/client/gui/widgets/GuiFluidSlot.java @@ -4,6 +4,7 @@ package appeng.fluids.client.gui.widgets; import java.util.Collections; +import appeng.container.slot.IJEITargetSlot; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.texture.TextureAtlasSprite; @@ -23,7 +24,7 @@ import appeng.fluids.util.AEFluidStack; import appeng.fluids.util.IAEFluidTank; -public class GuiFluidSlot extends GuiCustomSlot +public class GuiFluidSlot extends GuiCustomSlot implements IJEITargetSlot { private final IAEFluidTank fluids; private final int slot; From d1ddf53d996e774f0254af7112a7e2a83448a95c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salom=C3=A3o?= Date: Tue, 13 Apr 2021 14:54:52 -0300 Subject: [PATCH 3/5] wip 2 --- .../gui/implementations/GuiUpgradeable.java | 86 ++++++++----------- 1 file changed, 36 insertions(+), 50 deletions(-) diff --git a/src/main/java/appeng/client/gui/implementations/GuiUpgradeable.java b/src/main/java/appeng/client/gui/implementations/GuiUpgradeable.java index e77dab278..8e60e2d30 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiUpgradeable.java +++ b/src/main/java/appeng/client/gui/implementations/GuiUpgradeable.java @@ -26,6 +26,7 @@ import java.util.List; import appeng.client.gui.widgets.GuiCustomSlot; import appeng.container.interfaces.IJEIGhostIngredients; +import appeng.container.slot.IJEITargetSlot; import appeng.container.slot.SlotFake; import appeng.core.sync.packets.PacketInventoryAction; import appeng.fluids.client.gui.widgets.GuiFluidSlot; @@ -37,10 +38,7 @@ import net.minecraft.block.Block; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.fluids.BlockFluidBase; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidRegistry; -import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.*; import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import org.lwjgl.input.Mouse; @@ -264,28 +262,54 @@ public class GuiUpgradeable extends AEBaseGui implements IJEIGhostIngredients List> targets = new ArrayList<>(); - if( !itemStack.isEmpty() ) - { - for( Slot slot : this.inventorySlots.inventorySlots ) + List slots = new ArrayList<>(); + if (this.inventorySlots.inventorySlots.size() > 0) { + for (Slot slot : this.inventorySlots.inventorySlots) { + if (slot instanceof SlotFake) { + slots.add((IJEITargetSlot) slot); + } + } + } + if(this.getGuiSlots().size() > 0) { + for (GuiCustomSlot slot : this.getGuiSlots()) { + if (slot instanceof GuiFluidSlot) { + slots.add((IJEITargetSlot) slot); + } + } + } + for( Object slot : slots ) { - if( slot instanceof SlotFake ) - { ItemStack finalItemStack = itemStack; + FluidStack finalFluidStack = fluidStack; Target targetItem = new Target() { @Override public Rectangle getArea() { - return new Rectangle( getGuiLeft() + slot.xPos, getGuiTop() + slot.yPos, 16, 16 ); + if (slot instanceof SlotFake) + return new Rectangle( getGuiLeft() + ((SlotFake)slot).xPos, getGuiTop() + ((SlotFake)slot).yPos, 16, 16 ); + else { + return new Rectangle( getGuiLeft() + ((GuiFluidSlot)slot).xPos(), getGuiTop() + ((GuiFluidSlot)slot).yPos(), 16, 16 ); + } } @Override public void accept( Object ingredient ) { - final PacketInventoryAction p; + PacketInventoryAction p = null; try { - p = new PacketInventoryAction( InventoryAction.PLACE_JEI_GHOST_ITEM, (SlotFake) slot, AEItemStack.fromItemStack( finalItemStack ) ); + if (slot instanceof SlotFake) { + if (finalItemStack.isEmpty() && finalFluidStack != null) { + p = new PacketInventoryAction( InventoryAction.PLACE_JEI_GHOST_ITEM, (IJEITargetSlot) slot, AEItemStack.fromItemStack( FluidUtil.getFilledBucket(finalFluidStack) ) ); + } + else if (!finalItemStack.isEmpty()){ + p = new PacketInventoryAction(InventoryAction.PLACE_JEI_GHOST_ITEM, (IJEITargetSlot) slot, AEItemStack.fromItemStack(finalItemStack)); + } + } + else { + p = new PacketInventoryAction(InventoryAction.PLACE_JEI_GHOST_ITEM, (IJEITargetSlot) slot, AEItemStack.fromItemStack(AEFluidStack.fromFluidStack(finalFluidStack).asItemStackRepresentation())); + } NetworkHandler.instance().sendToServer( p ); } @@ -298,44 +322,6 @@ public class GuiUpgradeable extends AEBaseGui implements IJEIGhostIngredients targets.add( targetItem ); mapTargetSlot.putIfAbsent( targetItem, slot ); } - } - } - if( fluidStack != null ) - { - for( GuiCustomSlot guiCustomSlot : this.guiSlots ) - { - if( guiCustomSlot instanceof GuiFluidSlot ) - { - FluidStack finalFluidStack = fluidStack; - Target targetFluid = new Target() - { - @Override - public Rectangle getArea() - { - return new Rectangle( getGuiLeft() + guiCustomSlot.xPos(), getGuiTop() + guiCustomSlot.yPos(), 16, 16 ); - } - - @Override - public void accept( Object ingredient ) - { - final PacketInventoryAction p; - try - { - p = new PacketInventoryAction( InventoryAction.PLACE_JEI_GHOST_ITEM, (GuiFluidSlot) guiCustomSlot, AEItemStack.fromItemStack(AEFluidStack.fromFluidStack( finalFluidStack ).asItemStackRepresentation() )); - NetworkHandler.instance().sendToServer( p ); - - } - catch( IOException e ) - { - e.printStackTrace(); - } - } - }; - targets.add( targetFluid ); - mapTargetSlot.putIfAbsent( targetFluid, guiCustomSlot ); - } - } - } return targets; } From 10761a1e9d29554dbd30ffb82c83bda14b910d02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salom=C3=A3o?= Date: Wed, 14 Apr 2021 00:04:07 -0300 Subject: [PATCH 4/5] missing click cancel --- .../java/appeng/client/gui/AEBaseGui.java | 13 ++ .../java/appeng/client/gui/AEGuiHandler.java | 27 ++- .../gui/implementations/GuiUpgradeable.java | 157 +++++++++--------- .../sync/packets/PacketInventoryAction.java | 20 ++- .../integration/modules/jei/JEIPlugin.java | 19 ++- 5 files changed, 139 insertions(+), 97 deletions(-) diff --git a/src/main/java/appeng/client/gui/AEBaseGui.java b/src/main/java/appeng/client/gui/AEBaseGui.java index 6a7041886..1b5cfc51a 100644 --- a/src/main/java/appeng/client/gui/AEBaseGui.java +++ b/src/main/java/appeng/client/gui/AEBaseGui.java @@ -36,6 +36,8 @@ import com.google.common.base.Joiner; import com.google.common.base.Stopwatch; import com.google.common.collect.Lists; +import mezz.jei.api.JEIPlugin; +import mezz.jei.api.gui.IGhostIngredientHandler; import net.minecraftforge.fml.common.Optional; import net.minecraftforge.items.IItemHandler; import org.lwjgl.input.Keyboard; @@ -92,6 +94,8 @@ import appeng.fluids.container.slots.IMEFluidSlot; import appeng.helpers.InventoryAction; import yalter.mousetweaks.api.IMTModGuiContainer2; +import static appeng.integration.modules.jei.JEIPlugin.runtime; + @Optional.Interface( iface = "yalter.mousetweaks.api.IMTModGuiContainer2", modid = "mousetweaks" ) public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContainer2 @@ -106,6 +110,7 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain private Stopwatch dbl_clickTimer = Stopwatch.createStarted(); private ItemStack dbl_whichItem = ItemStack.EMPTY; private Slot bl_clicked; + private final AEGuiHandler aeGuiHandler = new AEGuiHandler(); public List getGuiSlots() { @@ -194,6 +199,14 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain this.drawTooltip( (ITooltip) c, mouseX, mouseY ); } } + + if ( isPointInRegion( -guiLeft,-guiTop, mc.displayWidth, mc.displayHeight, mouseX,mouseY)){ + Object o = runtime.getBookmarkOverlay().getIngredientUnderMouse(); + if (o != null) { + aeGuiHandler.getTargets( this,o,true ); + } + } + } protected void drawGuiSlot( GuiCustomSlot slot, int mouseX, int mouseY, float partialTicks ) diff --git a/src/main/java/appeng/client/gui/AEGuiHandler.java b/src/main/java/appeng/client/gui/AEGuiHandler.java index 22bc1a32e..fe571d76b 100644 --- a/src/main/java/appeng/client/gui/AEGuiHandler.java +++ b/src/main/java/appeng/client/gui/AEGuiHandler.java @@ -5,14 +5,16 @@ import appeng.api.storage.data.IAEItemStack; import appeng.client.gui.implementations.*; import appeng.container.interfaces.IJEIGhostIngredients; import appeng.container.slot.SlotFake; -import appeng.fluids.client.gui.*; import appeng.fluids.client.gui.widgets.GuiFluidSlot; import mezz.jei.api.gui.IAdvancedGuiHandler; import mezz.jei.api.gui.IGhostIngredientHandler; +import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; -import net.minecraftforge.fluids.FluidStack; +import net.minecraft.item.ItemStack; +import org.lwjgl.input.Mouse; import java.awt.*; +import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -20,7 +22,6 @@ import java.util.List; public class AEGuiHandler implements IAdvancedGuiHandler, IGhostIngredientHandler { - @Override public Class getGuiContainerClass() { @@ -106,7 +107,7 @@ public class AEGuiHandler implements IAdvancedGuiHandler, IGhostIngre } if( doStart ) { - if( GuiScreen.isShiftKeyDown() ) + if( GuiScreen.isShiftKeyDown() && Mouse.isButtonDown( 0 ) ) { if( gui instanceof GuiUpgradeable || gui instanceof GuiPatternTerm ) { @@ -117,7 +118,16 @@ public class AEGuiHandler implements IAdvancedGuiHandler, IGhostIngre { if( ( (SlotFake) ghostGui.getFakeSlotTargetMap().get( target ) ).getStack().isEmpty() ) { + Minecraft.getMinecraft().player.inventory.setItemStack( ItemStack.EMPTY ); target.accept( ingredient ); + try + { + gui.handleMouseInput(); + } + catch( IOException e ) + { + e.printStackTrace(); + } break; } } @@ -125,7 +135,16 @@ public class AEGuiHandler implements IAdvancedGuiHandler, IGhostIngre { if( ( (GuiFluidSlot) ghostGui.getFakeSlotTargetMap().get( target ) ).getFluidStack() == null ) { + Minecraft.getMinecraft().player.inventory.setItemStack( ItemStack.EMPTY ); target.accept( ingredient ); + try + { + gui.handleMouseInput(); + } + catch( IOException e ) + { + e.printStackTrace(); + } break; } } diff --git a/src/main/java/appeng/client/gui/implementations/GuiUpgradeable.java b/src/main/java/appeng/client/gui/implementations/GuiUpgradeable.java index 8e60e2d30..67b65c33d 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiUpgradeable.java +++ b/src/main/java/appeng/client/gui/implementations/GuiUpgradeable.java @@ -26,6 +26,7 @@ import java.util.List; import appeng.client.gui.widgets.GuiCustomSlot; import appeng.container.interfaces.IJEIGhostIngredients; +import appeng.container.slot.AppEngSlot; import appeng.container.slot.IJEITargetSlot; import appeng.container.slot.SlotFake; import appeng.core.sync.packets.PacketInventoryAction; @@ -34,12 +35,9 @@ import appeng.fluids.util.AEFluidStack; import appeng.helpers.InventoryAction; import appeng.util.item.AEItemStack; import mezz.jei.api.gui.IGhostIngredientHandler.Target; -import net.minecraft.block.Block; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.fluids.*; -import net.minecraftforge.fluids.capability.CapabilityFluidHandler; import org.lwjgl.input.Mouse; import net.minecraft.client.gui.GuiButton; @@ -231,97 +229,90 @@ public class GuiUpgradeable extends AEBaseGui implements IJEIGhostIngredients if( ingredient instanceof ItemStack ) { itemStack = (ItemStack) ingredient; - - if( itemStack.hasCapability( CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null ) ) - { - fluidStack = ( itemStack.getCapability( CapabilityFluidHandler.FLUID_HANDLER_ITEM_CAPABILITY, null ).drain( Integer.MAX_VALUE, false ) ); - } - if( fluidStack == null ) - { - NBTTagCompound tagCompound = itemStack.getTagCompound(); - if( tagCompound != null && tagCompound.hasKey( "Fluid" ) ) - { - Fluid fluid = FluidRegistry.getFluid( tagCompound.getString( "Fluid" ) ); - fluidStack = new FluidStack( fluid, 1000 ); - } - } - if( fluidStack == null ) - { - Block maybeFluidBlock = Block.getBlockFromItem( itemStack.getItem() ); - if( Block.getBlockFromItem( itemStack.getItem() ) instanceof BlockFluidBase ) - { - Fluid fluid = ( (BlockFluidBase) maybeFluidBlock ).getFluid(); - fluidStack = new FluidStack( fluid, 1000 ); - } - } + fluidStack = FluidUtil.getFluidContained( itemStack ); } else if( ingredient instanceof FluidStack ) { fluidStack = (FluidStack) ingredient; } + if( !( ingredient instanceof ItemStack ) && !( ingredient instanceof FluidStack ) ) + return Collections.emptyList(); + List> targets = new ArrayList<>(); List slots = new ArrayList<>(); - if (this.inventorySlots.inventorySlots.size() > 0) { - for (Slot slot : this.inventorySlots.inventorySlots) { - if (slot instanceof SlotFake) { - slots.add((IJEITargetSlot) slot); - } - } - } - if(this.getGuiSlots().size() > 0) { - for (GuiCustomSlot slot : this.getGuiSlots()) { - if (slot instanceof GuiFluidSlot) { - slots.add((IJEITargetSlot) slot); - } - } - } - for( Object slot : slots ) + if( this.inventorySlots.inventorySlots.size() > 0 ) + { + for( Slot slot : this.inventorySlots.inventorySlots ) { - ItemStack finalItemStack = itemStack; - FluidStack finalFluidStack = fluidStack; - Target targetItem = new Target() - { - @Override - public Rectangle getArea() - { - if (slot instanceof SlotFake) - return new Rectangle( getGuiLeft() + ((SlotFake)slot).xPos, getGuiTop() + ((SlotFake)slot).yPos, 16, 16 ); - else { - return new Rectangle( getGuiLeft() + ((GuiFluidSlot)slot).xPos(), getGuiTop() + ((GuiFluidSlot)slot).yPos(), 16, 16 ); - } - } - - @Override - public void accept( Object ingredient ) - { - PacketInventoryAction p = null; - try - { - if (slot instanceof SlotFake) { - if (finalItemStack.isEmpty() && finalFluidStack != null) { - p = new PacketInventoryAction( InventoryAction.PLACE_JEI_GHOST_ITEM, (IJEITargetSlot) slot, AEItemStack.fromItemStack( FluidUtil.getFilledBucket(finalFluidStack) ) ); - } - else if (!finalItemStack.isEmpty()){ - p = new PacketInventoryAction(InventoryAction.PLACE_JEI_GHOST_ITEM, (IJEITargetSlot) slot, AEItemStack.fromItemStack(finalItemStack)); - } - } - else { - p = new PacketInventoryAction(InventoryAction.PLACE_JEI_GHOST_ITEM, (IJEITargetSlot) slot, AEItemStack.fromItemStack(AEFluidStack.fromFluidStack(finalFluidStack).asItemStackRepresentation())); - } - NetworkHandler.instance().sendToServer( p ); - - } - catch( IOException e ) - { - e.printStackTrace(); - } - } - }; - targets.add( targetItem ); - mapTargetSlot.putIfAbsent( targetItem, slot ); + if( slot instanceof SlotFake && ( !itemStack.isEmpty() || this instanceof GuiCellWorkbench && fluidStack != null && !( (AppEngSlot) slot ).isItemValid( itemStack ) ) ) + { + slots.add( (IJEITargetSlot) slot ); } + } + } + if( this.getGuiSlots().size() > 0 ) + { + for( GuiCustomSlot slot : this.getGuiSlots() ) + { + if( slot instanceof GuiFluidSlot && fluidStack != null ) + { + slots.add( (IJEITargetSlot) slot ); + } + } + } + for( Object slot : slots ) + { + ItemStack finalItemStack = itemStack; + FluidStack finalFluidStack = fluidStack; + Target targetItem = new Target() + { + @Override + public Rectangle getArea() + { + if( slot instanceof SlotFake ) + return new Rectangle( getGuiLeft() + ( (SlotFake) slot ).xPos, getGuiTop() + ( (SlotFake) slot ).yPos, 16, 16 ); + else + { + return new Rectangle( getGuiLeft() + ( (GuiFluidSlot) slot ).xPos(), getGuiTop() + ( (GuiFluidSlot) slot ).yPos(), 16, 16 ); + } + } + + @Override + public void accept( Object ingredient ) + { + PacketInventoryAction p = null; + try + { + if( slot instanceof SlotFake ) + { + if( finalItemStack.isEmpty() && finalFluidStack != null ) + { + p = new PacketInventoryAction( InventoryAction.PLACE_JEI_GHOST_ITEM, (IJEITargetSlot) slot, AEItemStack.fromItemStack( FluidUtil.getFilledBucket( finalFluidStack ) ) ); + } + else if( !finalItemStack.isEmpty() ) + { + p = new PacketInventoryAction( InventoryAction.PLACE_JEI_GHOST_ITEM, (IJEITargetSlot) slot, AEItemStack.fromItemStack( finalItemStack ) ); + } + } + else + { + if( finalFluidStack == null ) return; + p = new PacketInventoryAction( InventoryAction.PLACE_JEI_GHOST_ITEM, (IJEITargetSlot) slot, AEItemStack.fromItemStack( AEFluidStack.fromFluidStack( finalFluidStack ).asItemStackRepresentation() ) ); + } + NetworkHandler.instance().sendToServer( p ); + + } + catch( IOException e ) + { + e.printStackTrace(); + } + } + }; + targets.add( targetItem ); + mapTargetSlot.putIfAbsent( targetItem, slot ); + } return targets; } diff --git a/src/main/java/appeng/core/sync/packets/PacketInventoryAction.java b/src/main/java/appeng/core/sync/packets/PacketInventoryAction.java index 88ad68e35..1ebad5fc2 100644 --- a/src/main/java/appeng/core/sync/packets/PacketInventoryAction.java +++ b/src/main/java/appeng/core/sync/packets/PacketInventoryAction.java @@ -197,7 +197,17 @@ public class PacketInventoryAction extends AppEngPacket { if( sender.openContainer.inventorySlots.get( this.slot ) instanceof SlotFake ) { - if( this.slotItem != null ) sender.openContainer.inventorySlots.get( this.slot ).putStack( this.slotItem.asItemStackRepresentation() ); + if( this.slotItem != null ) { + sender.openContainer.inventorySlots.get( this.slot ).putStack( this.slotItem.asItemStackRepresentation() ); + if (sender.openContainer.inventorySlots.get( this.slot ).getStack().isEmpty()){ + IAEFluidStack aefs = AEFluidStack.fromNBT( this.slotItem.getDefinition().getTagCompound() ); + if( aefs != null ) + { + FluidStack fluid = aefs.getFluidStack(); + sender.openContainer.inventorySlots.get( this.slot ).putStack( AEFluidStack.fromFluidStack( fluid ).asItemStackRepresentation() ); + } + } + } else sender.openContainer.inventorySlots.get( this.slot ).putStack( ItemStack.EMPTY ); } if( Minecraft.getMinecraft().currentScreen instanceof GuiUpgradeable ) @@ -209,11 +219,11 @@ public class PacketInventoryAction extends AppEngPacket GuiFluidSlot gfs = (GuiFluidSlot) ct; if( this.slotItem != null ) { - IAEFluidStack aefs = AEFluidStack.fromNBT(this.slotItem.getDefinition().getTagCompound()); - if (aefs != null) + IAEFluidStack aefs = AEFluidStack.fromNBT( this.slotItem.getDefinition().getTagCompound() ); + if( aefs != null ) { - FluidStack fluid = aefs.getFluidStack(); - gfs.setFluidStack(AEFluidStack.fromFluidStack(fluid)); + FluidStack fluid = aefs.getFluidStack(); + gfs.setFluidStack( AEFluidStack.fromFluidStack( fluid ) ); } } else diff --git a/src/main/java/appeng/integration/modules/jei/JEIPlugin.java b/src/main/java/appeng/integration/modules/jei/JEIPlugin.java index 50f98c693..2ce53fa69 100644 --- a/src/main/java/appeng/integration/modules/jei/JEIPlugin.java +++ b/src/main/java/appeng/integration/modules/jei/JEIPlugin.java @@ -19,6 +19,8 @@ package appeng.integration.modules.jei; +import javax.annotation.Nullable; + import java.util.ArrayList; import java.util.List; import java.util.Optional; @@ -27,14 +29,11 @@ import appeng.client.gui.AEGuiHandler; import com.google.common.collect.ImmutableList; import com.google.common.collect.Lists; +import mezz.jei.api.*; import mezz.jei.config.Constants; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import mezz.jei.api.IJeiRuntime; -import mezz.jei.api.IModPlugin; -import mezz.jei.api.IModRegistry; -import mezz.jei.api.ISubtypeRegistry; import mezz.jei.api.recipe.IRecipeCategoryRegistration; import mezz.jei.api.recipe.VanillaRecipeCategoryUid; @@ -55,8 +54,10 @@ import appeng.items.parts.ItemFacade; @mezz.jei.api.JEIPlugin -public class JEIPlugin implements IModPlugin +public class JEIPlugin implements IModPlugin, IBookmarkOverlay { + public static IJeiRuntime runtime; + @Override public void registerItemSubtypes( ISubtypeRegistry subtypeRegistry ) { @@ -220,5 +221,13 @@ public class JEIPlugin implements IModPlugin { JEIModule jeiModule = (JEIModule) Integrations.jei(); jeiModule.setJei( new JeiRuntimeAdapter( jeiRuntime ) ); + runtime = jeiRuntime; + } + + @Nullable + @Override + public Object getIngredientUnderMouse() + { + return runtime.getBookmarkOverlay().getIngredientUnderMouse(); } } From 399d67b42cc339b448f940960d2cee9a2b993dc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Salom=C3=A3o?= Date: Wed, 14 Apr 2021 21:37:06 -0300 Subject: [PATCH 5/5] made jei recipe transfer more strict when keeping items on the table few cleanup --- .../java/appeng/client/gui/AEBaseGui.java | 34 +++++++++--- .../java/appeng/client/gui/AEGuiHandler.java | 55 +++++-------------- .../gui/implementations/GuiUpgradeable.java | 2 +- .../sync/packets/PacketInventoryAction.java | 4 -- .../core/sync/packets/PacketJEIRecipe.java | 2 +- .../integration/modules/jei/JEIPlugin.java | 12 +--- 6 files changed, 47 insertions(+), 62 deletions(-) diff --git a/src/main/java/appeng/client/gui/AEBaseGui.java b/src/main/java/appeng/client/gui/AEBaseGui.java index 1b5cfc51a..213c08166 100644 --- a/src/main/java/appeng/client/gui/AEBaseGui.java +++ b/src/main/java/appeng/client/gui/AEBaseGui.java @@ -19,6 +19,7 @@ package appeng.client.gui; +import java.awt.*; import java.io.IOException; import java.text.DecimalFormat; import java.text.ParseException; @@ -31,15 +32,13 @@ import java.util.List; import java.util.Set; import java.util.concurrent.TimeUnit; -import appeng.tile.inventory.AppEngInternalInventory; import com.google.common.base.Joiner; import com.google.common.base.Stopwatch; import com.google.common.collect.Lists; -import mezz.jei.api.JEIPlugin; import mezz.jei.api.gui.IGhostIngredientHandler; +import net.minecraft.client.gui.Gui; import net.minecraftforge.fml.common.Optional; -import net.minecraftforge.items.IItemHandler; import org.lwjgl.input.Keyboard; import org.lwjgl.input.Mouse; import org.lwjgl.opengl.GL11; @@ -94,6 +93,7 @@ import appeng.fluids.container.slots.IMEFluidSlot; import appeng.helpers.InventoryAction; import yalter.mousetweaks.api.IMTModGuiContainer2; +import static appeng.integration.modules.jei.JEIPlugin.aeGuiHandler; import static appeng.integration.modules.jei.JEIPlugin.runtime; @@ -110,7 +110,6 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain private Stopwatch dbl_clickTimer = Stopwatch.createStarted(); private ItemStack dbl_whichItem = ItemStack.EMPTY; private Slot bl_clicked; - private final AEGuiHandler aeGuiHandler = new AEGuiHandler(); public List getGuiSlots() { @@ -199,14 +198,35 @@ public abstract class AEBaseGui extends GuiContainer implements IMTModGuiContain this.drawTooltip( (ITooltip) c, mouseX, mouseY ); } } - + /* if ( isPointInRegion( -guiLeft,-guiTop, mc.displayWidth, mc.displayHeight, mouseX,mouseY)){ Object o = runtime.getBookmarkOverlay().getIngredientUnderMouse(); if (o != null) { - aeGuiHandler.getTargets( this,o,true ); + List> hoveredIngredientTargets = aeGuiHandler.getTargets( this, o, false ); + if (hoveredIngredientTargets.size() > 0 ) + { + GlStateManager.disableLighting(); + GlStateManager.disableDepth(); + for( IGhostIngredientHandler.Target target : hoveredIngredientTargets ) + { + Rectangle area = target.getArea(); + Color color; + if( area.contains( mouseX, mouseY ) ) + { + color = new Color( 76, 201, 25, 128 ); + } + else + { + color = new Color( 19, 201, 10, 64 ); + } + Gui.drawRect( area.x, area.y, area.x + area.width, area.y + area.height, color.getRGB() ); + } + GlStateManager.color( 1f, 1f, 1f, 1f ); + aeGuiHandler.getTargets( this, o, true ); + } } } - + */ } protected void drawGuiSlot( GuiCustomSlot slot, int mouseX, int mouseY, float partialTicks ) diff --git a/src/main/java/appeng/client/gui/AEGuiHandler.java b/src/main/java/appeng/client/gui/AEGuiHandler.java index fe571d76b..431211abb 100644 --- a/src/main/java/appeng/client/gui/AEGuiHandler.java +++ b/src/main/java/appeng/client/gui/AEGuiHandler.java @@ -8,13 +8,9 @@ import appeng.container.slot.SlotFake; import appeng.fluids.client.gui.widgets.GuiFluidSlot; import mezz.jei.api.gui.IAdvancedGuiHandler; import mezz.jei.api.gui.IGhostIngredientHandler; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiScreen; -import net.minecraft.item.ItemStack; -import org.lwjgl.input.Mouse; import java.awt.*; -import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -40,7 +36,7 @@ public class AEGuiHandler implements IAdvancedGuiHandler, IGhostIngre public Object getIngredientUnderMouse( AEBaseGui guiContainer, int mouseX, int mouseY ) { List visual; - int guiSlotIdx = 0; + int guiSlotIdx; Object result = null; if( guiContainer instanceof GuiCraftConfirm ) { @@ -105,48 +101,27 @@ public class AEGuiHandler implements IAdvancedGuiHandler, IGhostIngre List> phantomTargets = g.getPhantomTargets( ingredient ); targets.addAll( (List>) (Object) phantomTargets ); } - if( doStart ) + if( doStart && GuiScreen.isShiftKeyDown() ) { - if( GuiScreen.isShiftKeyDown() && Mouse.isButtonDown( 0 ) ) + if( gui instanceof GuiUpgradeable || gui instanceof GuiPatternTerm ) { - if( gui instanceof GuiUpgradeable || gui instanceof GuiPatternTerm ) + IJEIGhostIngredients ghostGui = ( (IJEIGhostIngredients) gui ); + for( Target target : targets ) { - IJEIGhostIngredients ghostGui = ( (IJEIGhostIngredients) gui ); - for( Target target : targets ) + if( ghostGui.getFakeSlotTargetMap().get( target ) instanceof SlotFake ) { - if( ghostGui.getFakeSlotTargetMap().get( target ) instanceof SlotFake ) + if( ( (SlotFake) ghostGui.getFakeSlotTargetMap().get( target ) ).getStack().isEmpty() ) { - if( ( (SlotFake) ghostGui.getFakeSlotTargetMap().get( target ) ).getStack().isEmpty() ) - { - Minecraft.getMinecraft().player.inventory.setItemStack( ItemStack.EMPTY ); - target.accept( ingredient ); - try - { - gui.handleMouseInput(); - } - catch( IOException e ) - { - e.printStackTrace(); - } - break; - } + target.accept( ingredient ); + break; } - else if( ghostGui.getFakeSlotTargetMap().get( target ) instanceof GuiFluidSlot ) + } + else if( ghostGui.getFakeSlotTargetMap().get( target ) instanceof GuiFluidSlot ) + { + if( ( (GuiFluidSlot) ghostGui.getFakeSlotTargetMap().get( target ) ).getFluidStack() == null ) { - if( ( (GuiFluidSlot) ghostGui.getFakeSlotTargetMap().get( target ) ).getFluidStack() == null ) - { - Minecraft.getMinecraft().player.inventory.setItemStack( ItemStack.EMPTY ); - target.accept( ingredient ); - try - { - gui.handleMouseInput(); - } - catch( IOException e ) - { - e.printStackTrace(); - } - break; - } + target.accept( ingredient ); + break; } } } diff --git a/src/main/java/appeng/client/gui/implementations/GuiUpgradeable.java b/src/main/java/appeng/client/gui/implementations/GuiUpgradeable.java index 67b65c33d..f371d896a 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiUpgradeable.java +++ b/src/main/java/appeng/client/gui/implementations/GuiUpgradeable.java @@ -246,7 +246,7 @@ public class GuiUpgradeable extends AEBaseGui implements IJEIGhostIngredients { for( Slot slot : this.inventorySlots.inventorySlots ) { - if( slot instanceof SlotFake && ( !itemStack.isEmpty() || this instanceof GuiCellWorkbench && fluidStack != null && !( (AppEngSlot) slot ).isItemValid( itemStack ) ) ) + if( slot instanceof SlotFake && ( !itemStack.isEmpty() || this instanceof GuiCellWorkbench && fluidStack != null ) ) { slots.add( (IJEITargetSlot) slot ); } diff --git a/src/main/java/appeng/core/sync/packets/PacketInventoryAction.java b/src/main/java/appeng/core/sync/packets/PacketInventoryAction.java index 1ebad5fc2..4c9a73dd5 100644 --- a/src/main/java/appeng/core/sync/packets/PacketInventoryAction.java +++ b/src/main/java/appeng/core/sync/packets/PacketInventoryAction.java @@ -112,10 +112,6 @@ public class PacketInventoryAction extends AppEngPacket public PacketInventoryAction(final InventoryAction action, final IJEITargetSlot slot, final IAEItemStack slotItem ) throws IOException { - if( action != InventoryAction.PLACE_JEI_GHOST_ITEM ) - { - throw new IllegalStateException( "invalid packet, client cannot post inv actions with stacks." ); - } this.action = action; if (slot instanceof SlotFake) diff --git a/src/main/java/appeng/core/sync/packets/PacketJEIRecipe.java b/src/main/java/appeng/core/sync/packets/PacketJEIRecipe.java index f21b1a443..3c0f97c3c 100644 --- a/src/main/java/appeng/core/sync/packets/PacketJEIRecipe.java +++ b/src/main/java/appeng/core/sync/packets/PacketJEIRecipe.java @@ -303,7 +303,7 @@ public class PacketJEIRecipe extends AppEngPacket { for( ItemStack option : this.recipe[slot] ) { - if( is.isItemEqual( option ) ) + if( ItemStack.areItemStacksEqual( is, option ) ) { return is; } diff --git a/src/main/java/appeng/integration/modules/jei/JEIPlugin.java b/src/main/java/appeng/integration/modules/jei/JEIPlugin.java index 2ce53fa69..9a65009d4 100644 --- a/src/main/java/appeng/integration/modules/jei/JEIPlugin.java +++ b/src/main/java/appeng/integration/modules/jei/JEIPlugin.java @@ -54,9 +54,10 @@ import appeng.items.parts.ItemFacade; @mezz.jei.api.JEIPlugin -public class JEIPlugin implements IModPlugin, IBookmarkOverlay +public class JEIPlugin implements IModPlugin { public static IJeiRuntime runtime; + public static AEGuiHandler aeGuiHandler; @Override public void registerItemSubtypes( ISubtypeRegistry subtypeRegistry ) @@ -96,7 +97,7 @@ public class JEIPlugin implements IModPlugin, IBookmarkOverlay .addRecipeTransferHandler( new RecipeTransferHandler<>( ContainerPatternTerm.class ), Constants.UNIVERSAL_RECIPE_TRANSFER_UID ); - AEGuiHandler aeGuiHandler = new AEGuiHandler(); + aeGuiHandler = new AEGuiHandler(); registry.addAdvancedGuiHandlers(aeGuiHandler); registry.addGhostIngredientHandler( aeGuiHandler.getGuiContainerClass(), aeGuiHandler); } @@ -223,11 +224,4 @@ public class JEIPlugin implements IModPlugin, IBookmarkOverlay jeiModule.setJei( new JeiRuntimeAdapter( jeiRuntime ) ); runtime = jeiRuntime; } - - @Nullable - @Override - public Object getIngredientUnderMouse() - { - return runtime.getBookmarkOverlay().getIngredientUnderMouse(); - } }