11package com .cellterminal .container ;
22
3+ import appeng .api .config .Actionable ;
4+ import appeng .api .config .PowerMultiplier ;
5+ import com .cellterminal .integration .AE2WUTIntegration ;
6+ import com .cellterminal .items .ItemWirelessCellTerminal ;
7+ import com .cellterminal .util .AE2OldVersionSupport ;
38import net .minecraft .entity .player .EntityPlayer ;
49import net .minecraft .entity .player .InventoryPlayer ;
510import net .minecraft .item .ItemStack ;
611import net .minecraftforge .fml .common .Optional ;
712
813import appeng .api .AEApi ;
9- import appeng .api .config .Actionable ;
10- import appeng .api .features .ILocatable ;
1114import appeng .api .features .IWirelessTermHandler ;
12- import appeng .api .networking .IGridNode ;
13- import appeng .api .networking .security .IActionHost ;
1415import appeng .core .AEConfig ;
1516import appeng .core .localization .PlayerMessages ;
16- import appeng .util . Platform ;
17+ import appeng .helpers . WirelessTerminalGuiObject ;
1718
1819import baubles .api .BaublesApi ;
1920
20- import com .cellterminal .items .ItemWirelessCellTerminal ;
21-
2221
2322/**
2423 * Container for the Wireless Cell Terminal GUI.
2524 * Similar to ContainerCellTerminal but works with wireless connection.
2625 */
26+ @ Optional .Interface (iface = "appeng.helpers.WirelessTerminalGuiObject" , modid = "ae2wut" )
2727public class ContainerWirelessCellTerminal extends ContainerCellTerminalBase {
2828
29+ private final WirelessTerminalGuiObject wirelessTerminalGuiObject ;
2930 private final int slot ;
3031 private final boolean isBauble ;
31- private final ItemStack terminalStack ;
3232
3333 private int ticks = 0 ;
3434
35- public ContainerWirelessCellTerminal (InventoryPlayer ip , int slot , boolean isBauble ) {
36- super (ip , null );
37- this .slot = slot ;
38- this .isBauble = isBauble ;
39-
40- if (isBauble ) {
41- this .terminalStack = getBaubleStack (ip .player , slot );
42- } else {
43- this .terminalStack = ip .getStackInSlot (slot );
44- this .lockPlayerInventorySlot (slot );
45- }
46-
47- if (Platform .isServer () && !terminalStack .isEmpty ()) {
48- IWirelessTermHandler handler = AEApi .instance ().registries ().wireless ().getWirelessTerminalHandler (terminalStack );
49-
50- if (handler != null ) {
51- String encKey = handler .getEncryptionKey (terminalStack );
35+ public ContainerWirelessCellTerminal (InventoryPlayer ip , WirelessTerminalGuiObject wth ) {
36+ super (ip , wth );
5237
53- try {
54- long parsedKey = Long . parseLong ( encKey );
55- ILocatable obj = AEApi . instance (). registries (). locatable (). getLocatableBy ( parsedKey );
38+ this . wirelessTerminalGuiObject = wth ;
39+ this . slot = wth . getInventorySlot ( );
40+ this . isBauble = AE2OldVersionSupport . wirelessTerminalGuiObjectIsBauble ( wth , ip );
5641
57- if (obj instanceof IActionHost ) {
58- IGridNode n = ((IActionHost ) obj ).getActionableNode ();
59- if (n != null ) {
60- this .grid = n .getGrid ();
61- }
62- }
63- } catch (NumberFormatException e ) {
64- // Invalid key
65- }
66- }
67- }
42+ // Lock the slot if it's in the main inventory
43+ if (!isBauble && slot >= 0 && slot < ip .mainInventory .size ()) this .lockPlayerInventorySlot (slot );
6844
6945 this .bindPlayerInventory (ip , 0 , 0 );
7046 }
@@ -73,14 +49,27 @@ public ContainerWirelessCellTerminal(InventoryPlayer ip, int slot, boolean isBau
7349 private ItemStack getBaubleStack (EntityPlayer player , int baubleSlot ) {
7450 return BaublesApi .getBaublesHandler (player ).getStackInSlot (baubleSlot );
7551 }
52+ /**
53+ * Get the WirelessTerminalGuiObject for this container.
54+ * Used by the GUI to access WUT functionality.
55+ */
56+ public WirelessTerminalGuiObject getWirelessTerminalGuiObject () {
57+ return this .wirelessTerminalGuiObject ;
58+ }
59+
60+ private ItemStack getTerminalStack () {
61+ if (isBauble ) return getBaubleStack (getPlayerInv ().player , slot );
62+
63+ return getPlayerInv ().getStackInSlot (slot );
64+ }
65+
66+
7667
7768 @ Override
7869 protected boolean canSendUpdates () {
79- // Check terminal is still valid
80- ItemStack currentStack = isBauble ? getBaubleStack (getPlayerInv ().player , slot )
81- : getPlayerInv ().getStackInSlot (slot );
70+ ItemStack currentStack = getTerminalStack ();
8271
83- if (currentStack .isEmpty () || !(currentStack .getItem () instanceof ItemWirelessCellTerminal )) {
72+ if (currentStack .isEmpty () || !(currentStack .getItem () instanceof ItemWirelessCellTerminal || AE2WUTIntegration . isWirelessUniversalTerminal ( currentStack ) )) {
8473 this .setValidContainer (false );
8574
8675 return false ;
0 commit comments