2013-12-27 23:59:59 +01:00
|
|
|
package appeng.tile.misc;
|
|
|
|
|
2014-03-20 04:28:53 +01:00
|
|
|
import java.util.EnumSet;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2013-12-28 22:07:48 +01:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2014-01-05 09:44:31 +01:00
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-01-23 20:02:48 +01:00
|
|
|
import appeng.api.implementations.tiles.ISegmentedInventory;
|
|
|
|
import appeng.api.implementations.tiles.ITileStorageMonitorable;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.networking.IGridNode;
|
2014-04-18 05:33:48 +02:00
|
|
|
import appeng.api.networking.security.BaseActionSource;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.networking.ticking.IGridTickable;
|
|
|
|
import appeng.api.networking.ticking.TickRateModulation;
|
|
|
|
import appeng.api.networking.ticking.TickingRequest;
|
|
|
|
import appeng.api.storage.IMEMonitor;
|
2014-01-05 09:44:31 +01:00
|
|
|
import appeng.api.storage.IStorageMonitorable;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.storage.data.IAEFluidStack;
|
|
|
|
import appeng.api.storage.data.IAEItemStack;
|
|
|
|
import appeng.api.util.AECableType;
|
|
|
|
import appeng.api.util.DimensionalCoord;
|
2014-01-05 09:44:31 +01:00
|
|
|
import appeng.api.util.IConfigManager;
|
|
|
|
import appeng.api.util.IConfigureableObject;
|
|
|
|
import appeng.helpers.DualityInterface;
|
|
|
|
import appeng.helpers.IInterfaceHost;
|
2013-12-28 22:07:48 +01:00
|
|
|
import appeng.tile.events.AETileEventHandler;
|
|
|
|
import appeng.tile.events.TileEventType;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.tile.grid.AENetworkInvTile;
|
|
|
|
import appeng.tile.inventory.InvOperation;
|
2014-03-20 04:28:53 +01:00
|
|
|
import appeng.util.Platform;
|
2013-12-28 22:07:48 +01:00
|
|
|
import appeng.util.inv.IInventoryDestination;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-01-05 09:44:31 +01:00
|
|
|
public class TileInterface extends AENetworkInvTile implements IGridTickable, ISegmentedInventory, ITileStorageMonitorable, IStorageMonitorable,
|
|
|
|
IInventoryDestination, IInterfaceHost, IConfigureableObject
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
2014-03-20 04:28:53 +01:00
|
|
|
ForgeDirection pointAt = ForgeDirection.UNKNOWN;
|
2014-01-05 09:44:31 +01:00
|
|
|
DualityInterface duality = new DualityInterface( gridProxy, this );
|
2013-12-28 22:07:48 +01:00
|
|
|
|
2014-03-20 04:28:53 +01:00
|
|
|
public void setSide(ForgeDirection axis)
|
|
|
|
{
|
|
|
|
if ( Platform.isClient() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ( pointAt == axis.getOpposite() )
|
|
|
|
pointAt = axis;
|
|
|
|
else if ( pointAt == axis || pointAt == axis.getOpposite() )
|
|
|
|
pointAt = ForgeDirection.UNKNOWN;
|
|
|
|
else if ( pointAt == ForgeDirection.UNKNOWN )
|
|
|
|
pointAt = axis.getOpposite();
|
|
|
|
else
|
|
|
|
pointAt = Platform.rotateAround( pointAt, axis );
|
|
|
|
|
|
|
|
if ( ForgeDirection.UNKNOWN == pointAt )
|
|
|
|
setOrientation( pointAt, pointAt );
|
|
|
|
else
|
|
|
|
setOrientation( pointAt.offsetY != 0 ? ForgeDirection.SOUTH : ForgeDirection.UP, pointAt.getOpposite() );
|
|
|
|
|
|
|
|
gridProxy.setValidSides( EnumSet.complementOf( EnumSet.of( pointAt ) ) );
|
|
|
|
markForUpdate();
|
|
|
|
markDirty();
|
|
|
|
}
|
|
|
|
|
2013-12-28 22:07:48 +01:00
|
|
|
@Override
|
2014-01-05 09:44:31 +01:00
|
|
|
public void gridChanged()
|
2013-12-28 22:07:48 +01:00
|
|
|
{
|
2014-01-05 09:44:31 +01:00
|
|
|
duality.gridChanged();
|
2013-12-28 22:07:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class TileInterfaceHandler extends AETileEventHandler
|
|
|
|
{
|
|
|
|
|
|
|
|
public TileInterfaceHandler() {
|
2014-01-26 07:46:16 +01:00
|
|
|
super( TileEventType.WORLD_NBT );
|
2013-12-28 22:07:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToNBT(NBTTagCompound data)
|
|
|
|
{
|
2014-03-20 04:28:53 +01:00
|
|
|
data.setInteger( "pointAt", pointAt.ordinal() );
|
2014-01-05 09:44:31 +01:00
|
|
|
duality.writeToNBT( data );
|
2013-12-28 22:07:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readFromNBT(NBTTagCompound data)
|
|
|
|
{
|
2014-03-20 04:28:53 +01:00
|
|
|
int val = data.getInteger( "pointAt" );
|
|
|
|
|
|
|
|
if ( val >= 0 && val < ForgeDirection.values().length )
|
|
|
|
pointAt = ForgeDirection.values()[val];
|
|
|
|
else
|
|
|
|
pointAt = ForgeDirection.UNKNOWN;
|
|
|
|
|
2014-01-05 09:44:31 +01:00
|
|
|
duality.readFromNBT( data );
|
2013-12-28 22:07:48 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
public TileInterface() {
|
|
|
|
addNewHandler( new TileInterfaceHandler() );
|
|
|
|
}
|
|
|
|
|
2014-03-20 04:28:53 +01:00
|
|
|
@Override
|
|
|
|
public void onReady()
|
|
|
|
{
|
|
|
|
gridProxy.setValidSides( EnumSet.complementOf( EnumSet.of( pointAt ) ) );
|
|
|
|
super.onReady();
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
2014-01-05 09:44:31 +01:00
|
|
|
public AECableType getCableConnectionType(ForgeDirection dir)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-05 09:44:31 +01:00
|
|
|
return duality.getCableConnectionType( dir );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-05 09:44:31 +01:00
|
|
|
public DimensionalCoord getLocation()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-05 09:44:31 +01:00
|
|
|
return duality.getLocation();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-05 09:44:31 +01:00
|
|
|
public TileEntity getTileEntity()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-05 09:44:31 +01:00
|
|
|
return this;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-05 09:44:31 +01:00
|
|
|
public boolean canInsert(ItemStack stack)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-05 09:44:31 +01:00
|
|
|
return duality.canInsert( stack );
|
2013-12-28 22:07:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-05 09:44:31 +01:00
|
|
|
public IMEMonitor<IAEItemStack> getItemInventory()
|
2013-12-28 22:07:48 +01:00
|
|
|
{
|
2014-01-05 09:44:31 +01:00
|
|
|
return duality.getItemInventory();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-05 09:44:31 +01:00
|
|
|
public IMEMonitor<IAEFluidStack> getFluidInventory()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-05 09:44:31 +01:00
|
|
|
return duality.getFluidInventory();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-01-05 09:44:31 +01:00
|
|
|
@Override
|
|
|
|
public IInventory getInventoryByName(String name)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-05 09:44:31 +01:00
|
|
|
return duality.getInventoryByName( name );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-01-05 09:44:31 +01:00
|
|
|
@Override
|
|
|
|
public TickingRequest getTickingRequest(IGridNode node)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-05 09:44:31 +01:00
|
|
|
return duality.getTickingRequest( node );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-01-05 09:44:31 +01:00
|
|
|
@Override
|
|
|
|
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-05 09:44:31 +01:00
|
|
|
return duality.tickingRequest( node, TicksSinceLastCall );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-05 09:44:31 +01:00
|
|
|
public IInventory getInternalInventory()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-05 09:44:31 +01:00
|
|
|
return duality.getInternalInventory();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-01-31 02:23:12 +01:00
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public void markDirty()
|
2014-01-31 02:23:12 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
duality.markDirty();
|
2014-01-31 02:23:12 +01:00
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
2014-01-05 09:44:31 +01:00
|
|
|
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-05 09:44:31 +01:00
|
|
|
duality.onChangeInventory( inv, slot, mc, removed, added );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@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
|
|
|
return duality.getAccessibleSlotsFromSide( side.ordinal() );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-01-05 09:44:31 +01:00
|
|
|
public DualityInterface getInterfaceDuality()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-05 09:44:31 +01:00
|
|
|
return duality;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-04-18 05:33:48 +02:00
|
|
|
public IStorageMonitorable getMonitorable(ForgeDirection side, BaseActionSource src)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-04-18 05:33:48 +02:00
|
|
|
return duality.getMonitorable( side, src, this );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2013-12-30 06:58:51 +01:00
|
|
|
@Override
|
2014-01-05 09:44:31 +01:00
|
|
|
public IConfigManager getConfigManager()
|
2013-12-30 06:58:51 +01:00
|
|
|
{
|
2014-03-05 08:27:42 +01:00
|
|
|
return duality.getConfigManager();
|
2013-12-30 06:58:51 +01:00
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|