2014-01-20 17:41:37 +01:00
|
|
|
package appeng.helpers;
|
|
|
|
|
2014-05-09 06:10:12 +02:00
|
|
|
import java.util.EnumSet;
|
2014-07-09 10:17:11 +02:00
|
|
|
import java.util.HashSet;
|
2014-05-09 06:10:12 +02:00
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
2014-07-09 10:17:11 +02:00
|
|
|
import java.util.Set;
|
2014-05-09 06:10:12 +02:00
|
|
|
|
2014-07-08 05:48:21 +02:00
|
|
|
import net.minecraft.block.Block;
|
2014-01-20 17:41:37 +01:00
|
|
|
import net.minecraft.inventory.IInventory;
|
2014-07-13 00:30:41 +02:00
|
|
|
import net.minecraft.inventory.ISidedInventory;
|
2014-05-09 06:10:12 +02:00
|
|
|
import net.minecraft.inventory.InventoryCrafting;
|
2014-07-09 10:17:11 +02:00
|
|
|
import net.minecraft.item.Item;
|
2014-01-20 17:41:37 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2014-05-09 06:10:12 +02:00
|
|
|
import net.minecraft.nbt.NBTTagList;
|
2014-01-20 17:41:37 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2014-07-08 05:48:21 +02:00
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
|
|
|
import net.minecraft.util.Vec3;
|
2014-05-09 06:10:12 +02:00
|
|
|
import net.minecraft.world.World;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.api.AEApi;
|
|
|
|
import appeng.api.config.Actionable;
|
2014-07-05 03:59:50 +02:00
|
|
|
import appeng.api.config.Settings;
|
|
|
|
import appeng.api.config.Upgrades;
|
|
|
|
import appeng.api.config.YesNo;
|
2014-05-09 06:10:12 +02:00
|
|
|
import appeng.api.implementations.ICraftingPatternItem;
|
2014-07-05 03:59:50 +02:00
|
|
|
import appeng.api.implementations.IUpgradeableHost;
|
2014-06-19 08:28:45 +02:00
|
|
|
import appeng.api.implementations.tiles.ICraftingMachine;
|
2014-01-23 20:02:48 +01:00
|
|
|
import appeng.api.implementations.tiles.ISegmentedInventory;
|
2014-02-09 02:34:52 +01:00
|
|
|
import appeng.api.networking.GridFlags;
|
2014-07-13 00:14:01 +02:00
|
|
|
import appeng.api.networking.IGrid;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.api.networking.IGridNode;
|
2014-07-06 08:48:21 +02:00
|
|
|
import appeng.api.networking.crafting.ICraftingLink;
|
2014-05-09 06:10:12 +02:00
|
|
|
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
|
|
|
import appeng.api.networking.crafting.ICraftingProvider;
|
|
|
|
import appeng.api.networking.crafting.ICraftingProviderHelper;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.api.networking.energy.IEnergySource;
|
2014-05-20 06:13:43 +02:00
|
|
|
import appeng.api.networking.events.MENetworkCraftingPatternChange;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.api.networking.security.BaseActionSource;
|
|
|
|
import appeng.api.networking.security.MachineSource;
|
|
|
|
import appeng.api.networking.ticking.IGridTickable;
|
|
|
|
import appeng.api.networking.ticking.TickRateModulation;
|
|
|
|
import appeng.api.networking.ticking.TickingRequest;
|
|
|
|
import appeng.api.parts.IPart;
|
|
|
|
import appeng.api.storage.IMEInventory;
|
|
|
|
import appeng.api.storage.IMEMonitor;
|
|
|
|
import appeng.api.storage.IStorageMonitorable;
|
2014-07-23 21:11:12 +02:00
|
|
|
import appeng.api.storage.StorageChannel;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.api.storage.data.IAEFluidStack;
|
|
|
|
import appeng.api.storage.data.IAEItemStack;
|
|
|
|
import appeng.api.util.AECableType;
|
|
|
|
import appeng.api.util.DimensionalCoord;
|
2014-03-05 08:27:42 +01:00
|
|
|
import appeng.api.util.IConfigManager;
|
2014-09-20 22:20:00 +02:00
|
|
|
import appeng.api.util.IConfigurableObject;
|
2014-03-17 20:59:50 +01:00
|
|
|
import appeng.core.settings.TickRates;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.me.GridAccessException;
|
|
|
|
import appeng.me.helpers.AENetworkProxy;
|
|
|
|
import appeng.me.storage.MEMonitorIInventory;
|
|
|
|
import appeng.me.storage.MEMonitorPassthu;
|
|
|
|
import appeng.me.storage.NullInventory;
|
2014-07-05 03:59:50 +02:00
|
|
|
import appeng.parts.automation.UpgradeInventory;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.tile.inventory.AppEngInternalAEInventory;
|
|
|
|
import appeng.tile.inventory.AppEngInternalInventory;
|
|
|
|
import appeng.tile.inventory.IAEAppEngInventory;
|
|
|
|
import appeng.tile.inventory.InvOperation;
|
2014-03-05 08:27:42 +01:00
|
|
|
import appeng.util.ConfigManager;
|
|
|
|
import appeng.util.IConfigManagerHost;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.util.InventoryAdaptor;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
import appeng.util.inv.AdaptorIInventory;
|
|
|
|
import appeng.util.inv.IInventoryDestination;
|
|
|
|
import appeng.util.inv.WrapperInvSlot;
|
2014-07-06 08:48:21 +02:00
|
|
|
import appeng.util.item.AEItemStack;
|
|
|
|
|
|
|
|
import com.google.common.collect.ImmutableSet;
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-03-05 08:27:42 +01:00
|
|
|
public class DualityInterface implements IGridTickable, ISegmentedInventory, IStorageMonitorable, IInventoryDestination, IAEAppEngInventory,
|
2014-09-20 22:20:00 +02:00
|
|
|
IConfigurableObject, IConfigManagerHost, ICraftingProvider, IUpgradeableHost, IPriorityHost
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
final int sides[] = new int[] { 0, 1, 2, 3, 4, 5, 6, 7 };
|
|
|
|
final IAEItemStack requireWork[] = new IAEItemStack[] { null, null, null, null, null, null, null, null };
|
2014-07-06 08:48:21 +02:00
|
|
|
final MultiCraftingTracker craftingTracker;
|
2014-01-20 17:41:37 +01:00
|
|
|
|
|
|
|
boolean hasConfig = false;
|
|
|
|
AENetworkProxy gridProxy;
|
|
|
|
IInterfaceHost iHost;
|
|
|
|
BaseActionSource mySrc;
|
2014-03-05 08:27:42 +01:00
|
|
|
ConfigManager cm = new ConfigManager( this );
|
2014-07-18 05:38:57 +02:00
|
|
|
int priority;
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-05-09 06:10:12 +02:00
|
|
|
List<ICraftingPatternDetails> craftingList = null;
|
|
|
|
List<ItemStack> waitingToSend = null;
|
|
|
|
|
2014-07-05 03:59:50 +02:00
|
|
|
private UpgradeInventory upgrades;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getInstalledUpgrades(Upgrades u)
|
|
|
|
{
|
|
|
|
if ( upgrades == null )
|
|
|
|
return 0;
|
|
|
|
return upgrades.getInstalledUpgrades( u );
|
|
|
|
}
|
|
|
|
|
2014-05-09 06:10:12 +02:00
|
|
|
public boolean hasItemsToSend()
|
|
|
|
{
|
|
|
|
return waitingToSend != null && !waitingToSend.isEmpty();
|
|
|
|
}
|
|
|
|
|
2014-05-19 03:05:03 +02:00
|
|
|
public void updateCraftingList()
|
|
|
|
{
|
2014-05-20 06:13:43 +02:00
|
|
|
Boolean accountedFor[] = new Boolean[] { false, false, false, false, false, false, false, false, false }; // 9...
|
|
|
|
|
|
|
|
assert (accountedFor.length == patterns.getSizeInventory());
|
|
|
|
|
2014-07-18 05:38:57 +02:00
|
|
|
if ( !gridProxy.isReady() )
|
2014-07-15 19:02:26 +02:00
|
|
|
return;
|
2014-07-18 05:38:57 +02:00
|
|
|
|
2014-05-19 03:05:03 +02:00
|
|
|
if ( craftingList != null )
|
|
|
|
{
|
|
|
|
Iterator<ICraftingPatternDetails> i = craftingList.iterator();
|
|
|
|
while (i.hasNext())
|
|
|
|
{
|
|
|
|
ICraftingPatternDetails details = i.next();
|
|
|
|
boolean found = false;
|
|
|
|
|
|
|
|
for (int x = 0; x < accountedFor.length; x++)
|
|
|
|
{
|
|
|
|
ItemStack is = patterns.getStackInSlot( x );
|
|
|
|
if ( details.getPattern() == is )
|
|
|
|
{
|
|
|
|
accountedFor[x] = found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( !found )
|
|
|
|
i.remove();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int x = 0; x < accountedFor.length; x++)
|
|
|
|
{
|
|
|
|
if ( accountedFor[x] == false )
|
|
|
|
addToCraftingList( patterns.getStackInSlot( x ) );
|
|
|
|
}
|
2014-05-20 06:13:43 +02:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
gridProxy.getGrid().postEvent( new MENetworkCraftingPatternChange( this, gridProxy.getNode() ) );
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
2014-05-19 03:05:03 +02:00
|
|
|
}
|
|
|
|
|
2014-05-09 06:10:12 +02:00
|
|
|
public void addToCraftingList(ItemStack is)
|
|
|
|
{
|
|
|
|
if ( is == null )
|
|
|
|
return;
|
|
|
|
|
2014-07-18 05:38:57 +02:00
|
|
|
if ( is.getItem() instanceof ICraftingPatternItem )
|
2014-05-09 06:10:12 +02:00
|
|
|
{
|
|
|
|
ICraftingPatternItem cpi = (ICraftingPatternItem) is.getItem();
|
|
|
|
ICraftingPatternDetails details = cpi.getPatternForItem( is, iHost.getTileEntity().getWorldObj() );
|
|
|
|
|
|
|
|
if ( details != null )
|
|
|
|
{
|
|
|
|
if ( craftingList == null )
|
|
|
|
craftingList = new LinkedList();
|
|
|
|
|
|
|
|
craftingList.add( details );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addToSendList(ItemStack is)
|
|
|
|
{
|
|
|
|
if ( is == null )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( waitingToSend == null )
|
|
|
|
waitingToSend = new LinkedList();
|
|
|
|
|
|
|
|
waitingToSend.add( is );
|
2014-06-19 08:28:45 +02:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
gridProxy.getTick().wakeDevice( gridProxy.getNode() );
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
2014-05-09 06:10:12 +02:00
|
|
|
}
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
public DualityInterface(AENetworkProxy prox, IInterfaceHost ih) {
|
|
|
|
gridProxy = prox;
|
2014-02-09 02:34:52 +01:00
|
|
|
gridProxy.setFlags( GridFlags.REQUIRE_CHANNEL );
|
|
|
|
|
2014-07-05 03:59:50 +02:00
|
|
|
upgrades = new UpgradeInventory( gridProxy.getMachineRepresentation(), this, 1 );
|
|
|
|
cm.registerSetting( Settings.BLOCK, YesNo.NO );
|
2014-07-31 04:02:37 +02:00
|
|
|
cm.registerSetting( Settings.INTERFACE_TERMINAL, YesNo.YES );
|
2014-07-05 03:59:50 +02:00
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
iHost = ih;
|
2014-07-06 08:48:21 +02:00
|
|
|
craftingTracker = new MultiCraftingTracker( iHost, 9 );
|
2014-01-20 17:41:37 +01:00
|
|
|
mySrc = fluids.changeSource = items.changeSource = new MachineSource( iHost );
|
|
|
|
}
|
|
|
|
|
2014-01-31 01:50:11 +01:00
|
|
|
@Override
|
|
|
|
public void saveChanges()
|
|
|
|
{
|
|
|
|
iHost.saveChanges();
|
|
|
|
}
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
private void readConfig()
|
|
|
|
{
|
|
|
|
hasConfig = false;
|
|
|
|
|
|
|
|
for (ItemStack p : config)
|
|
|
|
{
|
|
|
|
if ( p != null )
|
|
|
|
{
|
|
|
|
hasConfig = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean had = hasWorkToDo();
|
|
|
|
|
|
|
|
for (int x = 0; x < 8; x++)
|
|
|
|
updatePlan( x );
|
|
|
|
|
|
|
|
boolean has = hasWorkToDo();
|
|
|
|
|
|
|
|
if ( had != has )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if ( has )
|
2014-02-12 05:43:06 +01:00
|
|
|
gridProxy.getTick().alertDevice( gridProxy.getNode() );
|
2014-01-20 17:41:37 +01:00
|
|
|
else
|
|
|
|
gridProxy.getTick().sleepDevice( gridProxy.getNode() );
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-23 07:08:38 +02:00
|
|
|
notifyNeightbors();
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void writeToNBT(NBTTagCompound data)
|
|
|
|
{
|
|
|
|
config.writeToNBT( data, "config" );
|
|
|
|
patterns.writeToNBT( data, "patterns" );
|
|
|
|
storage.writeToNBT( data, "storage" );
|
2014-07-12 21:27:51 +02:00
|
|
|
upgrades.writeToNBT( data, "upgrades" );
|
2014-07-31 03:57:33 +02:00
|
|
|
cm.writeToNBT( data );
|
2014-07-06 08:48:21 +02:00
|
|
|
craftingTracker.writeToNBT( data );
|
2014-07-18 05:38:57 +02:00
|
|
|
data.setInteger( "priority", priority );
|
2014-05-09 06:10:12 +02:00
|
|
|
|
|
|
|
NBTTagList waitingToSend = new NBTTagList();
|
|
|
|
if ( this.waitingToSend != null )
|
|
|
|
{
|
|
|
|
for (ItemStack is : this.waitingToSend)
|
|
|
|
{
|
|
|
|
NBTTagCompound item = new NBTTagCompound();
|
|
|
|
is.writeToNBT( item );
|
|
|
|
waitingToSend.appendTag( item );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
data.setTag( "waitingToSend", waitingToSend );
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void readFromNBT(NBTTagCompound data)
|
|
|
|
{
|
2014-05-09 06:10:12 +02:00
|
|
|
this.waitingToSend = null;
|
|
|
|
NBTTagList waitingList = data.getTagList( "waitingToSend", 10 );
|
|
|
|
if ( waitingList != null )
|
|
|
|
{
|
|
|
|
for (int x = 0; x < waitingList.tagCount(); x++)
|
|
|
|
{
|
|
|
|
NBTTagCompound c = waitingList.getCompoundTagAt( x );
|
|
|
|
if ( c != null )
|
|
|
|
{
|
|
|
|
ItemStack is = ItemStack.loadItemStackFromNBT( c );
|
|
|
|
addToSendList( is );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-06 08:48:21 +02:00
|
|
|
craftingTracker.readFromNBT( data );
|
2014-07-12 21:27:51 +02:00
|
|
|
upgrades.readFromNBT( data, "upgrades" );
|
2014-01-20 17:41:37 +01:00
|
|
|
config.readFromNBT( data, "config" );
|
|
|
|
patterns.readFromNBT( data, "patterns" );
|
|
|
|
storage.readFromNBT( data, "storage" );
|
2014-07-18 05:38:57 +02:00
|
|
|
priority = data.getInteger( "priority" );
|
2014-07-31 03:57:33 +02:00
|
|
|
cm.readFromNBT( data );
|
2014-01-20 17:41:37 +01:00
|
|
|
readConfig();
|
2014-05-23 04:41:24 +02:00
|
|
|
updateCraftingList();
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
AppEngInternalAEInventory config = new AppEngInternalAEInventory( this, 8 );
|
|
|
|
AppEngInternalInventory storage = new AppEngInternalInventory( this, 8 );
|
|
|
|
AppEngInternalInventory patterns = new AppEngInternalInventory( this, 9 );
|
|
|
|
|
|
|
|
WrapperInvSlot slotInv = new WrapperInvSlot( storage );
|
2014-07-12 23:28:55 +02:00
|
|
|
|
|
|
|
private InventoryAdaptor getAdaptor(int slot)
|
|
|
|
{
|
|
|
|
return new AdaptorIInventory( slotInv.getWrapper( slot ) );
|
|
|
|
}
|
2014-01-20 17:41:37 +01:00
|
|
|
|
|
|
|
IMEInventory<IAEItemStack> destination;
|
|
|
|
private boolean isWorking = false;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canInsert(ItemStack stack)
|
|
|
|
{
|
|
|
|
IAEItemStack out = destination.injectItems( AEApi.instance().storage().createItemStack( stack ), Actionable.SIMULATE, null );
|
|
|
|
if ( out == null )
|
|
|
|
return true;
|
|
|
|
return out.getStackSize() != stack.stackSize;
|
|
|
|
// ItemStack after = adaptor.simulateAdd( stack );
|
|
|
|
// if ( after == null )
|
|
|
|
// return true;
|
|
|
|
// return after.stackSize != stack.stackSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updatePlan(int slot)
|
|
|
|
{
|
|
|
|
IAEItemStack req = config.getAEStackInSlot( slot );
|
2014-04-09 21:22:17 +02:00
|
|
|
if ( req != null && req.getStackSize() <= 0 )
|
|
|
|
{
|
2014-04-18 05:33:48 +02:00
|
|
|
config.setInventorySlotContents( slot, null );
|
2014-04-09 21:22:17 +02:00
|
|
|
req = null;
|
|
|
|
}
|
2014-04-18 05:33:48 +02:00
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
ItemStack Stored = storage.getStackInSlot( slot );
|
|
|
|
|
|
|
|
if ( req == null && Stored != null )
|
|
|
|
{
|
|
|
|
IAEItemStack work = AEApi.instance().storage().createItemStack( Stored );
|
|
|
|
requireWork[slot] = work.setStackSize( -work.getStackSize() );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if ( req != null )
|
|
|
|
{
|
|
|
|
if ( Stored == null ) // need to add stuff!
|
|
|
|
{
|
|
|
|
requireWork[slot] = req.copy();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if ( req.isSameType( Stored ) ) // same type ( qty diffrent? )!
|
|
|
|
{
|
|
|
|
if ( req.getStackSize() != Stored.stackSize )
|
|
|
|
{
|
|
|
|
requireWork[slot] = req.copy();
|
|
|
|
requireWork[slot].setStackSize( req.getStackSize() - Stored.stackSize );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( Stored != null ) // dispose!
|
|
|
|
{
|
|
|
|
IAEItemStack work = AEApi.instance().storage().createItemStack( Stored );
|
|
|
|
requireWork[slot] = work.setStackSize( -work.getStackSize() );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// else
|
|
|
|
|
|
|
|
requireWork[slot] = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
static private boolean interfaceRequest = false;
|
|
|
|
|
|
|
|
class InterfaceInventory extends MEMonitorIInventory
|
|
|
|
{
|
|
|
|
|
|
|
|
public InterfaceInventory(DualityInterface tileInterface) {
|
2014-07-24 00:39:42 +02:00
|
|
|
super( new AdaptorIInventory( tileInterface.storage ) );
|
2014-01-20 17:41:37 +01:00
|
|
|
mySource = new MachineSource( iHost );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IAEItemStack injectItems(IAEItemStack input, Actionable type, BaseActionSource src)
|
|
|
|
{
|
|
|
|
if ( interfaceRequest )
|
|
|
|
return input;
|
|
|
|
|
|
|
|
return super.injectItems( input, type, src );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IAEItemStack extractItems(IAEItemStack request, Actionable type, BaseActionSource src)
|
|
|
|
{
|
|
|
|
if ( interfaceRequest )
|
|
|
|
return null;
|
|
|
|
|
|
|
|
return super.extractItems( request, type, src );
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
private boolean usePlan(int x, IAEItemStack itemStack)
|
|
|
|
{
|
|
|
|
boolean changed = false;
|
2014-07-12 23:28:55 +02:00
|
|
|
InventoryAdaptor adaptor = getAdaptor( x );
|
2014-01-20 17:41:37 +01:00
|
|
|
interfaceRequest = isWorking = true;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
destination = gridProxy.getStorage().getItemInventory();
|
|
|
|
IEnergySource src = gridProxy.getEnergy();
|
|
|
|
|
2014-07-06 08:48:21 +02:00
|
|
|
if ( craftingTracker.isBusy( x ) )
|
|
|
|
changed = handleCrafting( x, adaptor, itemStack ) || changed;
|
|
|
|
else if ( itemStack.getStackSize() > 0 )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
2014-06-02 08:32:38 +02:00
|
|
|
// make sure strange things didn't happen...
|
|
|
|
if ( adaptor.simulateAdd( itemStack.getItemStack() ) != null )
|
|
|
|
{
|
|
|
|
changed = true;
|
|
|
|
throw new GridAccessException();
|
|
|
|
}
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
IAEItemStack aquired = Platform.poweredExtraction( src, destination, itemStack, mySrc );
|
|
|
|
if ( aquired != null )
|
|
|
|
{
|
|
|
|
changed = true;
|
|
|
|
ItemStack issue = adaptor.addItems( aquired.getItemStack() );
|
|
|
|
if ( issue != null )
|
2014-04-09 21:22:17 +02:00
|
|
|
throw new RuntimeException( "bad attempt at managing inventory. ( addItems )" );
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
2014-07-06 08:48:21 +02:00
|
|
|
else
|
|
|
|
changed = handleCrafting( x, adaptor, itemStack ) || changed;
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
else if ( itemStack.getStackSize() < 0 )
|
|
|
|
{
|
|
|
|
IAEItemStack toStore = itemStack.copy();
|
|
|
|
toStore.setStackSize( -toStore.getStackSize() );
|
|
|
|
|
|
|
|
long diff = toStore.getStackSize();
|
|
|
|
|
2014-06-02 08:32:38 +02:00
|
|
|
// make sure strange things didn't happen...
|
|
|
|
ItemStack canExtract = adaptor.simulateRemove( (int) diff, toStore.getItemStack(), null );
|
|
|
|
if ( canExtract == null || canExtract.stackSize != diff )
|
|
|
|
{
|
|
|
|
changed = true;
|
|
|
|
throw new GridAccessException();
|
|
|
|
}
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
toStore = Platform.poweredInsert( src, destination, toStore, mySrc );
|
|
|
|
|
|
|
|
if ( toStore != null )
|
|
|
|
diff -= toStore.getStackSize();
|
|
|
|
|
|
|
|
if ( diff != 0 )
|
|
|
|
{
|
|
|
|
// extract items!
|
|
|
|
changed = true;
|
|
|
|
ItemStack removed = adaptor.removeItems( (int) diff, null, null );
|
|
|
|
if ( removed == null )
|
2014-06-02 08:32:38 +02:00
|
|
|
throw new RuntimeException( "bad attempt at managing inventory. ( removeItems )" );
|
2014-01-20 17:41:37 +01:00
|
|
|
else if ( removed.stackSize != diff )
|
2014-06-02 08:32:38 +02:00
|
|
|
throw new RuntimeException( "bad attempt at managing inventory. ( removeItems )" );
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// else wtf?
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( changed )
|
|
|
|
updatePlan( x );
|
|
|
|
|
|
|
|
interfaceRequest = isWorking = false;
|
|
|
|
return changed;
|
|
|
|
}
|
|
|
|
|
2014-07-06 08:48:21 +02:00
|
|
|
private boolean handleCrafting(int x, InventoryAdaptor d, IAEItemStack itemStack)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2014-07-12 22:50:50 +02:00
|
|
|
if ( getInstalledUpgrades( Upgrades.CRAFTING ) > 0 && itemStack != null )
|
2014-07-06 08:48:21 +02:00
|
|
|
{
|
2014-07-13 02:22:03 +02:00
|
|
|
return craftingTracker.handleCrafting( x, itemStack.getStackSize(), itemStack, d, iHost.getTileEntity().getWorldObj(), gridProxy.getGrid(),
|
2014-07-06 08:48:21 +02:00
|
|
|
gridProxy.getCrafting(), mySrc );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
public IInventory getConfig()
|
|
|
|
{
|
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IInventory getPatterns()
|
|
|
|
{
|
|
|
|
return patterns;
|
|
|
|
}
|
|
|
|
|
2014-07-23 21:11:12 +02:00
|
|
|
MEMonitorPassthu<IAEItemStack> items = new MEMonitorPassthu<IAEItemStack>( new NullInventory(), StorageChannel.ITEMS );
|
|
|
|
MEMonitorPassthu<IAEFluidStack> fluids = new MEMonitorPassthu<IAEFluidStack>( new NullInventory(), StorageChannel.FLUIDS );
|
2014-01-20 17:41:37 +01:00
|
|
|
|
|
|
|
public void gridChanged()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
items.setInternal( gridProxy.getStorage().getItemInventory() );
|
|
|
|
fluids.setInternal( gridProxy.getStorage().getFluidInventory() );
|
|
|
|
}
|
|
|
|
catch (GridAccessException gae)
|
|
|
|
{
|
|
|
|
items.setInternal( new NullInventory() );
|
|
|
|
fluids.setInternal( new NullInventory() );
|
|
|
|
}
|
|
|
|
|
2014-06-23 07:08:38 +02:00
|
|
|
notifyNeightbors();
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public AECableType getCableConnectionType(ForgeDirection dir)
|
|
|
|
{
|
|
|
|
return AECableType.SMART;
|
|
|
|
}
|
|
|
|
|
|
|
|
public DimensionalCoord getLocation()
|
|
|
|
{
|
|
|
|
return new DimensionalCoord( iHost.getTileEntity() );
|
|
|
|
}
|
|
|
|
|
|
|
|
public IInventory getInternalInventory()
|
|
|
|
{
|
|
|
|
return storage;
|
|
|
|
}
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
public void markDirty()
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
2014-01-31 02:23:12 +01:00
|
|
|
for (int slot = 0; slot < storage.getSizeInventory(); slot++)
|
2014-02-09 02:34:52 +01:00
|
|
|
onChangeInventory( storage, slot, InvOperation.markDirty, null, null );
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added)
|
|
|
|
{
|
|
|
|
if ( isWorking )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( inv == config )
|
|
|
|
readConfig();
|
2014-05-23 04:41:24 +02:00
|
|
|
else if ( inv == patterns && (removed != null || added != null) )
|
2014-05-20 06:13:43 +02:00
|
|
|
updateCraftingList();
|
2014-01-20 17:41:37 +01:00
|
|
|
else if ( inv == storage && slot >= 0 )
|
|
|
|
{
|
|
|
|
boolean had = hasWorkToDo();
|
|
|
|
|
|
|
|
updatePlan( slot );
|
|
|
|
|
|
|
|
boolean now = hasWorkToDo();
|
|
|
|
|
|
|
|
if ( had != now )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if ( now )
|
2014-02-12 05:43:06 +01:00
|
|
|
gridProxy.getTick().alertDevice( gridProxy.getNode() );
|
2014-01-20 17:41:37 +01:00
|
|
|
else
|
|
|
|
gridProxy.getTick().sleepDevice( gridProxy.getNode() );
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasWorkToDo()
|
|
|
|
{
|
2014-05-09 06:10:12 +02:00
|
|
|
return hasItemsToSend() || requireWork[0] != null || requireWork[1] != null || requireWork[2] != null || requireWork[3] != null
|
|
|
|
|| requireWork[4] != null || requireWork[5] != null || requireWork[6] != null || requireWork[7] != null;
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private boolean updateStorage()
|
|
|
|
{
|
|
|
|
boolean didSomething = false;
|
|
|
|
|
|
|
|
for (int x = 0; x < 8; x++)
|
|
|
|
{
|
|
|
|
if ( requireWork[x] != null )
|
|
|
|
{
|
|
|
|
didSomething = usePlan( x, requireWork[x] ) || didSomething;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return didSomething;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasConfig()
|
|
|
|
{
|
|
|
|
return hasConfig;
|
|
|
|
}
|
|
|
|
|
|
|
|
public int[] getAccessibleSlotsFromSide(int side)
|
|
|
|
{
|
|
|
|
return sides;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TickingRequest getTickingRequest(IGridNode node)
|
|
|
|
{
|
2014-03-17 20:59:50 +01:00
|
|
|
return new TickingRequest( TickRates.Interface.min, TickRates.Interface.max, !hasWorkToDo(), true );
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
|
|
|
|
{
|
2014-07-05 18:53:16 +02:00
|
|
|
if ( !gridProxy.isActive() )
|
|
|
|
return TickRateModulation.SLEEP;
|
|
|
|
|
2014-06-19 08:28:45 +02:00
|
|
|
if ( hasItemsToSend() )
|
|
|
|
pushItemsOut( EnumSet.allOf( ForgeDirection.class ) );
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
boolean couldDoWork = updateStorage();
|
|
|
|
return hasWorkToDo() ? (couldDoWork ? TickRateModulation.URGENT : TickRateModulation.SLOWER) : TickRateModulation.SLEEP;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IMEMonitor<IAEItemStack> getItemInventory()
|
|
|
|
{
|
|
|
|
if ( hasConfig() )
|
|
|
|
return new InterfaceInventory( this );
|
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IMEMonitor<IAEFluidStack> getFluidInventory()
|
|
|
|
{
|
|
|
|
if ( hasConfig() )
|
|
|
|
return null;
|
|
|
|
|
|
|
|
return fluids;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IInventory getInventoryByName(String name)
|
|
|
|
{
|
|
|
|
if ( name.equals( "storage" ) )
|
|
|
|
return storage;
|
|
|
|
|
|
|
|
if ( name.equals( "patterns" ) )
|
|
|
|
return patterns;
|
|
|
|
|
|
|
|
if ( name.equals( "config" ) )
|
|
|
|
return config;
|
|
|
|
|
2014-07-05 03:59:50 +02:00
|
|
|
if ( name.equals( "upgrades" ) )
|
|
|
|
return upgrades;
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IInventory getStorage()
|
|
|
|
{
|
|
|
|
return storage;
|
|
|
|
}
|
|
|
|
|
2014-07-05 03:59:50 +02:00
|
|
|
@Override
|
2014-01-20 17:41:37 +01:00
|
|
|
public TileEntity getTile()
|
|
|
|
{
|
|
|
|
return (TileEntity) (iHost instanceof TileEntity ? iHost : null);
|
|
|
|
}
|
|
|
|
|
|
|
|
public IPart getPart()
|
|
|
|
{
|
|
|
|
return (IPart) (iHost instanceof IPart ? iHost : null);
|
|
|
|
}
|
|
|
|
|
2014-03-05 08:27:42 +01:00
|
|
|
public appeng.api.util.IConfigManager getConfigManager()
|
|
|
|
{
|
|
|
|
return cm;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue)
|
2014-07-05 03:59:50 +02:00
|
|
|
{
|
|
|
|
if ( getInstalledUpgrades( Upgrades.CRAFTING ) == 0 )
|
|
|
|
cancelCrafting();
|
2014-07-31 03:57:33 +02:00
|
|
|
|
|
|
|
markDirty();
|
2014-07-05 03:59:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void cancelCrafting()
|
2014-03-05 08:27:42 +01:00
|
|
|
{
|
2014-07-06 08:48:21 +02:00
|
|
|
craftingTracker.cancel();
|
2014-04-18 05:33:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public IStorageMonitorable getMonitorable(ForgeDirection side, BaseActionSource src, IStorageMonitorable myInterface)
|
|
|
|
{
|
|
|
|
if ( Platform.canAccess( gridProxy, src ) )
|
|
|
|
return myInterface;
|
|
|
|
|
|
|
|
final DualityInterface di = this;
|
|
|
|
|
|
|
|
return new IStorageMonitorable() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IMEMonitor<IAEItemStack> getItemInventory()
|
|
|
|
{
|
|
|
|
return new InterfaceInventory( di );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IMEMonitor<IAEFluidStack> getFluidInventory()
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
};
|
2014-05-09 06:10:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-19 08:28:45 +02:00
|
|
|
public boolean isBusy()
|
|
|
|
{
|
|
|
|
if ( hasItemsToSend() )
|
|
|
|
return true;
|
|
|
|
|
|
|
|
boolean busy = false;
|
|
|
|
|
|
|
|
if ( isBlocking() )
|
|
|
|
{
|
|
|
|
EnumSet<ForgeDirection> possibleDirections = iHost.getTargets();
|
|
|
|
TileEntity tile = iHost.getTileEntity();
|
|
|
|
World w = tile.getWorldObj();
|
|
|
|
|
2014-07-30 03:02:51 +02:00
|
|
|
boolean allAreBusy = true;
|
|
|
|
|
2014-06-19 08:28:45 +02:00
|
|
|
for (ForgeDirection s : possibleDirections)
|
|
|
|
{
|
|
|
|
TileEntity te = w.getTileEntity( tile.xCoord + s.offsetX, tile.yCoord + s.offsetY, tile.zCoord + s.offsetZ );
|
|
|
|
|
|
|
|
InventoryAdaptor ad = InventoryAdaptor.getAdaptor( te, s.getOpposite() );
|
|
|
|
if ( ad != null )
|
|
|
|
{
|
2014-07-23 18:47:59 +02:00
|
|
|
if ( ad.simulateRemove( 1, null, null ) == null )
|
2014-06-19 08:28:45 +02:00
|
|
|
{
|
2014-07-23 18:47:59 +02:00
|
|
|
allAreBusy = false;
|
2014-06-19 08:28:45 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-07-30 03:02:51 +02:00
|
|
|
|
2014-07-23 18:47:59 +02:00
|
|
|
busy = allAreBusy;
|
2014-06-19 08:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return busy;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isBlocking()
|
|
|
|
{
|
2014-07-05 03:59:50 +02:00
|
|
|
return cm.getSetting( Settings.BLOCK ) == YesNo.YES;
|
2014-06-19 08:28:45 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCrafting table)
|
2014-05-09 06:10:12 +02:00
|
|
|
{
|
2014-07-12 21:28:24 +02:00
|
|
|
if ( hasItemsToSend() || !gridProxy.isActive() )
|
2014-05-09 06:10:12 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
TileEntity tile = iHost.getTileEntity();
|
|
|
|
World w = tile.getWorldObj();
|
|
|
|
|
|
|
|
EnumSet<ForgeDirection> possibleDirections = iHost.getTargets();
|
|
|
|
for (ForgeDirection s : possibleDirections)
|
|
|
|
{
|
|
|
|
TileEntity te = w.getTileEntity( tile.xCoord + s.offsetX, tile.yCoord + s.offsetY, tile.zCoord + s.offsetZ );
|
2014-07-13 00:14:01 +02:00
|
|
|
if ( te instanceof IInterfaceHost )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if ( ((IInterfaceHost) te).getInterfaceDuality().sameGrid( gridProxy.getGrid() ) )
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-19 08:28:45 +02:00
|
|
|
if ( te instanceof ICraftingMachine )
|
2014-05-09 06:10:12 +02:00
|
|
|
{
|
2014-06-20 09:12:39 +02:00
|
|
|
ICraftingMachine cm = (ICraftingMachine) te;
|
|
|
|
if ( cm.acceptsPlans() )
|
|
|
|
{
|
|
|
|
if ( cm.pushPattern( patternDetails, table, s.getOpposite() ) )
|
|
|
|
return true;
|
|
|
|
continue;
|
|
|
|
}
|
2014-05-09 06:10:12 +02:00
|
|
|
}
|
2014-06-20 09:12:39 +02:00
|
|
|
|
|
|
|
InventoryAdaptor ad = InventoryAdaptor.getAdaptor( te, s.getOpposite() );
|
|
|
|
if ( ad != null )
|
2014-05-09 06:10:12 +02:00
|
|
|
{
|
2014-07-23 18:47:59 +02:00
|
|
|
if ( isBlocking() )
|
|
|
|
{
|
|
|
|
if ( ad.simulateRemove( 1, null, null ) != null )
|
|
|
|
continue;
|
|
|
|
}
|
2014-07-30 03:02:51 +02:00
|
|
|
|
2014-07-12 01:59:55 +02:00
|
|
|
if ( acceptsItems( ad, table ) )
|
2014-06-20 09:12:39 +02:00
|
|
|
{
|
2014-07-12 01:59:55 +02:00
|
|
|
for (int x = 0; x < table.getSizeInventory(); x++)
|
2014-05-09 06:10:12 +02:00
|
|
|
{
|
2014-07-12 01:59:55 +02:00
|
|
|
ItemStack is = table.getStackInSlot( x );
|
|
|
|
if ( is != null )
|
|
|
|
{
|
|
|
|
addToSendList( ad.addItems( is ) );
|
|
|
|
}
|
2014-05-09 06:10:12 +02:00
|
|
|
}
|
2014-07-12 01:59:55 +02:00
|
|
|
pushItemsOut( possibleDirections );
|
|
|
|
return true;
|
2014-05-09 06:10:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-07-13 00:14:01 +02:00
|
|
|
private boolean sameGrid(IGrid grid) throws GridAccessException
|
|
|
|
{
|
|
|
|
return grid == gridProxy.getGrid();
|
|
|
|
}
|
|
|
|
|
2014-07-12 01:59:55 +02:00
|
|
|
private boolean acceptsItems(InventoryAdaptor ad, InventoryCrafting table)
|
|
|
|
{
|
|
|
|
for (int x = 0; x < table.getSizeInventory(); x++)
|
|
|
|
{
|
|
|
|
ItemStack is = table.getStackInSlot( x );
|
|
|
|
if ( is == null )
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if ( ad.simulateAdd( is.copy() ) != null )
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-09 06:10:12 +02:00
|
|
|
private void pushItemsOut(EnumSet<ForgeDirection> possibleDirections)
|
|
|
|
{
|
2014-06-19 08:28:45 +02:00
|
|
|
if ( !hasItemsToSend() )
|
2014-05-09 06:10:12 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
TileEntity tile = iHost.getTileEntity();
|
|
|
|
World w = tile.getWorldObj();
|
|
|
|
|
|
|
|
Iterator<ItemStack> i = waitingToSend.iterator();
|
|
|
|
while (i.hasNext())
|
|
|
|
{
|
|
|
|
ItemStack whatToSend = i.next();
|
|
|
|
|
|
|
|
for (ForgeDirection s : possibleDirections)
|
|
|
|
{
|
|
|
|
TileEntity te = w.getTileEntity( tile.xCoord + s.offsetX, tile.yCoord + s.offsetY, tile.zCoord + s.offsetZ );
|
2014-06-19 08:28:45 +02:00
|
|
|
if ( te == null )
|
|
|
|
continue;
|
2014-05-09 06:10:12 +02:00
|
|
|
|
|
|
|
InventoryAdaptor ad = InventoryAdaptor.getAdaptor( te, s.getOpposite() );
|
|
|
|
if ( ad != null )
|
|
|
|
{
|
2014-07-30 03:02:51 +02:00
|
|
|
ItemStack Result = ad.addItems( whatToSend );
|
|
|
|
|
|
|
|
if ( Result == null )
|
|
|
|
whatToSend = null;
|
|
|
|
else
|
|
|
|
whatToSend.stackSize -= whatToSend.stackSize - Result.stackSize;
|
|
|
|
|
2014-05-09 06:10:12 +02:00
|
|
|
if ( whatToSend == null )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( whatToSend == null )
|
|
|
|
i.remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( waitingToSend.isEmpty() )
|
|
|
|
waitingToSend = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void provideCrafting(ICraftingProviderHelper craftingTracker)
|
|
|
|
{
|
2014-07-12 21:28:24 +02:00
|
|
|
if ( gridProxy.isActive() && craftingList != null )
|
2014-05-20 06:13:43 +02:00
|
|
|
{
|
|
|
|
for (ICraftingPatternDetails details : craftingList)
|
2014-07-18 05:38:57 +02:00
|
|
|
{
|
|
|
|
details.setPriority( this.priority );
|
2014-05-20 06:13:43 +02:00
|
|
|
craftingTracker.addCraftingOption( this, details );
|
2014-07-18 05:38:57 +02:00
|
|
|
}
|
2014-05-20 06:13:43 +02:00
|
|
|
}
|
2014-05-09 06:10:12 +02:00
|
|
|
}
|
2014-03-05 08:27:42 +01:00
|
|
|
|
2014-06-23 06:51:20 +02:00
|
|
|
public void addDrops(List<ItemStack> drops)
|
|
|
|
{
|
|
|
|
if ( waitingToSend != null )
|
|
|
|
{
|
|
|
|
for (ItemStack is : waitingToSend)
|
|
|
|
if ( is != null )
|
|
|
|
drops.add( is );
|
|
|
|
}
|
|
|
|
|
2014-07-06 08:48:21 +02:00
|
|
|
for (ItemStack is : upgrades)
|
|
|
|
if ( is != null )
|
|
|
|
drops.add( is );
|
|
|
|
|
2014-06-23 06:51:20 +02:00
|
|
|
for (ItemStack is : storage)
|
|
|
|
if ( is != null )
|
|
|
|
drops.add( is );
|
|
|
|
|
|
|
|
for (ItemStack is : patterns)
|
|
|
|
if ( is != null )
|
|
|
|
drops.add( is );
|
|
|
|
}
|
|
|
|
|
2014-06-23 07:08:38 +02:00
|
|
|
public void notifyNeightbors()
|
|
|
|
{
|
2014-07-05 23:52:15 +02:00
|
|
|
if ( gridProxy.isActive() )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2014-07-12 21:28:24 +02:00
|
|
|
gridProxy.getGrid().postEvent( new MENetworkCraftingPatternChange( this, gridProxy.getNode() ) );
|
2014-07-05 23:52:15 +02:00
|
|
|
gridProxy.getTick().wakeDevice( gridProxy.getNode() );
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-23 07:08:38 +02:00
|
|
|
TileEntity te = iHost.getTileEntity();
|
|
|
|
if ( te != null && te.getWorldObj() != null )
|
2014-07-08 06:54:28 +02:00
|
|
|
Platform.notifyBlocksOfNeighbors( te.getWorldObj(), te.xCoord, te.yCoord, te.zCoord );
|
2014-06-23 07:08:38 +02:00
|
|
|
}
|
|
|
|
|
2014-07-05 03:59:50 +02:00
|
|
|
public IUpgradeableHost getHost()
|
|
|
|
{
|
|
|
|
if ( getPart() instanceof IUpgradeableHost )
|
|
|
|
return (IUpgradeableHost) getPart();
|
|
|
|
if ( getTile() instanceof IUpgradeableHost )
|
|
|
|
return (IUpgradeableHost) getTile();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-07-06 08:48:21 +02:00
|
|
|
public ImmutableSet<ICraftingLink> getRequestedJobs()
|
|
|
|
{
|
|
|
|
return craftingTracker.getRequestedJobs();
|
|
|
|
}
|
|
|
|
|
2014-09-20 22:36:48 +02:00
|
|
|
public IAEItemStack injectCraftedItems(ICraftingLink link, IAEItemStack aquired, Actionable mode)
|
2014-07-06 08:48:21 +02:00
|
|
|
{
|
2014-07-12 23:28:55 +02:00
|
|
|
int slot = craftingTracker.getSlot( link );
|
2014-07-06 08:48:21 +02:00
|
|
|
|
2014-07-12 23:28:55 +02:00
|
|
|
if ( aquired != null && slot >= 0 && slot <= requireWork.length )
|
2014-07-06 08:48:21 +02:00
|
|
|
{
|
2014-07-12 23:28:55 +02:00
|
|
|
InventoryAdaptor adaptor = getAdaptor( slot );
|
2014-07-06 08:48:21 +02:00
|
|
|
|
|
|
|
if ( mode == Actionable.SIMULATE )
|
|
|
|
return AEItemStack.create( adaptor.simulateAdd( aquired.getItemStack() ) );
|
|
|
|
else
|
|
|
|
{
|
|
|
|
IAEItemStack is = AEItemStack.create( adaptor.addItems( aquired.getItemStack() ) );
|
2014-07-12 23:28:55 +02:00
|
|
|
updatePlan( slot );
|
2014-07-06 08:48:21 +02:00
|
|
|
return is;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return aquired;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void jobStateChange(ICraftingLink link)
|
|
|
|
{
|
|
|
|
craftingTracker.jobStateChange( link );
|
|
|
|
}
|
|
|
|
|
2014-07-09 10:17:11 +02:00
|
|
|
static final Set<Block> badBlocks = new HashSet();
|
|
|
|
|
2014-07-08 05:48:21 +02:00
|
|
|
public String getTermName()
|
|
|
|
{
|
|
|
|
TileEntity tile = iHost.getTileEntity();
|
|
|
|
World w = tile.getWorldObj();
|
|
|
|
|
2014-07-13 08:45:41 +02:00
|
|
|
if ( ((ICustomNameObject) iHost).hasCustomName() )
|
|
|
|
return ((ICustomNameObject) iHost).getCustomName();
|
2014-07-13 00:30:41 +02:00
|
|
|
|
2014-07-08 05:48:21 +02:00
|
|
|
EnumSet<ForgeDirection> possibleDirections = iHost.getTargets();
|
|
|
|
for (ForgeDirection s : possibleDirections)
|
|
|
|
{
|
|
|
|
Vec3 from = Vec3.createVectorHelper( (double) tile.xCoord + 0.5, (double) tile.yCoord + 0.5, (double) tile.zCoord + 0.5 );
|
|
|
|
from = from.addVector( s.offsetX * 0.501, s.offsetY * 0.501, s.offsetZ * 0.501 );
|
|
|
|
Vec3 to = from.addVector( s.offsetX, s.offsetY, s.offsetZ );
|
|
|
|
|
|
|
|
Block blk = w.getBlock( tile.xCoord + s.offsetX, tile.yCoord + s.offsetY, tile.zCoord + s.offsetZ );
|
|
|
|
MovingObjectPosition mop = w.rayTraceBlocks( from, to, true );
|
|
|
|
|
|
|
|
TileEntity te = w.getTileEntity( tile.xCoord + s.offsetX, tile.yCoord + s.offsetY, tile.zCoord + s.offsetZ );
|
|
|
|
|
2014-07-09 10:17:11 +02:00
|
|
|
if ( te == null )
|
2014-07-13 00:30:41 +02:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if ( te instanceof IInterfaceHost )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if ( ((IInterfaceHost) te).getInterfaceDuality().sameGrid( gridProxy.getGrid() ) )
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
2014-07-09 10:17:11 +02:00
|
|
|
|
|
|
|
Item item = Item.getItemFromBlock( blk );
|
|
|
|
|
|
|
|
if ( item == null )
|
2014-07-08 05:48:21 +02:00
|
|
|
{
|
2014-07-09 10:17:11 +02:00
|
|
|
return blk.getUnlocalizedName();
|
|
|
|
}
|
|
|
|
|
|
|
|
ItemStack what = new ItemStack( item, 1, blk.getDamageValue( w, tile.xCoord + s.offsetX, tile.yCoord + s.offsetY, tile.zCoord + s.offsetZ ) );
|
|
|
|
|
2014-08-09 03:21:31 +02:00
|
|
|
if ( te instanceof ICraftingMachine || InventoryAdaptor.getAdaptor( te, s.getOpposite() ) != null )
|
2014-07-09 10:17:11 +02:00
|
|
|
{
|
2014-08-09 03:21:31 +02:00
|
|
|
if ( te instanceof IInventory && ((IInventory) te).getSizeInventory() == 0 )
|
|
|
|
continue;
|
2014-07-13 00:30:41 +02:00
|
|
|
|
2014-08-09 03:21:31 +02:00
|
|
|
if ( te instanceof ISidedInventory )
|
|
|
|
{
|
|
|
|
int[] sides = ((ISidedInventory) te).getAccessibleSlotsFromSide( s.getOpposite().ordinal() );
|
2014-08-01 06:52:16 +02:00
|
|
|
|
2014-08-09 03:21:31 +02:00
|
|
|
if ( sides == null || sides.length == 0 )
|
|
|
|
continue;
|
|
|
|
}
|
2014-07-13 00:30:41 +02:00
|
|
|
|
2014-08-09 03:21:31 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if ( mop != null && !badBlocks.contains( blk ) )
|
|
|
|
{
|
2014-07-09 10:17:11 +02:00
|
|
|
if ( mop.blockX == te.xCoord && mop.blockY == te.yCoord && mop.blockZ == te.zCoord )
|
|
|
|
{
|
|
|
|
ItemStack g = blk.getPickBlock( mop, w, te.xCoord, te.yCoord, te.zCoord );
|
|
|
|
if ( g != null )
|
|
|
|
what = g;
|
|
|
|
}
|
2014-07-08 05:48:21 +02:00
|
|
|
}
|
|
|
|
}
|
2014-08-09 03:21:31 +02:00
|
|
|
catch (Throwable t)
|
|
|
|
{
|
|
|
|
badBlocks.add( blk ); // nope!
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( what.getItem() != null )
|
|
|
|
return what.getUnlocalizedName();
|
2014-07-08 05:48:21 +02:00
|
|
|
}
|
2014-08-09 03:21:31 +02:00
|
|
|
|
2014-07-08 05:48:21 +02:00
|
|
|
}
|
|
|
|
|
2014-07-13 00:30:41 +02:00
|
|
|
return "Nothing";
|
2014-07-08 05:48:21 +02:00
|
|
|
}
|
2014-07-13 03:20:21 +02:00
|
|
|
|
|
|
|
public long getSortValue()
|
|
|
|
{
|
|
|
|
TileEntity te = iHost.getTileEntity();
|
|
|
|
return (te.zCoord << 24) ^ (te.xCoord << 8) ^ te.yCoord;
|
|
|
|
}
|
2014-07-15 19:02:26 +02:00
|
|
|
|
|
|
|
public void initalize()
|
|
|
|
{
|
|
|
|
updateCraftingList();
|
|
|
|
}
|
2014-07-18 05:38:57 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getPriority()
|
|
|
|
{
|
|
|
|
return priority;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setPriority(int newValue)
|
|
|
|
{
|
|
|
|
priority = newValue;
|
|
|
|
markDirty();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
gridProxy.getGrid().postEvent( new MENetworkCraftingPatternChange( this, gridProxy.getNode() ) );
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
}
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|