2013-12-27 23:59:59 +01:00
|
|
|
package appeng.tile.storage;
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
|
2014-03-02 09:35:11 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.inventory.IInventory;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraft.item.Item;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraftforge.fluids.Fluid;
|
|
|
|
import net.minecraftforge.fluids.FluidStack;
|
|
|
|
import net.minecraftforge.fluids.FluidTankInfo;
|
|
|
|
import net.minecraftforge.fluids.IFluidHandler;
|
|
|
|
import appeng.api.AEApi;
|
|
|
|
import appeng.api.config.AccessRestriction;
|
|
|
|
import appeng.api.config.Actionable;
|
|
|
|
import appeng.api.config.PowerMultiplier;
|
2014-02-18 18:43:38 +01:00
|
|
|
import appeng.api.config.Settings;
|
|
|
|
import appeng.api.config.SortDir;
|
|
|
|
import appeng.api.config.SortOrder;
|
|
|
|
import appeng.api.config.ViewItems;
|
2014-01-23 20:02:48 +01:00
|
|
|
import appeng.api.implementations.tiles.IMEChest;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.networking.GridFlags;
|
|
|
|
import appeng.api.networking.energy.IEnergyGrid;
|
|
|
|
import appeng.api.networking.events.MENetworkCellArrayUpdate;
|
|
|
|
import appeng.api.networking.events.MENetworkChannelsChanged;
|
|
|
|
import appeng.api.networking.events.MENetworkEventSubscribe;
|
|
|
|
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
|
|
|
import appeng.api.networking.events.MENetworkPowerStorage;
|
|
|
|
import appeng.api.networking.events.MENetworkPowerStorage.PowerEventType;
|
2014-01-05 09:43:49 +01:00
|
|
|
import appeng.api.networking.security.BaseActionSource;
|
|
|
|
import appeng.api.networking.security.MachineSource;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.api.networking.security.PlayerSource;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.networking.storage.IStorageGrid;
|
|
|
|
import appeng.api.storage.ICellHandler;
|
|
|
|
import appeng.api.storage.IMEInventory;
|
|
|
|
import appeng.api.storage.IMEInventoryHandler;
|
|
|
|
import appeng.api.storage.IMEMonitor;
|
2014-02-12 17:35:42 +01:00
|
|
|
import appeng.api.storage.IMEMonitorHandlerReceiver;
|
2014-01-03 19:28:52 +01:00
|
|
|
import appeng.api.storage.IStorageMonitorable;
|
2014-02-18 18:43:38 +01:00
|
|
|
import appeng.api.storage.ITerminalHost;
|
2014-01-01 22:46:16 +01:00
|
|
|
import appeng.api.storage.MEMonitorHandler;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.storage.StorageChannel;
|
2014-01-24 17:32:31 +01:00
|
|
|
import appeng.api.storage.data.IAEFluidStack;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.storage.data.IAEItemStack;
|
|
|
|
import appeng.api.storage.data.IAEStack;
|
2014-02-18 18:43:38 +01:00
|
|
|
import appeng.api.util.IConfigManager;
|
2014-01-26 07:46:16 +01:00
|
|
|
import appeng.helpers.IPriorityHost;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.me.GridAccessException;
|
|
|
|
import appeng.me.storage.MEInventoryHandler;
|
|
|
|
import appeng.tile.events.AETileEventHandler;
|
|
|
|
import appeng.tile.events.TileEventType;
|
|
|
|
import appeng.tile.grid.AENetworkPowerTile;
|
|
|
|
import appeng.tile.inventory.AppEngInternalInventory;
|
|
|
|
import appeng.tile.inventory.InvOperation;
|
2014-02-18 18:43:38 +01:00
|
|
|
import appeng.util.ConfigManager;
|
|
|
|
import appeng.util.IConfigManagerHost;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.util.Platform;
|
|
|
|
import appeng.util.item.AEFluidStack;
|
|
|
|
|
2014-02-18 18:43:38 +01:00
|
|
|
public class TileChest extends AENetworkPowerTile implements IMEChest, IFluidHandler, ITerminalHost, IPriorityHost, IConfigManagerHost
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
2014-03-02 09:35:11 +01:00
|
|
|
static private class ChestNoHandler extends Exception
|
|
|
|
{
|
|
|
|
|
|
|
|
private static final long serialVersionUID = 7995805326136526631L;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static final ChestNoHandler noHandler = new ChestNoHandler();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
static final int sides[] = new int[] { 0 };
|
|
|
|
static final int front[] = new int[] { 1 };
|
|
|
|
|
|
|
|
AppEngInternalInventory inv = new AppEngInternalInventory( this, 2 );
|
2014-01-05 09:43:49 +01:00
|
|
|
BaseActionSource mySrc = new MachineSource( this );
|
2014-03-02 09:35:11 +01:00
|
|
|
IConfigManager config = new ConfigManager( this );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
ItemStack storageType;
|
|
|
|
long lastStateChange = 0;
|
|
|
|
int priority = 0;
|
|
|
|
int state = 0;
|
2014-02-03 03:30:52 +01:00
|
|
|
boolean wasActive = false;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
private void recalculateDisplay()
|
|
|
|
{
|
|
|
|
int oldState = state;
|
|
|
|
|
|
|
|
for (int x = 0; x < getCellCount(); x++)
|
|
|
|
state |= (getCellStatus( x ) << (3 * x));
|
|
|
|
|
2014-02-03 03:30:52 +01:00
|
|
|
if ( isPowered() )
|
2013-12-27 23:59:59 +01:00
|
|
|
state |= 0x40;
|
|
|
|
else
|
|
|
|
state &= ~0x40;
|
|
|
|
|
2014-02-03 03:30:52 +01:00
|
|
|
boolean currentActive = gridProxy.isActive();
|
|
|
|
if ( wasActive != currentActive )
|
|
|
|
{
|
|
|
|
wasActive = currentActive;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
gridProxy.getGrid().postEvent( new MENetworkCellArrayUpdate() );
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( oldState != state )
|
|
|
|
markForUpdate();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void PowerEvent(PowerEventType x)
|
|
|
|
{
|
|
|
|
if ( x == PowerEventType.REQUEST_POWER )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
gridProxy.getGrid().postEvent( new MENetworkPowerStorage( this, PowerEventType.REQUEST_POWER ) );
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
// :(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
recalculateDisplay();
|
|
|
|
}
|
|
|
|
|
|
|
|
private class invManger extends AETileEventHandler
|
|
|
|
{
|
|
|
|
|
|
|
|
public invManger() {
|
2014-01-26 07:46:16 +01:00
|
|
|
super( TileEventType.TICK, TileEventType.NETWORK, TileEventType.WORLD_NBT );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void Tick()
|
|
|
|
{
|
2014-02-06 06:31:19 +01:00
|
|
|
if ( worldObj.isRemote )
|
2013-12-27 23:59:59 +01:00
|
|
|
return;
|
|
|
|
|
|
|
|
double idleUsage = gridProxy.getIdlePowerUsage();
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if ( !gridProxy.getEnergy().isNetworkPowered() )
|
|
|
|
{
|
|
|
|
double powerUsed = extractAEPower( idleUsage, Actionable.MODULATE, PowerMultiplier.CONFIG ); // drain
|
|
|
|
if ( powerUsed + 0.1 >= idleUsage != (state & 0x40) > 0 )
|
|
|
|
recalculateDisplay();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
double powerUsed = extractAEPower( gridProxy.getIdlePowerUsage(), Actionable.MODULATE, PowerMultiplier.CONFIG ); // drain
|
|
|
|
if ( powerUsed + 0.1 >= idleUsage != (state & 0x40) > 0 )
|
|
|
|
recalculateDisplay();
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( inv.getStackInSlot( 0 ) != null )
|
|
|
|
{
|
|
|
|
tryToStoreContents();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public void writeToStream(ByteBuf data) throws IOException
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
if ( worldObj.getTotalWorldTime() - lastStateChange > 8 )
|
|
|
|
state = 0;
|
|
|
|
else
|
|
|
|
state &= 0x24924924; // just keep the blinks...
|
|
|
|
|
|
|
|
for (int x = 0; x < getCellCount(); x++)
|
|
|
|
state |= (getCellStatus( x ) << (3 * x));
|
|
|
|
|
2014-02-03 03:30:52 +01:00
|
|
|
if ( isPowered() )
|
2013-12-27 23:59:59 +01:00
|
|
|
state |= 0x40;
|
|
|
|
else
|
|
|
|
state &= ~0x40;
|
|
|
|
|
|
|
|
data.writeByte( state );
|
|
|
|
ItemStack is = inv.getStackInSlot( 1 );
|
|
|
|
|
|
|
|
if ( is == null )
|
|
|
|
{
|
|
|
|
data.writeInt( 0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
data.writeInt( (is.getItemDamage() << Platform.DEF_OFFSET) | Item.getIdFromItem( is.getItem() ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public boolean readFromStream(ByteBuf data) throws IOException
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
int oldState = state;
|
|
|
|
ItemStack oldType = storageType;
|
|
|
|
|
|
|
|
state = data.readByte();
|
|
|
|
|
|
|
|
int item = data.readInt();
|
|
|
|
|
|
|
|
if ( item == 0 )
|
|
|
|
storageType = null;
|
|
|
|
else
|
2014-02-09 02:34:52 +01:00
|
|
|
storageType = new ItemStack( Item.getItemById( item & 0xffff ), 1, item >> Platform.DEF_OFFSET );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
lastStateChange = worldObj.getTotalWorldTime();
|
|
|
|
|
|
|
|
return (state & 0xDB6DB6DB) != (oldState & 0xDB6DB6DB) || oldType != storageType;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readFromNBT(NBTTagCompound data)
|
|
|
|
{
|
2014-03-02 09:35:11 +01:00
|
|
|
config.readFromNBT( data );
|
2013-12-27 23:59:59 +01:00
|
|
|
priority = data.getInteger( "priority" );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToNBT(NBTTagCompound data)
|
|
|
|
{
|
2014-03-02 09:35:11 +01:00
|
|
|
config.writeToNBT( data );
|
2013-12-27 23:59:59 +01:00
|
|
|
data.setInteger( "priority", priority );
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
@MENetworkEventSubscribe
|
|
|
|
public void powerRender(MENetworkPowerStatusChange c)
|
|
|
|
{
|
|
|
|
recalculateDisplay();
|
|
|
|
}
|
|
|
|
|
|
|
|
@MENetworkEventSubscribe
|
|
|
|
public void channelRender(MENetworkChannelsChanged c)
|
|
|
|
{
|
|
|
|
recalculateDisplay();
|
|
|
|
}
|
|
|
|
|
|
|
|
public TileChest() {
|
2014-03-10 03:11:29 +01:00
|
|
|
internalMaxPower = PowerMultiplier.CONFIG.multiply( 40 );
|
2014-01-31 22:12:15 +01:00
|
|
|
gridProxy.setFlags( GridFlags.REQUIRE_CHANNEL );
|
2013-12-27 23:59:59 +01:00
|
|
|
addNewHandler( new invManger() );
|
2014-03-02 09:35:11 +01:00
|
|
|
config.registerSetting( Settings.SORT_BY, SortOrder.NAME );
|
|
|
|
config.registerSetting( Settings.VIEW_MODE, ViewItems.ALL );
|
|
|
|
config.registerSetting( Settings.SORT_DIRECTION, SortDir.ASCENDING );
|
2014-02-18 18:43:38 +01:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
internalPublicPowerStorage = true;
|
|
|
|
internalPowerFlow = AccessRestriction.WRITE;
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean isCached = false;
|
|
|
|
|
|
|
|
private ICellHandler cellHandler;
|
2014-01-01 22:46:16 +01:00
|
|
|
private MEMonitorHandler icell;
|
|
|
|
private MEMonitorHandler fcell;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public IMEMonitor getItemInventory()
|
|
|
|
{
|
|
|
|
return icell;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IMEMonitor getFluidInventory()
|
|
|
|
{
|
|
|
|
return fcell;
|
|
|
|
}
|
|
|
|
|
2014-02-12 17:35:42 +01:00
|
|
|
class ChestNetNotifier<T extends IAEStack<T>> implements IMEMonitorHandlerReceiver<T>
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
final StorageChannel chan;
|
|
|
|
|
|
|
|
public ChestNetNotifier(StorageChannel chan) {
|
|
|
|
this.chan = chan;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-05 09:43:49 +01:00
|
|
|
public void postChange(IMEMonitor<T> monitor, T change, BaseActionSource source)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
if ( source == mySrc || (source instanceof PlayerSource && ((PlayerSource) source).via == TileChest.this) )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
try
|
|
|
|
{
|
2014-02-03 03:30:52 +01:00
|
|
|
if ( gridProxy.isActive() )
|
|
|
|
gridProxy.getStorage().postAlterationOfStoredItems( chan, change, mySrc );
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
// :(
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2014-01-20 17:41:37 +01:00
|
|
|
|
|
|
|
blinkCell( 0 );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isValid(Object verificationToken)
|
|
|
|
{
|
|
|
|
if ( chan == StorageChannel.ITEMS )
|
|
|
|
return verificationToken == icell;
|
|
|
|
if ( chan == StorageChannel.FLUIDS )
|
|
|
|
return verificationToken == fcell;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-28 05:31:06 +01:00
|
|
|
@Override
|
|
|
|
public void onListUpdate()
|
|
|
|
{
|
|
|
|
// not used here
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
};
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
class ChestMonitorHandler<T extends IAEStack> extends MEMonitorHandler<T>
|
|
|
|
{
|
|
|
|
|
|
|
|
public ChestMonitorHandler(IMEInventoryHandler<T> t) {
|
|
|
|
super( t );
|
|
|
|
}
|
|
|
|
|
|
|
|
public IMEInventoryHandler<T> getInternalHandler()
|
|
|
|
{
|
|
|
|
IMEInventoryHandler<T> h = getHandler();
|
|
|
|
if ( h instanceof MEInventoryHandler )
|
|
|
|
return (IMEInventoryHandler<T>) ((MEInventoryHandler) h).getInternal();
|
|
|
|
return this.getHandler();
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2014-01-01 22:46:16 +01:00
|
|
|
private <StackType extends IAEStack> MEMonitorHandler<StackType> wrap(IMEInventoryHandler h)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
if ( h == null )
|
|
|
|
return null;
|
|
|
|
|
2014-02-21 21:36:40 +01:00
|
|
|
MEInventoryHandler ih = new MEInventoryHandler( h, h.getChannel().type );
|
2013-12-27 23:59:59 +01:00
|
|
|
ih.myPriority = priority;
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
MEMonitorHandler<StackType> g = new ChestMonitorHandler<StackType>( ih );
|
2013-12-27 23:59:59 +01:00
|
|
|
g.addListener( new ChestNetNotifier( h.getChannel() ), g );
|
|
|
|
|
|
|
|
return g;
|
|
|
|
}
|
|
|
|
|
2014-03-02 09:35:11 +01:00
|
|
|
public IMEInventoryHandler getHandler(StorageChannel channel) throws ChestNoHandler
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
if ( !isCached )
|
|
|
|
{
|
2014-03-13 19:26:55 +01:00
|
|
|
icell = null;
|
|
|
|
fcell = null;
|
2014-03-14 03:59:37 +01:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
ItemStack is = inv.getStackInSlot( 1 );
|
|
|
|
if ( is != null )
|
|
|
|
{
|
|
|
|
isCached = true;
|
2014-03-28 01:33:35 +01:00
|
|
|
cellHandler = AEApi.instance().registries().cell().getHandler( is );
|
2014-03-13 19:26:55 +01:00
|
|
|
if ( cellHandler != null )
|
|
|
|
{
|
|
|
|
double power = 1.0;
|
2014-03-14 03:59:37 +01:00
|
|
|
|
2014-03-13 19:26:55 +01:00
|
|
|
IMEInventoryHandler<IAEItemStack> itemCell = cellHandler.getCellInventory( is, StorageChannel.ITEMS );
|
|
|
|
IMEInventoryHandler<IAEFluidStack> fluidCell = cellHandler.getCellInventory( is, StorageChannel.FLUIDS );
|
2014-03-14 03:59:37 +01:00
|
|
|
|
2014-03-13 19:26:55 +01:00
|
|
|
if ( itemCell != null )
|
|
|
|
power += cellHandler.cellIdleDrain( is, itemCell );
|
|
|
|
else if ( fluidCell != null )
|
|
|
|
power += cellHandler.cellIdleDrain( is, fluidCell );
|
2014-03-14 03:59:37 +01:00
|
|
|
|
2014-03-13 19:26:55 +01:00
|
|
|
gridProxy.setIdlePowerUsage( power );
|
2014-03-14 03:59:37 +01:00
|
|
|
|
2014-03-13 19:26:55 +01:00
|
|
|
icell = wrap( itemCell );
|
|
|
|
fcell = wrap( fluidCell );
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (channel)
|
|
|
|
{
|
|
|
|
case FLUIDS:
|
|
|
|
if ( fcell == null )
|
|
|
|
throw noHandler;
|
|
|
|
return fcell;
|
|
|
|
case ITEMS:
|
|
|
|
if ( icell == null )
|
|
|
|
throw noHandler;
|
|
|
|
return icell;
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IInventory getInternalInventory()
|
|
|
|
{
|
|
|
|
return inv;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added)
|
|
|
|
{
|
|
|
|
if ( slot == 1 )
|
|
|
|
{
|
|
|
|
icell = null;
|
|
|
|
fcell = null;
|
|
|
|
isCached = false; // recalculate the storage cell.
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
IStorageGrid gs = gridProxy.getStorage();
|
2014-01-05 09:43:49 +01:00
|
|
|
Platform.postChanges( gs, removed, added, mySrc );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
gridProxy.getGrid().postEvent( new MENetworkCellArrayUpdate() );
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// update the neighbors
|
|
|
|
if ( worldObj != null )
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
worldObj.notifyBlocksOfNeighborChange( xCoord, yCoord, zCoord, Platform.air );
|
2013-12-27 23:59:59 +01:00
|
|
|
markForUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setInventorySlotContents(int i, ItemStack itemstack)
|
|
|
|
{
|
|
|
|
inv.setInventorySlotContents( i, itemstack );
|
|
|
|
tryToStoreContents();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void tryToStoreContents()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if ( getStackInSlot( 0 ) != null )
|
|
|
|
{
|
|
|
|
IMEInventory<IAEItemStack> cell = getHandler( StorageChannel.ITEMS );
|
|
|
|
|
2014-01-05 09:43:49 +01:00
|
|
|
IAEItemStack returns = Platform.poweredInsert( this, cell, AEApi.instance().storage().createItemStack( inv.getStackInSlot( 0 ) ), mySrc );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
if ( returns == null )
|
|
|
|
inv.setInventorySlotContents( 0, null );
|
|
|
|
else
|
|
|
|
inv.setInventorySlotContents( 0, returns.getItemStack() );
|
|
|
|
}
|
|
|
|
}
|
2014-03-02 09:35:11 +01:00
|
|
|
catch (ChestNoHandler t)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canExtractItem(int i, ItemStack itemstack, int j)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canInsertItem(int i, ItemStack itemstack, int j)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
IMEInventory<IAEItemStack> cell = getHandler( StorageChannel.ITEMS );
|
2014-01-20 17:41:37 +01:00
|
|
|
IAEItemStack returns = cell.injectItems( AEApi.instance().storage().createItemStack( inv.getStackInSlot( 0 ) ), Actionable.SIMULATE, mySrc );
|
2013-12-27 23:59:59 +01:00
|
|
|
return returns == null || returns.getStackSize() != itemstack.stackSize;
|
|
|
|
}
|
2014-03-02 09:35:11 +01:00
|
|
|
catch (ChestNoHandler t)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-03-14 03:59:37 +01:00
|
|
|
public int[] getAccessibleSlotsBySide(ForgeDirection side)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-03-14 03:59:37 +01:00
|
|
|
if ( side == getForward() )
|
2013-12-27 23:59:59 +01:00
|
|
|
return front;
|
|
|
|
return sides;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public List<IMEInventoryHandler> getCellArray(StorageChannel channel)
|
|
|
|
{
|
2014-02-03 03:30:52 +01:00
|
|
|
if ( gridProxy.isActive() )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-02-03 03:30:52 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
return Arrays.asList( new IMEInventoryHandler[] { getHandler( channel ) } );
|
|
|
|
}
|
2014-03-02 09:35:11 +01:00
|
|
|
catch (ChestNoHandler e)
|
2014-02-03 03:30:52 +01:00
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2014-02-03 03:30:52 +01:00
|
|
|
return new ArrayList();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getPriority()
|
|
|
|
{
|
|
|
|
return priority;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCellCount()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void blinkCell(int slot)
|
|
|
|
{
|
|
|
|
long now = worldObj.getTotalWorldTime();
|
|
|
|
if ( now - lastStateChange > 8 )
|
|
|
|
state = 0;
|
|
|
|
lastStateChange = now;
|
|
|
|
|
|
|
|
state |= 1 << (slot * 3 + 2);
|
2014-01-20 17:41:37 +01:00
|
|
|
|
|
|
|
recalculateDisplay();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isCellBlinking(int slot)
|
|
|
|
{
|
|
|
|
long now = worldObj.getTotalWorldTime();
|
|
|
|
if ( now - lastStateChange > 8 )
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return ((state >> (slot * 3 + 2)) & 0x01) == 0x01;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCellStatus(int slot)
|
|
|
|
{
|
|
|
|
if ( Platform.isClient() )
|
|
|
|
return (state >> (slot * 3)) & 3;
|
|
|
|
|
|
|
|
ItemStack cell = inv.getStackInSlot( 1 );
|
2014-03-28 01:33:35 +01:00
|
|
|
ICellHandler ch = AEApi.instance().registries().cell().getHandler( cell );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
if ( ch != null )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
IMEInventoryHandler handler = getHandler( StorageChannel.ITEMS );
|
2014-01-20 17:41:37 +01:00
|
|
|
if ( ch != null && handler instanceof ChestMonitorHandler )
|
|
|
|
return ch.getStatusForCell( cell, ((ChestMonitorHandler) handler).getInternalHandler() );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2014-03-02 09:35:11 +01:00
|
|
|
catch (ChestNoHandler e)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
IMEInventoryHandler handler = getHandler( StorageChannel.FLUIDS );
|
2014-01-20 17:41:37 +01:00
|
|
|
if ( ch != null && handler instanceof ChestMonitorHandler )
|
|
|
|
return ch.getStatusForCell( cell, ((ChestMonitorHandler) handler).getInternalHandler() );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2014-03-02 09:35:11 +01:00
|
|
|
catch (ChestNoHandler e)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
|
|
|
|
{
|
|
|
|
double req = resource.amount / 500.0;
|
|
|
|
double available = extractAEPower( req, Actionable.SIMULATE, PowerMultiplier.CONFIG );
|
|
|
|
if ( available >= req - 0.01 )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
IMEInventoryHandler h = getHandler( StorageChannel.FLUIDS );
|
|
|
|
|
|
|
|
extractAEPower( req, Actionable.MODULATE, PowerMultiplier.CONFIG );
|
2014-01-20 17:41:37 +01:00
|
|
|
IAEStack results = h.injectItems( AEFluidStack.create( resource ), doFill ? Actionable.MODULATE : Actionable.SIMULATE, mySrc );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
if ( results == null )
|
|
|
|
return resource.amount;
|
|
|
|
|
|
|
|
return resource.amount - (int) results.getStackSize();
|
|
|
|
}
|
2014-03-02 09:35:11 +01:00
|
|
|
catch (ChestNoHandler e)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
|
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canFill(ForgeDirection from, Fluid fluid)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
IMEInventoryHandler h = getHandler( StorageChannel.FLUIDS );
|
|
|
|
return h.canAccept( AEFluidStack.create( new FluidStack( fluid, 1 ) ) );
|
|
|
|
}
|
2014-03-02 09:35:11 +01:00
|
|
|
catch (ChestNoHandler e)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canDrain(ForgeDirection from, Fluid fluid)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public FluidTankInfo[] getTankInfo(ForgeDirection from)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
IMEInventoryHandler h = getHandler( StorageChannel.FLUIDS );
|
|
|
|
if ( h.getChannel() == StorageChannel.FLUIDS )
|
|
|
|
return new FluidTankInfo[] { new FluidTankInfo( null ) }; // eh?
|
|
|
|
}
|
2014-03-02 09:35:11 +01:00
|
|
|
catch (ChestNoHandler e)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected double extractAEPower(double amt, Actionable mode)
|
|
|
|
{
|
|
|
|
double stash = 0.0;
|
|
|
|
|
|
|
|
IEnergyGrid eg;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
eg = gridProxy.getEnergy();
|
|
|
|
stash = eg.extractAEPower( amt, mode, PowerMultiplier.ONE );
|
|
|
|
if ( stash >= amt )
|
|
|
|
return stash;
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
// no grid :(
|
|
|
|
}
|
|
|
|
|
|
|
|
// local battery!
|
|
|
|
return super.extractAEPower( amt - stash, mode ) + stash;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isPowered()
|
|
|
|
{
|
|
|
|
if ( Platform.isClient() )
|
|
|
|
return (state & 0x40) == 0x40;
|
|
|
|
|
|
|
|
boolean gridPowered = getAECurrentPower() > 64;
|
|
|
|
|
|
|
|
if ( !gridPowered )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
gridPowered = gridProxy.getEnergy().isNetworkPowered();
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.getAECurrentPower() > 1 || gridPowered;
|
|
|
|
}
|
|
|
|
|
2014-01-03 19:28:52 +01:00
|
|
|
@Override
|
2014-04-18 05:33:48 +02:00
|
|
|
public IStorageMonitorable getMonitorable(ForgeDirection side, BaseActionSource src)
|
2014-01-03 19:28:52 +01:00
|
|
|
{
|
2014-04-18 05:33:48 +02:00
|
|
|
if ( Platform.canAccess( gridProxy, src ) )
|
|
|
|
return this;
|
|
|
|
return null;
|
2014-01-03 19:28:52 +01:00
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
public ItemStack getStorageType()
|
|
|
|
{
|
|
|
|
if ( isPowered() )
|
|
|
|
return storageType;
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-01-26 07:46:16 +01:00
|
|
|
@Override
|
|
|
|
public void setPriority(int newValue)
|
|
|
|
{
|
|
|
|
priority = newValue;
|
|
|
|
|
|
|
|
icell = null;
|
|
|
|
fcell = null;
|
|
|
|
isCached = false; // recalculate the storage cell.
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
gridProxy.getGrid().postEvent( new MENetworkCellArrayUpdate() );
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-18 18:43:38 +01:00
|
|
|
@Override
|
2014-03-02 09:35:11 +01:00
|
|
|
public IConfigManager getConfigManager()
|
|
|
|
{
|
2014-02-18 18:43:38 +01:00
|
|
|
return config;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-03-02 09:35:11 +01:00
|
|
|
public void updateSetting(IConfigManager manager, Enum settingName, Enum newValue)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean openGui(EntityPlayer p, ICellHandler ch, ItemStack cell, int side)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
IMEInventoryHandler ih = this.getHandler( StorageChannel.ITEMS );
|
|
|
|
if ( ch != null && ih != null )
|
|
|
|
{
|
|
|
|
IMEInventoryHandler mine = ih;
|
|
|
|
ch.openChestGui( p, this, ch, mine, cell, StorageChannel.ITEMS );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
catch (ChestNoHandler e)
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
IMEInventoryHandler fh = this.getHandler( StorageChannel.FLUIDS );
|
|
|
|
if ( ch != null && fh != null )
|
|
|
|
{
|
|
|
|
IMEInventoryHandler mine = fh;
|
|
|
|
ch.openChestGui( p, this, ch, mine, cell, StorageChannel.FLUIDS );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (ChestNoHandler e)
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2014-02-18 18:43:38 +01:00
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|