2013-12-27 23:59:59 +01:00
|
|
|
package appeng.core.sync;
|
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
import static appeng.core.sync.GuiHostType.ITEM;
|
|
|
|
import static appeng.core.sync.GuiHostType.ITEM_OR_WORLD;
|
|
|
|
import static appeng.core.sync.GuiHostType.WORLD;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import java.lang.reflect.Constructor;
|
2013-12-28 22:03:20 +01:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
2014-01-20 17:41:37 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2013-12-27 23:59:59 +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-02-03 05:33:50 +01:00
|
|
|
import appeng.api.AEApi;
|
2014-02-01 06:37:27 +01:00
|
|
|
import appeng.api.config.SecurityPermissions;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.exceptions.AppEngException;
|
2014-02-03 05:33:50 +01:00
|
|
|
import appeng.api.features.IWirelessTermHandler;
|
2014-01-23 20:02:48 +01:00
|
|
|
import appeng.api.implementations.IUpgradeableHost;
|
|
|
|
import appeng.api.implementations.guiobjects.IGuiItem;
|
|
|
|
import appeng.api.implementations.guiobjects.INetworkTool;
|
2014-01-24 17:35:58 +01:00
|
|
|
import appeng.api.implementations.guiobjects.IPortableCell;
|
2014-02-01 06:37:27 +01:00
|
|
|
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;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.parts.IPart;
|
|
|
|
import appeng.api.parts.IPartHost;
|
2014-02-17 01:50:25 +01:00
|
|
|
import appeng.api.storage.ITerminalHost;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.client.gui.GuiNull;
|
2014-01-26 07:44:50 +01:00
|
|
|
import appeng.container.AEBaseContainer;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.container.ContainerNull;
|
2014-01-26 07:44:50 +01:00
|
|
|
import appeng.container.ContainerOpenContext;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.container.implementations.ContainerCellWorkbench;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.container.implementations.ContainerChest;
|
|
|
|
import appeng.container.implementations.ContainerCondenser;
|
2014-05-24 06:20:56 +02:00
|
|
|
import appeng.container.implementations.ContainerCraftAmount;
|
2014-06-18 08:23:37 +02:00
|
|
|
import appeng.container.implementations.ContainerCraftConfirm;
|
2014-06-26 03:49:37 +02:00
|
|
|
import appeng.container.implementations.ContainerCraftingCPU;
|
2014-08-05 05:33:26 +02:00
|
|
|
import appeng.container.implementations.ContainerCraftingStatus;
|
2014-02-05 03:44:54 +01:00
|
|
|
import appeng.container.implementations.ContainerCraftingTerm;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.container.implementations.ContainerDrive;
|
2014-02-18 06:51:31 +01:00
|
|
|
import appeng.container.implementations.ContainerFormationPlane;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.container.implementations.ContainerGrinder;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.container.implementations.ContainerIOPort;
|
2014-03-07 07:15:54 +01:00
|
|
|
import appeng.container.implementations.ContainerInscriber;
|
2013-12-28 22:03:20 +01:00
|
|
|
import appeng.container.implementations.ContainerInterface;
|
2014-07-08 05:48:21 +02:00
|
|
|
import appeng.container.implementations.ContainerInterfaceTerminal;
|
2014-01-05 09:39:48 +01:00
|
|
|
import appeng.container.implementations.ContainerLevelEmitter;
|
2014-04-24 08:14:26 +02:00
|
|
|
import appeng.container.implementations.ContainerMAC;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.container.implementations.ContainerMEMonitorable;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.container.implementations.ContainerMEPortableCell;
|
2014-01-23 17:28:12 +01:00
|
|
|
import appeng.container.implementations.ContainerNetworkStatus;
|
|
|
|
import appeng.container.implementations.ContainerNetworkTool;
|
2014-04-08 02:43:57 +02:00
|
|
|
import appeng.container.implementations.ContainerPatternTerm;
|
2014-01-26 07:44:50 +01:00
|
|
|
import appeng.container.implementations.ContainerPriority;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.container.implementations.ContainerQNB;
|
2014-03-07 04:02:15 +01:00
|
|
|
import appeng.container.implementations.ContainerQuartzKnife;
|
2014-01-26 07:44:50 +01:00
|
|
|
import appeng.container.implementations.ContainerSecurity;
|
2014-02-28 09:12:00 +01:00
|
|
|
import appeng.container.implementations.ContainerSkyChest;
|
2014-03-05 08:27:42 +01:00
|
|
|
import appeng.container.implementations.ContainerSpatialIOPort;
|
2014-01-24 17:35:58 +01:00
|
|
|
import appeng.container.implementations.ContainerStorageBus;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.container.implementations.ContainerUpgradeable;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.container.implementations.ContainerVibrationChamber;
|
2014-02-04 05:23:14 +01:00
|
|
|
import appeng.container.implementations.ContainerWireless;
|
2014-02-03 05:33:50 +01:00
|
|
|
import appeng.container.implementations.ContainerWirelessTerm;
|
2014-01-05 09:39:48 +01:00
|
|
|
import appeng.helpers.IInterfaceHost;
|
2014-01-26 07:44:50 +01:00
|
|
|
import appeng.helpers.IPriorityHost;
|
2014-02-03 05:33:50 +01:00
|
|
|
import appeng.helpers.WirelessTerminalGuiObject;
|
2014-03-07 04:02:15 +01:00
|
|
|
import appeng.items.contents.QuartzKnifeObj;
|
2014-02-18 06:51:31 +01:00
|
|
|
import appeng.parts.automation.PartFormationPlane;
|
2014-01-05 09:39:48 +01:00
|
|
|
import appeng.parts.automation.PartLevelEmitter;
|
2014-01-24 17:35:58 +01:00
|
|
|
import appeng.parts.misc.PartStorageBus;
|
2014-02-05 03:44:54 +01:00
|
|
|
import appeng.parts.reporting.PartCraftingTerminal;
|
2014-07-08 05:48:21 +02:00
|
|
|
import appeng.parts.reporting.PartMonitor;
|
2014-04-08 02:43:57 +02:00
|
|
|
import appeng.parts.reporting.PartPatternTerminal;
|
2014-02-01 06:37:27 +01:00
|
|
|
import appeng.server.AccessType;
|
2014-06-26 03:49:37 +02:00
|
|
|
import appeng.tile.crafting.TileCraftingTile;
|
2014-04-24 08:14:26 +02:00
|
|
|
import appeng.tile.crafting.TileMolecularAssembler;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.tile.grindstone.TileGrinder;
|
2014-01-06 07:54:25 +01:00
|
|
|
import appeng.tile.misc.TileCellWorkbench;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.tile.misc.TileCondenser;
|
2014-03-07 07:15:54 +01:00
|
|
|
import appeng.tile.misc.TileInscriber;
|
2014-01-26 07:44:50 +01:00
|
|
|
import appeng.tile.misc.TileSecurity;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.tile.misc.TileVibrationChamber;
|
2014-02-04 05:23:14 +01:00
|
|
|
import appeng.tile.networking.TileWireless;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.tile.qnb.TileQuantumBridge;
|
2014-03-05 08:27:42 +01:00
|
|
|
import appeng.tile.spatial.TileSpatialIOPort;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.tile.storage.TileChest;
|
|
|
|
import appeng.tile.storage.TileDrive;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.tile.storage.TileIOPort;
|
2014-02-28 09:12:00 +01:00
|
|
|
import appeng.tile.storage.TileSkyChest;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.util.Platform;
|
|
|
|
import cpw.mods.fml.common.network.IGuiHandler;
|
|
|
|
import cpw.mods.fml.relauncher.ReflectionHelper;
|
|
|
|
|
|
|
|
public enum GuiBridge implements IGuiHandler
|
|
|
|
{
|
|
|
|
GUI_Handler(),
|
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
GUI_GRINDER(ContainerGrinder.class, TileGrinder.class, WORLD, null),
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
GUI_QNB(ContainerQNB.class, TileQuantumBridge.class, WORLD, SecurityPermissions.BUILD),
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
GUI_SKYCHEST(ContainerSkyChest.class, TileSkyChest.class, WORLD, null),
|
2014-02-28 09:12:00 +01:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
GUI_CHEST(ContainerChest.class, TileChest.class, WORLD, SecurityPermissions.BUILD),
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
GUI_WIRELESS(ContainerWireless.class, TileWireless.class, WORLD, SecurityPermissions.BUILD),
|
2014-02-04 05:23:14 +01:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
GUI_ME(ContainerMEMonitorable.class, ITerminalHost.class, WORLD, null),
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
GUI_PORTABLE_CELL(ContainerMEPortableCell.class, IPortableCell.class, ITEM, null),
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
GUI_WIRELESS_TERM(ContainerWirelessTerm.class, WirelessTerminalGuiObject.class, ITEM, null),
|
2014-02-03 05:33:50 +01:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
GUI_NETWORK_STATUS(ContainerNetworkStatus.class, INetworkTool.class, ITEM, null),
|
2014-01-23 17:28:12 +01:00
|
|
|
|
2014-06-26 03:49:37 +02:00
|
|
|
GUI_CRAFTING_CPU(ContainerCraftingCPU.class, TileCraftingTile.class, WORLD, SecurityPermissions.CRAFT),
|
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
GUI_NETWORK_TOOL(ContainerNetworkTool.class, INetworkTool.class, ITEM, null),
|
2014-01-23 17:28:12 +01:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
GUI_QUARTZ_KNIFE(ContainerQuartzKnife.class, QuartzKnifeObj.class, ITEM, null),
|
2014-03-07 04:02:15 +01:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
GUI_DRIVE(ContainerDrive.class, TileDrive.class, WORLD, SecurityPermissions.BUILD),
|
2013-12-28 22:03:20 +01:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
GUI_VIBRATIONCHAMBER(ContainerVibrationChamber.class, TileVibrationChamber.class, WORLD, null),
|
2013-12-30 06:56:43 +01:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
GUI_CONDENSER(ContainerCondenser.class, TileCondenser.class, WORLD, null),
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
GUI_INTERFACE(ContainerInterface.class, IInterfaceHost.class, WORLD, SecurityPermissions.BUILD),
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
GUI_BUS(ContainerUpgradeable.class, IUpgradeableHost.class, WORLD, SecurityPermissions.BUILD),
|
2014-01-20 17:41:37 +01:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
GUI_IOPORT(ContainerIOPort.class, TileIOPort.class, WORLD, SecurityPermissions.BUILD),
|
2014-01-05 09:39:48 +01:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
GUI_STORAGEBUS(ContainerStorageBus.class, PartStorageBus.class, WORLD, SecurityPermissions.BUILD),
|
2014-01-24 17:35:58 +01:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
GUI_FPLANE(ContainerFormationPlane.class, PartFormationPlane.class, WORLD, SecurityPermissions.BUILD),
|
2014-02-18 06:51:31 +01:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
GUI_PRIORITY(ContainerPriority.class, IPriorityHost.class, WORLD, SecurityPermissions.BUILD),
|
2014-01-26 07:44:50 +01:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
GUI_SECURITY(ContainerSecurity.class, TileSecurity.class, WORLD, SecurityPermissions.SECURITY),
|
2014-01-26 07:44:50 +01:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
GUI_CRAFTING_TERMINAL(ContainerCraftingTerm.class, PartCraftingTerminal.class, WORLD, SecurityPermissions.CRAFT),
|
2014-02-05 03:44:54 +01:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
GUI_PATTERN_TERMINAL(ContainerPatternTerm.class, PartPatternTerminal.class, WORLD, SecurityPermissions.CRAFT),
|
2014-04-08 02:43:57 +02:00
|
|
|
|
2014-01-05 09:39:48 +01:00
|
|
|
// extends (Container/Gui) + Bus
|
2014-05-24 06:20:56 +02:00
|
|
|
GUI_LEVELEMITTER(ContainerLevelEmitter.class, PartLevelEmitter.class, WORLD, SecurityPermissions.BUILD),
|
|
|
|
|
|
|
|
GUI_SPATIALIOPORT(ContainerSpatialIOPort.class, TileSpatialIOPort.class, WORLD, SecurityPermissions.BUILD),
|
2014-01-06 07:54:25 +01:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
GUI_INSCRIBER(ContainerInscriber.class, TileInscriber.class, WORLD, null),
|
2014-03-05 08:27:42 +01:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
GUI_CELLWORKBENCH(ContainerCellWorkbench.class, TileCellWorkbench.class, WORLD, null),
|
2014-03-05 08:27:42 +01:00
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
GUI_MAC(ContainerMAC.class, TileMolecularAssembler.class, WORLD, null),
|
2014-04-24 08:14:26 +02:00
|
|
|
|
2014-06-18 08:23:37 +02:00
|
|
|
GUI_CRAFTING_AMOUNT(ContainerCraftAmount.class, ITerminalHost.class, ITEM_OR_WORLD, SecurityPermissions.CRAFT),
|
|
|
|
|
2014-07-08 05:48:21 +02:00
|
|
|
GUI_CRAFTING_CONFIRM(ContainerCraftConfirm.class, ITerminalHost.class, ITEM_OR_WORLD, SecurityPermissions.CRAFT),
|
|
|
|
|
2014-08-05 05:33:26 +02:00
|
|
|
GUI_INTERFACE_TERMINAL(ContainerInterfaceTerminal.class, PartMonitor.class, WORLD, SecurityPermissions.BUILD),
|
|
|
|
|
|
|
|
GUI_CRAFTING_STATUS(ContainerCraftingStatus.class, ITerminalHost.class, ITEM_OR_WORLD, SecurityPermissions.CRAFT);
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
private Class Tile;
|
|
|
|
private Class Gui;
|
|
|
|
private Class Container;
|
2014-05-24 06:20:56 +02:00
|
|
|
private GuiHostType type;
|
2014-02-01 06:37:27 +01:00
|
|
|
private SecurityPermissions requiredPermission;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
private GuiBridge() {
|
|
|
|
Tile = null;
|
|
|
|
Gui = null;
|
|
|
|
Container = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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()
|
|
|
|
{
|
|
|
|
if ( Platform.isClient() )
|
|
|
|
{
|
|
|
|
String start = Container.getName();
|
|
|
|
String GuiClass = start.replaceFirst( "container.", "client.gui." ).replace( ".Container", ".Gui" );
|
|
|
|
if ( start.equals( GuiClass ) )
|
|
|
|
throw new RuntimeException( "Unable to find gui class" );
|
|
|
|
Gui = ReflectionHelper.getClass( this.getClass().getClassLoader(), GuiClass );
|
|
|
|
if ( Gui == null )
|
|
|
|
throw new RuntimeException( "Cannot Load class: " + GuiClass );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-01 06:37:27 +01:00
|
|
|
private GuiBridge(Class _Container, SecurityPermissions requiredPermission) {
|
|
|
|
this.requiredPermission = requiredPermission;
|
2013-12-27 23:59:59 +01:00
|
|
|
Container = _Container;
|
|
|
|
Tile = null;
|
|
|
|
getGui();
|
|
|
|
}
|
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
private GuiBridge(Class _Container, Class _Tile, GuiHostType type, SecurityPermissions requiredPermission) {
|
2014-02-01 06:37:27 +01:00
|
|
|
this.requiredPermission = requiredPermission;
|
2013-12-27 23:59:59 +01:00
|
|
|
Container = _Container;
|
2014-05-24 06:20:56 +02:00
|
|
|
this.type = type;
|
2013-12-27 23:59:59 +01:00
|
|
|
Tile = _Tile;
|
|
|
|
getGui();
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean CorrectTileOrPart(Object tE)
|
|
|
|
{
|
|
|
|
if ( Tile == null )
|
|
|
|
throw new RuntimeException( "This Gui Cannot use the standard Handler." );
|
|
|
|
|
|
|
|
return Tile.isInstance( tE );
|
|
|
|
}
|
|
|
|
|
|
|
|
public Object ConstructContainer(InventoryPlayer inventory, ForgeDirection side, Object tE)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Constructor[] c = Container.getConstructors();
|
|
|
|
if ( c.length == 0 )
|
|
|
|
throw new AppEngException( "Invalid Gui Class" );
|
2014-04-09 05:12:01 +02:00
|
|
|
|
|
|
|
Constructor target = findConstructor( c, inventory, tE );
|
|
|
|
|
|
|
|
if ( target == null )
|
|
|
|
{
|
2014-04-09 05:14:03 +02:00
|
|
|
throw new RuntimeException( "Cannot find " + Container.getName() + "( " + typeName( inventory ) + ", " + typeName( tE ) + " )" );
|
2014-04-09 05:12:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return target.newInstance( inventory, tE );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
catch (Throwable t)
|
|
|
|
{
|
|
|
|
throw new RuntimeException( t );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-28 22:03:20 +01:00
|
|
|
public Object ConstructGui(InventoryPlayer inventory, ForgeDirection side, Object tE)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
Constructor[] c = Gui.getConstructors();
|
|
|
|
if ( c.length == 0 )
|
|
|
|
throw new AppEngException( "Invalid Gui Class" );
|
2014-02-11 06:52:19 +01:00
|
|
|
|
2014-04-09 05:12:01 +02:00
|
|
|
Constructor target = findConstructor( c, inventory, tE );
|
|
|
|
|
|
|
|
if ( target == null )
|
|
|
|
{
|
2014-04-09 05:14:03 +02:00
|
|
|
throw new RuntimeException( "Cannot find " + Container.getName() + "( " + typeName( inventory ) + ", " + typeName( tE ) + " )" );
|
2014-04-09 05:12:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return target.newInstance( inventory, tE );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
catch (Throwable t)
|
|
|
|
{
|
|
|
|
throw new RuntimeException( t );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-09 05:12:01 +02:00
|
|
|
private String typeName(Object inventory)
|
|
|
|
{
|
|
|
|
if ( inventory == null )
|
|
|
|
return "NULL";
|
|
|
|
|
|
|
|
return inventory.getClass().getName();
|
|
|
|
}
|
|
|
|
|
2014-02-11 06:52:19 +01:00
|
|
|
private Constructor findConstructor(Constructor[] c, InventoryPlayer inventory, Object tE)
|
|
|
|
{
|
|
|
|
for (Constructor con : c)
|
|
|
|
{
|
|
|
|
Class[] types = con.getParameterTypes();
|
|
|
|
if ( types.length == 2 )
|
|
|
|
{
|
2014-04-09 06:26:04 +02:00
|
|
|
if ( types[0].isAssignableFrom( inventory.getClass() ) && types[1].isAssignableFrom( tE.getClass() ) )
|
2014-02-11 06:52:19 +01:00
|
|
|
return con;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-07-29 04:51:52 +02:00
|
|
|
private Object updateGui(Object newContainer, World w, int x, int y, int z, ForgeDirection side, Object myItem)
|
2014-01-26 07:44:50 +01:00
|
|
|
{
|
|
|
|
if ( newContainer instanceof AEBaseContainer )
|
|
|
|
{
|
|
|
|
AEBaseContainer bc = (AEBaseContainer) newContainer;
|
2014-07-29 04:51:52 +02:00
|
|
|
bc.openContext = new ContainerOpenContext( myItem );
|
2014-01-26 07:44:50 +01:00
|
|
|
bc.openContext.w = w;
|
|
|
|
bc.openContext.x = x;
|
|
|
|
bc.openContext.y = y;
|
|
|
|
bc.openContext.z = z;
|
|
|
|
bc.openContext.side = side;
|
|
|
|
}
|
|
|
|
|
|
|
|
return newContainer;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
|
|
|
public Object getServerGuiElement(int ID_ORDINAL, EntityPlayer player, World w, int x, int y, int z)
|
|
|
|
{
|
2013-12-28 22:03:20 +01:00
|
|
|
ForgeDirection side = ForgeDirection.getOrientation( ID_ORDINAL & 0x07 );
|
2014-08-09 04:18:54 +02:00
|
|
|
GuiBridge ID = values()[ID_ORDINAL >> 4];
|
|
|
|
boolean istem = ((ID_ORDINAL >> 3) & 1) == 1;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-08-09 04:18:54 +02:00
|
|
|
if ( ID.type.isItem() && istem )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
ItemStack it = player.inventory.getCurrentItem();
|
2014-02-03 05:33:50 +01:00
|
|
|
Object myItem = getGuiObject( it, player, w, x, y, z );
|
|
|
|
if ( myItem != null && ID.CorrectTileOrPart( myItem ) )
|
2014-07-29 04:51:52 +02:00
|
|
|
return updateGui( ID.ConstructContainer( player.inventory, side, myItem ), w, x, y, z, side, myItem );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2014-05-24 06:20:56 +02:00
|
|
|
|
|
|
|
if ( ID.type.isTile() )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
TileEntity TE = w.getTileEntity( x, y, z );
|
2014-01-20 17:41:37 +01:00
|
|
|
if ( TE instanceof IPartHost )
|
|
|
|
{
|
|
|
|
((IPartHost) TE).getPart( side );
|
|
|
|
IPart part = ((IPartHost) TE).getPart( side );
|
|
|
|
if ( ID.CorrectTileOrPart( part ) )
|
2014-07-29 04:51:52 +02:00
|
|
|
return updateGui( ID.ConstructContainer( player.inventory, side, part ), w, x, y, z, side, part );
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( ID.CorrectTileOrPart( TE ) )
|
2014-07-29 04:51:52 +02:00
|
|
|
return updateGui( ID.ConstructContainer( player.inventory, side, TE ), w, x, y, z, side, TE );
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2013-12-28 22:03:20 +01:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
return new ContainerNull();
|
|
|
|
}
|
|
|
|
|
2014-02-03 05:33:50 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
|
|
|
public Object getClientGuiElement(int ID_ORDINAL, EntityPlayer player, World w, int x, int y, int z)
|
|
|
|
{
|
2013-12-28 22:03:20 +01:00
|
|
|
ForgeDirection side = ForgeDirection.getOrientation( ID_ORDINAL & 0x07 );
|
2014-08-09 04:18:54 +02:00
|
|
|
GuiBridge ID = values()[ID_ORDINAL >> 4];
|
|
|
|
boolean istem = ((ID_ORDINAL >> 3) & 1) == 1;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-08-09 04:18:54 +02:00
|
|
|
if ( ID.type.isItem() && istem )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-01-20 17:41:37 +01:00
|
|
|
ItemStack it = player.inventory.getCurrentItem();
|
2014-02-03 05:33:50 +01:00
|
|
|
Object myItem = getGuiObject( it, player, w, x, y, z );
|
|
|
|
if ( ID.CorrectTileOrPart( myItem ) )
|
|
|
|
return ID.ConstructGui( player.inventory, side, myItem );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2014-05-24 06:20:56 +02:00
|
|
|
|
|
|
|
if ( ID.type.isTile() )
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
TileEntity TE = w.getTileEntity( x, y, z );
|
2014-01-20 17:41:37 +01:00
|
|
|
|
|
|
|
if ( TE instanceof IPartHost )
|
|
|
|
{
|
|
|
|
((IPartHost) TE).getPart( side );
|
|
|
|
IPart part = ((IPartHost) TE).getPart( side );
|
|
|
|
if ( ID.CorrectTileOrPart( part ) )
|
|
|
|
return ID.ConstructGui( player.inventory, side, part );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( ID.CorrectTileOrPart( TE ) )
|
|
|
|
return ID.ConstructGui( player.inventory, side, TE );
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
2013-12-28 22:03:20 +01:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
return new GuiNull( new ContainerNull() );
|
|
|
|
}
|
|
|
|
|
2014-02-01 06:37:27 +01:00
|
|
|
public boolean hasPermissions(TileEntity te, int x, int y, int z, ForgeDirection side, EntityPlayer player)
|
|
|
|
{
|
|
|
|
World w = player.getEntityWorld();
|
|
|
|
|
|
|
|
if ( Platform.hasPermissions( x, y, z, player, AccessType.BLOCK_ACCESS ) )
|
|
|
|
{
|
2014-05-24 06:20:56 +02:00
|
|
|
if ( type.isItem() )
|
2014-02-01 06:37:27 +01:00
|
|
|
{
|
|
|
|
ItemStack it = player.inventory.getCurrentItem();
|
|
|
|
if ( it != null && it.getItem() instanceof IGuiItem )
|
|
|
|
{
|
|
|
|
Object myItem = ((IGuiItem) it.getItem()).getGuiObject( it, w, x, y, z );
|
|
|
|
if ( CorrectTileOrPart( myItem ) )
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-05-24 06:20:56 +02:00
|
|
|
|
|
|
|
if ( type.isTile() )
|
2014-02-01 06:37:27 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
TileEntity TE = w.getTileEntity( x, y, z );
|
2014-02-01 06:37:27 +01:00
|
|
|
if ( TE instanceof IPartHost )
|
|
|
|
{
|
|
|
|
((IPartHost) TE).getPart( side );
|
|
|
|
IPart part = ((IPartHost) TE).getPart( side );
|
|
|
|
if ( CorrectTileOrPart( part ) )
|
|
|
|
return securityCheck( part, player );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if ( CorrectTileOrPart( TE ) )
|
|
|
|
return securityCheck( TE, player );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean securityCheck(Object te, EntityPlayer player)
|
|
|
|
{
|
|
|
|
if ( te instanceof IActionHost && requiredPermission != null )
|
|
|
|
{
|
|
|
|
boolean requirePower = false;
|
|
|
|
|
|
|
|
IGridNode gn = ((IActionHost) te).getActionableNode();
|
|
|
|
if ( gn != null )
|
|
|
|
{
|
|
|
|
IGrid g = gn.getGrid();
|
|
|
|
if ( g != null )
|
|
|
|
{
|
|
|
|
if ( requirePower )
|
|
|
|
{
|
|
|
|
IEnergyGrid eg = g.getCache( IEnergyGrid.class );
|
|
|
|
if ( !eg.isNetworkPowered() )
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ISecurityGrid sg = g.getCache( ISecurityGrid.class );
|
|
|
|
if ( sg.hasPermission( player, requiredPermission ) )
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-05-24 06:20:56 +02:00
|
|
|
public GuiHostType getType()
|
|
|
|
{
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|