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