Applied-Energistics-2-tiler.../src/main/java/appeng/tile/misc/TileInterface.java

383 lines
9.4 KiB
Java
Raw Normal View History

2014-11-14 12:02:52 +01:00
/*
* This file is part of Applied Energistics 2.
2015-05-18 00:34:37 +02:00
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
2014-11-14 12:02:52 +01:00
*
* 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>.
*/
package appeng.tile.misc;
2014-03-20 04:28:53 +01:00
import java.util.EnumSet;
2015-05-09 00:04:44 +02:00
import java.util.List;
2014-03-20 04:28:53 +01:00
import javax.annotation.Nullable;
2015-12-24 02:07:03 +01:00
import com.google.common.collect.ImmutableSet;
import io.netty.buffer.ByteBuf;
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;
2015-06-16 02:44:59 +02:00
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
2015-12-24 02:07:03 +01:00
import appeng.api.config.Actionable;
import appeng.api.config.Upgrades;
2014-01-23 20:02:48 +01:00
import appeng.api.implementations.tiles.ITileStorageMonitorable;
import appeng.api.networking.IGridNode;
import appeng.api.networking.crafting.ICraftingLink;
import appeng.api.networking.crafting.ICraftingPatternDetails;
import appeng.api.networking.crafting.ICraftingProviderHelper;
import appeng.api.networking.events.MENetworkChannelsChanged;
import appeng.api.networking.events.MENetworkEventSubscribe;
import appeng.api.networking.events.MENetworkPowerStatusChange;
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;
2015-06-16 02:44:59 +02:00
import appeng.api.util.AEPartLocation;
import appeng.api.util.DimensionalCoord;
2014-01-05 09:44:31 +01:00
import appeng.api.util.IConfigManager;
import appeng.helpers.DualityInterface;
import appeng.helpers.IInterfaceHost;
2014-07-18 05:38:57 +02:00
import appeng.helpers.IPriorityHost;
2014-08-28 09:39:52 +02:00
import appeng.tile.TileEvent;
2013-12-28 22:07:48 +01:00
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;
public class TileInterface extends AENetworkInvTile implements IGridTickable, ITileStorageMonitorable, IStorageMonitorable, IInventoryDestination, IInterfaceHost, IPriorityHost
{
private final DualityInterface duality = new DualityInterface( this.getProxy(), this );
// Indicates that this interface has no specific direction set
private boolean omniDirectional = true;
2013-12-28 22:07:48 +01:00
@MENetworkEventSubscribe
2015-09-30 14:24:40 +02:00
public void stateChange( final MENetworkChannelsChanged c )
{
2014-12-29 15:13:47 +01:00
this.duality.notifyNeighbors();
}
@MENetworkEventSubscribe
2015-09-30 14:24:40 +02:00
public void stateChange( final MENetworkPowerStatusChange c )
{
2014-12-29 15:13:47 +01:00
this.duality.notifyNeighbors();
}
public void setSide( final EnumFacing facing )
2014-03-20 04:28:53 +01:00
{
if( Platform.isClient() )
2015-04-29 02:30:53 +02:00
{
2014-03-20 04:28:53 +01:00
return;
2015-04-29 02:30:53 +02:00
}
2014-03-20 04:28:53 +01:00
EnumFacing newForward = facing;
if( !omniDirectional && getForward() == facing.getOpposite() )
2015-04-29 02:30:53 +02:00
{
newForward = facing;
2015-04-29 02:30:53 +02:00
}
else if( !omniDirectional && ( getForward() == facing || getForward() == facing.getOpposite() ) )
2015-04-29 02:30:53 +02:00
{
omniDirectional = true;
2015-04-29 02:30:53 +02:00
}
else if( omniDirectional )
2015-04-29 02:30:53 +02:00
{
newForward = facing.getOpposite();
omniDirectional = false;
2015-04-29 02:30:53 +02:00
}
2014-03-20 04:28:53 +01:00
else
2015-04-29 02:30:53 +02:00
{
newForward = Platform.rotateAround( getForward(), facing );
2015-04-29 02:30:53 +02:00
}
2014-03-20 04:28:53 +01:00
if( omniDirectional )
2015-04-29 02:30:53 +02:00
{
this.setOrientation( EnumFacing.NORTH, EnumFacing.UP );
2015-04-29 02:30:53 +02:00
}
2014-03-20 04:28:53 +01:00
else
2015-04-29 02:30:53 +02:00
{
EnumFacing newUp = EnumFacing.UP;
if( newForward == EnumFacing.UP || newForward == EnumFacing.DOWN )
{
newUp = EnumFacing.NORTH;
}
this.setOrientation( newForward, newUp );
2015-04-29 02:30:53 +02:00
}
2014-03-20 04:28:53 +01:00
2015-09-30 14:26:54 +02:00
this.configureNodeSides();
2014-12-29 15:13:47 +01:00
this.markForUpdate();
this.markDirty();
2014-03-20 04:28:53 +01:00
}
2015-06-16 02:44:59 +02:00
private void configureNodeSides()
{
if( omniDirectional )
2015-12-24 02:11:17 +01:00
{
this.getProxy().setValidSides( EnumSet.allOf( EnumFacing.class ) );
2015-12-24 02:11:17 +01:00
}
2015-06-16 02:44:59 +02:00
else
2015-12-24 02:11:17 +01:00
{
this.getProxy().setValidSides( EnumSet.complementOf( EnumSet.of( getForward() ) ) );
2015-12-24 02:11:17 +01:00
}
2015-06-16 02:44:59 +02:00
}
@Override
public void markDirty()
{
this.duality.markDirty();
}
@Override
public void getDrops( final World w, final BlockPos pos, final List<ItemStack> drops )
{
2014-12-29 15:13:47 +01:00
this.duality.addDrops( drops );
}
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-12-29 15:13:47 +01:00
this.duality.gridChanged();
2013-12-28 22:07:48 +01:00
}
@Override
public void onReady()
{
2015-09-30 14:26:54 +02:00
this.configureNodeSides();
super.onReady();
this.duality.initialize();
}
@TileEvent( TileEventType.WORLD_NBT_WRITE )
2015-09-30 14:24:40 +02:00
public void writeToNBT_TileInterface( final NBTTagCompound data )
2013-12-28 22:07:48 +01:00
{
data.setBoolean( "omniDirectional", omniDirectional );
2014-12-29 15:13:47 +01:00
this.duality.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_TileInterface( final NBTTagCompound data )
2014-08-28 09:39:52 +02:00
{
this.omniDirectional = data.getBoolean( "omniDirectional" );
2013-12-28 22:07:48 +01:00
2014-12-29 15:13:47 +01:00
this.duality.readFromNBT( data );
2013-12-28 22:07:48 +01:00
}
@TileEvent( TileEventType.NETWORK_READ )
public boolean readFromStream_TileInterface( final ByteBuf data )
{
boolean oldOmniDirectional = this.omniDirectional;
this.omniDirectional = data.readBoolean();
return oldOmniDirectional != omniDirectional;
}
@TileEvent( TileEventType.NETWORK_WRITE )
public void writeToStream_TileInterface( final ByteBuf data )
{
data.writeBoolean( omniDirectional );
}
2014-03-20 04:28:53 +01:00
@Override
2015-09-30 14:24:40 +02:00
public AECableType getCableConnectionType( final AEPartLocation dir )
{
2014-12-29 15:13:47 +01:00
return this.duality.getCableConnectionType( dir );
}
@Override
2014-01-05 09:44:31 +01:00
public DimensionalCoord getLocation()
{
2014-12-29 15:13:47 +01:00
return this.duality.getLocation();
}
@Override
2015-09-30 14:24:40 +02:00
public boolean canInsert( final ItemStack stack )
{
2014-12-29 15:13:47 +01:00
return this.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-12-29 15:13:47 +01:00
return this.duality.getItemInventory();
}
@Override
2014-01-05 09:44:31 +01:00
public IMEMonitor<IAEFluidStack> getFluidInventory()
{
2014-12-29 15:13:47 +01:00
return this.duality.getFluidInventory();
}
2014-01-05 09:44:31 +01:00
@Override
2015-09-30 14:24:40 +02:00
public IInventory getInventoryByName( final String name )
{
2014-12-29 15:13:47 +01:00
return this.duality.getInventoryByName( name );
}
2014-01-05 09:44:31 +01:00
@Override
2015-09-30 14:24:40 +02:00
public TickingRequest getTickingRequest( final IGridNode node )
{
2014-12-29 15:13:47 +01:00
return this.duality.getTickingRequest( node );
}
2014-01-05 09:44:31 +01:00
@Override
2015-09-30 14:24:40 +02:00
public TickRateModulation tickingRequest( final IGridNode node, final int ticksSinceLastCall )
{
return this.duality.tickingRequest( node, ticksSinceLastCall );
}
@Override
2014-01-05 09:44:31 +01:00
public IInventory getInternalInventory()
{
2014-12-29 15:13:47 +01:00
return this.duality.getInternalInventory();
}
@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-12-29 15:13:47 +01:00
this.duality.onChangeInventory( inv, slot, mc, removed, added );
}
@Override
2015-09-30 14:24:40 +02:00
public int[] getAccessibleSlotsBySide( final EnumFacing side )
{
2015-06-16 02:44:59 +02:00
return this.duality.getSlotsForFace( side );
}
@Override
2014-01-05 09:44:31 +01:00
public DualityInterface getInterfaceDuality()
{
2014-12-29 15:13:47 +01:00
return this.duality;
}
@Override
2015-06-16 02:44:59 +02:00
public EnumSet<EnumFacing> getTargets()
{
if( omniDirectional )
2015-04-29 02:30:53 +02:00
{
2015-06-16 02:44:59 +02:00
return EnumSet.allOf( EnumFacing.class );
2015-04-29 02:30:53 +02:00
}
return EnumSet.of( getForward() );
}
@Override
public TileEntity getTileEntity()
{
return this;
}
@Override
2015-09-30 14:24:40 +02:00
public IStorageMonitorable getMonitorable( final EnumFacing side, final BaseActionSource src )
{
return this.duality.getMonitorable( side, src, this );
}
@Override
public IConfigManager getConfigManager()
{
return this.duality.getConfigManager();
}
@Override
2015-09-30 14:24:40 +02:00
public boolean pushPattern( final ICraftingPatternDetails patternDetails, final InventoryCrafting table )
{
return this.duality.pushPattern( patternDetails, table );
}
@Override
public boolean isBusy()
{
2014-12-29 15:13:47 +01:00
return this.duality.isBusy();
}
@Override
2015-09-30 14:24:40 +02:00
public void provideCrafting( final ICraftingProviderHelper craftingTracker )
{
this.duality.provideCrafting( craftingTracker );
}
@Override
2015-09-30 14:24:40 +02:00
public int getInstalledUpgrades( final Upgrades u )
{
2014-12-29 15:13:47 +01:00
return this.duality.getInstalledUpgrades( u );
}
@Override
public ImmutableSet<ICraftingLink> getRequestedJobs()
{
2014-12-29 15:13:47 +01:00
return this.duality.getRequestedJobs();
}
@Override
2015-09-30 14:24:40 +02:00
public IAEItemStack injectCraftedItems( final ICraftingLink link, final IAEItemStack items, final Actionable mode )
{
2014-12-29 15:13:47 +01:00
return this.duality.injectCraftedItems( link, items, mode );
}
@Override
2015-09-30 14:24:40 +02:00
public void jobStateChange( final ICraftingLink link )
{
2014-12-29 15:13:47 +01:00
this.duality.jobStateChange( link );
}
2014-07-18 05:38:57 +02:00
@Override
public int getPriority()
{
2014-12-29 15:13:47 +01:00
return this.duality.getPriority();
2014-07-18 05:38:57 +02:00
}
@Override
2015-09-30 14:24:40 +02:00
public void setPriority( final int newValue )
2014-07-18 05:38:57 +02:00
{
2014-12-29 15:13:47 +01:00
this.duality.setPriority( newValue );
2014-07-18 05:38:57 +02:00
}
/**
* @return True if this interface is omni-directional.
*/
public boolean isOmniDirectional()
{
return this.omniDirectional;
}
@Override
public boolean hasCapability( Capability<?> capability, @Nullable EnumFacing facing )
{
return this.duality.hasCapability( capability, facing );
}
@Override
public <T> T getCapability( Capability<T> capability, @Nullable EnumFacing facing )
{
return this.duality.getCapability( capability, facing );
}
}