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

306 lines
8 KiB
Java
Raw Normal View History

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>.
*/
package appeng.tile.misc;
import java.util.ArrayList;
2014-03-20 04:28:53 +01:00
import java.util.EnumSet;
2014-12-29 21:59:05 +01:00
import com.google.common.collect.ImmutableSet;
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;
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
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;
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;
2014-10-04 08:08:28 +02:00
public class TileInterface extends AENetworkInvTile implements IGridTickable, ITileStorageMonitorable, IStorageMonitorable,
IInventoryDestination, IInterfaceHost, IPriorityHost
{
2014-03-20 04:28:53 +01:00
ForgeDirection pointAt = ForgeDirection.UNKNOWN;
2014-12-29 15:13:47 +01:00
final DualityInterface duality = new DualityInterface( this.gridProxy, this );
2013-12-28 22:07:48 +01:00
@MENetworkEventSubscribe
public void stateChange(MENetworkChannelsChanged c)
{
2014-12-29 15:13:47 +01:00
this.duality.notifyNeighbors();
}
@MENetworkEventSubscribe
public void stateChange(MENetworkPowerStatusChange c)
{
2014-12-29 15:13:47 +01:00
this.duality.notifyNeighbors();
}
2014-03-20 04:28:53 +01:00
public void setSide(ForgeDirection axis)
{
if ( Platform.isClient() )
return;
2014-12-29 15:13:47 +01:00
if ( this.pointAt == axis.getOpposite() )
this.pointAt = axis;
else if ( this.pointAt == axis || this.pointAt == axis.getOpposite() )
this.pointAt = ForgeDirection.UNKNOWN;
else if ( this.pointAt == ForgeDirection.UNKNOWN )
this.pointAt = axis.getOpposite();
2014-03-20 04:28:53 +01:00
else
2014-12-29 15:13:47 +01:00
this.pointAt = Platform.rotateAround( this.pointAt, axis );
2014-03-20 04:28:53 +01:00
2014-12-29 15:13:47 +01:00
if ( ForgeDirection.UNKNOWN == this.pointAt )
this.setOrientation( this.pointAt, this.pointAt );
2014-03-20 04:28:53 +01:00
else
2014-12-29 15:13:47 +01:00
this.setOrientation( this.pointAt.offsetY != 0 ? ForgeDirection.SOUTH : ForgeDirection.UP, this.pointAt.getOpposite() );
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
}
@Override
public void getDrops(World w, int x, int y, int z, ArrayList<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
}
2014-08-28 09:39:52 +02:00
@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
}
@TileEvent(TileEventType.WORLD_NBT_READ)
public void readFromNBT_TileInterface(NBTTagCompound data)
{
int val = data.getInteger( "pointAt" );
if ( val >= 0 && val < ForgeDirection.values().length )
2014-12-29 15:13:47 +01:00
this.pointAt = ForgeDirection.values()[val];
2014-08-28 09:39:52 +02:00
else
2014-12-29 15:13:47 +01:00
this.pointAt = ForgeDirection.UNKNOWN;
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
public void onReady()
{
2014-12-29 15:13:47 +01:00
this.gridProxy.setValidSides( EnumSet.complementOf( EnumSet.of( this.pointAt ) ) );
2014-03-20 04:28:53 +01:00
super.onReady();
2014-12-29 15:13:47 +01:00
this.duality.initialize();
2014-03-20 04:28:53 +01:00
}
@Override
2014-01-05 09:44:31 +01:00
public AECableType getCableConnectionType(ForgeDirection 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
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-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
public IInventory getInventoryByName(String name)
{
2014-12-29 15:13:47 +01:00
return this.duality.getInventoryByName( name );
}
2014-01-05 09:44:31 +01:00
@Override
public TickingRequest getTickingRequest(IGridNode node)
{
2014-12-29 15:13:47 +01:00
return this.duality.getTickingRequest( node );
}
2014-01-05 09:44:31 +01:00
@Override
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
{
2014-12-29 15:13:47 +01:00
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
2014-02-09 02:34:52 +01:00
public void markDirty()
{
2014-12-29 15:13:47 +01:00
this.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-12-29 15:13:47 +01:00
this.duality.onChangeInventory( inv, slot, mc, removed, added );
}
@Override
public int[] getAccessibleSlotsBySide(ForgeDirection side)
{
2014-12-29 15:13:47 +01:00
return this.duality.getAccessibleSlotsFromSide( side.ordinal() );
}
@Override
2014-01-05 09:44:31 +01:00
public DualityInterface getInterfaceDuality()
{
2014-12-29 15:13:47 +01:00
return this.duality;
}
@Override
public IStorageMonitorable getMonitorable(ForgeDirection side, BaseActionSource src)
{
2014-12-29 15:13:47 +01:00
return this.duality.getMonitorable( side, src, this );
}
@Override
2014-01-05 09:44:31 +01:00
public IConfigManager getConfigManager()
{
2014-12-29 15:13:47 +01:00
return this.duality.getConfigManager();
}
@Override
public boolean pushPattern(ICraftingPatternDetails patternDetails, InventoryCrafting table)
{
2014-12-29 15:13:47 +01:00
return this.duality.pushPattern( patternDetails, table );
}
@Override
public void provideCrafting(ICraftingProviderHelper craftingTracker)
{
2014-12-29 15:13:47 +01:00
this.duality.provideCrafting( craftingTracker );
}
@Override
public EnumSet<ForgeDirection> getTargets()
{
2014-12-29 15:13:47 +01:00
if ( this.pointAt == null || this.pointAt == ForgeDirection.UNKNOWN )
return EnumSet.complementOf( EnumSet.of( ForgeDirection.UNKNOWN ) );
2014-12-29 15:13:47 +01:00
return EnumSet.of( this.pointAt );
}
@Override
public boolean isBusy()
{
2014-12-29 15:13:47 +01:00
return this.duality.isBusy();
}
@Override
public int getInstalledUpgrades(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
2014-09-20 22:36:48 +02:00
public IAEItemStack injectCraftedItems(ICraftingLink link, IAEItemStack items, Actionable mode)
{
2014-12-29 15:13:47 +01:00
return this.duality.injectCraftedItems( link, items, mode );
}
@Override
public void jobStateChange(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
public void setPriority(int newValue)
{
2014-12-29 15:13:47 +01:00
this.duality.setPriority( newValue );
2014-07-18 05:38:57 +02:00
}
}