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>.
|
|
|
|
*/
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
package appeng.core.sync;
|
|
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Constructor;
|
2015-01-03 02:53:14 +01:00
|
|
|
import java.util.List;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
|
|
|
import net.minecraft.inventory.Slot;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
|
|
|
import cpw.mods.fml.common.network.IGuiHandler;
|
|
|
|
import cpw.mods.fml.relauncher.ReflectionHelper;
|
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
import com.google.common.collect.Lists;
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.api.AEApi;
|
|
|
|
import appeng.api.config.SecurityPermissions;
|
2015-01-03 02:53:14 +01:00
|
|
|
import appeng.api.definitions.IComparableDefinition;
|
|
|
|
import appeng.api.definitions.IMaterials;
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.api.exceptions.AppEngException;
|
|
|
|
import appeng.api.features.IWirelessTermHandler;
|
|
|
|
import appeng.api.implementations.IUpgradeableHost;
|
|
|
|
import appeng.api.implementations.guiobjects.IGuiItem;
|
|
|
|
import appeng.api.implementations.guiobjects.INetworkTool;
|
|
|
|
import appeng.api.implementations.guiobjects.IPortableCell;
|
|
|
|
import appeng.api.networking.IGrid;
|
|
|
|
import appeng.api.networking.IGridNode;
|
|
|
|
import appeng.api.networking.energy.IEnergyGrid;
|
|
|
|
import appeng.api.networking.security.IActionHost;
|
|
|
|
import appeng.api.networking.security.ISecurityGrid;
|
|
|
|
import appeng.api.parts.IPart;
|
|
|
|
import appeng.api.parts.IPartHost;
|
|
|
|
import appeng.api.storage.ITerminalHost;
|
|
|
|
import appeng.api.util.DimensionalCoord;
|
|
|
|
import appeng.client.gui.GuiNull;
|
|
|
|
import appeng.container.AEBaseContainer;
|
|
|
|
import appeng.container.ContainerNull;
|
|
|
|
import appeng.container.ContainerOpenContext;
|
|
|
|
import appeng.container.implementations.ContainerCellWorkbench;
|
|
|
|
import appeng.container.implementations.ContainerChest;
|
|
|
|
import appeng.container.implementations.ContainerCondenser;
|
|
|
|
import appeng.container.implementations.ContainerCraftAmount;
|
|
|
|
import appeng.container.implementations.ContainerCraftConfirm;
|
|
|
|
import appeng.container.implementations.ContainerCraftingCPU;
|
|
|
|
import appeng.container.implementations.ContainerCraftingStatus;
|
|
|
|
import appeng.container.implementations.ContainerCraftingTerm;
|
|
|
|
import appeng.container.implementations.ContainerDrive;
|
|
|
|
import appeng.container.implementations.ContainerFormationPlane;
|
|
|
|
import appeng.container.implementations.ContainerGrinder;
|
|
|
|
import appeng.container.implementations.ContainerIOPort;
|
|
|
|
import appeng.container.implementations.ContainerInscriber;
|
|
|
|
import appeng.container.implementations.ContainerInterface;
|
|
|
|
import appeng.container.implementations.ContainerInterfaceTerminal;
|
|
|
|
import appeng.container.implementations.ContainerLevelEmitter;
|
|
|
|
import appeng.container.implementations.ContainerMAC;
|
|
|
|
import appeng.container.implementations.ContainerMEMonitorable;
|
|
|
|
import appeng.container.implementations.ContainerMEPortableCell;
|
|
|
|
import appeng.container.implementations.ContainerNetworkStatus;
|
|
|
|
import appeng.container.implementations.ContainerNetworkTool;
|
|
|
|
import appeng.container.implementations.ContainerPatternTerm;
|
|
|
|
import appeng.container.implementations.ContainerPriority;
|
|
|
|
import appeng.container.implementations.ContainerQNB;
|
|
|
|
import appeng.container.implementations.ContainerQuartzKnife;
|
|
|
|
import appeng.container.implementations.ContainerSecurity;
|
|
|
|
import appeng.container.implementations.ContainerSkyChest;
|
|
|
|
import appeng.container.implementations.ContainerSpatialIOPort;
|
|
|
|
import appeng.container.implementations.ContainerStorageBus;
|
|
|
|
import appeng.container.implementations.ContainerUpgradeable;
|
|
|
|
import appeng.container.implementations.ContainerVibrationChamber;
|
|
|
|
import appeng.container.implementations.ContainerWireless;
|
|
|
|
import appeng.container.implementations.ContainerWirelessTerm;
|
|
|
|
import appeng.core.stats.Achievements;
|
|
|
|
import appeng.helpers.IInterfaceHost;
|
|
|
|
import appeng.helpers.IPriorityHost;
|
|
|
|
import appeng.helpers.WirelessTerminalGuiObject;
|
|
|
|
import appeng.items.contents.QuartzKnifeObj;
|
|
|
|
import appeng.parts.automation.PartFormationPlane;
|
|
|
|
import appeng.parts.automation.PartLevelEmitter;
|
|
|
|
import appeng.parts.misc.PartStorageBus;
|
|
|
|
import appeng.parts.reporting.PartCraftingTerminal;
|
|
|
|
import appeng.parts.reporting.PartMonitor;
|
|
|
|
import appeng.parts.reporting.PartPatternTerminal;
|
|
|
|
import appeng.tile.crafting.TileCraftingTile;
|
|
|
|
import appeng.tile.crafting.TileMolecularAssembler;
|
|
|
|
import appeng.tile.grindstone.TileGrinder;
|
|
|
|
import appeng.tile.misc.TileCellWorkbench;
|
|
|
|
import appeng.tile.misc.TileCondenser;
|
|
|
|
import appeng.tile.misc.TileInscriber;
|
|
|
|
import appeng.tile.misc.TileSecurity;
|
|
|
|
import appeng.tile.misc.TileVibrationChamber;
|
|
|
|
import appeng.tile.networking.TileWireless;
|
|
|
|
import appeng.tile.qnb.TileQuantumBridge;
|
|
|
|
import appeng.tile.spatial.TileSpatialIOPort;
|
|
|
|
import appeng.tile.storage.TileChest;
|
|
|
|
import appeng.tile.storage.TileDrive;
|
|
|
|
import appeng.tile.storage.TileIOPort;
|
|
|
|
import appeng.tile.storage.TileSkyChest;
|
|
|
|
import appeng.util.Platform;
|
|
|
|
|
2015-03-26 11:21:55 +01:00
|
|
|
import static appeng.core.sync.GuiHostType.ITEM;
|
|
|
|
import static appeng.core.sync.GuiHostType.ITEM_OR_WORLD;
|
|
|
|
import static appeng.core.sync.GuiHostType.WORLD;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
public enum GuiBridge implements IGuiHandler
|
|
|
|
{
|
|
|
|
GUI_Handler(),
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_GRINDER( ContainerGrinder.class, TileGrinder.class, WORLD, null ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_QNB( ContainerQNB.class, TileQuantumBridge.class, WORLD, SecurityPermissions.BUILD ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_SKYCHEST( ContainerSkyChest.class, TileSkyChest.class, WORLD, null ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_CHEST( ContainerChest.class, TileChest.class, WORLD, SecurityPermissions.BUILD ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_WIRELESS( ContainerWireless.class, TileWireless.class, WORLD, SecurityPermissions.BUILD ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_ME( ContainerMEMonitorable.class, ITerminalHost.class, WORLD, null ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_PORTABLE_CELL( ContainerMEPortableCell.class, IPortableCell.class, ITEM, null ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_WIRELESS_TERM( ContainerWirelessTerm.class, WirelessTerminalGuiObject.class, ITEM, null ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_NETWORK_STATUS( ContainerNetworkStatus.class, INetworkTool.class, ITEM, null ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_CRAFTING_CPU( ContainerCraftingCPU.class, TileCraftingTile.class, WORLD, SecurityPermissions.CRAFT ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_NETWORK_TOOL( ContainerNetworkTool.class, INetworkTool.class, ITEM, null ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_QUARTZ_KNIFE( ContainerQuartzKnife.class, QuartzKnifeObj.class, ITEM, null ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_DRIVE( ContainerDrive.class, TileDrive.class, WORLD, SecurityPermissions.BUILD ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_VIBRATION_CHAMBER( ContainerVibrationChamber.class, TileVibrationChamber.class, WORLD, null ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_CONDENSER( ContainerCondenser.class, TileCondenser.class, WORLD, null ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_INTERFACE( ContainerInterface.class, IInterfaceHost.class, WORLD, SecurityPermissions.BUILD ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_BUS( ContainerUpgradeable.class, IUpgradeableHost.class, WORLD, SecurityPermissions.BUILD ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_IOPORT( ContainerIOPort.class, TileIOPort.class, WORLD, SecurityPermissions.BUILD ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_STORAGEBUS( ContainerStorageBus.class, PartStorageBus.class, WORLD, SecurityPermissions.BUILD ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_FORMATION_PLANE( ContainerFormationPlane.class, PartFormationPlane.class, WORLD, SecurityPermissions.BUILD ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_PRIORITY( ContainerPriority.class, IPriorityHost.class, WORLD, SecurityPermissions.BUILD ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_SECURITY( ContainerSecurity.class, TileSecurity.class, WORLD, SecurityPermissions.SECURITY ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_CRAFTING_TERMINAL( ContainerCraftingTerm.class, PartCraftingTerminal.class, WORLD, SecurityPermissions.CRAFT ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_PATTERN_TERMINAL( ContainerPatternTerm.class, PartPatternTerminal.class, WORLD, SecurityPermissions.CRAFT ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
|
|
|
// extends (Container/Gui) + Bus
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_LEVEL_EMITTER( ContainerLevelEmitter.class, PartLevelEmitter.class, WORLD, SecurityPermissions.BUILD ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_SPATIAL_IO_PORT( ContainerSpatialIOPort.class, TileSpatialIOPort.class, WORLD, SecurityPermissions.BUILD ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_INSCRIBER( ContainerInscriber.class, TileInscriber.class, WORLD, null ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_CELL_WORKBENCH( ContainerCellWorkbench.class, TileCellWorkbench.class, WORLD, null ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_MAC( ContainerMAC.class, TileMolecularAssembler.class, WORLD, null ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_CRAFTING_AMOUNT( ContainerCraftAmount.class, ITerminalHost.class, ITEM_OR_WORLD, SecurityPermissions.CRAFT ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_CRAFTING_CONFIRM( ContainerCraftConfirm.class, ITerminalHost.class, ITEM_OR_WORLD, SecurityPermissions.CRAFT ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_INTERFACE_TERMINAL( ContainerInterfaceTerminal.class, PartMonitor.class, WORLD, SecurityPermissions.BUILD ),
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GUI_CRAFTING_STATUS( ContainerCraftingStatus.class, ITerminalHost.class, ITEM_OR_WORLD, SecurityPermissions.CRAFT );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-09-29 09:54:34 +02:00
|
|
|
private final Class Tile;
|
|
|
|
private final Class Container;
|
2015-04-03 08:54:31 +02:00
|
|
|
private Class Gui;
|
2014-09-24 02:26:27 +02:00
|
|
|
private GuiHostType type;
|
|
|
|
private SecurityPermissions requiredPermission;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GuiBridge()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
this.Tile = null;
|
|
|
|
this.Gui = null;
|
|
|
|
this.Container = null;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GuiBridge( Class _Container, SecurityPermissions requiredPermission )
|
|
|
|
{
|
|
|
|
this.requiredPermission = requiredPermission;
|
|
|
|
this.Container = _Container;
|
|
|
|
this.Tile = null;
|
|
|
|
this.getGui();
|
|
|
|
}
|
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
/**
|
|
|
|
* I honestly wish I could just use the GuiClass Names myself, but I can't access them without MC's Server
|
|
|
|
* Exploding.
|
|
|
|
*/
|
|
|
|
private void getGui()
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( Platform.isClient() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-03-26 11:33:08 +01:00
|
|
|
final String start = this.Container.getName();
|
2015-03-26 13:57:08 +01:00
|
|
|
String guiClass = start.replaceFirst( "container.", "client.gui." ).replace( ".Container", ".Gui" );
|
2015-03-26 11:33:08 +01:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( start.equals( guiClass ) )
|
2015-03-23 10:14:35 +01:00
|
|
|
throw new IllegalStateException( "Unable to find gui class" );
|
2015-03-26 13:57:08 +01:00
|
|
|
this.Gui = ReflectionHelper.getClass( this.getClass().getClassLoader(), guiClass );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.Gui == null )
|
2015-03-23 10:14:35 +01:00
|
|
|
throw new IllegalStateException( "Cannot Load class: " + guiClass );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
GuiBridge( Class _Container, Class _Tile, GuiHostType type, SecurityPermissions requiredPermission )
|
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
this.requiredPermission = requiredPermission;
|
2014-12-29 15:13:47 +01:00
|
|
|
this.Container = _Container;
|
2014-09-24 02:26:27 +02:00
|
|
|
this.type = type;
|
2014-12-29 15:13:47 +01:00
|
|
|
this.Tile = _Tile;
|
|
|
|
this.getGui();
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public Object getServerGuiElement( int ID_ORDINAL, EntityPlayer player, World w, int x, int y, int z )
|
|
|
|
{
|
|
|
|
ForgeDirection side = ForgeDirection.getOrientation( ID_ORDINAL & 0x07 );
|
|
|
|
GuiBridge ID = values()[ID_ORDINAL >> 4];
|
|
|
|
boolean stem = ( ( ID_ORDINAL >> 3 ) & 1 ) == 1;
|
2015-03-03 11:51:05 +01:00
|
|
|
if( ID.type.isItem() )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2015-03-03 11:51:05 +01:00
|
|
|
ItemStack it = null;
|
|
|
|
if( stem )
|
|
|
|
{
|
|
|
|
it = player.inventory.getCurrentItem();
|
|
|
|
}
|
|
|
|
else if( x >= 0 && x < player.inventory.mainInventory.length )
|
|
|
|
{
|
|
|
|
it = player.inventory.getStackInSlot( x );
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
Object myItem = this.getGuiObject( it, player, w, x, y, z );
|
|
|
|
if( myItem != null && ID.CorrectTileOrPart( myItem ) )
|
|
|
|
return this.updateGui( ID.ConstructContainer( player.inventory, side, myItem ), w, x, y, z, side, myItem );
|
|
|
|
}
|
|
|
|
if( ID.type.isTile() )
|
|
|
|
{
|
|
|
|
TileEntity TE = w.getTileEntity( x, y, z );
|
|
|
|
if( TE instanceof IPartHost )
|
|
|
|
{
|
|
|
|
( (IPartHost) TE ).getPart( side );
|
|
|
|
IPart part = ( (IPartHost) TE ).getPart( side );
|
|
|
|
if( ID.CorrectTileOrPart( part ) )
|
|
|
|
return this.updateGui( ID.ConstructContainer( player.inventory, side, part ), w, x, y, z, side, part );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( ID.CorrectTileOrPart( TE ) )
|
|
|
|
return this.updateGui( ID.ConstructContainer( player.inventory, side, TE ), w, x, y, z, side, TE );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new ContainerNull();
|
|
|
|
}
|
|
|
|
|
|
|
|
private Object getGuiObject( ItemStack it, EntityPlayer player, World w, int x, int y, int z )
|
|
|
|
{
|
|
|
|
if( it != null )
|
|
|
|
{
|
|
|
|
if( it.getItem() instanceof IGuiItem )
|
|
|
|
{
|
|
|
|
return ( (IGuiItem) it.getItem() ).getGuiObject( it, w, x, y, z );
|
|
|
|
}
|
|
|
|
|
|
|
|
IWirelessTermHandler wh = AEApi.instance().registries().wireless().getWirelessTerminalHandler( it );
|
|
|
|
if( wh != null )
|
|
|
|
return new WirelessTerminalGuiObject( wh, it, player, w, x, y, z );
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean CorrectTileOrPart( Object tE )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.Tile == null )
|
2015-03-23 10:14:35 +01:00
|
|
|
throw new IllegalArgumentException( "This Gui Cannot use the standard Handler." );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.Tile.isInstance( tE );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
private Object updateGui( Object newContainer, World w, int x, int y, int z, ForgeDirection side, Object myItem )
|
|
|
|
{
|
|
|
|
if( newContainer instanceof AEBaseContainer )
|
|
|
|
{
|
|
|
|
AEBaseContainer bc = (AEBaseContainer) newContainer;
|
|
|
|
bc.openContext = new ContainerOpenContext( myItem );
|
|
|
|
bc.openContext.w = w;
|
|
|
|
bc.openContext.x = x;
|
|
|
|
bc.openContext.y = y;
|
|
|
|
bc.openContext.z = z;
|
|
|
|
bc.openContext.side = side;
|
|
|
|
}
|
|
|
|
|
|
|
|
return newContainer;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Object ConstructContainer( InventoryPlayer inventory, ForgeDirection side, Object tE )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
Constructor[] c = this.Container.getConstructors();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( c.length == 0 )
|
2014-09-24 02:26:27 +02:00
|
|
|
throw new AppEngException( "Invalid Gui Class" );
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
Constructor target = this.findConstructor( c, inventory, tE );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( target == null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-03-23 10:14:35 +01:00
|
|
|
throw new IllegalStateException( "Cannot find " + this.Container.getName() + "( " + this.typeName( inventory ) + ", " + this.typeName( tE ) + " )" );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Object o = target.newInstance( inventory, tE );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* triggers achievement when the player sees presses.
|
|
|
|
*/
|
2015-04-03 08:54:31 +02:00
|
|
|
if( o instanceof AEBaseContainer )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
AEBaseContainer bc = (AEBaseContainer) o;
|
2015-04-03 08:54:31 +02:00
|
|
|
for( Object so : bc.inventorySlots )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( so instanceof Slot )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
ItemStack is = ( (Slot) so ).getStack();
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-01-03 02:53:14 +01:00
|
|
|
final IMaterials materials = AEApi.instance().definitions().materials();
|
|
|
|
this.addPressAchievementToPlayer( is, materials, inventory.player );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return o;
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( Throwable t )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-03-23 10:14:35 +01:00
|
|
|
throw new IllegalStateException( t );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
private Constructor findConstructor( Constructor[] c, InventoryPlayer inventory, Object tE )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
for( Constructor con : c )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
Class[] types = con.getParameterTypes();
|
|
|
|
if( types.length == 2 )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( types[0].isAssignableFrom( inventory.getClass() ) && types[1].isAssignableFrom( tE.getClass() ) )
|
|
|
|
return con;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
return null;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
private String typeName( Object inventory )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( inventory == null )
|
2014-09-24 02:26:27 +02:00
|
|
|
return "NULL";
|
|
|
|
|
|
|
|
return inventory.getClass().getName();
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
private void addPressAchievementToPlayer( ItemStack newItem, IMaterials possibleMaterials, EntityPlayer player )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
final IComparableDefinition logic = possibleMaterials.logicProcessorPress();
|
|
|
|
final IComparableDefinition eng = possibleMaterials.engProcessorPress();
|
|
|
|
final IComparableDefinition calc = possibleMaterials.calcProcessorPress();
|
|
|
|
final IComparableDefinition silicon = possibleMaterials.siliconPress();
|
|
|
|
|
|
|
|
final List<IComparableDefinition> presses = Lists.newArrayList( logic, eng, calc, silicon );
|
|
|
|
|
|
|
|
for( IComparableDefinition press : presses )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( press.isSameAs( newItem ) )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
Achievements.Presses.addToPlayer( player );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public Object getClientGuiElement( int ID_ORDINAL, EntityPlayer player, World w, int x, int y, int z )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
ForgeDirection side = ForgeDirection.getOrientation( ID_ORDINAL & 0x07 );
|
|
|
|
GuiBridge ID = values()[ID_ORDINAL >> 4];
|
2015-04-03 08:54:31 +02:00
|
|
|
boolean stem = ( ( ID_ORDINAL >> 3 ) & 1 ) == 1;
|
2015-03-03 11:51:05 +01:00
|
|
|
if( ID.type.isItem() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-03-03 11:51:05 +01:00
|
|
|
ItemStack it = null;
|
|
|
|
if( stem )
|
|
|
|
{
|
|
|
|
it = player.inventory.getCurrentItem();
|
|
|
|
}
|
|
|
|
else if( x >= 0 && x < player.inventory.mainInventory.length )
|
|
|
|
{
|
|
|
|
it = player.inventory.getStackInSlot( x );
|
|
|
|
}
|
2014-12-29 15:13:47 +01:00
|
|
|
Object myItem = this.getGuiObject( it, player, w, x, y, z );
|
2015-03-03 11:51:05 +01:00
|
|
|
if( myItem != null && ID.CorrectTileOrPart( myItem ) )
|
2015-04-03 08:54:31 +02:00
|
|
|
return ID.ConstructGui( player.inventory, side, myItem );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ID.type.isTile() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
TileEntity TE = w.getTileEntity( x, y, z );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( TE instanceof IPartHost )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
( (IPartHost) TE ).getPart( side );
|
|
|
|
IPart part = ( (IPartHost) TE ).getPart( side );
|
|
|
|
if( ID.CorrectTileOrPart( part ) )
|
|
|
|
return ID.ConstructGui( player.inventory, side, part );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( ID.CorrectTileOrPart( TE ) )
|
|
|
|
return ID.ConstructGui( player.inventory, side, TE );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
return new GuiNull( new ContainerNull() );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public Object ConstructGui( InventoryPlayer inventory, ForgeDirection side, Object tE )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
try
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
Constructor[] c = this.Gui.getConstructors();
|
|
|
|
if( c.length == 0 )
|
|
|
|
throw new AppEngException( "Invalid Gui Class" );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
Constructor target = this.findConstructor( c, inventory, tE );
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( target == null )
|
|
|
|
{
|
2015-03-23 10:14:35 +01:00
|
|
|
throw new IllegalStateException( "Cannot find " + this.Container.getName() + "( " + this.typeName( inventory ) + ", " + this.typeName( tE ) + " )" );
|
2015-04-03 08:54:31 +02:00
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
return target.newInstance( inventory, tE );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
2015-04-03 08:54:31 +02:00
|
|
|
catch( Throwable t )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-03-23 10:14:35 +01:00
|
|
|
throw new IllegalStateException( t );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public boolean hasPermissions( TileEntity te, int x, int y, int z, ForgeDirection side, EntityPlayer player )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
World w = player.getEntityWorld();
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( Platform.hasPermissions( te != null ? new DimensionalCoord( te ) : new DimensionalCoord( player.worldObj, x, y, z ), player ) )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.type.isItem() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
ItemStack it = player.inventory.getCurrentItem();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( it != null && it.getItem() instanceof IGuiItem )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
Object myItem = ( (IGuiItem) it.getItem() ).getGuiObject( it, w, x, y, z );
|
|
|
|
if( this.CorrectTileOrPart( myItem ) )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.type.isTile() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
TileEntity TE = w.getTileEntity( x, y, z );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( TE instanceof IPartHost )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
( (IPartHost) TE ).getPart( side );
|
|
|
|
IPart part = ( (IPartHost) TE ).getPart( side );
|
|
|
|
if( this.CorrectTileOrPart( part ) )
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.securityCheck( part, player );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.CorrectTileOrPart( TE ) )
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.securityCheck( TE, player );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
private boolean securityCheck( Object te, EntityPlayer player )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( te instanceof IActionHost && this.requiredPermission != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
boolean requirePower = false;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
IGridNode gn = ( (IActionHost) te ).getActionableNode();
|
|
|
|
if( gn != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
IGrid g = gn.getGrid();
|
2015-04-03 08:54:31 +02:00
|
|
|
if( g != null )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( requirePower )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
IEnergyGrid eg = g.getCache( IEnergyGrid.class );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( !eg.isNetworkPowered() )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ISecurityGrid sg = g.getCache( ISecurityGrid.class );
|
2015-04-03 08:54:31 +02:00
|
|
|
if( sg.hasPermission( player, this.requiredPermission ) )
|
2014-09-24 02:26:27 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public GuiHostType getType()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.type;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|