Applied-Energistics-2-tiler.../tile/misc/TileInterface.java

230 lines
5.6 KiB
Java
Raw Normal View History

package appeng.tile.misc;
2014-03-20 04:28:53 +01:00
import java.util.EnumSet;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
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;
import appeng.api.networking.IGridNode;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.networking.crafting.ICraftingProviderHelper;
import appeng.api.networking.security.BaseActionSource;
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;
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;
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;
2014-01-05 09:44:31 +01:00
public class TileInterface extends AENetworkInvTile implements IGridTickable, ISegmentedInventory, ITileStorageMonitorable, IStorageMonitorable,
IInventoryDestination, IInterfaceHost, IConfigureableObject
{
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();
}
@Override
2014-01-05 09:44:31 +01:00
public AECableType getCableConnectionType(ForgeDirection dir)
{
2014-01-05 09:44:31 +01:00
return duality.getCableConnectionType( dir );
}
@Override
2014-01-05 09:44:31 +01:00
public DimensionalCoord getLocation()
{
2014-01-05 09:44:31 +01:00
return duality.getLocation();
}
@Override
2014-01-05 09:44:31 +01:00
public TileEntity getTileEntity()
{
2014-01-05 09:44:31 +01:00
return this;
}
@Override
2014-01-05 09:44:31 +01:00
public boolean canInsert(ItemStack stack)
{
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();
}
@Override
2014-01-05 09:44:31 +01:00
public IMEMonitor<IAEFluidStack> getFluidInventory()
{
2014-01-05 09:44:31 +01:00
return duality.getFluidInventory();
}
2014-01-05 09:44:31 +01:00
@Override
public IInventory getInventoryByName(String name)
{
2014-01-05 09:44:31 +01:00
return duality.getInventoryByName( name );
}
2014-01-05 09:44:31 +01:00
@Override
public TickingRequest getTickingRequest(IGridNode node)
{
2014-01-05 09:44:31 +01:00
return duality.getTickingRequest( node );
}
2014-01-05 09:44:31 +01:00
@Override
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
{
2014-01-05 09:44:31 +01:00
return duality.tickingRequest( node, TicksSinceLastCall );
}
@Override
2014-01-05 09:44:31 +01:00
public IInventory getInternalInventory()
{
2014-01-05 09:44:31 +01:00
return duality.getInternalInventory();
}
@Override
2014-02-09 02:34:52 +01:00
public void markDirty()
{
2014-02-09 02:34:52 +01:00
duality.markDirty();
}
@Override
2014-01-05 09:44:31 +01:00
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added)
{
2014-01-05 09:44:31 +01:00
duality.onChangeInventory( inv, slot, mc, removed, added );
}
@Override
public int[] getAccessibleSlotsBySide(ForgeDirection side)
{
return duality.getAccessibleSlotsFromSide( side.ordinal() );
}
@Override
2014-01-05 09:44:31 +01:00
public DualityInterface getInterfaceDuality()
{
2014-01-05 09:44:31 +01:00
return duality;
}
@Override
public IStorageMonitorable getMonitorable(ForgeDirection side, BaseActionSource src)
{
return duality.getMonitorable( side, src, this );
}
@Override
2014-01-05 09:44:31 +01:00
public IConfigManager getConfigManager()
{
return duality.getConfigManager();
}
@Override
public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCrafting table, ForgeDirection where)
{
return duality.pushPattern( patternDetails, table, where );
}
@Override
public void provideCrafting(ICraftingProviderHelper craftingTracker)
{
duality.provideCrafting( craftingTracker );
}
@Override
public EnumSet<ForgeDirection> getTargets()
{
if ( pointAt == null || pointAt == ForgeDirection.UNKNOWN )
return EnumSet.complementOf( EnumSet.of( ForgeDirection.UNKNOWN ) );
return EnumSet.of( pointAt );
}
}