Applied-Energistics-2-tiler.../src/main/java/appeng/tile/crafting/TileMolecularAssembler.java

658 lines
16 KiB
Java
Raw Normal View History

2014-11-14 12:02:52 +01:00
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
2014-04-08 02:43:57 +02:00
package appeng.tile.crafting;
2014-06-24 05:55:16 +02:00
import java.io.IOException;
2015-05-09 00:04:44 +02:00
import java.util.List;
2015-12-24 02:07:03 +01:00
import io.netty.buffer.ByteBuf;
2014-04-08 02:43:57 +02:00
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
2014-04-08 02:43:57 +02:00
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
2015-06-16 02:44:59 +02:00
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
2014-06-22 09:00:38 +02:00
import net.minecraft.world.WorldServer;
2015-06-16 02:44:59 +02:00
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint;
2015-12-24 02:07:03 +01:00
2014-04-24 08:14:26 +02:00
import appeng.api.AEApi;
2014-05-09 06:09:42 +02:00
import appeng.api.config.Actionable;
import appeng.api.config.PowerMultiplier;
2014-04-24 08:14:26 +02:00
import appeng.api.config.RedstoneMode;
import appeng.api.config.Settings;
import appeng.api.config.Upgrades;
import appeng.api.definitions.ITileDefinition;
2014-06-24 05:55:16 +02:00
import appeng.api.implementations.IPowerChannelState;
2014-04-24 08:14:26 +02:00
import appeng.api.implementations.IUpgradeableHost;
import appeng.api.implementations.tiles.ICraftingMachine;
import appeng.api.networking.IGridNode;
import appeng.api.networking.crafting.ICraftingPatternDetails;
2014-06-24 05:55:16 +02:00
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;
2014-07-07 04:04:58 +02:00
import appeng.api.storage.data.IAEItemStack;
2014-04-08 02:43:57 +02:00
import appeng.api.util.AECableType;
2015-06-16 02:44:59 +02:00
import appeng.api.util.AEPartLocation;
2014-04-08 02:43:57 +02:00
import appeng.api.util.DimensionalCoord;
2014-04-24 08:14:26 +02:00
import appeng.api.util.IConfigManager;
import appeng.container.ContainerNull;
2014-07-07 04:04:58 +02:00
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;
2014-04-24 08:14:26 +02:00
import appeng.parts.automation.UpgradeInventory;
2014-08-28 09:39:52 +02:00
import appeng.tile.TileEvent;
2014-04-08 02:43:57 +02:00
import appeng.tile.events.TileEventType;
import appeng.tile.grid.AENetworkInvTile;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.InvOperation;
2014-04-24 08:14:26 +02:00
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
2014-07-07 04:04:58 +02:00
import appeng.util.item.AEItemStack;
2014-04-08 02:43:57 +02:00
public class TileMolecularAssembler extends AENetworkInvTile implements IUpgradeableHost, IConfigManagerHost, IGridTickable, ICraftingMachine, IPowerChannelState
{
private static final int[] SIDES = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
2014-04-08 02:43:57 +02:00
private final InventoryCrafting craftingInv;
private final AppEngInternalInventory inv = new AppEngInternalInventory( this, 9 + 2 );
private final IConfigManager settings;
private final UpgradeInventory upgrades;
private boolean isPowered = false;
2015-06-16 02:44:59 +02:00
private AEPartLocation pushDirection = AEPartLocation.INTERNAL;
private ItemStack myPattern = null;
private ICraftingPatternDetails myPlan = null;
2014-05-09 06:09:42 +02:00
private double progress = 0;
private boolean isAwake = false;
2014-05-14 04:42:14 +02:00
private boolean forcePlan = false;
private boolean reboot = true;
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.getProxy().setIdlePowerUsage( 0.0 );
this.upgrades = new DefinitionUpgradeInventory( assembler, this, this.getUpgradeSlots() );
this.craftingInv = new InventoryCrafting( new ContainerNull(), 3, 3 );
}
private int getUpgradeSlots()
{
return 5;
}
@Override
2015-09-30 14:24:40 +02:00
public boolean pushPattern( final ICraftingPatternDetails patternDetails, final InventoryCrafting table, final EnumFacing where )
{
if( this.myPattern == null )
2014-05-14 04:42:14 +02:00
{
boolean isEmpty = true;
for( int x = 0; x < this.inv.getSizeInventory(); x++ )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
isEmpty = this.inv.getStackInSlot( x ) == null && isEmpty;
2015-04-29 02:30:53 +02:00
}
2014-05-14 04:42:14 +02:00
if( isEmpty && patternDetails.isCraftable() )
2014-05-14 04:42:14 +02:00
{
2014-12-29 15:13:47 +01:00
this.forcePlan = true;
this.myPlan = patternDetails;
2015-06-16 02:44:59 +02:00
this.pushDirection = AEPartLocation.fromFacing( where );
2014-05-14 04:42:14 +02:00
for( int x = 0; x < table.getSizeInventory(); x++ )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.inv.setInventorySlotContents( x, table.getStackInSlot( x ) );
2015-04-29 02:30:53 +02:00
}
2014-05-14 04:42:14 +02:00
2014-12-29 15:13:47 +01:00
this.updateSleepiness();
this.markDirty();
2014-05-14 04:42:14 +02:00
return true;
}
}
return false;
}
2014-09-21 01:35:08 +02:00
private void updateSleepiness()
2014-05-14 04:42:14 +02:00
{
2015-09-30 14:24:40 +02:00
final boolean wasEnabled = this.isAwake;
2014-12-29 15:13:47 +01:00
this.isAwake = this.myPlan != null && this.hasMats() || this.canPush();
if( wasEnabled != this.isAwake )
{
try
{
if( this.isAwake )
2015-04-29 02:30:53 +02:00
{
this.getProxy().getTick().wakeDevice( this.getProxy().getNode() );
2015-04-29 02:30:53 +02:00
}
else
2015-04-29 02:30:53 +02:00
{
this.getProxy().getTick().sleepDevice( this.getProxy().getNode() );
2015-04-29 02:30:53 +02:00
}
}
2015-09-30 14:24:40 +02:00
catch( final GridAccessException e )
{
// :P
}
}
}
2014-05-09 06:09:42 +02:00
private boolean canPush()
{
2014-12-29 15:13:47 +01:00
return this.inv.getStackInSlot( 9 ) != null;
2014-05-09 06:09:42 +02:00
}
private boolean hasMats()
{
if( this.myPlan == null )
2015-04-29 02:30:53 +02:00
{
return false;
2015-04-29 02:30:53 +02:00
}
for( int x = 0; x < this.craftingInv.getSizeInventory(); x++ )
2015-04-29 02:30:53 +02:00
{
this.craftingInv.setInventorySlotContents( x, this.inv.getStackInSlot( x ) );
2015-04-29 02:30:53 +02:00
}
2015-06-16 02:44:59 +02:00
return this.myPlan.getOutput( this.craftingInv, this.getWorld() ) != null;
}
2014-04-24 08:14:26 +02:00
@Override
public boolean acceptsPlans()
2014-04-24 08:14:26 +02:00
{
return this.inv.getStackInSlot( 10 ) == null;
2014-04-24 08:14:26 +02:00
}
@Override
2015-09-30 14:24:40 +02:00
public int getInstalledUpgrades( final Upgrades u )
2014-04-24 08:14:26 +02:00
{
return this.upgrades.getInstalledUpgrades( u );
2014-04-24 08:14:26 +02:00
}
2014-04-08 02:43:57 +02:00
@TileEvent( TileEventType.NETWORK_READ )
2015-09-30 14:24:40 +02:00
public boolean readFromStream_TileMolecularAssembler( final ByteBuf data )
2014-04-08 02:43:57 +02:00
{
2015-09-30 14:24:40 +02:00
final boolean oldPower = this.isPowered;
2014-12-29 15:13:47 +01:00
this.isPowered = data.readBoolean();
return this.isPowered != oldPower;
2014-08-28 09:39:52 +02:00
}
2014-04-08 02:43:57 +02:00
@TileEvent( TileEventType.NETWORK_WRITE )
2015-09-30 14:24:40 +02:00
public void writeToStream_TileMolecularAssembler( final ByteBuf data )
2014-08-28 09:39:52 +02:00
{
2014-12-29 15:13:47 +01:00
data.writeBoolean( this.isPowered );
2014-08-28 09:39:52 +02:00
}
2014-04-08 02:43:57 +02:00
@TileEvent( TileEventType.WORLD_NBT_WRITE )
2015-09-30 14:24:40 +02:00
public void writeToNBT_TileMolecularAssembler( final NBTTagCompound data )
2014-08-28 09:39:52 +02:00
{
if( this.forcePlan && this.myPlan != null )
2014-04-08 02:43:57 +02:00
{
2015-09-30 14:24:40 +02:00
final ItemStack pattern = this.myPlan.getPattern();
if( pattern != null )
2014-05-14 04:42:14 +02:00
{
2015-09-30 14:24:40 +02:00
final NBTTagCompound compound = new NBTTagCompound();
pattern.writeToNBT( compound );
data.setTag( "myPlan", compound );
2014-12-29 15:13:47 +01:00
data.setInteger( "pushDirection", this.pushDirection.ordinal() );
2014-05-14 04:42:14 +02:00
}
2014-04-08 02:43:57 +02:00
}
2014-12-29 15:13:47 +01:00
this.upgrades.writeToNBT( data, "upgrades" );
this.inv.writeToNBT( data, "inv" );
this.settings.writeToNBT( data );
2014-08-28 09:39:52 +02:00
}
@TileEvent( TileEventType.WORLD_NBT_READ )
2015-09-30 14:24:40 +02:00
public void readFromNBT_TileMolecularAssembler( final NBTTagCompound data )
2014-08-28 09:39:52 +02:00
{
if( data.hasKey( "myPlan" ) )
2014-04-08 02:43:57 +02:00
{
2015-09-30 14:24:40 +02:00
final ItemStack myPat = ItemStack.loadItemStackFromNBT( data.getCompoundTag( "myPlan" ) );
2014-05-14 04:42:14 +02:00
if( myPat != null && myPat.getItem() instanceof ItemEncodedPattern )
2014-08-28 09:39:52 +02:00
{
2015-09-30 14:24:40 +02:00
final World w = this.getWorld();
final ItemEncodedPattern iep = (ItemEncodedPattern) myPat.getItem();
final ICraftingPatternDetails ph = iep.getPatternForItem( myPat, w );
if( ph != null && ph.isCraftable() )
2014-05-14 04:42:14 +02:00
{
2014-12-29 15:13:47 +01:00
this.forcePlan = true;
this.myPlan = ph;
2015-06-16 02:44:59 +02:00
this.pushDirection = AEPartLocation.fromOrdinal( data.getInteger( "pushDirection" ) );
2014-05-14 04:42:14 +02:00
}
}
2014-04-08 02:43:57 +02:00
}
2014-12-29 15:13:47 +01:00
this.upgrades.readFromNBT( data, "upgrades" );
this.inv.readFromNBT( data, "inv" );
this.settings.readFromNBT( data );
this.recalculatePlan();
2014-08-28 09:39:52 +02:00
}
2014-04-08 02:43:57 +02:00
private void recalculatePlan()
2014-04-08 02:43:57 +02:00
{
this.reboot = true;
2014-04-08 02:43:57 +02:00
if( this.forcePlan )
2015-04-29 02:30:53 +02:00
{
return;
2015-04-29 02:30:53 +02:00
}
2014-04-08 02:43:57 +02:00
2015-09-30 14:24:40 +02:00
final ItemStack is = this.inv.getStackInSlot( 10 );
if( is != null && is.getItem() instanceof ItemEncodedPattern )
{
if( !Platform.itemComparisons().isEqualItem( is, this.myPattern ) )
{
2015-09-30 14:24:40 +02:00
final World w = this.getWorld();
final ItemEncodedPattern iep = (ItemEncodedPattern) is.getItem();
final ICraftingPatternDetails ph = iep.getPatternForItem( is, w );
if( ph != null && ph.isCraftable() )
{
this.progress = 0;
this.myPattern = is;
this.myPlan = ph;
}
}
}
else
{
this.progress = 0;
this.forcePlan = false;
this.myPlan = null;
this.myPattern = null;
2015-06-16 02:44:59 +02:00
this.pushDirection = AEPartLocation.INTERNAL;
}
this.updateSleepiness();
2014-04-08 02:43:57 +02:00
}
@Override
2015-09-30 14:24:40 +02:00
public AECableType getCableConnectionType( final AEPartLocation dir )
{
return AECableType.COVERED;
}
@Override
public DimensionalCoord getLocation()
2014-04-24 08:14:26 +02:00
{
return new DimensionalCoord( this );
2014-04-24 08:14:26 +02:00
}
2014-04-08 02:43:57 +02:00
@Override
public IConfigManager getConfigManager()
2014-04-08 02:43:57 +02:00
{
return this.settings;
2014-04-08 02:43:57 +02:00
}
@Override
2015-09-30 14:24:40 +02:00
public IInventory getInventoryByName( final String name )
2014-04-08 02:43:57 +02:00
{
if( name.equals( "upgrades" ) )
2015-04-29 02:30:53 +02:00
{
return this.upgrades;
2015-04-29 02:30:53 +02:00
}
if( name.equals( "mac" ) )
2015-04-29 02:30:53 +02:00
{
return this.inv;
2015-04-29 02:30:53 +02:00
}
return null;
2014-04-08 02:43:57 +02:00
}
@Override
2015-09-30 14:24:40 +02:00
public void updateSetting( final IConfigManager manager, final Enum settingName, final Enum newValue )
2014-04-08 02:43:57 +02:00
{
2014-04-08 02:43:57 +02:00
}
@Override
public IInventory getInternalInventory()
{
return this.inv;
}
2014-04-08 02:43:57 +02:00
@Override
public int getInventoryStackLimit()
2014-04-08 02:43:57 +02:00
{
return 1;
2014-04-08 02:43:57 +02:00
}
@Override
2015-09-30 14:24:40 +02:00
public boolean isItemValidForSlot( final int i, final ItemStack itemstack )
2014-04-08 02:43:57 +02:00
{
if( i >= 9 )
2015-04-29 02:30:53 +02:00
{
return false;
2015-04-29 02:30:53 +02:00
}
if( this.hasPattern() )
2015-04-29 02:30:53 +02:00
{
2015-06-16 02:44:59 +02:00
return this.myPlan.isValidItemForSlot( i, itemstack, this.getWorld() );
2015-04-29 02:30:53 +02:00
}
return false;
2014-04-08 02:43:57 +02:00
}
private boolean hasPattern()
2014-04-08 02:43:57 +02:00
{
return this.myPlan != null && this.inv.getStackInSlot( 10 ) != null;
2014-04-08 02:43:57 +02:00
}
2014-04-24 08:14:26 +02:00
@Override
2015-09-30 14:24:40 +02:00
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added )
2014-04-24 08:14:26 +02:00
{
if( inv == this.inv )
2015-04-29 02:30:53 +02:00
{
this.recalculatePlan();
2015-04-29 02:30:53 +02:00
}
2014-04-24 08:14:26 +02:00
}
@Override
2015-09-30 14:24:40 +02:00
public boolean canExtractItem( final int slotIndex, final ItemStack extractedItem, final EnumFacing side )
2014-04-24 08:14:26 +02:00
{
return slotIndex == 9;
2014-04-24 08:14:26 +02:00
}
@Override
2015-09-30 14:24:40 +02:00
public int[] getAccessibleSlotsBySide( final EnumFacing whichSide )
{
return SIDES;
}
2014-05-08 02:59:05 +02:00
public int getCraftingProgress()
{
2014-12-29 15:13:47 +01:00
return (int) this.progress;
}
@Override
public void getDrops( final World w, final BlockPos pos, final List<ItemStack> drops )
{
2015-06-16 02:44:59 +02:00
super.getDrops( w, pos, drops );
for( int h = 0; h < this.upgrades.getSizeInventory(); h++ )
{
2015-09-30 14:24:40 +02:00
final ItemStack is = this.upgrades.getStackInSlot( h );
if( is != null )
2015-04-29 02:30:53 +02:00
{
drops.add( is );
2015-04-29 02:30:53 +02:00
}
}
}
@Override
2015-09-30 14:24:40 +02:00
public TickingRequest getTickingRequest( final IGridNode node )
{
2014-12-29 15:13:47 +01:00
this.recalculatePlan();
this.updateSleepiness();
return new TickingRequest( 1, 1, !this.isAwake, false );
2014-05-08 02:59:05 +02:00
}
@Override
2015-09-30 14:24:40 +02:00
public TickRateModulation tickingRequest( final IGridNode node, int ticksSinceLastCall )
{
if( this.inv.getStackInSlot( 9 ) != null )
{
2014-12-29 15:13:47 +01:00
this.pushOut( this.inv.getStackInSlot( 9 ) );
2014-09-05 04:57:56 +02:00
// did it eject?
if( this.inv.getStackInSlot( 9 ) == null )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.markDirty();
2015-04-29 02:30:53 +02:00
}
2014-09-05 04:57:56 +02:00
2014-12-29 15:13:47 +01:00
this.ejectHeldItems();
this.updateSleepiness();
this.progress = 0;
return this.isAwake ? TickRateModulation.IDLE : TickRateModulation.SLEEP;
}
if( this.myPlan == null )
{
2014-12-29 15:13:47 +01:00
this.updateSleepiness();
return TickRateModulation.SLEEP;
}
if( this.reboot )
2015-04-29 02:30:53 +02:00
{
ticksSinceLastCall = 1;
2015-04-29 02:30:53 +02:00
}
if( !this.isAwake )
2015-04-29 02:30:53 +02:00
{
return TickRateModulation.SLEEP;
2015-04-29 02:30:53 +02:00
}
2014-12-29 15:13:47 +01:00
this.reboot = false;
2014-07-07 04:04:58 +02:00
int speed = 10;
switch( this.upgrades.getInstalledUpgrades( Upgrades.SPEED ) )
2014-05-09 06:09:42 +02:00
{
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;
2014-05-09 06:09:42 +02:00
}
if( this.progress >= 100 )
{
for( int x = 0; x < this.craftingInv.getSizeInventory(); x++ )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.craftingInv.setInventorySlotContents( x, this.inv.getStackInSlot( x ) );
2015-04-29 02:30:53 +02:00
}
2014-12-29 15:13:47 +01:00
this.progress = 0;
2015-09-30 14:24:40 +02:00
final ItemStack output = this.myPlan.getOutput( this.craftingInv, this.getWorld() );
if( output != null )
{
2015-06-16 02:44:59 +02:00
FMLCommonHandler.instance().firePlayerCraftingEvent( Platform.getPlayer( (WorldServer) this.getWorld() ), output, this.craftingInv );
2014-06-22 09:00:38 +02:00
2014-12-29 15:13:47 +01:00
this.pushOut( output.copy() );
for( int x = 0; x < this.craftingInv.getSizeInventory(); x++ )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.inv.setInventorySlotContents( x, Platform.getContainerItem( this.craftingInv.getStackInSlot( x ) ) );
2015-04-29 02:30:53 +02:00
}
if( this.inv.getStackInSlot( 10 ) == null )
2014-06-27 07:45:10 +02:00
{
2014-12-29 15:13:47 +01:00
this.forcePlan = false;
this.myPlan = null;
2015-06-16 02:44:59 +02:00
this.pushDirection = AEPartLocation.INTERNAL;
2014-06-27 07:45:10 +02:00
}
2014-12-29 15:13:47 +01:00
this.ejectHeldItems();
2014-06-22 09:00:38 +02:00
2014-07-07 04:04:58 +02:00
try
{
final TargetPoint where = new TargetPoint( this.worldObj.provider.getDimension(), this.pos.getX(), this.pos.getY(), this.pos.getZ(), 32 );
2015-09-30 14:24:40 +02:00
final IAEItemStack item = AEItemStack.create( output );
2015-09-30 14:26:54 +02:00
NetworkHandler.instance.sendToAllAround( new PacketAssemblerAnimation( this.pos, (byte) speed, item ), where );
2014-07-07 04:04:58 +02:00
}
2015-09-30 14:24:40 +02:00
catch( final IOException e )
2014-07-07 04:04:58 +02:00
{
// ;P
}
2014-12-29 15:13:47 +01:00
this.markDirty();
this.updateSleepiness();
return this.isAwake ? TickRateModulation.IDLE : TickRateModulation.SLEEP;
}
}
return TickRateModulation.FASTER;
}
2014-06-22 09:00:38 +02:00
private void ejectHeldItems()
{
if( this.inv.getStackInSlot( 9 ) == null )
2014-06-22 09:00:38 +02:00
{
for( int x = 0; x < 9; x++ )
2014-06-22 09:00:38 +02:00
{
2015-09-30 14:24:40 +02:00
final ItemStack is = this.inv.getStackInSlot( x );
if( is != null )
2014-06-22 09:00:38 +02:00
{
if( this.myPlan == null || !this.myPlan.isValidItemForSlot( x, is, this.worldObj ) )
{
2014-12-29 15:13:47 +01:00
this.inv.setInventorySlotContents( 9, is );
this.inv.setInventorySlotContents( x, null );
this.markDirty();
return;
}
2014-06-22 09:00:38 +02:00
}
}
}
}
2015-09-30 14:24:40 +02:00
private int userPower( final int ticksPassed, final int bonusValue, final double acceleratorTax )
2014-05-09 06:09:42 +02:00
{
try
{
return (int) ( this.getProxy().getEnergy().extractAEPower( ticksPassed * bonusValue * acceleratorTax, Actionable.MODULATE, PowerMultiplier.CONFIG ) / acceleratorTax );
2014-05-09 06:09:42 +02:00
}
2015-09-30 14:24:40 +02:00
catch( final GridAccessException e )
2014-05-09 06:09:42 +02:00
{
return 0;
}
}
private void pushOut( ItemStack output )
{
2015-06-16 02:44:59 +02:00
if( this.pushDirection == AEPartLocation.INTERNAL )
{
2015-09-30 14:24:40 +02:00
for( final EnumFacing d : EnumFacing.VALUES )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
output = this.pushTo( output, d );
2015-04-29 02:30:53 +02:00
}
}
else
2015-04-29 02:30:53 +02:00
{
2015-06-16 02:44:59 +02:00
output = this.pushTo( output, this.pushDirection.getFacing() );
2015-04-29 02:30:53 +02:00
}
if( output == null && this.forcePlan )
2014-05-14 04:42:14 +02:00
{
2014-12-29 15:13:47 +01:00
this.forcePlan = false;
this.recalculatePlan();
2014-05-14 04:42:14 +02:00
}
2014-12-29 15:13:47 +01:00
this.inv.setInventorySlotContents( 9, output );
}
2015-09-30 14:24:40 +02:00
private ItemStack pushTo( ItemStack output, final EnumFacing d )
{
if( output == null )
2015-04-29 02:30:53 +02:00
{
return output;
2015-04-29 02:30:53 +02:00
}
2015-09-30 14:26:54 +02:00
final TileEntity te = this.getWorld().getTileEntity( this.pos.offset( d ) );
if( te == null )
2015-04-29 02:30:53 +02:00
{
return output;
2015-04-29 02:30:53 +02:00
}
2015-09-30 14:24:40 +02:00
final InventoryAdaptor adaptor = InventoryAdaptor.getAdaptor( te, d.getOpposite() );
if( adaptor == null )
2015-04-29 02:30:53 +02:00
{
return output;
2015-04-29 02:30:53 +02:00
}
2015-09-30 14:24:40 +02:00
final int size = output.stackSize;
output = adaptor.addItems( output );
2015-09-30 14:24:40 +02:00
final int newSize = output == null ? 0 : output.stackSize;
if( size != newSize )
2015-04-29 02:30:53 +02:00
{
2014-12-29 15:13:47 +01:00
this.markDirty();
2015-04-29 02:30:53 +02:00
}
return output;
}
2014-06-24 05:55:16 +02:00
@MENetworkEventSubscribe
2015-09-30 14:24:40 +02:00
public void onPowerEvent( final MENetworkPowerStatusChange p )
2014-06-24 05:55:16 +02:00
{
2014-12-29 15:13:47 +01:00
this.updatePowerState();
}
private void updatePowerState()
{
boolean newState = false;
try
{
newState = this.getProxy().isActive() && this.getProxy().getEnergy().extractAEPower( 1, Actionable.SIMULATE, PowerMultiplier.CONFIG ) > 0.0001;
}
2015-09-30 14:24:40 +02:00
catch( final GridAccessException ignored )
{
}
if( newState != this.isPowered )
2014-06-24 05:55:16 +02:00
{
2014-12-29 15:13:47 +01:00
this.isPowered = newState;
this.markForUpdate();
2014-06-24 05:55:16 +02:00
}
}
@Override
public boolean isPowered()
{
2014-12-29 15:13:47 +01:00
return this.isPowered;
2014-06-24 05:55:16 +02:00
}
@Override
public boolean isActive()
{
2014-12-29 15:13:47 +01:00
return this.isPowered;
2014-06-24 05:55:16 +02:00
}
2014-04-08 02:43:57 +02:00
}