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.misc;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-06-23 06:51:20 +02:00
|
|
|
import java.util.ArrayList;
|
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
|
|
|
|
2015-05-08 23:25:19 +02:00
|
|
|
import com.google.common.collect.ImmutableSet;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.inventory.IInventory;
|
2014-05-09 06:10:12 +02:00
|
|
|
import net.minecraft.inventory.InventoryCrafting;
|
2013-12-27 23:59:59 +01:00
|
|
|
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-06-23 06:51:20 +02:00
|
|
|
import net.minecraft.world.World;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
2014-07-06 08:48:21 +02:00
|
|
|
import appeng.api.config.Actionable;
|
2014-07-05 03:59:50 +02:00
|
|
|
import appeng.api.config.Upgrades;
|
2014-01-23 20:02:48 +01:00
|
|
|
import appeng.api.implementations.tiles.ITileStorageMonitorable;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.networking.IGridNode;
|
2014-07-06 08:48:21 +02:00
|
|
|
import appeng.api.networking.crafting.ICraftingLink;
|
2014-05-09 06:10:12 +02:00
|
|
|
import appeng.api.networking.crafting.ICraftingPatternDetails;
|
|
|
|
import appeng.api.networking.crafting.ICraftingProviderHelper;
|
2014-06-23 07:08:38 +02:00
|
|
|
import appeng.api.networking.events.MENetworkChannelsChanged;
|
|
|
|
import appeng.api.networking.events.MENetworkEventSubscribe;
|
|
|
|
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
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.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;
|
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
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
|
|
|
public class TileInterface extends AENetworkInvTile implements IGridTickable, ITileStorageMonitorable, IStorageMonitorable, IInventoryDestination, IInterfaceHost, IPriorityHost
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
final DualityInterface duality = new DualityInterface( this.gridProxy, this );
|
2015-04-03 08:54:31 +02:00
|
|
|
ForgeDirection pointAt = ForgeDirection.UNKNOWN;
|
2013-12-28 22:07:48 +01:00
|
|
|
|
2014-06-23 07:08:38 +02:00
|
|
|
@MENetworkEventSubscribe
|
2015-04-03 08:54:31 +02:00
|
|
|
public void stateChange( MENetworkChannelsChanged c )
|
2014-06-23 07:08:38 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.duality.notifyNeighbors();
|
2014-06-23 07:08:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@MENetworkEventSubscribe
|
2015-04-03 08:54:31 +02:00
|
|
|
public void stateChange( MENetworkPowerStatusChange c )
|
2014-06-23 07:08:38 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.duality.notifyNeighbors();
|
2014-06-23 07:08:38 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public void setSide( ForgeDirection axis )
|
2014-03-20 04:28:53 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02: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
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.pointAt == axis.getOpposite() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.pointAt = axis;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( this.pointAt == axis || this.pointAt == axis.getOpposite() )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.pointAt = ForgeDirection.UNKNOWN;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
else if( this.pointAt == ForgeDirection.UNKNOWN )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.pointAt = axis.getOpposite();
|
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
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.pointAt = Platform.rotateAround( this.pointAt, axis );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-03-20 04:28:53 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ForgeDirection.UNKNOWN == this.pointAt )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.setOrientation( this.pointAt, this.pointAt );
|
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
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.setOrientation( this.pointAt.offsetY != 0 ? ForgeDirection.SOUTH : ForgeDirection.UP, this.pointAt.getOpposite() );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-03-20 04:28:53 +01:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.gridProxy.setValidSides( EnumSet.complementOf( EnumSet.of( this.pointAt ) ) );
|
|
|
|
this.markForUpdate();
|
|
|
|
this.markDirty();
|
2014-03-20 04:28:53 +01:00
|
|
|
}
|
|
|
|
|
2014-06-23 06:51:20 +02:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void markDirty()
|
|
|
|
{
|
|
|
|
this.duality.markDirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-05-09 00:04:44 +02:00
|
|
|
public void getDrops( World w, int x, int y, int z, List<ItemStack> drops )
|
2014-06-23 06:51:20 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.duality.addDrops( drops );
|
2014-06-23 06:51:20 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public void onReady()
|
|
|
|
{
|
|
|
|
this.gridProxy.setValidSides( EnumSet.complementOf( EnumSet.of( this.pointAt ) ) );
|
|
|
|
super.onReady();
|
|
|
|
this.duality.initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
@TileEvent( TileEventType.WORLD_NBT_WRITE )
|
|
|
|
public void writeToNBT_TileInterface( NBTTagCompound data )
|
2013-12-28 22:07:48 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
data.setInteger( "pointAt", this.pointAt.ordinal() );
|
|
|
|
this.duality.writeToNBT( data );
|
2014-08-28 09:39:52 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@TileEvent( TileEventType.WORLD_NBT_READ )
|
|
|
|
public void readFromNBT_TileInterface( NBTTagCompound data )
|
2014-08-28 09:39:52 +02:00
|
|
|
{
|
|
|
|
int val = data.getInteger( "pointAt" );
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( val >= 0 && val < ForgeDirection.values().length )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.pointAt = ForgeDirection.values()[val];
|
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.pointAt = ForgeDirection.UNKNOWN;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2014-03-20 04:28:53 +01:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public AECableType getCableConnectionType( ForgeDirection dir )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.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-12-29 15:13:47 +01:00
|
|
|
return this.duality.getLocation();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public boolean canInsert( ItemStack stack )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
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();
|
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-12-29 15:13:47 +01:00
|
|
|
return this.duality.getFluidInventory();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-01-05 09:44:31 +01:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public IInventory getInventoryByName( String name )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.duality.getInventoryByName( name );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-01-05 09:44:31 +01:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public TickingRequest getTickingRequest( IGridNode node )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.duality.getTickingRequest( node );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-01-05 09:44:31 +01:00
|
|
|
@Override
|
2015-05-08 23:25:19 +02:00
|
|
|
public TickRateModulation tickingRequest( IGridNode node, int ticksSinceLastCall )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-05-08 23:25:19 +02:00
|
|
|
return this.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-12-29 15:13:47 +01:00
|
|
|
return this.duality.getInternalInventory();
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-01-31 02:23:12 +01:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void onChangeInventory( IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.duality.onChangeInventory( inv, slot, mc, removed, added );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public int[] getAccessibleSlotsBySide( ForgeDirection side )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.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-12-29 15:13:47 +01:00
|
|
|
return this.duality;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public EnumSet<ForgeDirection> getTargets()
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.pointAt == null || this.pointAt == ForgeDirection.UNKNOWN )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return EnumSet.complementOf( EnumSet.of( ForgeDirection.UNKNOWN ) );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
return EnumSet.of( this.pointAt );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2013-12-30 06:58:51 +01:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public TileEntity getTileEntity()
|
2013-12-30 06:58:51 +01:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return this;
|
2013-12-30 06:58:51 +01:00
|
|
|
}
|
|
|
|
|
2014-05-09 06:10:12 +02:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public IStorageMonitorable getMonitorable( ForgeDirection side, BaseActionSource src )
|
2014-05-09 06:10:12 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return this.duality.getMonitorable( side, src, this );
|
2014-05-09 06:10:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public IConfigManager getConfigManager()
|
2014-05-09 06:10:12 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return this.duality.getConfigManager();
|
2014-05-09 06:10:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public boolean pushPattern( ICraftingPatternDetails patternDetails, InventoryCrafting table )
|
2014-05-09 06:10:12 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
return this.duality.pushPattern( patternDetails, table );
|
2014-05-09 06:10:12 +02:00
|
|
|
}
|
|
|
|
|
2014-06-19 08:28:45 +02:00
|
|
|
@Override
|
|
|
|
public boolean isBusy()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.duality.isBusy();
|
2014-06-19 08:28:45 +02:00
|
|
|
}
|
|
|
|
|
2014-07-05 03:59:50 +02:00
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void provideCrafting( ICraftingProviderHelper craftingTracker )
|
|
|
|
{
|
|
|
|
this.duality.provideCrafting( craftingTracker );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getInstalledUpgrades( Upgrades u )
|
2014-07-05 03:59:50 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.duality.getInstalledUpgrades( u );
|
2014-07-05 03:59:50 +02:00
|
|
|
}
|
|
|
|
|
2014-07-06 08:48:21 +02:00
|
|
|
@Override
|
|
|
|
public ImmutableSet<ICraftingLink> getRequestedJobs()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.duality.getRequestedJobs();
|
2014-07-06 08:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public IAEItemStack injectCraftedItems( ICraftingLink link, IAEItemStack items, Actionable mode )
|
2014-07-06 08:48:21 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.duality.injectCraftedItems( link, items, mode );
|
2014-07-06 08:48:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void jobStateChange( ICraftingLink link )
|
2014-07-06 08:48:21 +02:00
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.duality.jobStateChange( link );
|
2014-07-06 08:48:21 +02:00
|
|
|
}
|
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-04-03 08:54:31 +02:00
|
|
|
public void setPriority( 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
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|