Improved NEI Integration and Pattern Terminal Support

This commit is contained in:
AlgorithmX2
2014-07-06 01:52:29 -05:00
parent e658c40381
commit 6ce5a8f4c5
10 changed files with 113 additions and 26 deletions
+8 -1
View File
@@ -57,7 +57,7 @@ public abstract class AEBaseGui extends GuiContainer
protected List<InternalSlotME> meSlots = new LinkedList<InternalSlotME>();
protected GuiScrollbar myScrollBar = null;
static public boolean switchingGuis;
final private boolean subGui;
private boolean subGui;
public AEBaseGui(Container container) {
super( container );
@@ -127,6 +127,13 @@ public abstract class AEBaseGui extends GuiContainer
}
}
@Override
public void onGuiClosed()
{
super.onGuiClosed();
subGui = true; // in case the gui is reopened later ( i'm looking at you NEI )
}
@Override
protected void mouseClicked(int xCoord, int yCoord, int btn)
{
@@ -9,12 +9,13 @@ import appeng.api.storage.ITerminalHost;
import appeng.container.ContainerNull;
import appeng.container.slot.SlotCraftingMatrix;
import appeng.container.slot.SlotCraftingTerm;
import appeng.helpers.IContainerCraftingPacket;
import appeng.parts.reporting.PartCraftingTerminal;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
public class ContainerCraftingTerm extends ContainerMEMonitorable implements IAEAppEngInventory
public class ContainerCraftingTerm extends ContainerMEMonitorable implements IAEAppEngInventory, IContainerCraftingPacket
{
AppEngInternalInventory output = new AppEngInternalInventory( this, 1 );
@@ -66,4 +67,16 @@ public class ContainerCraftingTerm extends ContainerMEMonitorable implements IAE
{
}
@Override
public IInventory getInventoryByName(String name)
{
return ct.getInventoryByName( name );
}
@Override
public boolean useRealItems()
{
return true;
}
}
@@ -28,11 +28,12 @@ import appeng.container.ContainerNull;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.IOptionalSlotHost;
import appeng.container.slot.OptionalSlotFake;
import appeng.container.slot.SlotFake;
import appeng.container.slot.SlotFakeCraftingMatrix;
import appeng.container.slot.SlotPatternTerm;
import appeng.container.slot.SlotRestrictedInput;
import appeng.container.slot.SlotRestrictedInput.PlaceableItemType;
import appeng.core.sync.packets.PacketPatternSlot;
import appeng.helpers.IContainerCraftingPacket;
import appeng.parts.reporting.PartPatternTerminal;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.IAEAppEngInventory;
@@ -42,13 +43,13 @@ import appeng.util.Platform;
import appeng.util.inv.AdaptorPlayerHand;
import appeng.util.item.AEItemStack;
public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEAppEngInventory, IOptionalSlotHost
public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEAppEngInventory, IOptionalSlotHost, IContainerCraftingPacket
{
AppEngInternalInventory cOut = new AppEngInternalInventory( null, 1 );
IInventory crafting;
SlotFake craftingSlots[] = new SlotFake[9];
SlotFakeCraftingMatrix craftingSlots[] = new SlotFakeCraftingMatrix[9];
OptionalSlotFake outputSlots[] = new OptionalSlotFake[3];
SlotPatternTerm craftSlot;
@@ -68,7 +69,7 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
for (int y = 0; y < 3; y++)
for (int x = 0; x < 3; x++)
addSlotToContainer( craftingSlots[x + y * 3] = new SlotFake( crafting, x + y * 3, 18 + x * 18, -76 + y * 18 ) );
addSlotToContainer( craftingSlots[x + y * 3] = new SlotFakeCraftingMatrix( crafting, x + y * 3, 18 + x * 18, -76 + y * 18 ) );
addSlotToContainer( craftSlot = new SlotPatternTerm( ip.player, mySrc, powerSrc, montiorable, crafting, patternInv, cOut, 110, -76 + 18, this, 2 ) );
craftSlot.IIcon = -1;
@@ -93,7 +94,7 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
{
if ( !craftingMode )
{
craftSlot.xDisplayPosition = 0;
craftSlot.xDisplayPosition = -9000;
for (int y = 0; y < 3; y++)
outputSlots[y].xDisplayPosition = outputSlots[y].defX;
@@ -103,7 +104,7 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
craftSlot.xDisplayPosition = craftSlot.defX;
for (int y = 0; y < 3; y++)
outputSlots[y].xDisplayPosition = 0;
outputSlots[y].xDisplayPosition = -9000;
}
}
@@ -346,7 +347,8 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
{
if ( ic.getStackInSlot( x ) != null )
{
ItemStack pulled = Platform.extractItemsByRecipe( powerSrc, mySrc, storage, p.worldObj, r, is, ic, ic.getStackInSlot( x ), x, all );
ItemStack pulled = Platform.extractItemsByRecipe( powerSrc, mySrc, storage, p.worldObj, r, is, ic, ic.getStackInSlot( x ), x, all,
Actionable.MODULATE );
real.setInventorySlotContents( x, pulled );
}
}
@@ -417,4 +419,16 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
detectAndSendChanges();
getAndUpdateOutput();
}
@Override
public IInventory getInventoryByName(String name)
{
return ct.getInventoryByName( name );
}
@Override
public boolean useRealItems()
{
return false;
}
}
+2 -1
View File
@@ -113,7 +113,8 @@ public class SlotCraftingTerm extends AppEngCraftingSlot
{
if ( pattern.getStackInSlot( x ) != null )
{
set[x] = Platform.extractItemsByRecipe( energySrc, mySrc, inv, p.worldObj, r, is, ic, pattern.getStackInSlot( x ), x, all );
set[x] = Platform.extractItemsByRecipe( energySrc, mySrc, inv, p.worldObj, r, is, ic, pattern.getStackInSlot( x ), x, all,
Actionable.MODULATE );
ic.setInventorySlotContents( x, set[x] );
}
}
@@ -0,0 +1,12 @@
package appeng.container.slot;
import net.minecraft.inventory.IInventory;
public class SlotFakeCraftingMatrix extends SlotFake
{
public SlotFakeCraftingMatrix(IInventory inv, int idx, int x, int y) {
super( inv, idx, x, y );
}
}
+11 -7
View File
@@ -17,6 +17,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import appeng.api.config.Actionable;
import appeng.api.config.SecurityPermissions;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridNode;
@@ -27,9 +28,9 @@ import appeng.api.storage.IMEMonitor;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
import appeng.container.ContainerNull;
import appeng.container.implementations.ContainerCraftingTerm;
import appeng.core.sync.AppEngPacket;
import appeng.core.sync.network.INetworkInfo;
import appeng.helpers.IContainerCraftingPacket;
import appeng.util.Platform;
import appeng.util.item.AEItemStack;
@@ -59,9 +60,9 @@ public class PacketNEIRecipe extends AppEngPacket
EntityPlayerMP pmp = (EntityPlayerMP) player;
Container con = pmp.openContainer;
if ( con != null && con instanceof ContainerCraftingTerm )
if ( con != null && con instanceof IContainerCraftingPacket )
{
ContainerCraftingTerm cct = (ContainerCraftingTerm) con;
IContainerCraftingPacket cct = (IContainerCraftingPacket) con;
IGridNode node = cct.getNetworkNode();
if ( node != null )
{
@@ -72,7 +73,9 @@ public class PacketNEIRecipe extends AppEngPacket
IStorageGrid inv = grid.getCache( IStorageGrid.class );
IEnergyGrid energy = grid.getCache( IEnergyGrid.class );
ISecurityGrid security = grid.getCache( ISecurityGrid.class );
IInventory craftMatrix = cct.ct.getInventoryByName( "crafting" );
IInventory craftMatrix = cct.getInventoryByName( "crafting" );
Actionable realForFake = cct.useRealItems() ? Actionable.MODULATE : Actionable.SIMULATE;
if ( inv != null && recipe != null && security != null )
{
@@ -107,7 +110,8 @@ public class PacketNEIRecipe extends AppEngPacket
IAEItemStack in = AEItemStack.create( currentItem );
if ( in != null )
{
IAEItemStack out = Platform.poweredInsert( energy, stor, in, cct.getSource() );
IAEItemStack out = realForFake == Actionable.SIMULATE ? null : Platform.poweredInsert( energy, stor, in,
cct.getSource() );
if ( out != null )
craftMatrix.setInventorySlotContents( x, out.getItemStack() );
else
@@ -120,8 +124,8 @@ public class PacketNEIRecipe extends AppEngPacket
if ( PatternItem != null && currentItem == null )
{
craftMatrix.setInventorySlotContents( x,
Platform.extractItemsByRecipe( energy, cct.getSource(), stor, player.worldObj, r, is, ic, PatternItem, x, all ) );
craftMatrix.setInventorySlotContents( x, Platform.extractItemsByRecipe( energy, cct.getSource(), stor, player.worldObj, r,
is, ic, PatternItem, x, all, realForFake ) );
}
}
con.onCraftMatrixChanged( craftMatrix );
+31
View File
@@ -0,0 +1,31 @@
package appeng.helpers;
import net.minecraft.inventory.IInventory;
import appeng.api.networking.IGridNode;
import appeng.api.networking.security.BaseActionSource;
public interface IContainerCraftingPacket
{
/**
* @return gain access to network infrastructure.
*/
IGridNode getNetworkNode();
/**
* @param string
* @return the inventory of the part/tile by name.
*/
IInventory getInventoryByName(String string);
/**
* @return who are we?
*/
BaseActionSource getSource();
/**
* @return consume items?
*/
boolean useRealItems();
}
+3
View File
@@ -10,6 +10,7 @@ import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import appeng.client.gui.implementations.GuiCraftingTerm;
import appeng.client.gui.implementations.GuiPatternTerm;
import appeng.integration.BaseModule;
import appeng.integration.IIntegrationModule;
import appeng.integration.abstraction.INEI;
@@ -64,9 +65,11 @@ public class NEI extends BaseModule implements IIntegrationModule, INEI
Method registerGuiOverlayHandler = API.getDeclaredMethod( "registerGuiOverlayHandler", new Class[] { Class.class, IOverlayHandler, String.class } );
registerGuiOverlay.invoke( API, GuiCraftingTerm.class, "crafting", 6, 75 );
registerGuiOverlay.invoke( API, GuiPatternTerm.class, "crafting", 6, 75 );
Constructor DefaultOverlayHandlerConstructor = DefaultOverlayHandler.getConstructor( new Class[] { int.class, int.class } );
registerGuiOverlayHandler.invoke( API, GuiCraftingTerm.class, DefaultOverlayHandlerConstructor.newInstance( 6, 75 ), "crafting" );
registerGuiOverlayHandler.invoke( API, GuiPatternTerm.class, DefaultOverlayHandlerConstructor.newInstance( 6, 75 ), "crafting" );
}
@Override
@@ -6,7 +6,9 @@ import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.inventory.Slot;
import net.minecraft.nbt.NBTTagCompound;
import appeng.client.gui.implementations.GuiCraftingTerm;
import appeng.client.gui.implementations.GuiPatternTerm;
import appeng.container.slot.SlotCraftingMatrix;
import appeng.container.slot.SlotFakeCraftingMatrix;
import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.packets.PacketNEIRecipe;
import codechicken.nei.PositionedStack;
@@ -47,7 +49,7 @@ public class NEICraftingHandler implements IOverlayHandler
{
NBTTagCompound recipe = new NBTTagCompound();
if ( gui instanceof GuiCraftingTerm )
if ( gui instanceof GuiCraftingTerm || gui instanceof GuiPatternTerm )
{
for (int i = 0; i < ingredients.size(); i++)// identify slots
{
@@ -58,14 +60,14 @@ public class NEICraftingHandler implements IOverlayHandler
{
for (Slot slot : (List<Slot>) gui.inventorySlots.inventorySlots)
{
if ( slot instanceof SlotCraftingMatrix )
if ( slot instanceof SlotCraftingMatrix || slot instanceof SlotFakeCraftingMatrix )
{
SlotCraftingMatrix ctSlot = (SlotCraftingMatrix) slot;
Slot ctSlot = (Slot) slot;
if ( ctSlot.getSlotIndex() == col + row * 3 )
{
NBTTagCompound inbt = new NBTTagCompound();
pstack.item.writeToNBT( inbt );
recipe.setTag( "#" + ((SlotCraftingMatrix) slot).getSlotIndex(), inbt );
recipe.setTag( "#" + ctSlot.getSlotIndex(), inbt );
break;
}
}
+5 -5
View File
@@ -1601,7 +1601,7 @@ public class Platform
}
public static ItemStack extractItemsByRecipe(IEnergySource energySrc, BaseActionSource mySrc, IMEMonitor<IAEItemStack> src, World w, IRecipe r,
ItemStack output, InventoryCrafting ci, ItemStack providedTemplate, int slot, IItemList<IAEItemStack> aitems)
ItemStack output, InventoryCrafting ci, ItemStack providedTemplate, int slot, IItemList<IAEItemStack> aitems, Actionable realForFake)
{
if ( energySrc.extractAEPower( 1, Actionable.SIMULATE, PowerMultiplier.CONFIG ) > 0.9 )
{
@@ -1611,13 +1611,13 @@ public class Platform
AEItemStack ae_req = AEItemStack.create( providedTemplate );
ae_req.setStackSize( 1 );
IAEItemStack ae_ext = src.extractItems( ae_req, Actionable.MODULATE, mySrc );
IAEItemStack ae_ext = src.extractItems( ae_req, realForFake, mySrc );
if ( ae_ext != null )
{
ItemStack extracted = ae_ext.getItemStack();
if ( extracted != null )
{
energySrc.extractAEPower( 1, Actionable.MODULATE, PowerMultiplier.CONFIG );
energySrc.extractAEPower( 1, realForFake, PowerMultiplier.CONFIG );
return extracted;
}
}
@@ -1634,10 +1634,10 @@ public class Platform
ci.setInventorySlotContents( slot, cp );
if ( r.matches( ci, w ) && Platform.isSameItem( r.getCraftingResult( ci ), output ) )
{
IAEItemStack ex = src.extractItems( AEItemStack.create( cp ), Actionable.MODULATE, mySrc );
IAEItemStack ex = src.extractItems( AEItemStack.create( cp ), realForFake, mySrc );
if ( ex != null )
{
energySrc.extractAEPower( 1, Actionable.MODULATE, PowerMultiplier.CONFIG );
energySrc.extractAEPower( 1, realForFake, PowerMultiplier.CONFIG );
return ex.getItemStack();
}
}