Partial progress on pattern slot.
This commit is contained in:
parent
2de3ab4505
commit
e20f26fc6d
3 changed files with 90 additions and 41 deletions
|
@ -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++)
|
||||
|
|
|
@ -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<IAEItemStack> inv, IItemList all)
|
||||
public ItemStack craftItem(EntityPlayer p, ItemStack request, IMEMonitor<IAEItemStack> 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<ItemStack> 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,27 +135,50 @@ 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] );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( preCraft( p, inv, set, is ) )
|
||||
{
|
||||
super.onPickupFromSlot( p, is );
|
||||
|
||||
postCraft( p, inv, set, is );
|
||||
}
|
||||
|
||||
// shouldn't be nessiary...
|
||||
p.openContainer.onCraftMatrixChanged( getCraftingMatrix() );
|
||||
|
||||
return is;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean preCraft(EntityPlayer p, IMEMonitor<IAEItemStack> inv, ItemStack[] set, ItemStack result)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void postCraft(EntityPlayer p, IMEMonitor<IAEItemStack> inv, ItemStack set[], ItemStack result)
|
||||
{
|
||||
List<ItemStack> 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 < craftMatrix.getSizeInventory(); x++)
|
||||
for (int x = 0; x < getCraftingMatrix().getSizeInventory(); x++)
|
||||
{
|
||||
if ( craftMatrix.getStackInSlot( x ) == null )
|
||||
craftMatrix.setInventorySlotContents( x, set[x] );
|
||||
if ( getCraftingMatrix().getStackInSlot( x ) == null )
|
||||
getCraftingMatrix().setInventorySlotContents( x, set[x] );
|
||||
else if ( set[x] != null )
|
||||
{
|
||||
// eek! put it back!
|
||||
|
@ -160,16 +189,8 @@ public class SlotCraftingTerm extends AppEngCraftingSlot
|
|||
}
|
||||
}
|
||||
|
||||
// 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 );
|
||||
|
||||
return is;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void doClick(InventoryAction action, EntityPlayer who)
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue