Added Pattern Terminal Crafting.
This commit is contained in:
@@ -1,26 +1,43 @@
|
||||
package appeng.container.implementations;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.inventory.SlotCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.security.MachineSource;
|
||||
import appeng.api.storage.IMEMonitor;
|
||||
import appeng.api.storage.ITerminalHost;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.container.ContainerNull;
|
||||
import appeng.container.slot.IOptionalSlotHost;
|
||||
import appeng.container.slot.OptionalSlotFake;
|
||||
import appeng.container.slot.SlotFake;
|
||||
import appeng.container.slot.SlotPatternTerm;
|
||||
import appeng.container.slot.SlotRestrictedInput;
|
||||
import appeng.container.slot.SlotRestrictedInput.PlaceableItemType;
|
||||
import appeng.core.sync.packets.PacketPatternSlot;
|
||||
import appeng.parts.reporting.PartPatternTerminal;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.IAEAppEngInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.AdaptorPlayerHand;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEAppEngInventory, IOptionalSlotHost
|
||||
{
|
||||
|
||||
AppEngInternalInventory output = new AppEngInternalInventory( this, 1 );
|
||||
AppEngInternalInventory craftSlotInv = new AppEngInternalInventory( this, 3 );
|
||||
AppEngInternalInventory cOut = new AppEngInternalInventory( null, 1 );
|
||||
IInventory crafting;
|
||||
|
||||
SlotFake craftingSlots[] = new SlotFake[9];
|
||||
OptionalSlotFake outputSlots[] = new OptionalSlotFake[3];
|
||||
@@ -39,14 +56,13 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
|
||||
|
||||
IInventory patternInv = ct.getInventoryByName( "pattern" );
|
||||
IInventory output = ct.getInventoryByName( "output" );
|
||||
IInventory crafting = ct.getInventoryByName( "crafting" );
|
||||
crafting = ct.getInventoryByName( "crafting" );
|
||||
|
||||
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( craftSlot = new SlotPatternTerm( ip.player, mySrc, powerSrc, montiorable, crafting, patternInv, craftSlotInv, output, 0, 110,
|
||||
-76 + 18, this, 2 ) );
|
||||
addSlotToContainer( craftSlot = new SlotPatternTerm( ip.player, mySrc, powerSrc, montiorable, crafting, patternInv, cOut, 110, -76 + 18, this, 2 ) );
|
||||
craftSlot.IIcon = -1;
|
||||
|
||||
for (int y = 0; y < 3; y++)
|
||||
@@ -55,6 +71,7 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
|
||||
outputSlots[y].renderDisabled = false;
|
||||
outputSlots[y].IIcon = -1;
|
||||
}
|
||||
|
||||
addSlotToContainer( patternSlotIN = new SlotRestrictedInput( PlaceableItemType.BLANK_PATTERN, patternInv, 0, 147, -72 - 9 ) );
|
||||
addSlotToContainer( patternSlotOUT = new SlotRestrictedInput( PlaceableItemType.ENCODED_PATTERN, patternInv, 1, 147, -72 + 34 ) );
|
||||
|
||||
@@ -82,19 +99,46 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putStackInSlot(int par1, ItemStack par2ItemStack)
|
||||
{
|
||||
super.putStackInSlot( par1, par2ItemStack );
|
||||
updateOutput();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putStacksInSlots(ItemStack[] par1ArrayOfItemStack)
|
||||
{
|
||||
super.putStacksInSlots( par1ArrayOfItemStack );
|
||||
updateOutput();
|
||||
}
|
||||
|
||||
public void updateOutput()
|
||||
{
|
||||
InventoryCrafting ic = new InventoryCrafting( this, 3, 3 );
|
||||
for (int x = 0; x < ic.getSizeInventory(); x++)
|
||||
ic.setInventorySlotContents( x, crafting.getStackInSlot( x ) );
|
||||
|
||||
ItemStack is = CraftingManager.getInstance().findMatchingRecipe( ic, this.getPlayerInv().player.worldObj );
|
||||
cOut.setInventorySlotContents( 0, is );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges()
|
||||
{
|
||||
super.detectAndSendChanges();
|
||||
if ( craftingMode != ct.craftingMode )
|
||||
if ( Platform.isServer() )
|
||||
{
|
||||
craftingMode = ct.craftingMode;
|
||||
updateOrderOfOutputSlots();
|
||||
|
||||
for (Object c : this.crafters)
|
||||
if ( craftingMode != ct.craftingMode )
|
||||
{
|
||||
if ( c instanceof ICrafting )
|
||||
((ICrafting) c).sendProgressBarUpdate( this, 97, craftingMode ? 1 : 0 );
|
||||
craftingMode = ct.craftingMode;
|
||||
updateOrderOfOutputSlots();
|
||||
|
||||
for (Object c : this.crafters)
|
||||
{
|
||||
if ( c instanceof ICrafting )
|
||||
((ICrafting) c).sendProgressBarUpdate( this, 97, craftingMode ? 1 : 0 );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,6 +150,7 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
|
||||
if ( idx == 97 )
|
||||
{
|
||||
craftingMode = value == 1;
|
||||
updateOutput();
|
||||
updateOrderOfOutputSlots();
|
||||
}
|
||||
}
|
||||
@@ -116,12 +161,6 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void encode()
|
||||
{
|
||||
|
||||
@@ -136,4 +175,94 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA
|
||||
return craftingMode == true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void craftOrGetItem(PacketPatternSlot packetPatternSlot)
|
||||
{
|
||||
if ( packetPatternSlot.slotItem != null && cellInv != null )
|
||||
{
|
||||
IAEItemStack out = packetPatternSlot.slotItem.copy();
|
||||
|
||||
InventoryAdaptor inv = new AdaptorPlayerHand( getPlayerInv().player );
|
||||
InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor( getPlayerInv().player, ForgeDirection.UNKNOWN );
|
||||
if ( packetPatternSlot.shift )
|
||||
inv = playerInv;
|
||||
|
||||
if ( inv.simulateAdd( out.getItemStack() ) != null )
|
||||
return;
|
||||
|
||||
IAEItemStack extracted = Platform.poweredExtraction( powerSrc, cellInv, out, mySrc );
|
||||
if ( extracted != null )
|
||||
{
|
||||
inv.addItems( extracted.getItemStack() );
|
||||
detectAndSendChanges();
|
||||
return;
|
||||
}
|
||||
|
||||
InventoryCrafting ic = new InventoryCrafting( new ContainerNull(), 3, 3 );
|
||||
InventoryCrafting real = new InventoryCrafting( new ContainerNull(), 3, 3 );
|
||||
for (int x = 0; x < 9; x++)
|
||||
{
|
||||
ic.setInventorySlotContents( x, packetPatternSlot.pattern[x] == null ? null : packetPatternSlot.pattern[x].getItemStack() );
|
||||
}
|
||||
|
||||
EntityPlayer p = getPlayerInv().player;
|
||||
IRecipe r = Platform.findMatchingRecipe( ic, p.worldObj );
|
||||
|
||||
if ( r == null )
|
||||
return;
|
||||
|
||||
IMEMonitor<IAEItemStack> storage = ct.getItemInventory();
|
||||
IItemList<IAEItemStack> all = storage.getStorageList();
|
||||
|
||||
ItemStack is = r.getCraftingResult( ic );
|
||||
|
||||
if ( r != null && inv != null )
|
||||
{
|
||||
for (int x = 0; x < ic.getSizeInventory(); x++)
|
||||
{
|
||||
if ( ic.getStackInSlot( x ) != null )
|
||||
{
|
||||
ItemStack pulled = Platform.extractItemsByRecipe( powerSrc, mySrc, storage, p.worldObj, r, is, ic, ic.getStackInSlot( x ), x, all );
|
||||
real.setInventorySlotContents( x, pulled );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IRecipe rr = Platform.findMatchingRecipe( real, p.worldObj );
|
||||
|
||||
if ( rr == r && Platform.isSameItemPrecise( rr.getCraftingResult( real ), is ) )
|
||||
{
|
||||
SlotCrafting sc = new SlotCrafting( p, real, cOut, 0, 0, 0 );
|
||||
sc.onPickupFromSlot( p, is );
|
||||
|
||||
for (int x = 0; x < real.getSizeInventory(); x++)
|
||||
{
|
||||
ItemStack failed = playerInv.addItems( real.getStackInSlot( x ) );
|
||||
if ( failed != null )
|
||||
p.dropPlayerItemWithRandomChoice( failed, false );
|
||||
}
|
||||
|
||||
inv.addItems( is );
|
||||
detectAndSendChanges();
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int x = 0; x < real.getSizeInventory(); x++)
|
||||
{
|
||||
ItemStack failed = real.getStackInSlot( x );
|
||||
if ( failed != null )
|
||||
{
|
||||
cellInv.injectItems( AEItemStack.create( failed ), Actionable.MODULATE, new MachineSource( ct ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user