diff --git a/container/implementations/ContainerPatternTerm.java b/container/implementations/ContainerPatternTerm.java index f721d8bae..bf68b7bca 100644 --- a/container/implementations/ContainerPatternTerm.java +++ b/container/implementations/ContainerPatternTerm.java @@ -19,7 +19,8 @@ import appeng.tile.inventory.InvOperation; public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEAppEngInventory, IOptionalSlotHost { - AppEngInternalInventory craftSlotInv = new AppEngInternalInventory( this, 1 ); + AppEngInternalInventory output = new AppEngInternalInventory( this, 1 ); + AppEngInternalInventory craftSlotInv = new AppEngInternalInventory( this, 3 ); SlotFake craftingSlots[] = new SlotFake[9]; OptionalSlotFake outputSlots[] = new OptionalSlotFake[3]; @@ -44,8 +45,8 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA 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( craftSlot = new SlotPatternTerm( craftSlotInv, this, 0, 110, -76 + 18, 2 ) ); - craftSlot.renderDisabled = false; + addSlotToContainer( craftSlot = new SlotPatternTerm( ip.player, mySrc, powerSrc, montiorable, crafting, patternInv, craftSlotInv, output, 0, 110, + -76 + 18, this, 2 ) ); craftSlot.IIcon = -1; for (int y = 0; y < 3; y++) diff --git a/container/slot/SlotCraftingTerm.java b/container/slot/SlotCraftingTerm.java index 77dc6fe03..6b5894c88 100644 --- a/container/slot/SlotCraftingTerm.java +++ b/container/slot/SlotCraftingTerm.java @@ -27,19 +27,26 @@ import appeng.util.item.AEItemStack; public class SlotCraftingTerm extends AppEngCraftingSlot { - private final IInventory craftMatrix; + private final IInventory craftInv; + private final IInventory pattern; private final BaseActionSource mySrc; private final IEnergySource energySrc; private final IStorageMonitorable storage; public SlotCraftingTerm(EntityPlayer player, BaseActionSource mySrc, IEnergySource energySrc, IStorageMonitorable storage, IInventory cMatrix, - IInventory output, int x, int y) { + IInventory secondMatrix, IInventory output, int x, int y) { super( player, cMatrix, output, 0, x, y ); this.energySrc = energySrc; this.storage = storage; this.mySrc = mySrc; - craftMatrix = cMatrix; + pattern = cMatrix; + craftInv = secondMatrix; + } + + public IInventory getCraftingMatrix() + { + return craftInv; } @Override @@ -103,22 +110,21 @@ public class SlotCraftingTerm extends AppEngCraftingSlot return null; } - ItemStack craftItem(EntityPlayer p, ItemStack request, IMEMonitor inv, IItemList all) + public ItemStack craftItem(EntityPlayer p, ItemStack request, IMEMonitor inv, IItemList all) { // update crafting matrx... ItemStack is = getStack(); if ( is != null && Platform.isSameItem( request, is ) ) { - ItemStack[] set = new ItemStack[craftMatrix.getSizeInventory()]; + ItemStack[] set = new ItemStack[pattern.getSizeInventory()]; // add one of each item to the items on the board... - List drops = new ArrayList(); if ( Platform.isServer() ) { InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 ); for (int x = 0; x < 9; x++) - ic.setInventorySlotContents( x, craftMatrix.getStackInSlot( x ) ); + ic.setInventorySlotContents( x, pattern.getStackInSlot( x ) ); IRecipe r = Platform.findMatchingRecipe( ic, p.worldObj ); @@ -129,42 +135,26 @@ public class SlotCraftingTerm extends AppEngCraftingSlot if ( r != null && inv != null ) { - for (int x = 0; x < craftMatrix.getSizeInventory(); x++) + for (int x = 0; x < pattern.getSizeInventory(); x++) { - if ( craftMatrix.getStackInSlot( x ) != null ) + if ( pattern.getStackInSlot( x ) != null ) { - set[x] = extractItemsByRecipe( inv, p.worldObj, r, is, ic, craftMatrix.getStackInSlot( x ), x, all ); + set[x] = extractItemsByRecipe( inv, p.worldObj, r, is, ic, pattern.getStackInSlot( x ), x, all ); ic.setInventorySlotContents( x, set[x] ); } } } } - super.onPickupFromSlot( p, is ); - - // add one of each item to the items on the board... - if ( Platform.isServer() ) + if ( preCraft( p, inv, set, is ) ) { - // set new items onto the crafting table... - for (int x = 0; x < craftMatrix.getSizeInventory(); x++) - { - if ( craftMatrix.getStackInSlot( x ) == null ) - craftMatrix.setInventorySlotContents( x, set[x] ); - else if ( set[x] != null ) - { - // eek! put it back! - IAEItemStack fail = inv.injectItems( AEItemStack.create( set[x] ), Actionable.MODULATE, mySrc ); - if ( fail != null ) - drops.add( fail.getItemStack() ); - } - } + super.onPickupFromSlot( p, is ); + + postCraft( p, inv, set, is ); } // shouldn't be nessiary... - p.openContainer.onCraftMatrixChanged( craftMatrix ); - - if ( drops.size() > 0 ) - Platform.spawnDrops( p.worldObj, (int) p.posX, (int) p.posY, (int) p.posZ, drops ); + p.openContainer.onCraftMatrixChanged( getCraftingMatrix() ); return is; } @@ -172,6 +162,37 @@ public class SlotCraftingTerm extends AppEngCraftingSlot return null; } + public boolean preCraft(EntityPlayer p, IMEMonitor inv, ItemStack[] set, ItemStack result) + { + return true; + } + + public void postCraft(EntityPlayer p, IMEMonitor inv, ItemStack set[], ItemStack result) + { + List drops = new ArrayList(); + + // add one of each item to the items on the board... + if ( Platform.isServer() ) + { + // set new items onto the crafting table... + for (int x = 0; x < getCraftingMatrix().getSizeInventory(); x++) + { + if ( getCraftingMatrix().getStackInSlot( x ) == null ) + getCraftingMatrix().setInventorySlotContents( x, set[x] ); + else if ( set[x] != null ) + { + // eek! put it back! + IAEItemStack fail = inv.injectItems( AEItemStack.create( set[x] ), Actionable.MODULATE, mySrc ); + if ( fail != null ) + drops.add( fail.getItemStack() ); + } + } + } + + if ( drops.size() > 0 ) + Platform.spawnDrops( p.worldObj, (int) p.posX, (int) p.posY, (int) p.posZ, drops ); + } + public void doClick(InventoryAction action, EntityPlayer who) { if ( getStack() == null ) @@ -201,6 +222,8 @@ public class SlotCraftingTerm extends AppEngCraftingSlot maxTimesToCraft = 1; } + maxTimesToCraft = CapCraftingAttempts( maxTimesToCraft ); + if ( ia == null ) return; @@ -225,4 +248,9 @@ public class SlotCraftingTerm extends AppEngCraftingSlot } } + protected int CapCraftingAttempts(int maxTimesToCraft) + { + return maxTimesToCraft; + } + } diff --git a/container/slot/SlotPatternTerm.java b/container/slot/SlotPatternTerm.java index ab732f8c3..8d8891794 100644 --- a/container/slot/SlotPatternTerm.java +++ b/container/slot/SlotPatternTerm.java @@ -3,24 +3,44 @@ package appeng.container.slot; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import appeng.api.networking.energy.IEnergySource; +import appeng.api.networking.security.BaseActionSource; +import appeng.api.storage.IStorageMonitorable; -public class SlotPatternTerm extends OptionalSlotFake +public class SlotPatternTerm extends SlotCraftingTerm { - public SlotPatternTerm(IInventory inv, IOptionalSlotHost h, int idx, int x, int y, int grpnum) { - super( inv, h, idx, x, y, 0, 0, grpnum ); + int groupNum; + IOptionalSlotHost host; + + public SlotPatternTerm(EntityPlayer player, BaseActionSource mySrc, IEnergySource energySrc, IStorageMonitorable storage, IInventory cMatrix, + IInventory secondMatrix, IInventory output, int x, int y, IOptionalSlotHost h, int grpnum) { + super( player, mySrc, energySrc, storage, cMatrix, secondMatrix, output, x, y ); + + host = h; + groupNum = grpnum; + } @Override - public boolean canTakeStack(EntityPlayer par1EntityPlayer) + public ItemStack getStack() { - return super.canTakeStack( par1EntityPlayer ); + if ( !isEnabled() ) + { + if ( getDisplayStack() != null ) + clearStack(); + } + + return super.getStack(); } @Override - public void onPickupFromSlot(EntityPlayer p, ItemStack is) + public boolean isEnabled() { - super.onPickupFromSlot( p, is ); + if ( host == null ) + return false; + + return host.isSlotEnabled( groupNum ); } }