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>.
|
|
|
|
*/
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
package appeng.tile.storage;
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
|
2015-06-16 02:44:59 +02:00
|
|
|
import io.netty.buffer.ByteBuf;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.util.ArrayList;
|
2014-11-28 04:36:46 +01:00
|
|
|
import java.util.Collections;
|
2013-12-27 23:59:59 +01:00
|
|
|
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;
|
2015-06-16 02:44:59 +02:00
|
|
|
import net.minecraft.server.gui.IUpdatePlayerListBox;
|
|
|
|
import net.minecraft.util.EnumFacing;
|
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;
|
2014-11-28 04:36:46 +01:00
|
|
|
import appeng.api.config.AccessRestriction;
|
|
|
|
import appeng.api.config.Actionable;
|
|
|
|
import appeng.api.config.PowerMultiplier;
|
|
|
|
import appeng.api.config.SecurityPermissions;
|
|
|
|
import appeng.api.config.Settings;
|
|
|
|
import appeng.api.config.SortDir;
|
|
|
|
import appeng.api.config.SortOrder;
|
|
|
|
import appeng.api.config.ViewItems;
|
2014-07-17 06:44:02 +02:00
|
|
|
import appeng.api.implementations.tiles.IColorableTile;
|
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;
|
2014-11-28 04:36:46 +01:00
|
|
|
import appeng.api.networking.IGrid;
|
|
|
|
import appeng.api.networking.IGridNode;
|
2013-12-27 23:59:59 +01:00
|
|
|
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-11-28 04:36:46 +01:00
|
|
|
import appeng.api.networking.security.BaseActionSource;
|
|
|
|
import appeng.api.networking.security.IActionHost;
|
|
|
|
import appeng.api.networking.security.ISecurityGrid;
|
|
|
|
import appeng.api.networking.security.MachineSource;
|
|
|
|
import appeng.api.networking.security.PlayerSource;
|
2014-06-27 07:44:56 +02:00
|
|
|
import appeng.api.networking.storage.IBaseMonitor;
|
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-07-17 06:44:02 +02:00
|
|
|
import appeng.api.util.AEColor;
|
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;
|
2014-08-28 09:39:52 +02:00
|
|
|
import appeng.tile.TileEvent;
|
2013-12-27 23:59:59 +01:00
|
|
|
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;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2015-06-16 02:44:59 +02:00
|
|
|
public class TileChest extends AENetworkPowerTile implements IMEChest, IFluidHandler, ITerminalHost, IPriorityHost, IConfigManagerHost, IColorableTile, IUpdatePlayerListBox
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
2015-01-01 22:13:10 +01:00
|
|
|
static final ChestNoHandler NO_HANDLER = new ChestNoHandler();
|
2015-09-25 23:04:36 +02:00
|
|
|
static final int[] SIDES = { 0 };
|
|
|
|
static final int[] FRONT = { 1 };
|
|
|
|
static final int[] NO_SLOTS = {};
|
2014-09-29 09:54:34 +02:00
|
|
|
final AppEngInternalInventory inv = new AppEngInternalInventory( this, 2 );
|
|
|
|
final BaseActionSource mySrc = new MachineSource( this );
|
|
|
|
final 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;
|
2014-07-17 06:44:02 +02:00
|
|
|
AEColor paintedColor = AEColor.Transparent;
|
2015-04-03 08:54:31 +02:00
|
|
|
boolean isCached = false;
|
|
|
|
private ICellHandler cellHandler;
|
|
|
|
private MEMonitorHandler itemCell;
|
|
|
|
private MEMonitorHandler fluidCell;
|
|
|
|
|
|
|
|
public TileChest()
|
|
|
|
{
|
|
|
|
this.internalMaxPower = PowerMultiplier.CONFIG.multiply( 40 );
|
|
|
|
this.gridProxy.setFlags( GridFlags.REQUIRE_CHANNEL );
|
|
|
|
this.config.registerSetting( Settings.SORT_BY, SortOrder.NAME );
|
|
|
|
this.config.registerSetting( Settings.VIEW_MODE, ViewItems.ALL );
|
|
|
|
this.config.registerSetting( Settings.SORT_DIRECTION, SortDir.ASCENDING );
|
|
|
|
|
|
|
|
this.internalPublicPowerStorage = true;
|
|
|
|
this.internalPowerFlow = AccessRestriction.WRITE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void PowerEvent( PowerEventType x )
|
|
|
|
{
|
|
|
|
if( x == PowerEventType.REQUEST_POWER )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
this.gridProxy.getGrid().postEvent( new MENetworkPowerStorage( this, PowerEventType.REQUEST_POWER ) );
|
|
|
|
}
|
|
|
|
catch( GridAccessException e )
|
|
|
|
{
|
|
|
|
// :(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.recalculateDisplay();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
2014-07-17 06:44:02 +02:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
private void recalculateDisplay()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
int oldState = this.state;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int x = 0; x < this.getCellCount(); x++ )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.state |= ( this.getCellStatus( x ) << ( 3 * x ) );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.isPowered() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.state |= 0x40;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.state &= ~0x40;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
boolean currentActive = this.gridProxy.isActive();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.wasActive != currentActive )
|
2014-02-03 03:30:52 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.wasActive = currentActive;
|
2014-02-03 03:30:52 +01:00
|
|
|
try
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.gridProxy.getGrid().postEvent( new MENetworkCellArrayUpdate() );
|
2014-02-03 03:30:52 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( GridAccessException e )
|
2014-02-03 03:30:52 +01:00
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( oldState != this.state )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.markForUpdate();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public int getCellCount()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IMEInventoryHandler getHandler( StorageChannel channel ) throws ChestNoHandler
|
|
|
|
{
|
|
|
|
if( !this.isCached )
|
|
|
|
{
|
|
|
|
this.itemCell = null;
|
|
|
|
this.fluidCell = null;
|
|
|
|
|
|
|
|
ItemStack is = this.inv.getStackInSlot( 1 );
|
|
|
|
if( is != null )
|
|
|
|
{
|
|
|
|
this.isCached = true;
|
|
|
|
this.cellHandler = AEApi.instance().registries().cell().getHandler( is );
|
|
|
|
if( this.cellHandler != null )
|
|
|
|
{
|
|
|
|
double power = 1.0;
|
|
|
|
|
|
|
|
IMEInventoryHandler<IAEItemStack> itemCell = this.cellHandler.getCellInventory( is, this, StorageChannel.ITEMS );
|
|
|
|
IMEInventoryHandler<IAEFluidStack> fluidCell = this.cellHandler.getCellInventory( is, this, StorageChannel.FLUIDS );
|
|
|
|
|
|
|
|
if( itemCell != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
power += this.cellHandler.cellIdleDrain( is, itemCell );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( fluidCell != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
power += this.cellHandler.cellIdleDrain( is, fluidCell );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
this.gridProxy.setIdlePowerUsage( power );
|
|
|
|
|
|
|
|
this.itemCell = this.wrap( itemCell );
|
|
|
|
this.fluidCell = this.wrap( fluidCell );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
switch( channel )
|
|
|
|
{
|
|
|
|
case FLUIDS:
|
|
|
|
if( this.fluidCell == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
throw NO_HANDLER;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
return this.fluidCell;
|
|
|
|
case ITEMS:
|
|
|
|
if( this.itemCell == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
throw NO_HANDLER;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
return this.itemCell;
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
private <StackType extends IAEStack> MEMonitorHandler<StackType> wrap( IMEInventoryHandler h )
|
|
|
|
{
|
|
|
|
if( h == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return null;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
MEInventoryHandler ih = new MEInventoryHandler( h, h.getChannel() );
|
|
|
|
ih.setPriority( this.priority );
|
|
|
|
|
|
|
|
MEMonitorHandler<StackType> g = new ChestMonitorHandler<StackType>( ih );
|
|
|
|
g.addListener( new ChestNetNotifier( h.getChannel() ), g );
|
|
|
|
|
|
|
|
return g;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCellStatus( int slot )
|
|
|
|
{
|
|
|
|
if( Platform.isClient() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return ( this.state >> ( slot * 3 ) ) & 3;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
ItemStack cell = this.inv.getStackInSlot( 1 );
|
|
|
|
ICellHandler ch = AEApi.instance().registries().cell().getHandler( cell );
|
|
|
|
|
|
|
|
if( ch != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
IMEInventoryHandler handler = this.getHandler( StorageChannel.ITEMS );
|
|
|
|
if( handler instanceof ChestMonitorHandler )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return ch.getStatusForCell( cell, ( (ChestMonitorHandler) handler ).getInternalHandler() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( ChestNoHandler ignored )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
IMEInventoryHandler handler = this.getHandler( StorageChannel.FLUIDS );
|
|
|
|
if( handler instanceof ChestMonitorHandler )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return ch.getStatusForCell( cell, ( (ChestMonitorHandler) handler ).getInternalHandler() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
catch( ChestNoHandler ignored )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isPowered()
|
|
|
|
{
|
|
|
|
if( Platform.isClient() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return ( this.state & 0x40 ) == 0x40;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
boolean gridPowered = this.getAECurrentPower() > 64;
|
|
|
|
|
|
|
|
if( !gridPowered )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
gridPowered = this.gridProxy.getEnergy().isNetworkPowered();
|
|
|
|
}
|
|
|
|
catch( GridAccessException ignored )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.getAECurrentPower() > 1 || gridPowered;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isCellBlinking( int slot )
|
|
|
|
{
|
|
|
|
long now = this.worldObj.getTotalWorldTime();
|
|
|
|
if( now - this.lastStateChange > 8 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
return ( ( this.state >> ( slot * 3 + 2 ) ) & 0x01 ) == 0x01;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected double extractAEPower( double amt, Actionable mode )
|
|
|
|
{
|
|
|
|
double stash = 0.0;
|
|
|
|
|
|
|
|
IEnergyGrid eg;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
eg = this.gridProxy.getEnergy();
|
|
|
|
stash = eg.extractAEPower( amt, mode, PowerMultiplier.ONE );
|
|
|
|
if( stash >= amt )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return stash;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
catch( GridAccessException e )
|
|
|
|
{
|
|
|
|
// no grid :(
|
|
|
|
}
|
|
|
|
|
|
|
|
// local battery!
|
|
|
|
return super.extractAEPower( amt - stash, mode ) + stash;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@TileEvent( TileEventType.TICK )
|
2014-08-28 09:39:52 +02:00
|
|
|
public void Tick_TileChest()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.worldObj.isRemote )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-08-28 09:39:52 +02:00
|
|
|
return;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
double idleUsage = this.gridProxy.getIdlePowerUsage();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-08-28 09:39:52 +02:00
|
|
|
try
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !this.gridProxy.getEnergy().isNetworkPowered() )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
double powerUsed = this.extractAEPower( idleUsage, Actionable.MODULATE, PowerMultiplier.CONFIG ); // drain
|
2015-04-03 08:54:31 +02:00
|
|
|
if( powerUsed + 0.1 >= idleUsage != ( this.state & 0x40 ) > 0 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.recalculateDisplay();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2014-08-28 09:39:52 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( GridAccessException e )
|
2014-08-28 09:39:52 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
double powerUsed = this.extractAEPower( this.gridProxy.getIdlePowerUsage(), Actionable.MODULATE, PowerMultiplier.CONFIG ); // drain
|
2015-04-03 08:54:31 +02:00
|
|
|
if( powerUsed + 0.1 >= idleUsage != ( this.state & 0x40 ) > 0 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.recalculateDisplay();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.inv.getStackInSlot( 0 ) != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.tryToStoreContents();
|
2014-08-28 09:39:52 +02:00
|
|
|
}
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@TileEvent( TileEventType.NETWORK_WRITE )
|
|
|
|
public void writeToStream_TileChest( ByteBuf data )
|
2014-08-28 09:39:52 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.worldObj.getTotalWorldTime() - this.lastStateChange > 8 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.state = 0;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-08-28 09:39:52 +02:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.state &= 0x24924924; // just keep the blinks...
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
for( int x = 0; x < this.getCellCount(); x++ )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.state |= ( this.getCellStatus( x ) << ( 3 * x ) );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.isPowered() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.state |= 0x40;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-08-28 09:39:52 +02:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.state &= ~0x40;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-17 06:44:02 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
data.writeByte( this.state );
|
|
|
|
data.writeByte( this.paintedColor.ordinal() );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
ItemStack is = this.inv.getStackInSlot( 1 );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( is == null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-08-28 09:39:52 +02:00
|
|
|
data.writeInt( 0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
data.writeInt( ( is.getItemDamage() << Platform.DEF_OFFSET ) | Item.getIdFromItem( is.getItem() ) );
|
2014-08-28 09:39:52 +02:00
|
|
|
}
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@TileEvent( TileEventType.NETWORK_READ )
|
|
|
|
public boolean readFromStream_TileChest( ByteBuf data )
|
2014-08-28 09:39:52 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
int oldState = this.state;
|
|
|
|
ItemStack oldType = this.storageType;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.state = data.readByte();
|
|
|
|
AEColor oldPaintedColor = this.paintedColor;
|
|
|
|
this.paintedColor = AEColor.values()[data.readByte()];
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-08-28 09:39:52 +02:00
|
|
|
int item = data.readInt();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( item == 0 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.storageType = null;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-08-28 09:39:52 +02:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.storageType = new ItemStack( Item.getItemById( item & 0xffff ), 1, item >> Platform.DEF_OFFSET );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.lastStateChange = this.worldObj.getTotalWorldTime();
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
return oldPaintedColor != this.paintedColor || ( this.state & 0xDB6DB6DB ) != ( oldState & 0xDB6DB6DB ) || !Platform.isSameItemPrecise( oldType, this.storageType );
|
2014-08-28 09:39:52 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@TileEvent( TileEventType.WORLD_NBT_READ )
|
|
|
|
public void readFromNBT_TileChest( NBTTagCompound data )
|
2014-08-28 09:39:52 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.config.readFromNBT( data );
|
|
|
|
this.priority = data.getInteger( "priority" );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( data.hasKey( "paintedColor" ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.paintedColor = AEColor.values()[data.getByte( "paintedColor" )];
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-08-28 09:39:52 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@TileEvent( TileEventType.WORLD_NBT_WRITE )
|
|
|
|
public void writeToNBT_TileChest( NBTTagCompound data )
|
2014-08-28 09:39:52 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.config.writeToNBT( data );
|
|
|
|
data.setInteger( "priority", this.priority );
|
|
|
|
data.setByte( "paintedColor", (byte) this.paintedColor.ordinal() );
|
2014-08-28 09:39:52 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
@MENetworkEventSubscribe
|
2015-04-03 08:54:31 +02:00
|
|
|
public void powerRender( MENetworkPowerStatusChange c )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.recalculateDisplay();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@MENetworkEventSubscribe
|
2015-04-03 08:54:31 +02:00
|
|
|
public void channelRender( MENetworkChannelsChanged c )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.recalculateDisplay();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IMEMonitor getItemInventory()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.itemCell;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IMEMonitor getFluidInventory()
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
return this.fluidCell;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IInventory getInternalInventory()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.inv;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void setInventorySlotContents( int i, ItemStack itemstack )
|
|
|
|
{
|
|
|
|
this.inv.setInventorySlotContents( i, itemstack );
|
|
|
|
this.tryToStoreContents();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onChangeInventory( IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( slot == 1 )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.itemCell = null;
|
|
|
|
this.fluidCell = null;
|
|
|
|
this.isCached = false; // recalculate the storage cell.
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.gridProxy.getGrid().postEvent( new MENetworkCellArrayUpdate() );
|
2014-07-16 04:18:22 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
IStorageGrid gs = this.gridProxy.getStorage();
|
|
|
|
Platform.postChanges( gs, removed, added, this.mySrc );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( GridAccessException ignored )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// update the neighbors
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.worldObj != null )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-06-16 02:44:59 +02:00
|
|
|
Platform.notifyBlocksOfNeighbors( this.worldObj, pos );
|
2014-12-29 15:13:47 +01:00
|
|
|
this.markForUpdate();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-16 02:44:59 +02:00
|
|
|
public boolean canInsertItem( int slotIndex, ItemStack insertingItem, EnumFacing side )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( slotIndex == 1 )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( AEApi.instance().registries().cell().getCellInventory( insertingItem, this, StorageChannel.ITEMS ) != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-05-25 01:25:22 +02:00
|
|
|
return true;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
if( AEApi.instance().registries().cell().getCellInventory( insertingItem, this, StorageChannel.FLUIDS ) != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-05-25 01:25:22 +02:00
|
|
|
return true;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2014-05-25 01:25:22 +02:00
|
|
|
else
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-05-25 01:25:22 +02:00
|
|
|
try
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
IMEInventory<IAEItemStack> cell = this.getHandler( StorageChannel.ITEMS );
|
|
|
|
IAEItemStack returns = cell.injectItems( AEApi.instance().storage().createItemStack( this.inv.getStackInSlot( 0 ) ), Actionable.SIMULATE, this.mySrc );
|
2015-03-22 11:07:25 +01:00
|
|
|
return returns == null || returns.getStackSize() != insertingItem.stackSize;
|
2014-05-25 01:25:22 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( ChestNoHandler ignored )
|
2014-05-25 01:25:22 +02:00
|
|
|
{
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-16 02:44:59 +02:00
|
|
|
public boolean canExtractItem( int slotIndex, ItemStack extractedItem, EnumFacing side )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
return slotIndex == 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-16 02:44:59 +02:00
|
|
|
public int[] getAccessibleSlotsBySide( EnumFacing side )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-06-16 02:44:59 +02:00
|
|
|
if( EnumFacing.SOUTH == side )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-01 22:13:10 +01:00
|
|
|
return FRONT;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-05-25 01:25:22 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.isPowered() )
|
2014-05-25 01:25:22 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.getHandler( StorageChannel.ITEMS ) != null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-01-01 22:13:10 +01:00
|
|
|
return SIDES;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-05-25 01:25:22 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( ChestNoHandler e )
|
2014-05-25 01:25:22 +02:00
|
|
|
{
|
|
|
|
// nope!
|
|
|
|
}
|
|
|
|
}
|
2015-01-01 22:13:10 +01:00
|
|
|
return NO_SLOTS;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
private void tryToStoreContents()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if( this.getStackInSlot( 0 ) != null )
|
|
|
|
{
|
|
|
|
IMEInventory<IAEItemStack> cell = this.getHandler( StorageChannel.ITEMS );
|
|
|
|
|
|
|
|
IAEItemStack returns = Platform.poweredInsert( this, cell, AEApi.instance().storage().createItemStack( this.inv.getStackInSlot( 0 ) ), this.mySrc );
|
|
|
|
|
|
|
|
if( returns == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.inv.setInventorySlotContents( 0, null );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.inv.setInventorySlotContents( 0, returns.getItemStack() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch( ChestNoHandler ignored )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public List<IMEInventoryHandler> getCellArray( StorageChannel channel )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.gridProxy.isActive() )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-02-03 03:30:52 +01:00
|
|
|
try
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return Collections.singletonList( this.getHandler( channel ) );
|
2014-02-03 03:30:52 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( ChestNoHandler e )
|
2014-02-03 03:30:52 +01:00
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2014-09-29 09:12:06 +02:00
|
|
|
return new ArrayList<IMEInventoryHandler>();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getPriority()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.priority;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void setPriority( int newValue )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
this.priority = newValue;
|
|
|
|
|
|
|
|
this.itemCell = null;
|
|
|
|
this.fluidCell = null;
|
|
|
|
this.isCached = false; // recalculate the storage cell.
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
this.gridProxy.getGrid().postEvent( new MENetworkCellArrayUpdate() );
|
|
|
|
}
|
|
|
|
catch( GridAccessException e )
|
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void blinkCell( int slot )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
long now = this.worldObj.getTotalWorldTime();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( now - this.lastStateChange > 8 )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.state = 0;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-12-29 15:13:47 +01:00
|
|
|
this.lastStateChange = now;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
this.state |= 1 << ( slot * 3 + 2 );
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.recalculateDisplay();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-16 02:44:59 +02:00
|
|
|
public int fill( EnumFacing from, FluidStack resource, boolean doFill )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
double req = resource.amount / 500.0;
|
2014-12-29 15:13:47 +01:00
|
|
|
double available = this.extractAEPower( req, Actionable.SIMULATE, PowerMultiplier.CONFIG );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( available >= req - 0.01 )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
IMEInventoryHandler h = this.getHandler( StorageChannel.FLUIDS );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.extractAEPower( req, Actionable.MODULATE, PowerMultiplier.CONFIG );
|
|
|
|
IAEStack results = h.injectItems( AEFluidStack.create( resource ), doFill ? Actionable.MODULATE : Actionable.SIMULATE, this.mySrc );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( results == null )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2013-12-27 23:59:59 +01:00
|
|
|
return resource.amount;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
return resource.amount - (int) results.getStackSize();
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( ChestNoHandler ignored )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-16 02:44:59 +02:00
|
|
|
public FluidStack drain( EnumFacing from, FluidStack resource, boolean doDrain )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-16 02:44:59 +02:00
|
|
|
public FluidStack drain( EnumFacing from, int maxDrain, boolean doDrain )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-16 02:44:59 +02:00
|
|
|
public boolean canFill( EnumFacing from, Fluid fluid )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
IMEInventoryHandler h = this.getHandler( StorageChannel.FLUIDS );
|
2013-12-27 23:59:59 +01:00
|
|
|
return h.canAccept( AEFluidStack.create( new FluidStack( fluid, 1 ) ) );
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( ChestNoHandler ignored )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-16 02:44:59 +02:00
|
|
|
public boolean canDrain( EnumFacing from, Fluid fluid )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-16 02:44:59 +02:00
|
|
|
public FluidTankInfo[] getTankInfo( EnumFacing from )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
IMEInventoryHandler h = this.getHandler( StorageChannel.FLUIDS );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( h.getChannel() == StorageChannel.FLUIDS )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-05-25 01:25:22 +02:00
|
|
|
return new FluidTankInfo[] { new FluidTankInfo( null, 1 ) }; // eh?
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( ChestNoHandler ignored )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-06-16 02:44:59 +02:00
|
|
|
public IStorageMonitorable getMonitorable( EnumFacing side, BaseActionSource src )
|
2014-01-03 19:28:52 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( Platform.canAccess( this.gridProxy, src ) && side != this.getForward() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-04-18 05:33:48 +02:00
|
|
|
return this;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-04-18 05:33:48 +02:00
|
|
|
return null;
|
2014-01-03 19:28:52 +01:00
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
public ItemStack getStorageType()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.isPowered() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.storageType;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-02-18 18:43:38 +01:00
|
|
|
@Override
|
2014-03-02 09:35:11 +01:00
|
|
|
public IConfigManager getConfigManager()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.config;
|
2014-02-18 18:43:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void updateSetting( IConfigManager manager, Enum settingName, Enum newValue )
|
2014-03-02 09:35:11 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-06-16 02:44:59 +02:00
|
|
|
public boolean openGui( EntityPlayer p, ICellHandler ch, ItemStack cell, EnumFacing side )
|
2014-03-02 09:35:11 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2014-10-01 11:34:27 +02:00
|
|
|
IMEInventoryHandler invHandler = this.getHandler( StorageChannel.ITEMS );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ch != null && invHandler != null )
|
2014-03-02 09:35:11 +01:00
|
|
|
{
|
2014-10-01 11:34:27 +02:00
|
|
|
ch.openChestGui( p, this, ch, invHandler, cell, StorageChannel.ITEMS );
|
2014-03-02 09:35:11 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( ChestNoHandler e )
|
2014-03-02 09:35:11 +01:00
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2014-10-01 11:34:27 +02:00
|
|
|
IMEInventoryHandler invHandler = this.getHandler( StorageChannel.FLUIDS );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ch != null && invHandler != null )
|
2014-03-02 09:35:11 +01:00
|
|
|
{
|
2014-10-01 11:34:27 +02:00
|
|
|
ch.openChestGui( p, this, ch, invHandler, cell, StorageChannel.FLUIDS );
|
2014-03-02 09:35:11 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( ChestNoHandler e )
|
2014-03-02 09:35:11 +01:00
|
|
|
{
|
|
|
|
// :P
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2014-02-18 18:43:38 +01:00
|
|
|
}
|
|
|
|
|
2014-09-28 20:34:00 +02:00
|
|
|
@Override
|
2014-07-17 06:44:02 +02:00
|
|
|
public AEColor getColor()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.paintedColor;
|
2014-07-17 06:44:02 +02:00
|
|
|
}
|
|
|
|
|
2014-07-21 05:45:08 +02:00
|
|
|
@Override
|
2015-06-16 02:44:59 +02:00
|
|
|
public boolean recolourBlock(
|
|
|
|
EnumFacing side,
|
|
|
|
AEColor newPaintedColor,
|
|
|
|
EntityPlayer who )
|
2014-07-17 06:44:02 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.paintedColor == newPaintedColor )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-21 05:45:08 +02:00
|
|
|
return false;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-21 05:45:08 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.paintedColor = newPaintedColor;
|
|
|
|
this.markDirty();
|
|
|
|
this.markForUpdate();
|
2014-07-21 05:45:08 +02:00
|
|
|
return true;
|
2014-07-17 06:44:02 +02:00
|
|
|
}
|
2014-07-28 07:11:34 +02:00
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void saveChanges( IMEInventory cellInventory )
|
2014-07-28 07:11:34 +02:00
|
|
|
{
|
2015-06-16 02:44:59 +02:00
|
|
|
this.worldObj.markChunkDirty( pos, this );
|
2014-07-28 07:11:34 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2015-04-06 00:35:42 +02:00
|
|
|
private static class ChestNoHandler extends Exception
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
|
|
|
private static final long serialVersionUID = 7995805326136526631L;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class ChestNetNotifier<T extends IAEStack<T>> implements IMEMonitorHandlerReceiver<T>
|
|
|
|
{
|
|
|
|
|
|
|
|
final StorageChannel chan;
|
|
|
|
|
|
|
|
public ChestNetNotifier( StorageChannel chan )
|
|
|
|
{
|
|
|
|
this.chan = chan;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isValid( Object verificationToken )
|
|
|
|
{
|
|
|
|
if( this.chan == StorageChannel.ITEMS )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return verificationToken == TileChest.this.itemCell;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.chan == StorageChannel.FLUIDS )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return verificationToken == TileChest.this.fluidCell;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void postChange( IBaseMonitor<T> monitor, Iterable<T> change, BaseActionSource source )
|
|
|
|
{
|
|
|
|
if( source == TileChest.this.mySrc || ( source instanceof PlayerSource && ( (PlayerSource) source ).via == TileChest.this ) )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if( TileChest.this.gridProxy.isActive() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
TileChest.this.gridProxy.getStorage().postAlterationOfStoredItems( this.chan, change, TileChest.this.mySrc );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
catch( GridAccessException e )
|
|
|
|
{
|
|
|
|
// :(
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TileChest.this.blinkCell( 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onListUpdate()
|
|
|
|
{
|
|
|
|
// not used here
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class ChestMonitorHandler<T extends IAEStack> extends MEMonitorHandler<T>
|
|
|
|
{
|
|
|
|
|
|
|
|
public ChestMonitorHandler( IMEInventoryHandler<T> t )
|
|
|
|
{
|
|
|
|
super( t );
|
|
|
|
}
|
|
|
|
|
|
|
|
public IMEInventoryHandler<T> getInternalHandler()
|
|
|
|
{
|
|
|
|
IMEInventoryHandler<T> h = this.getHandler();
|
|
|
|
if( h instanceof MEInventoryHandler )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return (IMEInventoryHandler<T>) ( (MEInventoryHandler) h ).getInternal();
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
return this.getHandler();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public T injectItems( T input, Actionable mode, BaseActionSource src )
|
|
|
|
{
|
|
|
|
if( src.isPlayer() && !this.securityCheck( ( (PlayerSource) src ).player, SecurityPermissions.INJECT ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return input;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
return super.injectItems( input, mode, src );
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean securityCheck( EntityPlayer player, SecurityPermissions requiredPermission )
|
|
|
|
{
|
|
|
|
if( TileChest.this.getTile() instanceof IActionHost && requiredPermission != null )
|
|
|
|
{
|
|
|
|
boolean requirePower = false;
|
|
|
|
|
|
|
|
IGridNode gn = ( (IActionHost) TileChest.this.getTile() ).getActionableNode();
|
|
|
|
if( gn != null )
|
|
|
|
{
|
|
|
|
IGrid g = gn.getGrid();
|
|
|
|
if( g != null )
|
|
|
|
{
|
|
|
|
if( requirePower )
|
|
|
|
{
|
|
|
|
IEnergyGrid eg = g.getCache( IEnergyGrid.class );
|
|
|
|
if( !eg.isNetworkPowered() )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ISecurityGrid sg = g.getCache( ISecurityGrid.class );
|
|
|
|
if( sg.hasPermission( player, requiredPermission ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return true;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public T extractItems( T request, Actionable mode, BaseActionSource src )
|
|
|
|
{
|
|
|
|
if( src.isPlayer() && !this.securityCheck( ( (PlayerSource) src ).player, SecurityPermissions.EXTRACT ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return null;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
return super.extractItems( request, mode, src );
|
|
|
|
}
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|