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>.
|
|
|
|
*/
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
package appeng.tile.misc;
|
|
|
|
|
2022-12-02 17:40:47 +01:00
|
|
|
import java.util.EnumSet;
|
|
|
|
import java.util.List;
|
2015-04-03 08:54:31 +02: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;
|
2017-04-12 16:10:13 +02:00
|
|
|
import com.google.common.collect.ImmutableSet;
|
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.inventory.InventoryCrafting;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
|
|
|
|
public class TileInterface extends AENetworkInvTile
|
2022-12-02 17:40:47 +01:00
|
|
|
implements IGridTickable, ITileStorageMonitorable, IStorageMonitorable,
|
|
|
|
IInventoryDestination, IInterfaceHost, IPriorityHost {
|
|
|
|
private final DualityInterface duality = new DualityInterface(this.getProxy(), this);
|
|
|
|
private ForgeDirection pointAt = ForgeDirection.UNKNOWN;
|
|
|
|
|
|
|
|
@MENetworkEventSubscribe
|
|
|
|
public void stateChange(final MENetworkChannelsChanged c) {
|
|
|
|
this.duality.notifyNeighbors();
|
|
|
|
}
|
|
|
|
|
|
|
|
@MENetworkEventSubscribe
|
|
|
|
public void stateChange(final MENetworkPowerStatusChange c) {
|
|
|
|
this.duality.notifyNeighbors();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setSide(final ForgeDirection axis) {
|
|
|
|
if (Platform.isClient()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
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();
|
|
|
|
} else {
|
|
|
|
this.pointAt = Platform.rotateAround(this.pointAt, axis);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ForgeDirection.UNKNOWN == this.pointAt) {
|
|
|
|
this.setOrientation(this.pointAt, this.pointAt);
|
|
|
|
} else {
|
|
|
|
this.setOrientation(
|
|
|
|
this.pointAt.offsetY != 0 ? ForgeDirection.SOUTH : ForgeDirection.UP,
|
|
|
|
this.pointAt.getOpposite()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
this.getProxy().setValidSides(EnumSet.complementOf(EnumSet.of(this.pointAt)));
|
|
|
|
this.markForUpdate();
|
|
|
|
this.markDirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void markDirty() {
|
|
|
|
this.duality.markDirty();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void getDrops(
|
|
|
|
final World w, final int x, final int y, final int z, final List<ItemStack> drops
|
|
|
|
) {
|
|
|
|
this.duality.addDrops(drops);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void gridChanged() {
|
|
|
|
this.duality.gridChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReady() {
|
|
|
|
this.getProxy().setValidSides(EnumSet.complementOf(EnumSet.of(this.pointAt)));
|
|
|
|
super.onReady();
|
|
|
|
this.duality.initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
@TileEvent(TileEventType.WORLD_NBT_WRITE)
|
|
|
|
public void writeToNBT_TileInterface(final NBTTagCompound data) {
|
|
|
|
data.setInteger("pointAt", this.pointAt.ordinal());
|
|
|
|
this.duality.writeToNBT(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
@TileEvent(TileEventType.WORLD_NBT_READ)
|
|
|
|
public void readFromNBT_TileInterface(final NBTTagCompound data) {
|
|
|
|
final int val = data.getInteger("pointAt");
|
|
|
|
|
|
|
|
if (val >= 0 && val < ForgeDirection.values().length) {
|
|
|
|
this.pointAt = ForgeDirection.values()[val];
|
|
|
|
} else {
|
|
|
|
this.pointAt = ForgeDirection.UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.duality.readFromNBT(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public AECableType getCableConnectionType(final ForgeDirection dir) {
|
|
|
|
return this.duality.getCableConnectionType(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public DimensionalCoord getLocation() {
|
|
|
|
return this.duality.getLocation();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canInsert(final ItemStack stack) {
|
|
|
|
return this.duality.canInsert(stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IMEMonitor<IAEItemStack> getItemInventory() {
|
|
|
|
return this.duality.getItemInventory();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IMEMonitor<IAEFluidStack> getFluidInventory() {
|
|
|
|
return this.duality.getFluidInventory();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IInventory getInventoryByName(final String name) {
|
|
|
|
return this.duality.getInventoryByName(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TickingRequest getTickingRequest(final IGridNode node) {
|
|
|
|
return this.duality.getTickingRequest(node);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TickRateModulation
|
|
|
|
tickingRequest(final IGridNode node, final int ticksSinceLastCall) {
|
|
|
|
return this.duality.tickingRequest(node, ticksSinceLastCall);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IInventory getInternalInventory() {
|
|
|
|
return this.duality.getInternalInventory();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onChangeInventory(
|
|
|
|
final IInventory inv,
|
|
|
|
final int slot,
|
|
|
|
final InvOperation mc,
|
|
|
|
final ItemStack removed,
|
|
|
|
final ItemStack added
|
|
|
|
) {
|
|
|
|
this.duality.onChangeInventory(inv, slot, mc, removed, added);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int[] getAccessibleSlotsBySide(final ForgeDirection side) {
|
|
|
|
return this.duality.getAccessibleSlotsFromSide(side.ordinal());
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public DualityInterface getInterfaceDuality() {
|
|
|
|
return this.duality;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnumSet<ForgeDirection> getTargets() {
|
|
|
|
if (this.pointAt == null || this.pointAt == ForgeDirection.UNKNOWN) {
|
|
|
|
return EnumSet.complementOf(EnumSet.of(ForgeDirection.UNKNOWN));
|
|
|
|
}
|
|
|
|
return EnumSet.of(this.pointAt);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TileEntity getTileEntity() {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IStorageMonitorable
|
|
|
|
getMonitorable(final ForgeDirection side, final BaseActionSource src) {
|
|
|
|
return this.duality.getMonitorable(side, src, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IConfigManager getConfigManager() {
|
|
|
|
return this.duality.getConfigManager();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean pushPattern(
|
|
|
|
final ICraftingPatternDetails patternDetails, final InventoryCrafting table
|
|
|
|
) {
|
|
|
|
return this.duality.pushPattern(patternDetails, table);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isBusy() {
|
|
|
|
return this.duality.isBusy();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void provideCrafting(final ICraftingProviderHelper craftingTracker) {
|
|
|
|
this.duality.provideCrafting(craftingTracker);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getInstalledUpgrades(final Upgrades u) {
|
|
|
|
return this.duality.getInstalledUpgrades(u);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ImmutableSet<ICraftingLink> getRequestedJobs() {
|
|
|
|
return this.duality.getRequestedJobs();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IAEItemStack injectCraftedItems(
|
|
|
|
final ICraftingLink link, final IAEItemStack items, final Actionable mode
|
|
|
|
) {
|
|
|
|
return this.duality.injectCraftedItems(link, items, mode);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void jobStateChange(final ICraftingLink link) {
|
|
|
|
this.duality.jobStateChange(link);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getPriority() {
|
|
|
|
return this.duality.getPriority();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setPriority(final int newValue) {
|
|
|
|
this.duality.setPriority(newValue);
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|