Fixes #675 No disabled feature should log spam or crash anymore.
Deprecates the old usage of the AEItemDefinitions via the direct method access of * blocks() * parts() * items() * materials() and thus use the new re-direct via definitions(). All definitions are now initialized, no matter what. But SubItems, Items and Blocks are not registered, if by chance are disabled.
This commit is contained in:
@@ -21,25 +21,40 @@ package appeng.tile.crafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.definitions.IBlocks;
|
||||
|
||||
|
||||
public class TileCraftingStorageTile extends TileCraftingTile
|
||||
{
|
||||
|
||||
static final ItemStack STACK_4K_STORAGE = AEApi.instance().blocks().blockCraftingStorage4k.stack( 1 );
|
||||
static final ItemStack STACK_16K_STORAGE = AEApi.instance().blocks().blockCraftingStorage16k.stack( 1 );
|
||||
static final ItemStack STACK_64K_STORAGE = AEApi.instance().blocks().blockCraftingStorage64k.stack( 1 );
|
||||
public static final int KILO_SCALAR = 1024;
|
||||
|
||||
@Override
|
||||
protected ItemStack getItemFromTile(Object obj)
|
||||
{
|
||||
int storage = ((TileCraftingTile) obj).getStorageBytes() / 1024;
|
||||
final IBlocks blocks = AEApi.instance().definitions().blocks();
|
||||
final int storage = ((TileCraftingTile) obj).getStorageBytes() / KILO_SCALAR;
|
||||
|
||||
if ( storage == 4 )
|
||||
return STACK_4K_STORAGE;
|
||||
if ( storage == 16 )
|
||||
return STACK_16K_STORAGE;
|
||||
if ( storage == 64 )
|
||||
return STACK_64K_STORAGE;
|
||||
switch ( storage )
|
||||
{
|
||||
case 4:
|
||||
for ( ItemStack stack : blocks.craftingStorage4k().maybeStack( 1 ).asSet() )
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
break;
|
||||
case 16:
|
||||
for ( ItemStack stack : blocks.craftingStorage16k().maybeStack( 1 ).asSet() )
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
break;
|
||||
case 64:
|
||||
for ( ItemStack stack : blocks.craftingStorage64k().maybeStack( 1 ).asSet() )
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return super.getItemFromTile( obj );
|
||||
}
|
||||
|
||||
@@ -52,18 +52,22 @@ import appeng.tile.events.TileEventType;
|
||||
import appeng.tile.grid.AENetworkTile;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock, IPowerChannelState
|
||||
{
|
||||
|
||||
CraftingCPUCluster cluster;
|
||||
final CraftingCPUCalculator calc = new CraftingCPUCalculator( this );
|
||||
private final CraftingCPUCalculator calc = new CraftingCPUCalculator( this );
|
||||
|
||||
public ISimplifiedBundle lightCache;
|
||||
|
||||
public NBTTagCompound previousState = null;
|
||||
public boolean isCoreBlock = false;
|
||||
CraftingCPUCluster cluster;
|
||||
|
||||
static final ItemStack STACK_CO_PROCESSOR = AEApi.instance().blocks().blockCraftingAccelerator.stack( 1 );
|
||||
public TileCraftingTile()
|
||||
{
|
||||
this.gridProxy.setFlags( GridFlags.MULTIBLOCK, GridFlags.REQUIRE_CHANNEL );
|
||||
this.gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AENetworkProxy createProxy()
|
||||
@@ -72,59 +76,39 @@ public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock, IP
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack getItemFromTile(Object obj)
|
||||
protected ItemStack getItemFromTile( Object obj )
|
||||
{
|
||||
if ( ((TileCraftingTile) obj).isAccelerator() )
|
||||
return STACK_CO_PROCESSOR;
|
||||
if ( ( (TileCraftingTile) obj ).isAccelerator() )
|
||||
{
|
||||
for ( ItemStack accelerator : AEApi.instance().definitions().blocks().craftingAccelerator().maybeStack( 1 ).asSet() )
|
||||
{
|
||||
return accelerator;
|
||||
}
|
||||
}
|
||||
|
||||
return super.getItemFromTile( obj );
|
||||
}
|
||||
|
||||
public void updateStatus(CraftingCPUCluster c)
|
||||
@Override
|
||||
public boolean canBeRotated()
|
||||
{
|
||||
if ( this.cluster != null && this.cluster != c )
|
||||
this.cluster.breakCluster();
|
||||
|
||||
this.cluster = c;
|
||||
this.updateMeta( true );
|
||||
}
|
||||
|
||||
public void updateMultiBlock()
|
||||
{
|
||||
this.calc.calculateMultiblock( this.worldObj, this.getLocation() );
|
||||
return true;// return BlockCraftingUnit.checkType( worldObj.getBlockMetadata( xCoord, yCoord, zCoord ),
|
||||
// BlockCraftingUnit.BASE_MONITOR );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name)
|
||||
public void setName( String name )
|
||||
{
|
||||
super.setName( name );
|
||||
if ( this.cluster != null )
|
||||
this.cluster.updateName();
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_WRITE)
|
||||
public void writeToNBT_TileCraftingTile(NBTTagCompound data)
|
||||
public boolean isAccelerator()
|
||||
{
|
||||
data.setBoolean( "core", this.isCoreBlock );
|
||||
if ( this.isCoreBlock && this.cluster != null )
|
||||
this.cluster.writeToNBT( data );
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_READ)
|
||||
public void readFromNBT_TileCraftingTile(NBTTagCompound data)
|
||||
{
|
||||
this.isCoreBlock = data.getBoolean( "core" );
|
||||
if ( this.isCoreBlock )
|
||||
{
|
||||
if ( this.cluster != null )
|
||||
this.cluster.readFromNBT( data );
|
||||
else
|
||||
this.previousState = (NBTTagCompound) data.copy();
|
||||
}
|
||||
}
|
||||
|
||||
public TileCraftingTile() {
|
||||
this.gridProxy.setFlags( GridFlags.MULTIBLOCK, GridFlags.REQUIRE_CHANNEL );
|
||||
this.gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
||||
if ( this.worldObj == null )
|
||||
return false;
|
||||
return ( this.worldObj.getBlockMetadata( this.xCoord, this.yCoord, this.zCoord ) & 3 ) == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -135,37 +119,21 @@ public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock, IP
|
||||
this.updateMultiBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeRotated()
|
||||
public void updateMultiBlock()
|
||||
{
|
||||
return true;// return BlockCraftingUnit.checkType( worldObj.getBlockMetadata( xCoord, yCoord, zCoord ),
|
||||
// BlockCraftingUnit.BASE_MONITOR );
|
||||
this.calc.calculateMultiblock( this.worldObj, this.getLocation() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect(boolean update)
|
||||
public void updateStatus( CraftingCPUCluster c )
|
||||
{
|
||||
if ( this.cluster != null )
|
||||
{
|
||||
this.cluster.destroy();
|
||||
if ( update )
|
||||
this.updateMeta( true );
|
||||
}
|
||||
if ( this.cluster != null && this.cluster != c )
|
||||
this.cluster.breakCluster();
|
||||
|
||||
this.cluster = c;
|
||||
this.updateMeta( true );
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void onPowerStateChange(MENetworkChannelsChanged ev)
|
||||
{
|
||||
this.updateMeta( false );
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void onPowerStateChange(MENetworkPowerStatusChange ev)
|
||||
{
|
||||
this.updateMeta( false );
|
||||
}
|
||||
|
||||
public void updateMeta(boolean updateFormed)
|
||||
public void updateMeta( boolean updateFormed )
|
||||
{
|
||||
if ( this.worldObj == null || this.notLoaded() )
|
||||
return;
|
||||
@@ -177,7 +145,7 @@ public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock, IP
|
||||
power = this.gridProxy.isActive();
|
||||
|
||||
int current = this.worldObj.getBlockMetadata( this.xCoord, this.yCoord, this.zCoord );
|
||||
int newMeta = (current & 3) | (formed ? 8 : 0) | (power ? 4 : 0);
|
||||
int newMeta = ( current & 3 ) | ( formed ? 8 : 0 ) | ( power ? 4 : 0 );
|
||||
|
||||
if ( current != newMeta )
|
||||
this.worldObj.setBlockMetadataWithNotify( this.xCoord, this.yCoord, this.zCoord, newMeta, 2 );
|
||||
@@ -191,6 +159,45 @@ public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock, IP
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isFormed()
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return ( this.worldObj.getBlockMetadata( this.xCoord, this.yCoord, this.zCoord ) & 8 ) == 8;
|
||||
return this.cluster != null;
|
||||
}
|
||||
|
||||
@TileEvent( TileEventType.WORLD_NBT_WRITE )
|
||||
public void writeToNBT_TileCraftingTile( NBTTagCompound data )
|
||||
{
|
||||
data.setBoolean( "core", this.isCoreBlock );
|
||||
if ( this.isCoreBlock && this.cluster != null )
|
||||
this.cluster.writeToNBT( data );
|
||||
}
|
||||
|
||||
@TileEvent( TileEventType.WORLD_NBT_READ )
|
||||
public void readFromNBT_TileCraftingTile( NBTTagCompound data )
|
||||
{
|
||||
this.isCoreBlock = data.getBoolean( "core" );
|
||||
if ( this.isCoreBlock )
|
||||
{
|
||||
if ( this.cluster != null )
|
||||
this.cluster.readFromNBT( data );
|
||||
else
|
||||
this.previousState = (NBTTagCompound) data.copy();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect( boolean update )
|
||||
{
|
||||
if ( this.cluster != null )
|
||||
{
|
||||
this.cluster.destroy();
|
||||
if ( update )
|
||||
this.updateMeta( true );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAECluster getCluster()
|
||||
{
|
||||
@@ -203,31 +210,27 @@ public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock, IP
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPowered()
|
||||
@MENetworkEventSubscribe
|
||||
public void onPowerStateChange( MENetworkChannelsChanged ev )
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return (this.worldObj.getBlockMetadata( this.xCoord, this.yCoord, this.zCoord ) & 4) == 4;
|
||||
return this.gridProxy.isActive();
|
||||
this.updateMeta( false );
|
||||
}
|
||||
|
||||
public boolean isFormed()
|
||||
@MENetworkEventSubscribe
|
||||
public void onPowerStateChange( MENetworkPowerStatusChange ev )
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return (this.worldObj.getBlockMetadata( this.xCoord, this.yCoord, this.zCoord ) & 8) == 8;
|
||||
return this.cluster != null;
|
||||
}
|
||||
|
||||
public boolean isAccelerator()
|
||||
{
|
||||
if ( this.worldObj == null )
|
||||
return false;
|
||||
return (this.worldObj.getBlockMetadata( this.xCoord, this.yCoord, this.zCoord ) & 3) == 1;
|
||||
this.updateMeta( false );
|
||||
}
|
||||
|
||||
public boolean isStatus()
|
||||
{
|
||||
return false;
|
||||
} @Override
|
||||
public boolean isPowered()
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return ( this.worldObj.getBlockMetadata( this.xCoord, this.yCoord, this.zCoord ) & 4 ) == 4;
|
||||
return this.gridProxy.isActive();
|
||||
}
|
||||
|
||||
public boolean isStorage()
|
||||
@@ -240,14 +243,6 @@ public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock, IP
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive()
|
||||
{
|
||||
if ( Platform.isServer() )
|
||||
return this.gridProxy.isActive();
|
||||
return this.isPowered() && this.isFormed();
|
||||
}
|
||||
|
||||
public void breakCluster()
|
||||
{
|
||||
if ( this.cluster != null )
|
||||
@@ -258,7 +253,7 @@ public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock, IP
|
||||
LinkedList<WorldCoord> places = new LinkedList<WorldCoord>();
|
||||
|
||||
Iterator<IGridHost> i = this.cluster.getTiles();
|
||||
while (i.hasNext())
|
||||
while ( i.hasNext() )
|
||||
{
|
||||
IGridHost h = i.next();
|
||||
if ( h == this )
|
||||
@@ -267,14 +262,13 @@ public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock, IP
|
||||
{
|
||||
TileEntity te = (TileEntity) h;
|
||||
|
||||
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS)
|
||||
for ( ForgeDirection d : ForgeDirection.VALID_DIRECTIONS )
|
||||
{
|
||||
WorldCoord wc = new WorldCoord( te );
|
||||
wc.add( d, 1 );
|
||||
if ( this.worldObj.isAirBlock( wc.x, wc.y, wc.z ) )
|
||||
places.add( wc );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,11 +277,11 @@ public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock, IP
|
||||
if ( places.isEmpty() )
|
||||
throw new RuntimeException( "No air or even the tile hat was destroyed?!?!" );
|
||||
|
||||
for (IAEItemStack ais : inv.getAvailableItems( AEApi.instance().storage().createItemList() ))
|
||||
for ( IAEItemStack ais : inv.getAvailableItems( AEApi.instance().storage().createItemList() ) )
|
||||
{
|
||||
ais = ais.copy();
|
||||
ais.setStackSize( ais.getItemStack().getMaxStackSize() );
|
||||
while (true)
|
||||
while ( true )
|
||||
{
|
||||
IAEItemStack g = inv.extractItems( ais.copy(), Actionable.MODULATE, this.cluster.getActionSource() );
|
||||
if ( g == null )
|
||||
@@ -298,10 +292,19 @@ public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock, IP
|
||||
|
||||
Platform.spawnDrops( this.worldObj, wc.x, wc.y, wc.z, Collections.singletonList( g.getItemStack() ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.cluster.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isActive()
|
||||
{
|
||||
if ( Platform.isServer() )
|
||||
return this.gridProxy.isActive();
|
||||
return this.isPowered() && this.isFormed();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.tile.crafting;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -41,6 +42,7 @@ import appeng.api.config.PowerMultiplier;
|
||||
import appeng.api.config.RedstoneMode;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.definitions.ITileDefinition;
|
||||
import appeng.api.implementations.IPowerChannelState;
|
||||
import appeng.api.implementations.IUpgradeableHost;
|
||||
import appeng.api.implementations.tiles.ICraftingMachine;
|
||||
@@ -61,6 +63,7 @@ import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketAssemblerAnimation;
|
||||
import appeng.items.misc.ItemEncodedPattern;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.parts.automation.DefinitionUpgradeInventory;
|
||||
import appeng.parts.automation.UpgradeInventory;
|
||||
import appeng.tile.TileEvent;
|
||||
import appeng.tile.events.TileEventType;
|
||||
@@ -73,35 +76,50 @@ import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
public class TileMolecularAssembler extends AENetworkInvTile implements IUpgradeableHost, IConfigManagerHost,
|
||||
IGridTickable, ICraftingMachine, IPowerChannelState
|
||||
|
||||
public class TileMolecularAssembler extends AENetworkInvTile
|
||||
implements IUpgradeableHost, IConfigManagerHost, IGridTickable, ICraftingMachine, IPowerChannelState
|
||||
{
|
||||
|
||||
private static final int[] SIDES = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
private static final ItemStack STACK_ASSEMBLER = AEApi.instance().blocks().blockMolecularAssembler.stack( 1 );
|
||||
|
||||
private final InventoryCrafting craftingInv = new InventoryCrafting( new ContainerNull(), 3, 3 );
|
||||
private final InventoryCrafting craftingInv;
|
||||
private final AppEngInternalInventory inv = new AppEngInternalInventory( this, 9 + 2 );
|
||||
private final IConfigManager settings = new ConfigManager( this );
|
||||
private final UpgradeInventory upgrades = new UpgradeInventory( STACK_ASSEMBLER, this, this.getUpgradeSlots() );
|
||||
|
||||
private final IConfigManager settings;
|
||||
private final UpgradeInventory upgrades;
|
||||
public ISimplifiedBundle lightCache;
|
||||
private boolean isPowered = false;
|
||||
private ForgeDirection pushDirection = ForgeDirection.UNKNOWN;
|
||||
private ItemStack myPattern = null;
|
||||
private ICraftingPatternDetails myPlan = null;
|
||||
private double progress = 0;
|
||||
private boolean isAwake = false;
|
||||
private boolean forcePlan = false;
|
||||
|
||||
private boolean reboot = true;
|
||||
public ISimplifiedBundle lightCache;
|
||||
|
||||
public TileMolecularAssembler()
|
||||
{
|
||||
final ITileDefinition assembler = AEApi.instance().definitions().blocks().molecularAssembler();
|
||||
|
||||
this.settings = new ConfigManager( this );
|
||||
this.settings.registerSetting( Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE );
|
||||
this.inv.setMaxStackSize( 1 );
|
||||
this.gridProxy.setIdlePowerUsage( 0.0 );
|
||||
this.upgrades = new DefinitionUpgradeInventory( assembler, this, this.getUpgradeSlots() );
|
||||
this.craftingInv = new InventoryCrafting( new ContainerNull(), 3, 3 );
|
||||
}
|
||||
|
||||
protected int getUpgradeSlots()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCrafting table, ForgeDirection where)
|
||||
public boolean pushPattern( ICraftingPatternDetails patternDetails, InventoryCrafting table, ForgeDirection where )
|
||||
{
|
||||
if ( this.myPattern == null )
|
||||
{
|
||||
boolean isEmpty = true;
|
||||
for (int x = 0; x < this.inv.getSizeInventory(); x++)
|
||||
for ( int x = 0; x < this.inv.getSizeInventory(); x++ )
|
||||
isEmpty = this.inv.getStackInSlot( x ) == null && isEmpty;
|
||||
|
||||
if ( isEmpty && patternDetails.isCraftable() )
|
||||
@@ -110,7 +128,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
this.myPlan = patternDetails;
|
||||
this.pushDirection = where;
|
||||
|
||||
for (int x = 0; x < table.getSizeInventory(); x++)
|
||||
for ( int x = 0; x < table.getSizeInventory(); x++ )
|
||||
this.inv.setInventorySlotContents( x, table.getStackInSlot( x ) );
|
||||
|
||||
this.updateSleepiness();
|
||||
@@ -121,6 +139,115 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
return false;
|
||||
}
|
||||
|
||||
private void updateSleepiness()
|
||||
{
|
||||
boolean wasEnabled = this.isAwake;
|
||||
this.isAwake = this.myPlan != null && this.hasMats() || this.canPush();
|
||||
if ( wasEnabled != this.isAwake )
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( this.isAwake )
|
||||
this.gridProxy.getTick().wakeDevice( this.gridProxy.getNode() );
|
||||
else
|
||||
this.gridProxy.getTick().sleepDevice( this.gridProxy.getNode() );
|
||||
}
|
||||
catch ( GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canPush()
|
||||
{
|
||||
return this.inv.getStackInSlot( 9 ) != null;
|
||||
}
|
||||
|
||||
private boolean hasMats()
|
||||
{
|
||||
if ( this.myPlan == null )
|
||||
return false;
|
||||
|
||||
for ( int x = 0; x < this.craftingInv.getSizeInventory(); x++ )
|
||||
this.craftingInv.setInventorySlotContents( x, this.inv.getStackInSlot( x ) );
|
||||
|
||||
return this.myPlan.getOutput( this.craftingInv, this.getWorldObj() ) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsPlans()
|
||||
{
|
||||
return this.inv.getStackInSlot( 10 ) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInstalledUpgrades( Upgrades u )
|
||||
{
|
||||
return this.upgrades.getInstalledUpgrades( u );
|
||||
}
|
||||
|
||||
@TileEvent( TileEventType.NETWORK_READ )
|
||||
public boolean readFromStream_TileMolecularAssembler( ByteBuf data )
|
||||
{
|
||||
boolean oldPower = this.isPowered;
|
||||
this.isPowered = data.readBoolean();
|
||||
return this.isPowered != oldPower;
|
||||
}
|
||||
|
||||
@TileEvent( TileEventType.NETWORK_WRITE )
|
||||
public void writeToStream_TileMolecularAssembler( ByteBuf data )
|
||||
{
|
||||
data.writeBoolean( this.isPowered );
|
||||
}
|
||||
|
||||
@TileEvent( TileEventType.WORLD_NBT_WRITE )
|
||||
public void writeToNBT_TileMolecularAssembler( NBTTagCompound data )
|
||||
{
|
||||
if ( this.forcePlan && this.myPlan != null )
|
||||
{
|
||||
ItemStack pattern = this.myPlan.getPattern();
|
||||
if ( pattern != null )
|
||||
{
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
pattern.writeToNBT( compound );
|
||||
data.setTag( "myPlan", compound );
|
||||
data.setInteger( "pushDirection", this.pushDirection.ordinal() );
|
||||
}
|
||||
}
|
||||
|
||||
this.upgrades.writeToNBT( data, "upgrades" );
|
||||
this.inv.writeToNBT( data, "inv" );
|
||||
this.settings.writeToNBT( data );
|
||||
}
|
||||
|
||||
@TileEvent( TileEventType.WORLD_NBT_READ )
|
||||
public void readFromNBT_TileMolecularAssembler( NBTTagCompound data )
|
||||
{
|
||||
if ( data.hasKey( "myPlan" ) )
|
||||
{
|
||||
ItemStack myPat = ItemStack.loadItemStackFromNBT( data.getCompoundTag( "myPlan" ) );
|
||||
|
||||
if ( myPat != null && myPat.getItem() instanceof ItemEncodedPattern )
|
||||
{
|
||||
World w = this.getWorldObj();
|
||||
ItemEncodedPattern iep = (ItemEncodedPattern) myPat.getItem();
|
||||
ICraftingPatternDetails ph = iep.getPatternForItem( myPat, w );
|
||||
if ( ph != null && ph.isCraftable() )
|
||||
{
|
||||
this.forcePlan = true;
|
||||
this.myPlan = ph;
|
||||
this.pushDirection = ForgeDirection.getOrientation( data.getInteger( "pushDirection" ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.upgrades.readFromNBT( data, "upgrades" );
|
||||
this.inv.readFromNBT( data, "inv" );
|
||||
this.settings.readFromNBT( data );
|
||||
this.recalculatePlan();
|
||||
}
|
||||
|
||||
private void recalculatePlan()
|
||||
{
|
||||
this.reboot = true;
|
||||
@@ -158,111 +285,50 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
this.updateSleepiness();
|
||||
}
|
||||
|
||||
private void updateSleepiness()
|
||||
@Override
|
||||
public AECableType getCableConnectionType( ForgeDirection dir )
|
||||
{
|
||||
boolean wasEnabled = this.isAwake;
|
||||
this.isAwake = this.myPlan != null && this.hasMats() || this.canPush();
|
||||
if ( wasEnabled != this.isAwake )
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( this.isAwake )
|
||||
this.gridProxy.getTick().wakeDevice( this.gridProxy.getNode() );
|
||||
else
|
||||
this.gridProxy.getTick().sleepDevice( this.gridProxy.getNode() );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canPush()
|
||||
{
|
||||
return this.inv.getStackInSlot( 9 ) != null;
|
||||
return AECableType.COVERED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInstalledUpgrades(Upgrades u)
|
||||
public DimensionalCoord getLocation()
|
||||
{
|
||||
return this.upgrades.getInstalledUpgrades( u );
|
||||
}
|
||||
|
||||
protected int getUpgradeSlots()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_READ)
|
||||
public boolean readFromStream_TileMolecularAssembler(ByteBuf data)
|
||||
{
|
||||
boolean oldPower = this.isPowered;
|
||||
this.isPowered = data.readBoolean();
|
||||
return this.isPowered != oldPower;
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_WRITE)
|
||||
public void writeToStream_TileMolecularAssembler(ByteBuf data)
|
||||
{
|
||||
data.writeBoolean( this.isPowered );
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_WRITE)
|
||||
public void writeToNBT_TileMolecularAssembler(NBTTagCompound data)
|
||||
{
|
||||
if ( this.forcePlan && this.myPlan != null )
|
||||
{
|
||||
ItemStack pattern = this.myPlan.getPattern();
|
||||
if ( pattern != null )
|
||||
{
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
pattern.writeToNBT( compound );
|
||||
data.setTag( "myPlan", compound );
|
||||
data.setInteger( "pushDirection", this.pushDirection.ordinal() );
|
||||
}
|
||||
}
|
||||
|
||||
this.upgrades.writeToNBT( data, "upgrades" );
|
||||
this.inv.writeToNBT( data, "inv" );
|
||||
this.settings.writeToNBT( data );
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_READ)
|
||||
public void readFromNBT_TileMolecularAssembler(NBTTagCompound data)
|
||||
{
|
||||
if ( data.hasKey( "myPlan" ) )
|
||||
{
|
||||
ItemStack myPat = ItemStack.loadItemStackFromNBT( data.getCompoundTag( "myPlan" ) );
|
||||
|
||||
if ( myPat != null && myPat.getItem() instanceof ItemEncodedPattern )
|
||||
{
|
||||
World w = this.getWorldObj();
|
||||
ItemEncodedPattern iep = (ItemEncodedPattern) myPat.getItem();
|
||||
ICraftingPatternDetails ph = iep.getPatternForItem( myPat, w );
|
||||
if ( ph != null && ph.isCraftable() )
|
||||
{
|
||||
this.forcePlan = true;
|
||||
this.myPlan = ph;
|
||||
this.pushDirection = ForgeDirection.getOrientation( data.getInteger( "pushDirection" ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.upgrades.readFromNBT( data, "upgrades" );
|
||||
this.inv.readFromNBT( data, "inv" );
|
||||
this.settings.readFromNBT( data );
|
||||
this.recalculatePlan();
|
||||
}
|
||||
|
||||
public TileMolecularAssembler() {
|
||||
this.settings.registerSetting( Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE );
|
||||
this.inv.setMaxStackSize( 1 );
|
||||
this.gridProxy.setIdlePowerUsage( 0.0 );
|
||||
return new DimensionalCoord( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
public IConfigManager getConfigManager()
|
||||
{
|
||||
return this.settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInventoryByName( String name )
|
||||
{
|
||||
if ( name.equals( "upgrades" ) )
|
||||
return this.upgrades;
|
||||
|
||||
if ( name.equals( "mac" ) )
|
||||
return this.inv;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting( IConfigManager manager, Enum settingName, Enum newValue )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( int i, ItemStack itemstack )
|
||||
{
|
||||
if ( i >= 9 )
|
||||
return false;
|
||||
@@ -273,12 +339,6 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsPlans()
|
||||
{
|
||||
return this.inv.getStackInSlot( 10 ) == null;
|
||||
}
|
||||
|
||||
private boolean hasPattern()
|
||||
{
|
||||
return this.myPlan != null && this.inv.getStackInSlot( 10 ) != null;
|
||||
@@ -297,71 +357,29 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added)
|
||||
public void onChangeInventory( IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added )
|
||||
{
|
||||
if ( inv == this.inv )
|
||||
this.recalculatePlan();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsBySide(ForgeDirection whichSide)
|
||||
public int[] getAccessibleSlotsBySide( ForgeDirection whichSide )
|
||||
{
|
||||
return SIDES;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType(ForgeDirection dir)
|
||||
{
|
||||
return AECableType.COVERED;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DimensionalCoord getLocation()
|
||||
{
|
||||
return new DimensionalCoord( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IConfigManager getConfigManager()
|
||||
{
|
||||
return this.settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInventoryByName(String name)
|
||||
{
|
||||
if ( name.equals( "upgrades" ) )
|
||||
return this.upgrades;
|
||||
|
||||
if ( name.equals( "mac" ) )
|
||||
return this.inv;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public int getCraftingProgress()
|
||||
{
|
||||
return (int) this.progress;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops(World w, int x, int y, int z, ArrayList<ItemStack> drops)
|
||||
public void getDrops( World w, int x, int y, int z, ArrayList<ItemStack> drops )
|
||||
{
|
||||
super.getDrops( w, x, y, z, drops );
|
||||
|
||||
for (int h = 0; h < this.upgrades.getSizeInventory(); h++)
|
||||
for ( int h = 0; h < this.upgrades.getSizeInventory(); h++ )
|
||||
{
|
||||
ItemStack is = this.upgrades.getStackInSlot( h );
|
||||
if ( is != null )
|
||||
@@ -370,26 +388,15 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node)
|
||||
public TickingRequest getTickingRequest( IGridNode node )
|
||||
{
|
||||
this.recalculatePlan();
|
||||
this.updateSleepiness();
|
||||
return new TickingRequest( 1, 1, !this.isAwake, false );
|
||||
}
|
||||
|
||||
private boolean hasMats()
|
||||
{
|
||||
if ( this.myPlan == null )
|
||||
return false;
|
||||
|
||||
for (int x = 0; x < this.craftingInv.getSizeInventory(); x++)
|
||||
this.craftingInv.setInventorySlotContents( x, this.inv.getStackInSlot( x ) );
|
||||
|
||||
return this.myPlan.getOutput( this.craftingInv, this.getWorldObj() ) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
|
||||
public TickRateModulation tickingRequest( IGridNode node, int TicksSinceLastCall )
|
||||
{
|
||||
if ( this.inv.getStackInSlot( 9 ) != null )
|
||||
{
|
||||
@@ -419,31 +426,31 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
|
||||
this.reboot = false;
|
||||
int speed = 10;
|
||||
switch (this.upgrades.getInstalledUpgrades( Upgrades.SPEED ))
|
||||
switch ( this.upgrades.getInstalledUpgrades( Upgrades.SPEED ) )
|
||||
{
|
||||
case 0:
|
||||
this.progress += this.userPower( TicksSinceLastCall, speed = 10, 1.0 );
|
||||
break;
|
||||
case 1:
|
||||
this.progress += this.userPower( TicksSinceLastCall, speed = 13, 1.3 );
|
||||
break;
|
||||
case 2:
|
||||
this.progress += this.userPower( TicksSinceLastCall, speed = 17, 1.7 );
|
||||
break;
|
||||
case 3:
|
||||
this.progress += this.userPower( TicksSinceLastCall, speed = 20, 2.0 );
|
||||
break;
|
||||
case 4:
|
||||
this.progress += this.userPower( TicksSinceLastCall, speed = 25, 2.5 );
|
||||
break;
|
||||
case 5:
|
||||
this.progress += this.userPower( TicksSinceLastCall, speed = 50, 5.0 );
|
||||
break;
|
||||
case 0:
|
||||
this.progress += this.userPower( TicksSinceLastCall, speed = 10, 1.0 );
|
||||
break;
|
||||
case 1:
|
||||
this.progress += this.userPower( TicksSinceLastCall, speed = 13, 1.3 );
|
||||
break;
|
||||
case 2:
|
||||
this.progress += this.userPower( TicksSinceLastCall, speed = 17, 1.7 );
|
||||
break;
|
||||
case 3:
|
||||
this.progress += this.userPower( TicksSinceLastCall, speed = 20, 2.0 );
|
||||
break;
|
||||
case 4:
|
||||
this.progress += this.userPower( TicksSinceLastCall, speed = 25, 2.5 );
|
||||
break;
|
||||
case 5:
|
||||
this.progress += this.userPower( TicksSinceLastCall, speed = 50, 5.0 );
|
||||
break;
|
||||
}
|
||||
|
||||
if ( this.progress >= 100 )
|
||||
{
|
||||
for (int x = 0; x < this.craftingInv.getSizeInventory(); x++)
|
||||
for ( int x = 0; x < this.craftingInv.getSizeInventory(); x++ )
|
||||
this.craftingInv.setInventorySlotContents( x, this.inv.getStackInSlot( x ) );
|
||||
|
||||
this.progress = 0;
|
||||
@@ -454,7 +461,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
|
||||
this.pushOut( output.copy() );
|
||||
|
||||
for (int x = 0; x < this.craftingInv.getSizeInventory(); x++)
|
||||
for ( int x = 0; x < this.craftingInv.getSizeInventory(); x++ )
|
||||
this.inv.setInventorySlotContents( x, Platform.getContainerItem( this.craftingInv.getStackInSlot( x ) ) );
|
||||
|
||||
if ( this.inv.getStackInSlot( 10 ) == null )
|
||||
@@ -472,7 +479,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
IAEItemStack item = AEItemStack.create( output );
|
||||
NetworkHandler.instance.sendToAllAround( new PacketAssemblerAnimation( this.xCoord, this.yCoord, this.zCoord, (byte) speed, item ), where );
|
||||
}
|
||||
catch (IOException e)
|
||||
catch ( IOException e )
|
||||
{
|
||||
// ;P
|
||||
}
|
||||
@@ -490,7 +497,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
{
|
||||
if ( this.inv.getStackInSlot( 9 ) == null )
|
||||
{
|
||||
for (int x = 0; x < 9; x++)
|
||||
for ( int x = 0; x < 9; x++ )
|
||||
{
|
||||
ItemStack is = this.inv.getStackInSlot( x );
|
||||
if ( is != null )
|
||||
@@ -507,23 +514,23 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
}
|
||||
}
|
||||
|
||||
private int userPower(int ticksPassed, int bonusValue, double acceleratorTax)
|
||||
private int userPower( int ticksPassed, int bonusValue, double acceleratorTax )
|
||||
{
|
||||
try
|
||||
{
|
||||
return (int) (this.gridProxy.getEnergy().extractAEPower( ticksPassed * bonusValue * acceleratorTax, Actionable.MODULATE, PowerMultiplier.CONFIG ) / acceleratorTax);
|
||||
return (int) ( this.gridProxy.getEnergy().extractAEPower( ticksPassed * bonusValue * acceleratorTax, Actionable.MODULATE, PowerMultiplier.CONFIG ) / acceleratorTax );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
catch ( GridAccessException e )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void pushOut(ItemStack output)
|
||||
private void pushOut( ItemStack output )
|
||||
{
|
||||
if ( this.pushDirection == ForgeDirection.UNKNOWN )
|
||||
{
|
||||
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS)
|
||||
for ( ForgeDirection d : ForgeDirection.VALID_DIRECTIONS )
|
||||
output = this.pushTo( output, d );
|
||||
}
|
||||
else
|
||||
@@ -538,7 +545,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
this.inv.setInventorySlotContents( 9, output );
|
||||
}
|
||||
|
||||
private ItemStack pushTo(ItemStack output, ForgeDirection d)
|
||||
private ItemStack pushTo( ItemStack output, ForgeDirection d )
|
||||
{
|
||||
if ( output == null )
|
||||
return output;
|
||||
@@ -563,10 +570,8 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
return output;
|
||||
}
|
||||
|
||||
boolean isPowered = false;
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void onPowerEvent(MENetworkPowerStatusChange p)
|
||||
public void onPowerEvent( MENetworkPowerStatusChange p )
|
||||
{
|
||||
this.updatePowerState();
|
||||
}
|
||||
@@ -579,7 +584,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
{
|
||||
newState = this.gridProxy.isActive() && this.gridProxy.getEnergy().extractAEPower( 1, Actionable.SIMULATE, PowerMultiplier.CONFIG ) > 0.0001;
|
||||
}
|
||||
catch (GridAccessException ignored)
|
||||
catch ( GridAccessException ignored )
|
||||
{
|
||||
|
||||
}
|
||||
@@ -602,5 +607,4 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
{
|
||||
return this.isPowered;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.tile.inventory;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -31,15 +32,23 @@ import appeng.me.storage.MEIInventoryWrapper;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.iterators.InvIterator;
|
||||
|
||||
|
||||
public class AppEngInternalInventory implements IInventory, Iterable<ItemStack>
|
||||
{
|
||||
|
||||
protected IAEAppEngInventory te;
|
||||
protected final int size;
|
||||
protected final ItemStack[] inv;
|
||||
public boolean enableClientEvents = false;
|
||||
protected IAEAppEngInventory te;
|
||||
protected int maxStack;
|
||||
|
||||
public boolean enableClientEvents = false;
|
||||
protected final ItemStack[] inv;
|
||||
public AppEngInternalInventory( IAEAppEngInventory inventory, int size )
|
||||
{
|
||||
this.te = inventory;
|
||||
this.size = size;
|
||||
this.maxStack = 64;
|
||||
this.inv = new ItemStack[size];
|
||||
}
|
||||
|
||||
public IMEInventory getMEInventory()
|
||||
{
|
||||
@@ -54,31 +63,20 @@ public class AppEngInternalInventory implements IInventory, Iterable<ItemStack>
|
||||
return true;
|
||||
}
|
||||
|
||||
public AppEngInternalInventory(IAEAppEngInventory _te, int s) {
|
||||
this.te = _te;
|
||||
this.size = s;
|
||||
this.maxStack = 64;
|
||||
this.inv = new ItemStack[s];
|
||||
}
|
||||
|
||||
protected boolean eventsEnabled()
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return Platform.isServer() || this.enableClientEvents;
|
||||
}
|
||||
|
||||
public void setMaxStackSize(int s)
|
||||
{
|
||||
this.maxStack = s;
|
||||
return this.size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int var1)
|
||||
public ItemStack getStackInSlot( int var1 )
|
||||
{
|
||||
return this.inv[var1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int slot, int qty)
|
||||
public ItemStack decrStackSize( int slot, int qty )
|
||||
{
|
||||
if ( this.inv[slot] != null )
|
||||
{
|
||||
@@ -105,14 +103,19 @@ public class AppEngInternalInventory implements IInventory, Iterable<ItemStack>
|
||||
return null;
|
||||
}
|
||||
|
||||
protected boolean eventsEnabled()
|
||||
{
|
||||
return Platform.isServer() || this.enableClientEvents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int var1)
|
||||
public ItemStack getStackInSlotOnClosing( int var1 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int slot, ItemStack newItemStack)
|
||||
public void setInventorySlotContents( int slot, ItemStack newItemStack )
|
||||
{
|
||||
ItemStack oldStack = this.inv[slot];
|
||||
this.inv[slot] = newItemStack;
|
||||
@@ -148,106 +151,6 @@ public class AppEngInternalInventory implements IInventory, Iterable<ItemStack>
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
if ( this.te != null && this.eventsEnabled() )
|
||||
{
|
||||
this.te.onChangeInventory( this, -1, InvOperation.markDirty, null, null );
|
||||
}
|
||||
}
|
||||
|
||||
// for guis...
|
||||
public void markDirty(int slotIndex)
|
||||
{
|
||||
if ( this.te != null && this.eventsEnabled() )
|
||||
{
|
||||
this.te.onChangeInventory( this, slotIndex, InvOperation.markDirty, null, null );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return this.maxStack > 64 ? 64 : this.maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer var1)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory()
|
||||
{
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound target)
|
||||
{
|
||||
for (int x = 0; x < this.size; x++)
|
||||
{
|
||||
try
|
||||
{
|
||||
NBTTagCompound c = new NBTTagCompound();
|
||||
|
||||
if ( this.inv[x] != null )
|
||||
{
|
||||
this.inv[x].writeToNBT( c );
|
||||
}
|
||||
|
||||
target.setTag( "#" + x, c );
|
||||
}
|
||||
catch (Exception ignored)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound target)
|
||||
{
|
||||
for (int x = 0; x < this.size; x++)
|
||||
{
|
||||
try
|
||||
{
|
||||
NBTTagCompound c = target.getCompoundTag( "#" + x );
|
||||
|
||||
if ( c != null )
|
||||
this.inv[x] = ItemStack.loadItemStackFromNBT( c );
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound data, String name)
|
||||
{
|
||||
NBTTagCompound c = new NBTTagCompound();
|
||||
this.writeToNBT( c );
|
||||
data.setTag( name, c );
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound data, String name)
|
||||
{
|
||||
NBTTagCompound c = data.getCompoundTag( name );
|
||||
if ( c != null )
|
||||
this.readFromNBT( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return this.size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName()
|
||||
{
|
||||
@@ -261,15 +164,112 @@ public class AppEngInternalInventory implements IInventory, Iterable<ItemStack>
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return this.maxStack > 64 ? 64 : this.maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
if ( this.te != null && this.eventsEnabled() )
|
||||
{
|
||||
this.te.onChangeInventory( this, -1, InvOperation.markDirty, null, null );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer( EntityPlayer var1 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( int i, ItemStack itemstack )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setMaxStackSize( int s )
|
||||
{
|
||||
this.maxStack = s;
|
||||
}
|
||||
|
||||
// for guis...
|
||||
public void markDirty( int slotIndex )
|
||||
{
|
||||
if ( this.te != null && this.eventsEnabled() )
|
||||
{
|
||||
this.te.onChangeInventory( this, slotIndex, InvOperation.markDirty, null, null );
|
||||
}
|
||||
}
|
||||
|
||||
public void writeToNBT( NBTTagCompound data, String name )
|
||||
{
|
||||
NBTTagCompound c = new NBTTagCompound();
|
||||
this.writeToNBT( c );
|
||||
data.setTag( name, c );
|
||||
}
|
||||
|
||||
public void writeToNBT( NBTTagCompound target )
|
||||
{
|
||||
for ( int x = 0; x < this.size; x++ )
|
||||
{
|
||||
try
|
||||
{
|
||||
NBTTagCompound c = new NBTTagCompound();
|
||||
|
||||
if ( this.inv[x] != null )
|
||||
{
|
||||
this.inv[x].writeToNBT( c );
|
||||
}
|
||||
|
||||
target.setTag( "#" + x, c );
|
||||
}
|
||||
catch ( Exception ignored )
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void readFromNBT( NBTTagCompound data, String name )
|
||||
{
|
||||
NBTTagCompound c = data.getCompoundTag( name );
|
||||
if ( c != null )
|
||||
this.readFromNBT( c );
|
||||
}
|
||||
|
||||
public void readFromNBT( NBTTagCompound target )
|
||||
{
|
||||
for ( int x = 0; x < this.size; x++ )
|
||||
{
|
||||
try
|
||||
{
|
||||
NBTTagCompound c = target.getCompoundTag( "#" + x );
|
||||
|
||||
if ( c != null )
|
||||
this.inv[x] = ItemStack.loadItemStackFromNBT( c );
|
||||
}
|
||||
catch ( Exception e )
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemStack> iterator()
|
||||
{
|
||||
return new InvIterator( this );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,6 +34,8 @@ import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.PowerMultiplier;
|
||||
import appeng.api.config.PowerUnits;
|
||||
import appeng.api.definitions.IItemDefinition;
|
||||
import appeng.api.definitions.IMaterials;
|
||||
import appeng.api.implementations.items.IAEItemPowerStorage;
|
||||
import appeng.api.implementations.tiles.ICrankable;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
@@ -124,6 +126,8 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable
|
||||
if ( myItem == null )
|
||||
return;
|
||||
|
||||
final IMaterials materials = AEApi.instance().definitions().materials();
|
||||
|
||||
if ( this.internalCurrentPower > 149 && Platform.isChargeable( myItem ) )
|
||||
{
|
||||
IAEItemPowerStorage ps = (IAEItemPowerStorage) myItem.getItem();
|
||||
@@ -138,12 +142,16 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable
|
||||
this.tickTickTimer = 20; // keep ticking...
|
||||
}
|
||||
}
|
||||
else if ( this.internalCurrentPower > 1499 && AEApi.instance().materials().materialCertusQuartzCrystal.sameAsStack( myItem ) )
|
||||
else if ( this.internalCurrentPower > 1499 && materials.certusQuartzCrystal().isSameAs( myItem ) )
|
||||
{
|
||||
if ( Platform.getRandomFloat() > 0.8f ) // simulate wait
|
||||
{
|
||||
this.extractAEPower( this.internalMaxPower, Actionable.MODULATE, PowerMultiplier.CONFIG );// 1500
|
||||
this.setInventorySlotContents( 0, AEApi.instance().materials().materialCertusQuartzCrystalCharged.stack( myItem.stackSize ) );
|
||||
|
||||
for ( ItemStack charged : materials.certusQuartzCrystalCharged().maybeStack( myItem.stackSize ).asSet() )
|
||||
{
|
||||
this.setInventorySlotContents( 0, charged );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -175,10 +183,19 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable
|
||||
this.injectExternalPower( PowerUnits.AE, 150 );
|
||||
|
||||
ItemStack myItem = this.getStackInSlot( 0 );
|
||||
if ( this.internalCurrentPower > 1499 && AEApi.instance().materials().materialCertusQuartzCrystal.sameAsStack( myItem ) )
|
||||
if ( this.internalCurrentPower > 1499 )
|
||||
{
|
||||
this.extractAEPower( this.internalMaxPower, Actionable.MODULATE, PowerMultiplier.CONFIG );// 1500
|
||||
this.setInventorySlotContents( 0, AEApi.instance().materials().materialCertusQuartzCrystalCharged.stack( myItem.stackSize ) );
|
||||
final IMaterials materials = AEApi.instance().definitions().materials();
|
||||
|
||||
if ( materials.certusQuartzCrystal().isSameAs( myItem ) )
|
||||
{
|
||||
this.extractAEPower( this.internalMaxPower, Actionable.MODULATE, PowerMultiplier.CONFIG );// 1500
|
||||
|
||||
for ( ItemStack charged : materials.certusQuartzCrystalCharged().maybeStack( myItem.stackSize ).asSet() )
|
||||
{
|
||||
this.setInventorySlotContents( 0, charged );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,7 +232,9 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
return Platform.isChargeable( itemstack ) || AEApi.instance().materials().materialCertusQuartzCrystal.sameAsStack( itemstack );
|
||||
final IItemDefinition cert = AEApi.instance().definitions().materials().certusQuartzCrystal();
|
||||
|
||||
return Platform.isChargeable( itemstack ) || cert.isSameAs( itemstack );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -228,7 +247,7 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable
|
||||
return true;
|
||||
}
|
||||
|
||||
return AEApi.instance().materials().materialCertusQuartzCrystalCharged.sameAsStack( extractedItem );
|
||||
return AEApi.instance().definitions().materials().certusQuartzCrystalCharged().isSameAs( extractedItem );
|
||||
}
|
||||
|
||||
public void activate(EntityPlayer player)
|
||||
@@ -240,7 +259,8 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable
|
||||
if ( myItem == null )
|
||||
{
|
||||
ItemStack held = player.inventory.getCurrentItem();
|
||||
if ( AEApi.instance().materials().materialCertusQuartzCrystal.sameAsStack( held ) || Platform.isChargeable( held ) )
|
||||
|
||||
if ( AEApi.instance().definitions().materials().certusQuartzCrystal().isSameAs( held ) || Platform.isChargeable( held ) )
|
||||
{
|
||||
held = player.inventory.decrStackSize( player.inventory.currentItem, 1 );
|
||||
this.setInventorySlotContents( 0, held );
|
||||
|
||||
@@ -30,6 +30,7 @@ import net.minecraftforge.fluids.IFluidHandler;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.CondenserOutput;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.definitions.IMaterials;
|
||||
import appeng.api.implementations.items.IStorageComponent;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.api.util.IConfigurableObject;
|
||||
@@ -102,7 +103,6 @@ public class TileCondenser extends AEBaseInvTile implements IFluidHandler, IConf
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private boolean canAddOutput(ItemStack output)
|
||||
@@ -130,14 +130,24 @@ public class TileCondenser extends AEBaseInvTile implements IFluidHandler, IConf
|
||||
|
||||
private ItemStack getOutput()
|
||||
{
|
||||
final IMaterials materials = AEApi.instance().definitions().materials();
|
||||
|
||||
switch ((CondenserOutput) this.cm.getSetting( Settings.CONDENSER_OUTPUT ))
|
||||
{
|
||||
case MATTER_BALLS:
|
||||
return AEApi.instance().materials().materialMatterBall.stack( 1 );
|
||||
case SINGULARITY:
|
||||
return AEApi.instance().materials().materialSingularity.stack( 1 );
|
||||
case TRASH:
|
||||
default:
|
||||
case MATTER_BALLS:
|
||||
for ( ItemStack matterBallStack : materials.matterBall().maybeStack( 1 ).asSet() )
|
||||
{
|
||||
return matterBallStack;
|
||||
}
|
||||
|
||||
case SINGULARITY:
|
||||
for ( ItemStack singularityStack : materials.singularity().maybeStack( 1 ).asSet() )
|
||||
{
|
||||
return singularityStack;
|
||||
}
|
||||
|
||||
case TRASH:
|
||||
default:
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.tile.misc;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
@@ -34,6 +35,8 @@ import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.PowerMultiplier;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.definitions.IComparableDefinition;
|
||||
import appeng.api.definitions.ITileDefinition;
|
||||
import appeng.api.implementations.IUpgradeableHost;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.energy.IEnergyGrid;
|
||||
@@ -44,7 +47,9 @@ import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.core.settings.TickRates;
|
||||
import appeng.helpers.Reflected;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.parts.automation.DefinitionUpgradeInventory;
|
||||
import appeng.parts.automation.UpgradeInventory;
|
||||
import appeng.recipes.handlers.Inscribe;
|
||||
import appeng.recipes.handlers.Inscribe.InscriberRecipe;
|
||||
@@ -60,57 +65,69 @@ import appeng.util.Platform;
|
||||
import appeng.util.inv.WrapperInventoryRange;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
|
||||
public class TileInscriber extends AENetworkPowerTile implements IGridTickable, IUpgradeableHost, IConfigManagerHost
|
||||
{
|
||||
|
||||
public final int maxProcessingTime = 100;
|
||||
final int[] top = new int[] { 0 };
|
||||
final int[] bottom = new int[] { 1 };
|
||||
final int[] sides = new int[] { 2, 3 };
|
||||
|
||||
final AppEngInternalInventory inv = new AppEngInternalInventory( this, 4 );
|
||||
|
||||
public final int maxProcessingTime = 100;
|
||||
private final IConfigManager settings;
|
||||
private final UpgradeInventory upgrades;
|
||||
public int processingTime = 0;
|
||||
|
||||
// cycles from 0 - 16, at 8 it preforms the action, at 16 it re-enables the normal routine.
|
||||
public boolean smash;
|
||||
public int finalStep;
|
||||
|
||||
public long clientStart;
|
||||
|
||||
static final ItemStack STACK_INSCRIBER = AEApi.instance().blocks().blockInscriber.stack( 1 );
|
||||
private final IConfigManager settings = new ConfigManager( this );
|
||||
private final UpgradeInventory upgrades = new UpgradeInventory( STACK_INSCRIBER, this, this.getUpgradeSlots() );
|
||||
@Reflected
|
||||
public TileInscriber()
|
||||
{
|
||||
this.gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
||||
this.internalMaxPower = 1500;
|
||||
this.gridProxy.setIdlePowerUsage( 0 );
|
||||
this.settings = new ConfigManager( this );
|
||||
|
||||
final ITileDefinition inscriberDefinition = AEApi.instance().definitions().blocks().inscriber();
|
||||
this.upgrades = new DefinitionUpgradeInventory( inscriberDefinition, this, this.getUpgradeSlots() );
|
||||
}
|
||||
|
||||
protected int getUpgradeSlots()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType(ForgeDirection dir)
|
||||
public AECableType getCableConnectionType( ForgeDirection dir )
|
||||
{
|
||||
return AECableType.COVERED;
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_WRITE)
|
||||
public void writeToNBT_TileInscriber(NBTTagCompound data)
|
||||
@TileEvent( TileEventType.WORLD_NBT_WRITE )
|
||||
public void writeToNBT_TileInscriber( NBTTagCompound data )
|
||||
{
|
||||
this.inv.writeToNBT( data, "inscriberInv" );
|
||||
this.upgrades.writeToNBT( data, "upgrades" );
|
||||
this.settings.writeToNBT( data );
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_READ)
|
||||
public void readFromNBT_TileInscriber(NBTTagCompound data)
|
||||
@TileEvent( TileEventType.WORLD_NBT_READ )
|
||||
public void readFromNBT_TileInscriber( NBTTagCompound data )
|
||||
{
|
||||
this.inv.readFromNBT( data, "inscriberInv" );
|
||||
this.upgrades.readFromNBT( data, "upgrades" );
|
||||
this.settings.readFromNBT( data );
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_READ)
|
||||
public boolean readFromStream_TileInscriber(ByteBuf data) throws IOException
|
||||
@TileEvent( TileEventType.NETWORK_READ )
|
||||
public boolean readFromStream_TileInscriber( ByteBuf data ) throws IOException
|
||||
{
|
||||
int slot = data.readByte();
|
||||
|
||||
boolean oldSmash = this.smash;
|
||||
boolean newSmash = (slot & 64) == 64;
|
||||
boolean newSmash = ( slot & 64 ) == 64;
|
||||
|
||||
if ( oldSmash != newSmash && newSmash )
|
||||
{
|
||||
@@ -118,9 +135,9 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
|
||||
this.clientStart = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
for (int num = 0; num < this.inv.getSizeInventory(); num++)
|
||||
for ( int num = 0; num < this.inv.getSizeInventory(); num++ )
|
||||
{
|
||||
if ( (slot & (1 << num)) > 0 )
|
||||
if ( ( slot & ( 1 << num ) ) > 0 )
|
||||
this.inv.setInventorySlotContents( num, AEItemStack.loadItemStackFromPacket( data ).getItemStack() );
|
||||
else
|
||||
this.inv.setInventorySlotContents( num, null );
|
||||
@@ -129,21 +146,21 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
|
||||
return false;
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_WRITE)
|
||||
public void writeToStream_TileInscriber(ByteBuf data) throws IOException
|
||||
@TileEvent( TileEventType.NETWORK_WRITE )
|
||||
public void writeToStream_TileInscriber( ByteBuf data ) throws IOException
|
||||
{
|
||||
int slot = this.smash ? 64 : 0;
|
||||
|
||||
for (int num = 0; num < this.inv.getSizeInventory(); num++)
|
||||
for ( int num = 0; num < this.inv.getSizeInventory(); num++ )
|
||||
{
|
||||
if ( this.inv.getStackInSlot( num ) != null )
|
||||
slot |= ( 1 << num );
|
||||
}
|
||||
|
||||
data.writeByte( slot );
|
||||
for (int num = 0; num < this.inv.getSizeInventory(); num++)
|
||||
for ( int num = 0; num < this.inv.getSizeInventory(); num++ )
|
||||
{
|
||||
if ( (slot & (1 << num)) > 0 )
|
||||
if ( ( slot & ( 1 << num ) ) > 0 )
|
||||
{
|
||||
AEItemStack st = AEItemStack.create( this.inv.getStackInSlot( num ) );
|
||||
st.writeToPacket( data );
|
||||
@@ -151,45 +168,33 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOrientation( ForgeDirection inForward, ForgeDirection inUp )
|
||||
{
|
||||
super.setOrientation( inForward, inUp );
|
||||
this.gridProxy.setValidSides( EnumSet.complementOf( EnumSet.of( this.getForward() ) ) );
|
||||
this.setPowerSides( EnumSet.complementOf( EnumSet.of( this.getForward() ) ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops( World w, int x, int y, int z, ArrayList<ItemStack> drops )
|
||||
{
|
||||
super.getDrops( w, x, y, z, drops );
|
||||
|
||||
for ( int h = 0; h < this.upgrades.getSizeInventory(); h++ )
|
||||
{
|
||||
ItemStack is = this.upgrades.getStackInSlot( h );
|
||||
if ( is != null )
|
||||
drops.add( is );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requiresTESR()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public TileInscriber()
|
||||
{
|
||||
this.gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
||||
this.internalMaxPower = 1500;
|
||||
this.gridProxy.setIdlePowerUsage( 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOrientation(ForgeDirection inForward, ForgeDirection inUp)
|
||||
{
|
||||
super.setOrientation( inForward, inUp );
|
||||
this.gridProxy.setValidSides( EnumSet.complementOf( EnumSet.of( this.getForward() ) ) );
|
||||
this.setPowerSides( EnumSet.complementOf( EnumSet.of( this.getForward() ) ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInternalInventory()
|
||||
{
|
||||
return this.inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsBySide(ForgeDirection d)
|
||||
{
|
||||
if ( d == ForgeDirection.UP )
|
||||
return this.top;
|
||||
|
||||
if ( d == ForgeDirection.DOWN )
|
||||
return this.bottom;
|
||||
|
||||
return this.sides;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
@@ -197,30 +202,24 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
public boolean isItemValidForSlot( int i, ItemStack itemstack )
|
||||
{
|
||||
if ( this.smash )
|
||||
return false;
|
||||
|
||||
if ( i == 0 || i == 1 )
|
||||
{
|
||||
if ( AEApi.instance().materials().materialNamePress.sameAsStack( itemstack ) )
|
||||
if ( AEApi.instance().definitions().materials().namePress().isSameAs( itemstack ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
for (ItemStack s : Inscribe.PLATES )
|
||||
for ( ItemStack s : Inscribe.PLATES )
|
||||
if ( Platform.isSameItemPrecise( s, itemstack ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
if ( i == 2 )
|
||||
{
|
||||
return true;
|
||||
// for (ItemStack s : Inscribe.inputs)
|
||||
// if ( Platform.isSameItemPrecise( s, itemstack ) )
|
||||
// return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return i == 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -233,7 +232,13 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added)
|
||||
public IInventory getInternalInventory()
|
||||
{
|
||||
return this.inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory( IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added )
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -248,45 +253,73 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
|
||||
this.gridProxy.getTick().wakeDevice( this.gridProxy.getNode() );
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
catch ( GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsBySide( ForgeDirection d )
|
||||
{
|
||||
if ( d == ForgeDirection.UP )
|
||||
return this.top;
|
||||
|
||||
if ( d == ForgeDirection.DOWN )
|
||||
return this.bottom;
|
||||
|
||||
return this.sides;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest( IGridNode node )
|
||||
{
|
||||
return new TickingRequest( TickRates.Inscriber.min, TickRates.Inscriber.max, !this.hasWork(), false );
|
||||
}
|
||||
|
||||
private boolean hasWork()
|
||||
{
|
||||
if ( this.getTask() != null )
|
||||
return true;
|
||||
|
||||
this.processingTime = 0;
|
||||
return this.smash;
|
||||
}
|
||||
|
||||
public InscriberRecipe getTask()
|
||||
{
|
||||
ItemStack PlateA = this.getStackInSlot( 0 );
|
||||
ItemStack PlateB = this.getStackInSlot( 1 );
|
||||
ItemStack plateA = this.getStackInSlot( 0 );
|
||||
ItemStack plateB = this.getStackInSlot( 1 );
|
||||
ItemStack renamedItem = this.getStackInSlot( 2 );
|
||||
|
||||
if ( PlateA != null && PlateA.stackSize > 1 )
|
||||
if ( plateA != null && plateA.stackSize > 1 )
|
||||
return null;
|
||||
|
||||
if ( PlateB != null && PlateB.stackSize > 1 )
|
||||
if ( plateB != null && plateB.stackSize > 1 )
|
||||
return null;
|
||||
|
||||
if ( renamedItem != null && renamedItem.stackSize > 1 )
|
||||
return null;
|
||||
|
||||
boolean isNameA = AEApi.instance().materials().materialNamePress.sameAsStack( PlateA );
|
||||
boolean isNameB = AEApi.instance().materials().materialNamePress.sameAsStack( PlateB );
|
||||
final IComparableDefinition namePress = AEApi.instance().definitions().materials().namePress();
|
||||
boolean isNameA = namePress.isSameAs( plateA );
|
||||
boolean isNameB = namePress.isSameAs( plateB );
|
||||
|
||||
if ( (isNameA || isNameB) && (isNameA || PlateA == null) && (isNameB || PlateB == null) )
|
||||
if ( ( isNameA || isNameB ) && ( isNameA || plateA == null ) && ( isNameB || plateB == null ) )
|
||||
{
|
||||
if ( renamedItem != null )
|
||||
{
|
||||
String name = "";
|
||||
|
||||
if ( PlateA != null )
|
||||
if ( plateA != null )
|
||||
{
|
||||
NBTTagCompound tag = Platform.openNbtData( PlateA );
|
||||
NBTTagCompound tag = Platform.openNbtData( plateA );
|
||||
name += tag.getString( "InscribeName" );
|
||||
}
|
||||
|
||||
if ( PlateB != null )
|
||||
if ( plateB != null )
|
||||
{
|
||||
NBTTagCompound tag = Platform.openNbtData( PlateB );
|
||||
NBTTagCompound tag = Platform.openNbtData( plateB );
|
||||
if ( name.length() > 0 )
|
||||
name += " ";
|
||||
name += tag.getString( "InscribeName" );
|
||||
@@ -304,49 +337,33 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
|
||||
else
|
||||
display.removeTag( "Name" );
|
||||
|
||||
return new InscriberRecipe( new ItemStack[] { startingItem }, PlateA, PlateB, renamedItem, false );
|
||||
return new InscriberRecipe( new ItemStack[] { startingItem }, plateA, plateB, renamedItem, false );
|
||||
}
|
||||
}
|
||||
|
||||
for (InscriberRecipe i : Inscribe.RECIPES )
|
||||
for ( InscriberRecipe i : Inscribe.RECIPES )
|
||||
{
|
||||
|
||||
boolean matchA = (PlateA == null && i.plateA == null) || (Platform.isSameItemPrecise( PlateA, i.plateA )) && // and...
|
||||
(PlateB == null && i.plateB == null) | (Platform.isSameItemPrecise( PlateB, i.plateB ));
|
||||
boolean matchA = ( plateA == null && i.plateA == null ) || ( Platform.isSameItemPrecise( plateA, i.plateA ) ) && // and...
|
||||
( plateB == null && i.plateB == null ) | ( Platform.isSameItemPrecise( plateB, i.plateB ) );
|
||||
|
||||
boolean matchB = (PlateB == null && i.plateA == null) || (Platform.isSameItemPrecise( PlateB, i.plateA )) && // and...
|
||||
(PlateA == null && i.plateB == null) | (Platform.isSameItemPrecise( PlateA, i.plateB ));
|
||||
boolean matchB = ( plateB == null && i.plateA == null ) || ( Platform.isSameItemPrecise( plateB, i.plateA ) ) && // and...
|
||||
( plateA == null && i.plateB == null ) | ( Platform.isSameItemPrecise( plateA, i.plateB ) );
|
||||
|
||||
if ( matchA || matchB )
|
||||
{
|
||||
for (ItemStack option : i.imprintable)
|
||||
for ( ItemStack option : i.imprintable )
|
||||
{
|
||||
if ( Platform.isSameItemPrecise( option, this.getStackInSlot( 2 ) ) )
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean hasWork()
|
||||
{
|
||||
if ( this.getTask() != null )
|
||||
return true;
|
||||
|
||||
this.processingTime = 0;
|
||||
return this.smash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node)
|
||||
{
|
||||
return new TickingRequest( TickRates.Inscriber.min, TickRates.Inscriber.max, !this.hasWork(), false );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
|
||||
public TickRateModulation tickingRequest( IGridNode node, int TicksSinceLastCall )
|
||||
{
|
||||
if ( this.smash )
|
||||
{
|
||||
@@ -374,7 +391,6 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
|
||||
}
|
||||
|
||||
this.markDirty();
|
||||
|
||||
}
|
||||
else if ( this.finalStep == 16 )
|
||||
{
|
||||
@@ -413,7 +429,7 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
|
||||
this.processingTime += TicksSinceLastCall * speedFactor;
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
catch ( GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
@@ -446,7 +462,7 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInventoryByName(String name)
|
||||
public IInventory getInventoryByName( String name )
|
||||
{
|
||||
if ( name.equals( "inv" ) )
|
||||
return this.inv;
|
||||
@@ -458,31 +474,13 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInstalledUpgrades(Upgrades u)
|
||||
public int getInstalledUpgrades( Upgrades u )
|
||||
{
|
||||
return this.upgrades.getInstalledUpgrades( u );
|
||||
}
|
||||
|
||||
protected int getUpgradeSlots()
|
||||
{
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops(World w, int x, int y, int z, ArrayList<ItemStack> drops)
|
||||
{
|
||||
super.getDrops( w, x, y, z, drops );
|
||||
|
||||
for (int h = 0; h < this.upgrades.getSizeInventory(); h++)
|
||||
{
|
||||
ItemStack is = this.upgrades.getStackInSlot( h );
|
||||
if ( is != null )
|
||||
drops.add( is );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue)
|
||||
public void updateSetting( IConfigManager manager, Enum settingName, Enum newValue )
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,7 +193,7 @@ public class TileWireless extends AENetworkInvTile implements IWirelessAccessPoi
|
||||
@Override
|
||||
public boolean isItemValidForSlot( int i, ItemStack itemstack )
|
||||
{
|
||||
return AEApi.instance().materials().materialWirelessBooster.sameAsStack( itemstack );
|
||||
return AEApi.instance().definitions().materials().wirelessBooster().isSameAs( itemstack );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,17 +18,22 @@
|
||||
|
||||
package appeng.tile.qnb;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import com.google.common.base.Optional;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.definitions.IBlockDefinition;
|
||||
import appeng.api.networking.GridFlags;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
@@ -46,29 +51,32 @@ import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock
|
||||
{
|
||||
|
||||
final private static ItemStack RING_STACK = ( AEApi.instance().blocks().blockQuantumRing != null ) ? AEApi.instance().blocks().blockQuantumRing.stack( 1 ) : null;
|
||||
|
||||
private static final IBlockDefinition RING_DEFINITION = AEApi.instance().definitions().blocks().quantumRing();
|
||||
public final byte corner = 16;
|
||||
final int[] sidesRing = new int[] { };
|
||||
final int[] sidesLink = new int[] { 0 };
|
||||
|
||||
final AppEngInternalInventory internalInventory = new AppEngInternalInventory( this, 1 );
|
||||
|
||||
public final byte corner = 16;
|
||||
final byte hasSingularity = 32;
|
||||
final byte powered = 64;
|
||||
|
||||
private final QuantumCalculator calc = new QuantumCalculator( this );
|
||||
byte constructed = -1;
|
||||
|
||||
QuantumCluster cluster;
|
||||
public boolean bridgePowered;
|
||||
|
||||
byte constructed = -1;
|
||||
QuantumCluster cluster;
|
||||
private boolean updateStatus = false;
|
||||
|
||||
@TileEvent(TileEventType.TICK)
|
||||
public TileQuantumBridge()
|
||||
{
|
||||
this.gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
||||
this.gridProxy.setFlags( GridFlags.DENSE_CAPACITY );
|
||||
this.gridProxy.setIdlePowerUsage( 22 );
|
||||
this.internalInventory.setMaxStackSize( 1 );
|
||||
}
|
||||
|
||||
@TileEvent( TileEventType.TICK )
|
||||
public void onTickEvent()
|
||||
{
|
||||
if ( this.updateStatus )
|
||||
@@ -80,7 +88,7 @@ public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock
|
||||
}
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_WRITE)
|
||||
@TileEvent( TileEventType.NETWORK_WRITE )
|
||||
public void onNetworkWriteEvent( ByteBuf data )
|
||||
{
|
||||
int out = this.constructed;
|
||||
@@ -94,7 +102,7 @@ public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock
|
||||
data.writeByte( (byte) out );
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_READ)
|
||||
@TileEvent( TileEventType.NETWORK_READ )
|
||||
public boolean onNetworkReadEvent( ByteBuf data )
|
||||
{
|
||||
int oldValue = this.constructed;
|
||||
@@ -103,19 +111,37 @@ public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock
|
||||
return this.constructed != oldValue;
|
||||
}
|
||||
|
||||
public TileQuantumBridge() {
|
||||
this.gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
||||
this.gridProxy.setFlags( GridFlags.DENSE_CAPACITY );
|
||||
this.gridProxy.setIdlePowerUsage( 22 );
|
||||
this.internalInventory.setMaxStackSize( 1 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInternalInventory()
|
||||
{
|
||||
return this.internalInventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory( IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added )
|
||||
{
|
||||
if ( this.cluster != null )
|
||||
this.cluster.updateStatus( true );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsBySide( ForgeDirection side )
|
||||
{
|
||||
if ( this.isCenter() )
|
||||
return this.sidesLink;
|
||||
return this.sidesRing;
|
||||
}
|
||||
|
||||
public boolean isCenter()
|
||||
{
|
||||
for ( Block link : AEApi.instance().definitions().blocks().quantumLink().maybeBlock().asSet() )
|
||||
{
|
||||
return this.getBlockType() == link;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void onPowerStatusChange( MENetworkPowerStatusChange c )
|
||||
{
|
||||
@@ -123,22 +149,40 @@ public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added)
|
||||
public void onReady()
|
||||
{
|
||||
if ( this.cluster != null )
|
||||
this.cluster.updateStatus( true );
|
||||
super.onReady();
|
||||
|
||||
final IBlockDefinition quantumRing = AEApi.instance().definitions().blocks().quantumRing();
|
||||
final Optional<Block> maybeLinkBlock = quantumRing.maybeBlock();
|
||||
final Optional<ItemStack> maybeLinkStack = quantumRing.maybeStack( 1 );
|
||||
|
||||
final boolean isPresent = maybeLinkBlock.isPresent() && maybeLinkStack.isPresent();
|
||||
|
||||
if ( isPresent && this.getBlockType() == maybeLinkBlock.get() )
|
||||
{
|
||||
final ItemStack linkStack = maybeLinkStack.get();
|
||||
|
||||
this.gridProxy.setVisualRepresentation( linkStack );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsBySide(ForgeDirection side)
|
||||
public void onChunkUnload()
|
||||
{
|
||||
if ( this.isCenter() )
|
||||
return this.sidesLink;
|
||||
return this.sidesRing;
|
||||
this.disconnect( false );
|
||||
super.onChunkUnload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect(boolean affectWorld)
|
||||
public void invalidate()
|
||||
{
|
||||
this.disconnect( false );
|
||||
super.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect( boolean affectWorld )
|
||||
{
|
||||
if ( this.cluster != null )
|
||||
{
|
||||
@@ -166,29 +210,7 @@ public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock
|
||||
return !this.isInvalid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReady()
|
||||
{
|
||||
super.onReady();
|
||||
if ( this.worldObj.getBlock( this.xCoord, this.yCoord, this.zCoord ) == AEApi.instance().blocks().blockQuantumRing.block() )
|
||||
this.gridProxy.setVisualRepresentation( RING_STACK );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
this.disconnect( false );
|
||||
super.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload()
|
||||
{
|
||||
this.disconnect( false );
|
||||
super.onChunkUnload();
|
||||
}
|
||||
|
||||
public void updateStatus(QuantumCluster c, byte flags, boolean affectWorld)
|
||||
public void updateStatus( QuantumCluster c, byte flags, boolean affectWorld )
|
||||
{
|
||||
this.cluster = c;
|
||||
|
||||
@@ -209,6 +231,25 @@ public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isCorner()
|
||||
{
|
||||
return ( this.constructed & this.corner ) == this.corner && this.constructed != -1;
|
||||
}
|
||||
|
||||
public EnumSet<ForgeDirection> getConnections()
|
||||
{
|
||||
EnumSet<ForgeDirection> set = EnumSet.noneOf( ForgeDirection.class );
|
||||
|
||||
for ( ForgeDirection d : ForgeDirection.VALID_DIRECTIONS )
|
||||
{
|
||||
TileEntity te = this.worldObj.getTileEntity( this.xCoord + d.offsetX, this.yCoord + d.offsetY, this.zCoord + d.offsetZ );
|
||||
if ( te instanceof TileQuantumBridge )
|
||||
set.add( d );
|
||||
}
|
||||
|
||||
return set;
|
||||
}
|
||||
|
||||
public long getQEFrequency()
|
||||
{
|
||||
ItemStack is = this.internalInventory.getStackInSlot( 0 );
|
||||
@@ -221,16 +262,6 @@ public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean isCenter()
|
||||
{
|
||||
return this.getBlockType() == AEApi.instance().blocks().blockQuantumLink.block();
|
||||
}
|
||||
|
||||
public boolean isCorner()
|
||||
{
|
||||
return ( this.constructed & this.corner ) == this.corner && this.constructed != -1;
|
||||
}
|
||||
|
||||
public boolean isPowered()
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
@@ -240,7 +271,7 @@ public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock
|
||||
{
|
||||
return this.gridProxy.getEnergy().isNetworkPowered();
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
catch ( GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
@@ -254,34 +285,20 @@ public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType(ForgeDirection dir)
|
||||
public AECableType getCableConnectionType( ForgeDirection dir )
|
||||
{
|
||||
return AECableType.DENSE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DimensionalCoord getLocation()
|
||||
{
|
||||
return new DimensionalCoord( this );
|
||||
}
|
||||
|
||||
public void neighborUpdate()
|
||||
{
|
||||
this.calc.calculateMultiblock( this.worldObj, this.getLocation() );
|
||||
}
|
||||
|
||||
public EnumSet<ForgeDirection> getConnections()
|
||||
@Override
|
||||
public DimensionalCoord getLocation()
|
||||
{
|
||||
EnumSet<ForgeDirection> set = EnumSet.noneOf( ForgeDirection.class );
|
||||
|
||||
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity te = this.worldObj.getTileEntity( this.xCoord + d.offsetX, this.yCoord + d.offsetY, this.zCoord + d.offsetZ );
|
||||
if ( te instanceof TileQuantumBridge )
|
||||
set.add( d );
|
||||
}
|
||||
|
||||
return set;
|
||||
return new DimensionalCoord( this );
|
||||
}
|
||||
|
||||
public boolean hasQES()
|
||||
@@ -296,5 +313,4 @@ public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock
|
||||
if ( this.cluster != null )
|
||||
this.cluster.destroy();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -55,7 +55,9 @@ import appeng.api.util.AECableType;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.core.settings.TickRates;
|
||||
import appeng.helpers.Reflected;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.parts.automation.BlockUpgradeInventory;
|
||||
import appeng.parts.automation.UpgradeInventory;
|
||||
import appeng.tile.TileEvent;
|
||||
import appeng.tile.events.TileEventType;
|
||||
@@ -85,27 +87,34 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
private static final int OUTPUT_SLOT_INDEX_BOTTOM_LEFT = 10;
|
||||
private static final int OUTPUT_SLOT_INDEX_BOTTOM_RIGHT = 11;
|
||||
|
||||
private final ConfigManager manager = new ConfigManager( this );
|
||||
private final ConfigManager manager;
|
||||
|
||||
private final int[] input = { INPUT_SLOT_INDEX_TOP_LEFT, INPUT_SLOT_INDEX_TOP_RIGHT, INPUT_SLOT_INDEX_CENTER_LEFT, INPUT_SLOT_INDEX_CENTER_RIGHT, INPUT_SLOT_INDEX_BOTTOM_LEFT, INPUT_SLOT_INDEX_BOTTOM_RIGHT };
|
||||
private final int[] output = { OUTPUT_SLOT_INDEX_TOP_LEFT, OUTPUT_SLOT_INDEX_TOP_RIGHT, OUTPUT_SLOT_INDEX_CENTER_LEFT, OUTPUT_SLOT_INDEX_CENTER_RIGHT, OUTPUT_SLOT_INDEX_BOTTOM_LEFT, OUTPUT_SLOT_INDEX_BOTTOM_RIGHT };
|
||||
|
||||
private final AppEngInternalInventory cells = new AppEngInternalInventory( this, 12 );
|
||||
private final UpgradeInventory upgrades = new UpgradeInventory( AEApi.instance().blocks().blockIOPort.block(), this, 3 );
|
||||
private final AppEngInternalInventory cells;
|
||||
private final UpgradeInventory upgrades;
|
||||
|
||||
private final BaseActionSource mySrc = new MachineSource( this );
|
||||
private final BaseActionSource mySrc;
|
||||
|
||||
private YesNo lastRedstoneState = YesNo.UNDECIDED;
|
||||
private YesNo lastRedstoneState;
|
||||
private ItemStack currentCell;
|
||||
private IMEInventory<IAEFluidStack> cachedFluid;
|
||||
private IMEInventory<IAEItemStack> cachedItem;
|
||||
|
||||
@Reflected
|
||||
public TileIOPort()
|
||||
{
|
||||
this.gridProxy.setFlags( GridFlags.REQUIRE_CHANNEL );
|
||||
this.manager = new ConfigManager( this );
|
||||
this.manager.registerSetting( Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE );
|
||||
this.manager.registerSetting( Settings.FULLNESS_MODE, FullnessMode.EMPTY );
|
||||
this.manager.registerSetting( Settings.OPERATION_MODE, OperationMode.EMPTY );
|
||||
this.cells = new AppEngInternalInventory( this, 12 );
|
||||
this.mySrc = new MachineSource( this );
|
||||
this.lastRedstoneState = YesNo.UNDECIDED;
|
||||
|
||||
this.upgrades = new BlockUpgradeInventory( this.getBlockType(), this, 3 );
|
||||
}
|
||||
|
||||
@TileEvent( TileEventType.WORLD_NBT_WRITE )
|
||||
@@ -123,7 +132,7 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
this.manager.readFromNBT( data );
|
||||
this.cells.readFromNBT( data, "cells" );
|
||||
this.upgrades.readFromNBT( data, "upgrades" );
|
||||
if ( data.hasKey( "lastRedstoneState" ) )
|
||||
if( data.hasKey( "lastRedstoneState" ) )
|
||||
this.lastRedstoneState = YesNo.values()[data.getInteger( "lastRedstoneState" )];
|
||||
}
|
||||
|
||||
@@ -143,12 +152,12 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( this.hasWork() )
|
||||
if( this.hasWork() )
|
||||
this.gridProxy.getTick().wakeDevice( this.gridProxy.getNode() );
|
||||
else
|
||||
this.gridProxy.getTick().sleepDevice( this.gridProxy.getNode() );
|
||||
}
|
||||
catch ( GridAccessException e )
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
@@ -157,7 +166,7 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
public void updateRedstoneState()
|
||||
{
|
||||
YesNo currentState = this.worldObj.isBlockIndirectlyGettingPowered( this.xCoord, this.yCoord, this.zCoord ) ? YesNo.YES : YesNo.NO;
|
||||
if ( this.lastRedstoneState != currentState )
|
||||
if( this.lastRedstoneState != currentState )
|
||||
{
|
||||
this.lastRedstoneState = currentState;
|
||||
this.updateTask();
|
||||
@@ -166,7 +175,7 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
|
||||
public boolean getRedstoneState()
|
||||
{
|
||||
if ( this.lastRedstoneState == YesNo.UNDECIDED )
|
||||
if( this.lastRedstoneState == YesNo.UNDECIDED )
|
||||
this.updateRedstoneState();
|
||||
|
||||
return this.lastRedstoneState == YesNo.YES;
|
||||
@@ -174,11 +183,11 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
|
||||
private boolean isEnabled()
|
||||
{
|
||||
if ( this.getInstalledUpgrades( Upgrades.REDSTONE ) == 0 )
|
||||
if( this.getInstalledUpgrades( Upgrades.REDSTONE ) == 0 )
|
||||
return true;
|
||||
|
||||
RedstoneMode rs = (RedstoneMode) this.manager.getSetting( Settings.REDSTONE_CONTROLLED );
|
||||
if ( rs == RedstoneMode.HIGH_SIGNAL )
|
||||
if( rs == RedstoneMode.HIGH_SIGNAL )
|
||||
return this.getRedstoneState();
|
||||
return !this.getRedstoneState();
|
||||
}
|
||||
@@ -192,10 +201,10 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
@Override
|
||||
public IInventory getInventoryByName( String name )
|
||||
{
|
||||
if ( name.equals( "upgrades" ) )
|
||||
if( name.equals( "upgrades" ) )
|
||||
return this.upgrades;
|
||||
|
||||
if ( name.equals( "cells" ) )
|
||||
if( name.equals( "cells" ) )
|
||||
return this.cells;
|
||||
|
||||
return null;
|
||||
@@ -209,10 +218,10 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
|
||||
boolean hasWork()
|
||||
{
|
||||
if ( this.isEnabled() )
|
||||
if( this.isEnabled() )
|
||||
{
|
||||
for ( int x = 0; x < 6; x++ )
|
||||
if ( this.cells.getStackInSlot( x ) != null )
|
||||
for( int x = 0; x < 6; x++ )
|
||||
if( this.cells.getStackInSlot( x ) != null )
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -222,9 +231,9 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
@Override
|
||||
public boolean canInsertItem( int slotIndex, ItemStack insertingItem, int side )
|
||||
{
|
||||
for ( int inputSlotIndex : this.input )
|
||||
for( int inputSlotIndex : this.input )
|
||||
{
|
||||
if ( inputSlotIndex == slotIndex )
|
||||
if( inputSlotIndex == slotIndex )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -236,9 +245,9 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
@Override
|
||||
public boolean canExtractItem( int slotIndex, ItemStack extractedItem, int side )
|
||||
{
|
||||
for ( int outputSlotIndex : this.output )
|
||||
for( int outputSlotIndex : this.output )
|
||||
{
|
||||
if ( outputSlotIndex == slotIndex )
|
||||
if( outputSlotIndex == slotIndex )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -256,7 +265,7 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
@Override
|
||||
public void onChangeInventory( IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added )
|
||||
{
|
||||
if ( this.cells == inv )
|
||||
if( this.cells == inv )
|
||||
{
|
||||
this.updateTask();
|
||||
}
|
||||
@@ -265,7 +274,7 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
@Override
|
||||
public int[] getAccessibleSlotsBySide( ForgeDirection d )
|
||||
{
|
||||
if ( d == ForgeDirection.UP || d == ForgeDirection.DOWN )
|
||||
if( d == ForgeDirection.UP || d == ForgeDirection.DOWN )
|
||||
return this.input;
|
||||
|
||||
return this.output;
|
||||
@@ -280,12 +289,12 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
@Override
|
||||
public TickRateModulation tickingRequest( IGridNode node, int TicksSinceLastCall )
|
||||
{
|
||||
if ( !this.gridProxy.isActive() )
|
||||
if( !this.gridProxy.isActive() )
|
||||
return TickRateModulation.IDLE;
|
||||
|
||||
long ItemsToMove = 256;
|
||||
|
||||
switch ( this.getInstalledUpgrades( Upgrades.SPEED ) )
|
||||
switch( this.getInstalledUpgrades( Upgrades.SPEED ) )
|
||||
{
|
||||
case 1:
|
||||
ItemsToMove *= 2;
|
||||
@@ -303,32 +312,32 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
IMEInventory<IAEItemStack> itemNet = this.gridProxy.getStorage().getItemInventory();
|
||||
IMEInventory<IAEFluidStack> fluidNet = this.gridProxy.getStorage().getFluidInventory();
|
||||
IEnergySource energy = this.gridProxy.getEnergy();
|
||||
for ( int x = 0; x < 6; x++ )
|
||||
for( int x = 0; x < 6; x++ )
|
||||
{
|
||||
ItemStack is = this.cells.getStackInSlot( x );
|
||||
if ( is != null )
|
||||
if( is != null )
|
||||
{
|
||||
if ( ItemsToMove > 0 )
|
||||
if( ItemsToMove > 0 )
|
||||
{
|
||||
IMEInventory<IAEItemStack> itemInv = this.getInv( is, StorageChannel.ITEMS );
|
||||
IMEInventory<IAEFluidStack> fluidInv = this.getInv( is, StorageChannel.FLUIDS );
|
||||
|
||||
if ( this.manager.getSetting( Settings.OPERATION_MODE ) == OperationMode.EMPTY )
|
||||
if( this.manager.getSetting( Settings.OPERATION_MODE ) == OperationMode.EMPTY )
|
||||
{
|
||||
if ( itemInv != null )
|
||||
if( itemInv != null )
|
||||
ItemsToMove = this.transferContents( energy, itemInv, itemNet, ItemsToMove, StorageChannel.ITEMS );
|
||||
if ( fluidInv != null )
|
||||
if( fluidInv != null )
|
||||
ItemsToMove = this.transferContents( energy, fluidInv, fluidNet, ItemsToMove, StorageChannel.FLUIDS );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( itemInv != null )
|
||||
if( itemInv != null )
|
||||
ItemsToMove = this.transferContents( energy, itemNet, itemInv, ItemsToMove, StorageChannel.ITEMS );
|
||||
if ( fluidInv != null )
|
||||
if( fluidInv != null )
|
||||
ItemsToMove = this.transferContents( energy, fluidNet, fluidInv, ItemsToMove, StorageChannel.FLUIDS );
|
||||
}
|
||||
|
||||
if ( ItemsToMove > 0 && this.shouldMove( itemInv, fluidInv ) && !this.moveSlot( x ) )
|
||||
if( ItemsToMove > 0 && this.shouldMove( itemInv, fluidInv ) && !this.moveSlot( x ) )
|
||||
return TickRateModulation.IDLE;
|
||||
|
||||
return TickRateModulation.URGENT;
|
||||
@@ -338,7 +347,7 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
}
|
||||
}
|
||||
}
|
||||
catch ( GridAccessException e )
|
||||
catch( GridAccessException e )
|
||||
{
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
@@ -355,14 +364,14 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
|
||||
private IMEInventory getInv( ItemStack is, StorageChannel chan )
|
||||
{
|
||||
if ( this.currentCell != is )
|
||||
if( this.currentCell != is )
|
||||
{
|
||||
this.currentCell = is;
|
||||
this.cachedFluid = AEApi.instance().registries().cell().getCellInventory( is, null, StorageChannel.FLUIDS );
|
||||
this.cachedItem = AEApi.instance().registries().cell().getCellInventory( is, null, StorageChannel.ITEMS );
|
||||
}
|
||||
|
||||
if ( StorageChannel.ITEMS == chan )
|
||||
if( StorageChannel.ITEMS == chan )
|
||||
return this.cachedItem;
|
||||
|
||||
return this.cachedFluid;
|
||||
@@ -371,7 +380,7 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
private long transferContents( IEnergySource energy, IMEInventory src, IMEInventory destination, long itemsToMove, StorageChannel chan )
|
||||
{
|
||||
IItemList<? extends IAEStack> myList;
|
||||
if ( src instanceof IMEMonitor )
|
||||
if( src instanceof IMEMonitor )
|
||||
myList = ( (IMEMonitor) src ).getStorageList();
|
||||
else
|
||||
myList = src.getAvailableItems( src.getChannel().createList() );
|
||||
@@ -382,37 +391,37 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
{
|
||||
didStuff = false;
|
||||
|
||||
for ( IAEStack s : myList )
|
||||
for( IAEStack s : myList )
|
||||
{
|
||||
long totalStackSize = s.getStackSize();
|
||||
if ( totalStackSize > 0 )
|
||||
if( totalStackSize > 0 )
|
||||
{
|
||||
IAEStack stack = destination.injectItems( s, Actionable.SIMULATE, this.mySrc );
|
||||
|
||||
long possible = 0;
|
||||
if ( stack == null )
|
||||
if( stack == null )
|
||||
possible = totalStackSize;
|
||||
else
|
||||
possible = totalStackSize - stack.getStackSize();
|
||||
|
||||
if ( possible > 0 )
|
||||
if( possible > 0 )
|
||||
{
|
||||
possible = Math.min( possible, itemsToMove );
|
||||
s.setStackSize( possible );
|
||||
|
||||
IAEStack extracted = src.extractItems( s, Actionable.MODULATE, this.mySrc );
|
||||
if ( extracted != null )
|
||||
if( extracted != null )
|
||||
{
|
||||
possible = extracted.getStackSize();
|
||||
IAEStack failed = Platform.poweredInsert( energy, destination, extracted, this.mySrc );
|
||||
|
||||
if ( failed != null )
|
||||
if( failed != null )
|
||||
{
|
||||
possible -= failed.getStackSize();
|
||||
src.injectItems( failed, Actionable.MODULATE, this.mySrc );
|
||||
}
|
||||
|
||||
if ( possible > 0 )
|
||||
if( possible > 0 )
|
||||
{
|
||||
itemsToMove -= possible;
|
||||
didStuff = true;
|
||||
@@ -424,7 +433,7 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
}
|
||||
}
|
||||
}
|
||||
while ( itemsToMove > 0 && didStuff );
|
||||
while( itemsToMove > 0 && didStuff );
|
||||
|
||||
return itemsToMove;
|
||||
}
|
||||
@@ -433,11 +442,11 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
{
|
||||
FullnessMode fm = (FullnessMode) this.manager.getSetting( Settings.FULLNESS_MODE );
|
||||
|
||||
if ( itemInv != null && fluidInv != null )
|
||||
if( itemInv != null && fluidInv != null )
|
||||
return this.matches( fm, itemInv ) && this.matches( fm, fluidInv );
|
||||
else if ( itemInv != null )
|
||||
else if( itemInv != null )
|
||||
return this.matches( fm, itemInv );
|
||||
else if ( fluidInv != null )
|
||||
else if( fluidInv != null )
|
||||
return this.matches( fm, fluidInv );
|
||||
|
||||
return true;
|
||||
@@ -448,7 +457,7 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
WrapperInventoryRange wir = new WrapperInventoryRange( this, this.output, true );
|
||||
ItemStack result = InventoryAdaptor.getAdaptor( wir, ForgeDirection.UNKNOWN ).addItems( this.getStackInSlot( x ) );
|
||||
|
||||
if ( result == null )
|
||||
if( result == null )
|
||||
{
|
||||
this.setInventorySlotContents( x, null );
|
||||
return true;
|
||||
@@ -459,21 +468,21 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
|
||||
private boolean matches( FullnessMode fm, IMEInventory src )
|
||||
{
|
||||
if ( fm == FullnessMode.HALF )
|
||||
if( fm == FullnessMode.HALF )
|
||||
return true;
|
||||
|
||||
IItemList<? extends IAEStack> myList;
|
||||
|
||||
if ( src instanceof IMEMonitor )
|
||||
if( src instanceof IMEMonitor )
|
||||
myList = ( (IMEMonitor) src ).getStorageList();
|
||||
else
|
||||
myList = src.getAvailableItems( src.getChannel().createList() );
|
||||
|
||||
if ( fm == FullnessMode.EMPTY )
|
||||
if( fm == FullnessMode.EMPTY )
|
||||
return myList.isEmpty();
|
||||
|
||||
IAEStack test = myList.getFirstItem();
|
||||
if ( test != null )
|
||||
if( test != null )
|
||||
{
|
||||
test.setStackSize( 1 );
|
||||
return src.injectItems( test, Actionable.SIMULATE, this.mySrc ) != null;
|
||||
@@ -495,11 +504,11 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
{
|
||||
super.getDrops( w, x, y, z, drops );
|
||||
|
||||
for ( int upgradeIndex = 0; upgradeIndex < this.upgrades.getSizeInventory(); upgradeIndex++ )
|
||||
for( int upgradeIndex = 0; upgradeIndex < this.upgrades.getSizeInventory(); upgradeIndex++ )
|
||||
{
|
||||
ItemStack stackInSlot = this.upgrades.getStackInSlot( upgradeIndex );
|
||||
|
||||
if ( stackInSlot != null )
|
||||
if( stackInSlot != null )
|
||||
{
|
||||
drops.add( stackInSlot );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user