Relocate Source to proper directory.
This commit is contained in:
@@ -0,0 +1,129 @@
|
||||
package appeng.tile.crafting;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.implementations.tiles.IColorableTile;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.tile.TileEvent;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class TileCraftingMonitorTile extends TileCraftingTile implements IColorableTile
|
||||
{
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public Integer dspList;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean updateList;
|
||||
|
||||
IAEItemStack dspPlay;
|
||||
AEColor paintedColor = AEColor.Transparent;
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_READ)
|
||||
public boolean readFromStream_TileCraftingMonitorTile(ByteBuf data) throws IOException
|
||||
{
|
||||
AEColor oldPaintedColor = paintedColor;
|
||||
paintedColor = AEColor.values()[data.readByte()];
|
||||
|
||||
boolean hasItem = data.readBoolean();
|
||||
|
||||
if ( hasItem )
|
||||
dspPlay = AEItemStack.loadItemStackFromPacket( data );
|
||||
else
|
||||
dspPlay = null;
|
||||
|
||||
updateList = true;
|
||||
return oldPaintedColor != paintedColor; // tesr!
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_WRITE)
|
||||
public void writeToStream_TileCraftingMonitorTile(ByteBuf data) throws IOException
|
||||
{
|
||||
data.writeByte( paintedColor.ordinal() );
|
||||
|
||||
if ( dspPlay == null )
|
||||
data.writeBoolean( false );
|
||||
else
|
||||
{
|
||||
data.writeBoolean( true );
|
||||
dspPlay.writeToPacket( data );
|
||||
}
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_READ)
|
||||
public void readFromNBT_TileCraftingMonitorTile(NBTTagCompound data)
|
||||
{
|
||||
if ( data.hasKey( "paintedColor" ) )
|
||||
paintedColor = AEColor.values()[data.getByte( "paintedColor" )];
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_WRITE)
|
||||
public void writeToNBT_TileCraftingMonitorTile(NBTTagCompound data)
|
||||
{
|
||||
data.setByte( "paintedColor", (byte) paintedColor.ordinal() );
|
||||
}
|
||||
|
||||
public boolean isAccelerator()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isStatus()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setJob(IAEItemStack is)
|
||||
{
|
||||
if ( (is == null) != (dspPlay == null) )
|
||||
{
|
||||
dspPlay = is == null ? null : is.copy();
|
||||
markForUpdate();
|
||||
}
|
||||
else if ( is != null && dspPlay != null )
|
||||
{
|
||||
if ( is.getStackSize() != dspPlay.getStackSize() )
|
||||
{
|
||||
dspPlay = is == null ? null : is.copy();
|
||||
markForUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IAEItemStack getJobProgress()
|
||||
{
|
||||
return dspPlay;// AEItemStack.create( new ItemStack( Items.diamond, 64 ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean requiresTESR()
|
||||
{
|
||||
return getJobProgress() != null;
|
||||
}
|
||||
|
||||
public AEColor getColor()
|
||||
{
|
||||
return paintedColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean recolourBlock(ForgeDirection side, AEColor newPaintedColor, EntityPlayer who)
|
||||
{
|
||||
if ( paintedColor == newPaintedColor )
|
||||
return false;
|
||||
|
||||
paintedColor = newPaintedColor;
|
||||
markDirty();
|
||||
markForUpdate();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package appeng.tile.crafting;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.api.AEApi;
|
||||
|
||||
public class TileCraftingStorageTile extends TileCraftingTile
|
||||
{
|
||||
|
||||
static final ItemStack stackStorage4k = AEApi.instance().blocks().blockCraftingStorage4k.stack( 1 );
|
||||
static final ItemStack stackStorage16k = AEApi.instance().blocks().blockCraftingStorage16k.stack( 1 );
|
||||
static final ItemStack stackStorage64k = AEApi.instance().blocks().blockCraftingStorage64k.stack( 1 );
|
||||
|
||||
@Override
|
||||
protected ItemStack getItemFromTile(Object obj)
|
||||
{
|
||||
int storage = ((TileCraftingTile) obj).getStorageBytes() / 1024;
|
||||
|
||||
if ( storage == 4 )
|
||||
return stackStorage4k;
|
||||
if ( storage == 16 )
|
||||
return stackStorage16k;
|
||||
if ( storage == 64 )
|
||||
return stackStorage64k;
|
||||
|
||||
return super.getItemFromTile( obj );
|
||||
}
|
||||
|
||||
public boolean isAccelerator()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isStorage()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public int getStorageBytes()
|
||||
{
|
||||
if ( worldObj == null || notLoaded() )
|
||||
return 0;
|
||||
|
||||
switch (worldObj.getBlockMetadata( xCoord, yCoord, zCoord ) & 3)
|
||||
{
|
||||
default:
|
||||
case 0:
|
||||
return 1 * 1024;
|
||||
case 1:
|
||||
return 4 * 1024;
|
||||
case 2:
|
||||
return 16 * 1024;
|
||||
case 3:
|
||||
return 64 * 1024;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,287 @@
|
||||
package appeng.tile.crafting;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.implementations.IPowerChannelState;
|
||||
import appeng.api.networking.GridFlags;
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.parts.ISimplifiedBundle;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.util.WorldCoord;
|
||||
import appeng.me.cluster.IAECluster;
|
||||
import appeng.me.cluster.IAEMultiBlock;
|
||||
import appeng.me.cluster.implementations.CraftingCPUCalculator;
|
||||
import appeng.me.cluster.implementations.CraftingCPUCluster;
|
||||
import appeng.me.helpers.AENetworkProxy;
|
||||
import appeng.me.helpers.AENetworkProxyMultiblock;
|
||||
import appeng.tile.TileEvent;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.tile.grid.AENetworkTile;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class TileCraftingTile extends AENetworkTile implements IAEMultiBlock, IPowerChannelState
|
||||
{
|
||||
|
||||
CraftingCPUCluster clust;
|
||||
final CraftingCPUCalculator calc = new CraftingCPUCalculator( this );
|
||||
|
||||
public ISimplifiedBundle lightCache;
|
||||
|
||||
public NBTTagCompound previousState = null;
|
||||
public boolean isCoreBlock = false;
|
||||
|
||||
static final ItemStack coProcessorStack = AEApi.instance().blocks().blockCraftingAccelerator.stack( 1 );
|
||||
|
||||
@Override
|
||||
protected AENetworkProxy createProxy()
|
||||
{
|
||||
return new AENetworkProxyMultiblock( this, "proxy", getItemFromTile( this ), true );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ItemStack getItemFromTile(Object obj)
|
||||
{
|
||||
if ( ((TileCraftingTile) obj).isAccelerator() )
|
||||
return coProcessorStack;
|
||||
return super.getItemFromTile( obj );
|
||||
}
|
||||
|
||||
public void updateStatus(CraftingCPUCluster c)
|
||||
{
|
||||
if ( clust != null && clust != c )
|
||||
clust.breakCluster();
|
||||
|
||||
clust = c;
|
||||
updateMeta( true );
|
||||
}
|
||||
|
||||
public void updateMultiBlock()
|
||||
{
|
||||
calc.calculateMultiblock( worldObj, getLocation() );
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
super.setName( name );
|
||||
if ( clust != null )
|
||||
clust.updateName();
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_WRITE)
|
||||
public void writeToNBT_TileCraftingTile(NBTTagCompound data)
|
||||
{
|
||||
data.setBoolean( "core", isCoreBlock );
|
||||
if ( isCoreBlock && clust != null )
|
||||
clust.writeToNBT( data );
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_READ)
|
||||
public void readFromNBT_TileCraftingTile(NBTTagCompound data)
|
||||
{
|
||||
isCoreBlock = data.getBoolean( "core" );
|
||||
if ( isCoreBlock )
|
||||
{
|
||||
if ( clust != null )
|
||||
clust.readFromNBT( data );
|
||||
else
|
||||
previousState = (NBTTagCompound) data.copy();
|
||||
}
|
||||
}
|
||||
|
||||
public TileCraftingTile() {
|
||||
gridProxy.setFlags( GridFlags.MULTIBLOCK, GridFlags.REQUIRE_CHANNEL );
|
||||
gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReady()
|
||||
{
|
||||
super.onReady();
|
||||
gridProxy.setVisualRepresentation( getItemFromTile( this ) );
|
||||
updateMultiBlock();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canBeRotated()
|
||||
{
|
||||
return true;// return BlockCraftingUnit.checkType( worldObj.getBlockMetadata( xCoord, yCoord, zCoord ),
|
||||
// BlockCraftingUnit.BASE_MONITOR );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disconnect(boolean update)
|
||||
{
|
||||
if ( clust != null )
|
||||
{
|
||||
clust.destroy();
|
||||
if ( update )
|
||||
updateMeta( true );
|
||||
}
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void onPowerStateChange(MENetworkChannelsChanged ev)
|
||||
{
|
||||
updateMeta( false );
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void onPowerStateChange(MENetworkPowerStatusChange ev)
|
||||
{
|
||||
updateMeta( false );
|
||||
}
|
||||
|
||||
public void updateMeta(boolean updateFormed)
|
||||
{
|
||||
if ( worldObj == null || notLoaded() )
|
||||
return;
|
||||
|
||||
boolean formed = isFormed();
|
||||
boolean power = false;
|
||||
|
||||
if ( gridProxy.isReady() )
|
||||
power = gridProxy.isActive();
|
||||
|
||||
int current = worldObj.getBlockMetadata( xCoord, yCoord, zCoord );
|
||||
int newmeta = (current & 3) | (formed ? 8 : 0) | (power ? 4 : 0);
|
||||
|
||||
if ( current != newmeta )
|
||||
worldObj.setBlockMetadataWithNotify( xCoord, yCoord, zCoord, newmeta, 2 );
|
||||
|
||||
if ( updateFormed )
|
||||
{
|
||||
if ( formed )
|
||||
gridProxy.setValidSides( EnumSet.allOf( ForgeDirection.class ) );
|
||||
else
|
||||
gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAECluster getCluster()
|
||||
{
|
||||
return clust;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPowered()
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return (worldObj.getBlockMetadata( xCoord, yCoord, zCoord ) & 4) == 4;
|
||||
return gridProxy.isActive();
|
||||
}
|
||||
|
||||
public boolean isFormed()
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
return (worldObj.getBlockMetadata( xCoord, yCoord, zCoord ) & 8) == 8;
|
||||
return clust != null;
|
||||
}
|
||||
|
||||
public boolean isAccelerator()
|
||||
{
|
||||
if ( worldObj == null )
|
||||
return false;
|
||||
return (worldObj.getBlockMetadata( xCoord, yCoord, zCoord ) & 3) == 1;
|
||||
}
|
||||
|
||||
public boolean isStatus()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isStorage()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getStorageBytes()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive()
|
||||
{
|
||||
if ( Platform.isServer() )
|
||||
return gridProxy.isActive();
|
||||
return isPowered() && isFormed();
|
||||
}
|
||||
|
||||
public void breakCluster()
|
||||
{
|
||||
if ( clust != null )
|
||||
{
|
||||
clust.cancel();
|
||||
IMEInventory<IAEItemStack> inv = clust.getInventory();
|
||||
|
||||
LinkedList<WorldCoord> places = new LinkedList<WorldCoord>();
|
||||
|
||||
Iterator<IGridHost> i = clust.getTiles();
|
||||
while (i.hasNext())
|
||||
{
|
||||
IGridHost h = i.next();
|
||||
if ( h == this )
|
||||
places.add( new WorldCoord( this ) );
|
||||
else
|
||||
{
|
||||
TileEntity te = (TileEntity) h;
|
||||
|
||||
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
WorldCoord wc = new WorldCoord( te );
|
||||
wc.add( d, 1 );
|
||||
if ( worldObj.isAirBlock( wc.x, wc.y, wc.z ) )
|
||||
places.add( wc );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Collections.shuffle( places );
|
||||
|
||||
if ( places.isEmpty() )
|
||||
throw new RuntimeException( "No air or even the tile hat was destroyed?!?!" );
|
||||
|
||||
for (IAEItemStack ais : inv.getAvailableItems( AEApi.instance().storage().createItemList() ))
|
||||
{
|
||||
ais = ais.copy();
|
||||
ais.setStackSize( ais.getItemStack().getMaxStackSize() );
|
||||
while (true)
|
||||
{
|
||||
IAEItemStack g = inv.extractItems( ais.copy(), Actionable.MODULATE, clust.getActionSource() );
|
||||
if ( g == null )
|
||||
break;
|
||||
|
||||
WorldCoord wc = places.poll();
|
||||
places.add( wc );
|
||||
|
||||
Platform.spawnDrops( worldObj, wc.x, wc.y, wc.z, Arrays.asList( g.getItemStack() ) );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
clust.destroy();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,587 @@
|
||||
package appeng.tile.crafting;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.inventory.InventoryCrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.PowerMultiplier;
|
||||
import appeng.api.config.RedstoneMode;
|
||||
import appeng.api.config.Settings;
|
||||
import appeng.api.config.Upgrades;
|
||||
import appeng.api.implementations.IPowerChannelState;
|
||||
import appeng.api.implementations.IUpgradeableHost;
|
||||
import appeng.api.implementations.tiles.ICraftingMachine;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.api.parts.ISimplifiedBundle;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.api.util.IConfigManager;
|
||||
import appeng.container.ContainerNull;
|
||||
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.UpgradeInventory;
|
||||
import appeng.tile.TileEvent;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.tile.grid.AENetworkInvTile;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.IAEAppEngInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.ConfigManager;
|
||||
import appeng.util.IConfigManagerHost;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
|
||||
|
||||
public class TileMolecularAssembler extends AENetworkInvTile implements IAEAppEngInventory, ISidedInventory, IUpgradeableHost, IConfigManagerHost,
|
||||
IGridTickable, ICraftingMachine, IPowerChannelState
|
||||
{
|
||||
|
||||
static final int[] sides = new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
static final ItemStack assemblerStack = AEApi.instance().blocks().blockMolecularAssembler.stack( 1 );
|
||||
|
||||
private InventoryCrafting craftingInv = new InventoryCrafting( new ContainerNull(), 3, 3 );
|
||||
private AppEngInternalInventory inv = new AppEngInternalInventory( this, 9 + 2 );
|
||||
private IConfigManager settings = new ConfigManager( this );
|
||||
private UpgradeInventory upgrades = new UpgradeInventory( assemblerStack, this, getUpgradeSlots() );
|
||||
|
||||
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 boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCrafting table, ForgeDirection where)
|
||||
{
|
||||
if ( myPattern == null )
|
||||
{
|
||||
boolean isEmpty = true;
|
||||
for (int x = 0; x < inv.getSizeInventory(); x++)
|
||||
isEmpty = inv.getStackInSlot( x ) == null && isEmpty;
|
||||
|
||||
if ( isEmpty && patternDetails.isCraftable() )
|
||||
{
|
||||
forcePlan = true;
|
||||
myPlan = patternDetails;
|
||||
pushDirection = where;
|
||||
|
||||
for (int x = 0; x < table.getSizeInventory(); x++)
|
||||
inv.setInventorySlotContents( x, table.getStackInSlot( x ) );
|
||||
|
||||
updateSleepiness();
|
||||
markDirty();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void recalculatePlan()
|
||||
{
|
||||
reboot = true;
|
||||
|
||||
if ( forcePlan )
|
||||
return;
|
||||
|
||||
ItemStack is = inv.getStackInSlot( 10 );
|
||||
|
||||
if ( is != null && is.getItem() instanceof ItemEncodedPattern )
|
||||
{
|
||||
if ( !Platform.isSameItem( is, myPattern ) )
|
||||
{
|
||||
World w = getWorldObj();
|
||||
ItemEncodedPattern iep = (ItemEncodedPattern) is.getItem();
|
||||
ICraftingPatternDetails ph = iep.getPatternForItem( is, w );
|
||||
|
||||
if ( ph != null && ph.isCraftable() )
|
||||
{
|
||||
progress = 0;
|
||||
myPattern = is;
|
||||
myPlan = ph;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
progress = 0;
|
||||
forcePlan = false;
|
||||
myPlan = null;
|
||||
myPattern = null;
|
||||
pushDirection = ForgeDirection.UNKNOWN;
|
||||
}
|
||||
|
||||
updateSleepiness();
|
||||
}
|
||||
|
||||
private void updateSleepiness()
|
||||
{
|
||||
boolean wasEnabled = isAwake;
|
||||
isAwake = myPlan != null && hasMats() || canPush();
|
||||
if ( wasEnabled != isAwake )
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( isAwake )
|
||||
gridProxy.getTick().wakeDevice( gridProxy.getNode() );
|
||||
else
|
||||
gridProxy.getTick().sleepDevice( gridProxy.getNode() );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean canPush()
|
||||
{
|
||||
return inv.getStackInSlot( 9 ) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInstalledUpgrades(Upgrades u)
|
||||
{
|
||||
return upgrades.getInstalledUpgrades( u );
|
||||
}
|
||||
|
||||
protected int getUpgradeSlots()
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_READ)
|
||||
public boolean readFromStream_TileMolecularAssembler(ByteBuf data) throws IOException
|
||||
{
|
||||
boolean oldPower = isPowered;
|
||||
isPowered = data.readBoolean();
|
||||
return isPowered != oldPower;
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.NETWORK_WRITE)
|
||||
public void writeToStream_TileMolecularAssembler(ByteBuf data) throws IOException
|
||||
{
|
||||
data.writeBoolean( isPowered );
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_WRITE)
|
||||
public void writeToNBT_TileMolecularAssembler(NBTTagCompound data)
|
||||
{
|
||||
if ( forcePlan && myPlan != null )
|
||||
{
|
||||
ItemStack pattern = myPlan.getPattern();
|
||||
if ( pattern != null )
|
||||
{
|
||||
NBTTagCompound pdata = new NBTTagCompound();
|
||||
pattern.writeToNBT( pdata );
|
||||
data.setTag( "myPlan", pdata );
|
||||
data.setInteger( "pushDirection", pushDirection.ordinal() );
|
||||
}
|
||||
}
|
||||
|
||||
upgrades.writeToNBT( data, "upgrades" );
|
||||
inv.writeToNBT( data, "inv" );
|
||||
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 = getWorldObj();
|
||||
ItemEncodedPattern iep = (ItemEncodedPattern) myPat.getItem();
|
||||
ICraftingPatternDetails ph = iep.getPatternForItem( myPat, w );
|
||||
if ( ph != null && ph.isCraftable() )
|
||||
{
|
||||
forcePlan = true;
|
||||
myPlan = ph;
|
||||
pushDirection = ForgeDirection.getOrientation( data.getInteger( "pushDirection" ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
upgrades.readFromNBT( data, "upgrades" );
|
||||
inv.readFromNBT( data, "inv" );
|
||||
settings.readFromNBT( data );
|
||||
recalculatePlan();
|
||||
}
|
||||
|
||||
public TileMolecularAssembler() {
|
||||
settings.registerSetting( Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE );
|
||||
inv.setMaxStackSize( 1 );
|
||||
gridProxy.setIdlePowerUsage( 0.0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
if ( i >= 9 )
|
||||
return false;
|
||||
|
||||
if ( hasPattern() )
|
||||
return myPlan.isValidItemForSlot( i, itemstack, getWorldObj() );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsPlans()
|
||||
{
|
||||
return inv.getStackInSlot( 10 ) == null;
|
||||
}
|
||||
|
||||
private boolean hasPattern()
|
||||
{
|
||||
return myPlan != null && inv.getStackInSlot( 10 ) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int i, ItemStack itemstack, int j)
|
||||
{
|
||||
return i == 9;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInternalInventory()
|
||||
{
|
||||
return inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added)
|
||||
{
|
||||
if ( inv == this.inv )
|
||||
recalculatePlan();
|
||||
}
|
||||
|
||||
@Override
|
||||
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 settings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInventoryByName(String name)
|
||||
{
|
||||
if ( name.equals( "upgrades" ) )
|
||||
return upgrades;
|
||||
|
||||
if ( name.equals( "mac" ) )
|
||||
return inv;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
public int getCraftingProgress()
|
||||
{
|
||||
return (int) progress;
|
||||
}
|
||||
|
||||
@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 < upgrades.getSizeInventory(); h++)
|
||||
{
|
||||
ItemStack is = upgrades.getStackInSlot( h );
|
||||
if ( is != null )
|
||||
drops.add( is );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node)
|
||||
{
|
||||
recalculatePlan();
|
||||
updateSleepiness();
|
||||
return new TickingRequest( 1, 1, !isAwake, false );
|
||||
}
|
||||
|
||||
private boolean hasMats()
|
||||
{
|
||||
if ( myPlan == null )
|
||||
return false;
|
||||
|
||||
for (int x = 0; x < craftingInv.getSizeInventory(); x++)
|
||||
craftingInv.setInventorySlotContents( x, inv.getStackInSlot( x ) );
|
||||
|
||||
return myPlan.getOutput( craftingInv, getWorldObj() ) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
|
||||
{
|
||||
if ( inv.getStackInSlot( 9 ) != null )
|
||||
{
|
||||
pushOut( inv.getStackInSlot( 9 ) );
|
||||
|
||||
// did it eject?
|
||||
if ( inv.getStackInSlot( 9 ) == null )
|
||||
markDirty();
|
||||
|
||||
ejectHeldItems();
|
||||
updateSleepiness();
|
||||
progress = 0;
|
||||
return isAwake ? TickRateModulation.IDLE : TickRateModulation.SLEEP;
|
||||
}
|
||||
|
||||
if ( myPlan == null )
|
||||
{
|
||||
updateSleepiness();
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
|
||||
if ( reboot )
|
||||
TicksSinceLastCall = 1;
|
||||
|
||||
if ( !isAwake )
|
||||
return TickRateModulation.SLEEP;
|
||||
|
||||
reboot = false;
|
||||
int speed = 10;
|
||||
switch (upgrades.getInstalledUpgrades( Upgrades.SPEED ))
|
||||
{
|
||||
case 0:
|
||||
progress += userPower( TicksSinceLastCall, speed = 10, 1.0 );
|
||||
break;
|
||||
case 1:
|
||||
progress += userPower( TicksSinceLastCall, speed = 13, 1.3 );
|
||||
break;
|
||||
case 2:
|
||||
progress += userPower( TicksSinceLastCall, speed = 17, 1.7 );
|
||||
break;
|
||||
case 3:
|
||||
progress += userPower( TicksSinceLastCall, speed = 20, 2.0 );
|
||||
break;
|
||||
case 4:
|
||||
progress += userPower( TicksSinceLastCall, speed = 25, 2.5 );
|
||||
break;
|
||||
case 5:
|
||||
progress += userPower( TicksSinceLastCall, speed = 50, 5.0 );
|
||||
break;
|
||||
}
|
||||
|
||||
if ( progress >= 100 )
|
||||
{
|
||||
for (int x = 0; x < craftingInv.getSizeInventory(); x++)
|
||||
craftingInv.setInventorySlotContents( x, inv.getStackInSlot( x ) );
|
||||
|
||||
progress = 0;
|
||||
ItemStack output = myPlan.getOutput( craftingInv, getWorldObj() );
|
||||
if ( output != null )
|
||||
{
|
||||
FMLCommonHandler.instance().firePlayerCraftingEvent( Platform.getPlayer( (WorldServer) getWorldObj() ), output, craftingInv );
|
||||
|
||||
pushOut( output.copy() );
|
||||
|
||||
for (int x = 0; x < craftingInv.getSizeInventory(); x++)
|
||||
inv.setInventorySlotContents( x, Platform.getContainerItem( craftingInv.getStackInSlot( x ) ) );
|
||||
|
||||
if ( inv.getStackInSlot( 10 ) == null )
|
||||
{
|
||||
forcePlan = false;
|
||||
myPlan = null;
|
||||
pushDirection = ForgeDirection.UNKNOWN;
|
||||
}
|
||||
|
||||
ejectHeldItems();
|
||||
|
||||
try
|
||||
{
|
||||
TargetPoint where = new TargetPoint( worldObj.provider.dimensionId, xCoord, yCoord, zCoord, 32 );
|
||||
IAEItemStack item = AEItemStack.create( output );
|
||||
NetworkHandler.instance.sendToAllAround( new PacketAssemblerAnimation( xCoord, yCoord, zCoord, (byte) speed, item ), where );
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
// ;P
|
||||
}
|
||||
|
||||
markDirty();
|
||||
updateSleepiness();
|
||||
return isAwake ? TickRateModulation.IDLE : TickRateModulation.SLEEP;
|
||||
}
|
||||
}
|
||||
|
||||
return TickRateModulation.FASTER;
|
||||
}
|
||||
|
||||
private void ejectHeldItems()
|
||||
{
|
||||
if ( inv.getStackInSlot( 9 ) == null )
|
||||
{
|
||||
for (int x = 0; x < 9; x++)
|
||||
{
|
||||
ItemStack is = inv.getStackInSlot( x );
|
||||
if ( is != null )
|
||||
{
|
||||
if ( myPlan == null || !myPlan.isValidItemForSlot( x, is, worldObj ) )
|
||||
{
|
||||
inv.setInventorySlotContents( 9, is );
|
||||
inv.setInventorySlotContents( x, null );
|
||||
markDirty();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int userPower(int ticksPassed, int bonusValue, double acceleratorTax)
|
||||
{
|
||||
try
|
||||
{
|
||||
return (int) (gridProxy.getEnergy().extractAEPower( ticksPassed * bonusValue * acceleratorTax, Actionable.MODULATE, PowerMultiplier.CONFIG ) / acceleratorTax);
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
private void pushOut(ItemStack output)
|
||||
{
|
||||
if ( pushDirection == ForgeDirection.UNKNOWN )
|
||||
{
|
||||
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS)
|
||||
output = pushTo( output, d );
|
||||
}
|
||||
else
|
||||
output = pushTo( output, pushDirection );
|
||||
|
||||
if ( output == null && forcePlan )
|
||||
{
|
||||
forcePlan = false;
|
||||
recalculatePlan();
|
||||
}
|
||||
|
||||
inv.setInventorySlotContents( 9, output );
|
||||
}
|
||||
|
||||
private ItemStack pushTo(ItemStack output, ForgeDirection d)
|
||||
{
|
||||
if ( output == null )
|
||||
return output;
|
||||
|
||||
TileEntity te = getWorldObj().getTileEntity( xCoord + d.offsetX, yCoord + d.offsetY, zCoord + d.offsetZ );
|
||||
|
||||
if ( te == null )
|
||||
return output;
|
||||
|
||||
InventoryAdaptor adaptor = InventoryAdaptor.getAdaptor( te, d.getOpposite() );
|
||||
|
||||
if ( adaptor == null )
|
||||
return output;
|
||||
|
||||
int size = output.stackSize;
|
||||
output = adaptor.addItems( output );
|
||||
int newSize = output == null ? 0 : output.stackSize;
|
||||
|
||||
if ( size != newSize )
|
||||
markDirty();
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
boolean isPowered = false;
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void onPowerEvent(MENetworkPowerStatusChange p)
|
||||
{
|
||||
updatePowerState();
|
||||
}
|
||||
|
||||
private void updatePowerState()
|
||||
{
|
||||
boolean newState = false;
|
||||
|
||||
try
|
||||
{
|
||||
newState = gridProxy.isActive() && gridProxy.getEnergy().extractAEPower( 1, Actionable.SIMULATE, PowerMultiplier.CONFIG ) > 0.0001;
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if ( newState != isPowered )
|
||||
{
|
||||
isPowered = newState;
|
||||
markForUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPowered()
|
||||
{
|
||||
return isPowered;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isActive()
|
||||
{
|
||||
return isPowered;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user