JEI Ghost items work, missing some click interactions and GUI work
This commit is contained in:
@@ -19,8 +19,10 @@
|
||||
package appeng.client.gui.implementations;
|
||||
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import java.util.List;
|
||||
|
||||
import appeng.api.config.ActionItems;
|
||||
import appeng.api.config.Settings;
|
||||
@@ -30,6 +32,7 @@ import appeng.client.gui.widgets.GuiImgButton;
|
||||
import appeng.client.me.SlotME;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.implementations.ContainerConfiguringTerminal;
|
||||
import appeng.container.interfaces.IJEIGhostIngredients;
|
||||
import appeng.container.slot.SlotFake;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketInventoryAction;
|
||||
@@ -41,8 +44,10 @@ import appeng.parts.reporting.PartConfiguringTerminal;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.misc.TileInterface;
|
||||
import appeng.util.BlockPosUtils;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import com.google.common.collect.HashMultimap;
|
||||
|
||||
import mezz.jei.api.gui.IGhostIngredientHandler;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
@@ -72,7 +77,7 @@ import org.lwjgl.input.Mouse;
|
||||
import static appeng.client.render.BlockPosHighlighter.hilightBlock;
|
||||
|
||||
|
||||
public class GuiConfiguringTerminal extends AEBaseGui
|
||||
public class GuiConfiguringTerminal extends AEBaseGui implements IJEIGhostIngredients
|
||||
{
|
||||
|
||||
private static final int LINES_ON_PAGE = 6;
|
||||
@@ -95,6 +100,7 @@ public class GuiConfiguringTerminal extends AEBaseGui
|
||||
private MEGuiTextField searchFieldInputs;
|
||||
private PartConfiguringTerminal partInterfaceTerminal;
|
||||
private HashMap<ClientDCInternalInv, Integer> dimHashMap = new HashMap<>();
|
||||
public Map<IGhostIngredientHandler.Target<?>, Object> mapTargetSlot = new HashMap<>();
|
||||
|
||||
public GuiConfiguringTerminal( final InventoryPlayer inventoryPlayer, final PartConfiguringTerminal te )
|
||||
{
|
||||
@@ -544,4 +550,54 @@ public class GuiConfiguringTerminal extends AEBaseGui
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<IGhostIngredientHandler.Target<?>> getPhantomTargets( Object ingredient )
|
||||
{
|
||||
if( !( ingredient instanceof ItemStack ) )
|
||||
{
|
||||
return Collections.emptyList();
|
||||
}
|
||||
List<IGhostIngredientHandler.Target<?>> targets = new ArrayList<>();
|
||||
for( Slot slot : this.inventorySlots.inventorySlots )
|
||||
{
|
||||
if( slot instanceof SlotDisconnected )
|
||||
{
|
||||
ItemStack itemStack = (ItemStack) ingredient;
|
||||
IGhostIngredientHandler.Target<Object> target = new IGhostIngredientHandler.Target<Object>()
|
||||
{
|
||||
@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, (SlotDisconnected) 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<IGhostIngredientHandler.Target<?>, Object> getFakeSlotTargetMap()
|
||||
{
|
||||
return IJEIGhostIngredients.super.getFakeSlotTargetMap();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
package appeng.client.me;
|
||||
|
||||
|
||||
import appeng.container.slot.IJEITargetSlot;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -28,7 +29,7 @@ import appeng.items.misc.ItemEncodedPattern;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public class SlotDisconnected extends AppEngSlot
|
||||
public class SlotDisconnected extends AppEngSlot implements IJEITargetSlot
|
||||
{
|
||||
|
||||
private final ClientDCInternalInv mySlot;
|
||||
|
||||
@@ -53,7 +53,6 @@ import appeng.util.helpers.ItemHandlerUtil;
|
||||
import appeng.util.inv.AdaptorItemHandler;
|
||||
import appeng.util.inv.WrapperCursorItemHandler;
|
||||
import appeng.util.inv.WrapperRangeItemHandler;
|
||||
import appeng.util.inv.filter.IAEItemFilter;
|
||||
|
||||
|
||||
public final class ContainerConfiguringTerminal extends AEBaseContainer
|
||||
@@ -199,19 +198,19 @@ public final class ContainerConfiguringTerminal extends AEBaseContainer
|
||||
}
|
||||
}
|
||||
|
||||
public ConfigTracker getSlotByID( long id )
|
||||
{
|
||||
return this.byId.get( id );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doAction( final EntityPlayerMP player, final InventoryAction action, final int slot, final long id )
|
||||
{
|
||||
final ConfigTracker inv = this.byId.get( id );
|
||||
if( inv != null )
|
||||
{
|
||||
final ItemStack is = inv.server.getStackInSlot( slot );
|
||||
final boolean hasItemInHand = !player.inventory.getItemStack().isEmpty();
|
||||
|
||||
final InventoryAdaptor playerHand = new AdaptorItemHandler( new WrapperCursorItemHandler( player.inventory ) );
|
||||
|
||||
final IItemHandler theSlot = new WrapperRangeItemHandler( inv.server, slot, slot + 1 );
|
||||
final InventoryAdaptor interfaceSlot = new AdaptorItemHandler( theSlot );
|
||||
|
||||
ItemStack inSlot = theSlot.getStackInSlot( 0 );
|
||||
|
||||
@@ -255,7 +254,7 @@ public final class ContainerConfiguringTerminal extends AEBaseContainer
|
||||
}
|
||||
|
||||
}
|
||||
else if( !is.isEmpty() )
|
||||
else if( !inSlot.isEmpty() )
|
||||
{
|
||||
inSlot.shrink( 1 );
|
||||
ItemHandlerUtil.setStackInSlot( theSlot, 0, inSlot.copy() );
|
||||
@@ -373,7 +372,7 @@ public final class ContainerConfiguringTerminal extends AEBaseContainer
|
||||
data.setTag( name, tag );
|
||||
}
|
||||
|
||||
private static class ConfigTracker
|
||||
public static class ConfigTracker
|
||||
{
|
||||
|
||||
private final long sortBy;
|
||||
@@ -393,5 +392,10 @@ public final class ContainerConfiguringTerminal extends AEBaseContainer
|
||||
this.pos = dual.getLocation().getPos();
|
||||
this.dim = dual.getLocation().getWorld().provider.getDimension();
|
||||
}
|
||||
|
||||
public IItemHandler getServer()
|
||||
{
|
||||
return server;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,9 @@ import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
|
||||
import appeng.api.storage.data.IAEFluidStack;
|
||||
import appeng.client.me.SlotDisconnected;
|
||||
import appeng.container.implementations.ContainerConfiguringTerminal;
|
||||
import appeng.container.implementations.ContainerConfiguringTerminal.ConfigTracker;
|
||||
import appeng.container.slot.IJEITargetSlot;
|
||||
import appeng.container.slot.SlotFake;
|
||||
import appeng.core.AELog;
|
||||
@@ -30,11 +33,14 @@ import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.fluids.client.gui.widgets.GuiFluidSlot;
|
||||
import appeng.fluids.container.ContainerFluidConfigurable;
|
||||
import appeng.fluids.util.AEFluidStack;
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
import appeng.util.inv.WrapperRangeItemHandler;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
@@ -50,6 +56,7 @@ import appeng.helpers.InventoryAction;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
|
||||
public class PacketInventoryAction extends AppEngPacket
|
||||
@@ -111,14 +118,25 @@ public class PacketInventoryAction extends AppEngPacket
|
||||
this.configureWrite( data );
|
||||
}
|
||||
|
||||
public PacketInventoryAction(final InventoryAction action, final IJEITargetSlot slot, final IAEItemStack slotItem ) throws IOException
|
||||
public PacketInventoryAction( final InventoryAction action, final IJEITargetSlot slot, final IAEItemStack slotItem ) throws IOException
|
||||
{
|
||||
|
||||
this.action = action;
|
||||
if (slot instanceof SlotFake)
|
||||
this.slot = ((SlotFake) slot).slotNumber;
|
||||
else this.slot = ((GuiFluidSlot) slot).getId();
|
||||
this.id = 0;
|
||||
if( slot instanceof SlotFake )
|
||||
{
|
||||
this.slot = ( (SlotFake) slot ).slotNumber;
|
||||
this.id = 0;
|
||||
}
|
||||
else if( slot instanceof SlotDisconnected )
|
||||
{
|
||||
this.slot = ( (SlotDisconnected) slot ).getSlotIndex();
|
||||
this.id = ( (SlotDisconnected) slot ).getSlot().getId();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.slot = ( (GuiFluidSlot) slot ).getId();
|
||||
this.id = 0;
|
||||
}
|
||||
this.slotItem = slotItem;
|
||||
|
||||
final ByteBuf data = Unpooled.buffer();
|
||||
@@ -205,29 +223,44 @@ public class PacketInventoryAction extends AppEngPacket
|
||||
}
|
||||
}
|
||||
}
|
||||
else if( this.slot < sender.openContainer.inventorySlots.size() && sender.openContainer.inventorySlots.get( this.slot ) instanceof SlotFake )
|
||||
else if( sender.openContainer instanceof ContainerConfiguringTerminal )
|
||||
{
|
||||
if( this.slotItem != null )
|
||||
ConfigTracker inv = ( (ContainerConfiguringTerminal) sender.openContainer ).getSlotByID( this.id );
|
||||
final IItemHandler theSlot = new WrapperRangeItemHandler( inv.getServer(), 0, slot + 1 );
|
||||
|
||||
ItemHandlerUtil.setStackInSlot( theSlot, this.slot, this.slotItem.createItemStack() );
|
||||
|
||||
}
|
||||
else if( this.slot < sender.openContainer.inventorySlots.size() )
|
||||
{
|
||||
Slot senderSlot = sender.openContainer.inventorySlots.get( this.slot );
|
||||
if( senderSlot instanceof SlotFake )
|
||||
{
|
||||
sender.openContainer.inventorySlots.get( this.slot ).putStack( this.slotItem.createItemStack() );
|
||||
if( sender.openContainer.inventorySlots.get( this.slot ).getStack().isEmpty() )
|
||||
if( this.slotItem != null )
|
||||
{
|
||||
IAEFluidStack aefs = AEFluidStack.fromNBT( this.slotItem.getDefinition().getTagCompound() );
|
||||
if( aefs != null )
|
||||
senderSlot.putStack( this.slotItem.createItemStack() );
|
||||
if( senderSlot.getStack().isEmpty() )
|
||||
{
|
||||
FluidStack fluid = aefs.getFluidStack();
|
||||
sender.openContainer.inventorySlots.get( this.slot ).putStack( AEFluidStack.fromFluidStack( fluid ).asItemStackRepresentation() );
|
||||
IAEFluidStack aefs = AEFluidStack.fromNBT( this.slotItem.getDefinition().getTagCompound() );
|
||||
if( aefs != null )
|
||||
{
|
||||
FluidStack fluid = aefs.getFluidStack();
|
||||
senderSlot.putStack( AEFluidStack.fromFluidStack( fluid ).asItemStackRepresentation() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else sender.openContainer.inventorySlots.get( this.slot ).putStack( ItemStack.EMPTY );
|
||||
try
|
||||
{
|
||||
NetworkHandler.instance().sendTo( new PacketInventoryAction( InventoryAction.UPDATE_HAND, 0, AEItemStack.fromItemStack( ItemStack.EMPTY ) ), sender );
|
||||
}
|
||||
catch( final IOException e )
|
||||
{
|
||||
AELog.debug( e );
|
||||
else
|
||||
{
|
||||
senderSlot.putStack( ItemStack.EMPTY );
|
||||
}
|
||||
try
|
||||
{
|
||||
NetworkHandler.instance().sendTo( new PacketInventoryAction( InventoryAction.UPDATE_HAND, 0, AEItemStack.fromItemStack( ItemStack.EMPTY ) ), sender );
|
||||
}
|
||||
catch( final IOException e )
|
||||
{
|
||||
AELog.debug( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user