diff --git a/client/gui/AEBaseGui.java b/client/gui/AEBaseGui.java index 4e8b3dc4a..1359bd458 100644 --- a/client/gui/AEBaseGui.java +++ b/client/gui/AEBaseGui.java @@ -57,7 +57,7 @@ public abstract class AEBaseGui extends GuiContainer protected List meSlots = new LinkedList(); 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) { diff --git a/container/implementations/ContainerCraftingTerm.java b/container/implementations/ContainerCraftingTerm.java index 9e4ca8b80..41836cc25 100644 --- a/container/implementations/ContainerCraftingTerm.java +++ b/container/implementations/ContainerCraftingTerm.java @@ -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; + } } diff --git a/container/implementations/ContainerPatternTerm.java b/container/implementations/ContainerPatternTerm.java index a04415c4c..02ca43bba 100644 --- a/container/implementations/ContainerPatternTerm.java +++ b/container/implementations/ContainerPatternTerm.java @@ -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; + } } diff --git a/container/slot/SlotCraftingTerm.java b/container/slot/SlotCraftingTerm.java index b82cdbd27..b775dbc88 100644 --- a/container/slot/SlotCraftingTerm.java +++ b/container/slot/SlotCraftingTerm.java @@ -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] ); } } diff --git a/container/slot/SlotFakeCraftingMatrix.java b/container/slot/SlotFakeCraftingMatrix.java new file mode 100644 index 000000000..0283b2dbe --- /dev/null +++ b/container/slot/SlotFakeCraftingMatrix.java @@ -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 ); + } + +} diff --git a/core/sync/packets/PacketNEIRecipe.java b/core/sync/packets/PacketNEIRecipe.java index f5a93e238..1578b1793 100644 --- a/core/sync/packets/PacketNEIRecipe.java +++ b/core/sync/packets/PacketNEIRecipe.java @@ -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 ); diff --git a/helpers/IContainerCraftingPacket.java b/helpers/IContainerCraftingPacket.java new file mode 100644 index 000000000..602cf268d --- /dev/null +++ b/helpers/IContainerCraftingPacket.java @@ -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(); + +} diff --git a/integration/modules/NEI.java b/integration/modules/NEI.java index 98e7addf9..2e32d799e 100644 --- a/integration/modules/NEI.java +++ b/integration/modules/NEI.java @@ -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 diff --git a/integration/modules/NEIHelpers/NEICraftingHandler.java b/integration/modules/NEIHelpers/NEICraftingHandler.java index 4c65669c2..068c45a25 100644 --- a/integration/modules/NEIHelpers/NEICraftingHandler.java +++ b/integration/modules/NEIHelpers/NEICraftingHandler.java @@ -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) 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; } } diff --git a/util/Platform.java b/util/Platform.java index ea50dba22..47f70b187 100644 --- a/util/Platform.java +++ b/util/Platform.java @@ -1601,7 +1601,7 @@ public class Platform } public static ItemStack extractItemsByRecipe(IEnergySource energySrc, BaseActionSource mySrc, IMEMonitor src, World w, IRecipe r, - ItemStack output, InventoryCrafting ci, ItemStack providedTemplate, int slot, IItemList aitems) + ItemStack output, InventoryCrafting ci, ItemStack providedTemplate, int slot, IItemList 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(); } }