From 8b81545abf6e3dd2226b886e4d31d875a3194b59 Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Sun, 2 Feb 2014 23:02:54 -0600 Subject: [PATCH] Wireless Terminal Gui Works, dose not support range, or WAPs --- .../gui/implementations/GuiMEMonitorable.java | 3 + .../gui/implementations/GuiWirelessTerm.java | 1 + .../ContainerMEMonitorable.java | 37 ++++---- .../ContainerWirelessTerm.java | 19 +++- .../features/registries/WirelessRegistry.java | 3 + core/localization/GuiText.java | 2 +- core/localization/PlayerMessages.java | 4 +- helpers/WirelessTerminalGuiObject.java | 88 +++++++++++++++---- 8 files changed, 121 insertions(+), 36 deletions(-) diff --git a/client/gui/implementations/GuiMEMonitorable.java b/client/gui/implementations/GuiMEMonitorable.java index 8c329467..1a3802f7 100644 --- a/client/gui/implementations/GuiMEMonitorable.java +++ b/client/gui/implementations/GuiMEMonitorable.java @@ -19,6 +19,7 @@ import appeng.container.implementations.ContainerMEMonitorable; import appeng.container.slot.AppEngSlot; import appeng.core.Configuration; import appeng.core.localization.GuiText; +import appeng.helpers.WirelessTerminalGuiObject; import appeng.parts.reporting.PartTerminal; import appeng.tile.misc.TileSecurity; import appeng.util.Platform; @@ -52,6 +53,8 @@ public class GuiMEMonitorable extends AEBaseMEGui if ( te instanceof TileSecurity ) myName = GuiText.Security; + else if ( te instanceof WirelessTerminalGuiObject ) + myName = GuiText.WirelessTerminal; else if ( te instanceof IPortableCell ) myName = GuiText.PortableCell; else if ( te instanceof IMEChest ) diff --git a/client/gui/implementations/GuiWirelessTerm.java b/client/gui/implementations/GuiWirelessTerm.java index 51adb7fc..bc4eaebf 100644 --- a/client/gui/implementations/GuiWirelessTerm.java +++ b/client/gui/implementations/GuiWirelessTerm.java @@ -8,6 +8,7 @@ public class GuiWirelessTerm extends GuiMEPortableCell public GuiWirelessTerm(InventoryPlayer inventoryPlayer, IPortableCell te) { super( inventoryPlayer, te ); + maxRows = Integer.MAX_VALUE; } } diff --git a/container/implementations/ContainerMEMonitorable.java b/container/implementations/ContainerMEMonitorable.java index 919ea68d..397099c8 100644 --- a/container/implementations/ContainerMEMonitorable.java +++ b/container/implementations/ContainerMEMonitorable.java @@ -40,24 +40,29 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IMEMonito if ( Platform.isServer() ) { monitor = montiorable.getItemInventory(); - monitor.addListener( this, null ); - - cellInv = monitor; - - if ( montiorable instanceof IPortableCell ) - powerSrc = (IPortableCell) montiorable; - else if ( montiorable instanceof IMEChest ) - powerSrc = (IMEChest) montiorable; - else if ( montiorable instanceof IGridHost ) + if ( monitor != null ) { - IGridNode node = ((IGridHost) montiorable).getGridNode( ForgeDirection.UNKNOWN ); - if ( node != null ) + monitor.addListener( this, null ); + + cellInv = monitor; + + if ( montiorable instanceof IPortableCell ) + powerSrc = (IPortableCell) montiorable; + else if ( montiorable instanceof IMEChest ) + powerSrc = (IMEChest) montiorable; + else if ( montiorable instanceof IGridHost ) { - IGrid g = node.getGrid(); - if ( g != null ) - powerSrc = g.getCache( IEnergyGrid.class ); + IGridNode node = ((IGridHost) montiorable).getGridNode( ForgeDirection.UNKNOWN ); + if ( node != null ) + { + IGrid g = node.getGrid(); + if ( g != null ) + powerSrc = g.getCache( IEnergyGrid.class ); + } } } + else + ip.player.closeScreen(); } else monitor = null; @@ -122,7 +127,7 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IMEMonito { super.addCraftingToCrafters( c ); - if ( Platform.isServer() && c instanceof Player ) + if ( Platform.isServer() && c instanceof Player && monitor != null ) { try { @@ -168,7 +173,7 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IMEMonito { super.removeCraftingFromCrafters( c ); - if ( this.crafters.isEmpty() ) + if ( this.crafters.isEmpty() && monitor != null ) monitor.removeListener( this ); } diff --git a/container/implementations/ContainerWirelessTerm.java b/container/implementations/ContainerWirelessTerm.java index 411c2c63..caf087a3 100644 --- a/container/implementations/ContainerWirelessTerm.java +++ b/container/implementations/ContainerWirelessTerm.java @@ -1,13 +1,28 @@ package appeng.container.implementations; import net.minecraft.entity.player.InventoryPlayer; -import appeng.api.implementations.guiobjects.IPortableCell; +import appeng.core.localization.PlayerMessages; +import appeng.helpers.WirelessTerminalGuiObject; public class ContainerWirelessTerm extends ContainerMEPortableCell { - public ContainerWirelessTerm(InventoryPlayer ip, IPortableCell montiorable) { + WirelessTerminalGuiObject wtgo; + + public ContainerWirelessTerm(InventoryPlayer ip, WirelessTerminalGuiObject montiorable) { super( ip, montiorable ); + wtgo = montiorable; } + @Override + public void detectAndSendChanges() + { + super.detectAndSendChanges(); + + if ( !wtgo.rangeCheck() ) + { + getPlayerInv().player.closeScreen(); + getPlayerInv().player.sendChatToPlayer( PlayerMessages.OutOfRange.get() ); + } + } } diff --git a/core/features/registries/WirelessRegistry.java b/core/features/registries/WirelessRegistry.java index d02afe60..7f77ac56 100644 --- a/core/features/registries/WirelessRegistry.java +++ b/core/features/registries/WirelessRegistry.java @@ -8,6 +8,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.world.World; import appeng.api.features.IWirelessTermHandler; import appeng.api.features.IWirelessTermRegistery; +import appeng.core.localization.PlayerMessages; import appeng.core.sync.GuiBridge; import appeng.util.Platform; @@ -66,6 +67,8 @@ public class WirelessRegistry implements IWirelessTermRegistery { Platform.openGUI( player, null, null, GuiBridge.GUI_WIRELESS_TERM ); } + else + player.sendChatToPlayer( PlayerMessages.DeviceNotPowered.get() ); } diff --git a/core/localization/GuiText.java b/core/localization/GuiText.java index 0a9682f1..e51d54f5 100644 --- a/core/localization/GuiText.java +++ b/core/localization/GuiText.java @@ -21,7 +21,7 @@ public enum GuiText StorageBus, Priority, Security, Encoded, Blank, Unlinked, Linked, - SecurityCardEditor, NoPermissions, + SecurityCardEditor, NoPermissions, WirelessTerminal, METunnel, ItemTunnel, RedstoneTunnel, MJTunnel, EUTunnel, FluidTunnel; diff --git a/core/localization/PlayerMessages.java b/core/localization/PlayerMessages.java index 1a4e2cb8..8342b297 100644 --- a/core/localization/PlayerMessages.java +++ b/core/localization/PlayerMessages.java @@ -5,7 +5,9 @@ import appeng.core.AELog; public enum PlayerMessages { - ChestCannotReadStorageCell, InvalidMachine, LoadedSettings, SavedSettings, MachineNotPowered, isNowLocked, isNowUnlocked, AmmoDepleted, CommunicationError; + ChestCannotReadStorageCell, InvalidMachine, LoadedSettings, SavedSettings, MachineNotPowered, + + isNowLocked, isNowUnlocked, AmmoDepleted, CommunicationError, OutOfRange, DeviceNotPowered; private PlayerMessages() { AELog.localization( "chat", getName() ); diff --git a/helpers/WirelessTerminalGuiObject.java b/helpers/WirelessTerminalGuiObject.java index 3f250281..2996527f 100644 --- a/helpers/WirelessTerminalGuiObject.java +++ b/helpers/WirelessTerminalGuiObject.java @@ -3,12 +3,16 @@ package appeng.helpers; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.world.World; +import net.minecraftforge.common.ForgeDirection; +import appeng.api.AEApi; import appeng.api.config.AccessRestriction; import appeng.api.config.Actionable; import appeng.api.config.PowerMultiplier; import appeng.api.features.IWirelessTermHandler; import appeng.api.implementations.guiobjects.IPortableCell; import appeng.api.networking.IGrid; +import appeng.api.networking.IGridHost; +import appeng.api.networking.IGridNode; import appeng.api.networking.security.BaseActionSource; import appeng.api.networking.storage.IStorageGrid; import appeng.api.storage.IMEMonitor; @@ -36,104 +40,156 @@ public class WirelessTerminalGuiObject implements IPortableCell effectiveItem = is; myPlayer = ep; wth = wh; + + long encKey = Long.parseLong( encryptionKey ); + Object obj = AEApi.instance().registries().locateable().findLocateableBySerial( encKey ); + if ( obj instanceof IGridHost ) + { + IGridNode n = ((IGridHost) obj).getGridNode( ForgeDirection.UNKNOWN ); + if ( n != null ) + { + targetGrid = n.getGrid(); + if ( targetGrid != null ) + { + sg = targetGrid.getCache( IStorageGrid.class ); + if ( sg != null ) + itemStorage = sg.getItemInventory(); + } + } + } } - boolean rangeCheck() + public boolean rangeCheck() { + if ( targetGrid != null && itemStorage != null ) + { + + return true; + } return false; } @Override public IMEMonitor getItemInventory() { + if ( sg == null ) + return null; return sg.getItemInventory(); } @Override public IMEMonitor getFluidInventory() { + if ( sg == null ) + return null; return sg.getFluidInventory(); } @Override public void addListener(IMEMonitorHandlerReciever l, Object verificationToken) { - itemStorage.addListener( l, verificationToken ); + if ( itemStorage != null ) + itemStorage.addListener( l, verificationToken ); } @Override public void removeListener(IMEMonitorHandlerReciever l) { - itemStorage.removeListener( l ); + if ( itemStorage != null ) + itemStorage.removeListener( l ); } @SuppressWarnings("deprecation") @Override public IItemList getAvailableItems(IItemList out) { - return itemStorage.getAvailableItems( out ); + if ( itemStorage != null ) + return itemStorage.getAvailableItems( out ); + return out; } @Override public IItemList getStorageList() { - return itemStorage.getStorageList(); + if ( itemStorage != null ) + return itemStorage.getStorageList(); + return null; } @Override public AccessRestriction getAccess() { - return itemStorage.getAccess(); + if ( itemStorage != null ) + return itemStorage.getAccess(); + return AccessRestriction.NO_ACCESS; } @Override public boolean isPrioritized(IAEItemStack input) { - return itemStorage.isPrioritized( input ); + if ( itemStorage != null ) + return itemStorage.isPrioritized( input ); + return false; } @Override public boolean canAccept(IAEItemStack input) { - return itemStorage.canAccept( input ); + if ( itemStorage != null ) + return itemStorage.canAccept( input ); + return false; } @Override public int getPriority() { - return itemStorage.getPriority(); + if ( itemStorage != null ) + return itemStorage.getPriority(); + return 0; } @Override public int getSlot() { - return itemStorage.getSlot(); + if ( itemStorage != null ) + return itemStorage.getSlot(); + return 0; } @Override public IAEItemStack injectItems(IAEItemStack input, Actionable type, BaseActionSource src) { - return itemStorage.injectItems( input, type, src ); + if ( itemStorage != null ) + return itemStorage.injectItems( input, type, src ); + return input; } @Override public IAEItemStack extractItems(IAEItemStack request, Actionable mode, BaseActionSource src) { - return itemStorage.extractItems( request, mode, src ); + if ( itemStorage != null ) + return itemStorage.extractItems( request, mode, src ); + return null; } @Override public StorageChannel getChannel() { - return itemStorage.getChannel(); + if ( itemStorage != null ) + return itemStorage.getChannel(); + return StorageChannel.ITEMS; } @Override public double extractAEPower(double amt, Actionable mode, PowerMultiplier usePowerMultiplier) { - if ( mode == Actionable.SIMULATE ) - return wth.hasPower( myPlayer, amt, getItemStack() ) ? amt : 0; - return wth.usePower( myPlayer, amt, getItemStack() ) ? amt : 0; + if ( wth != null && effectiveItem != null ) + { + if ( mode == Actionable.SIMULATE ) + return wth.hasPower( myPlayer, amt, getItemStack() ) ? amt : 0; + return wth.usePower( myPlayer, amt, getItemStack() ) ? amt : 0; + } + return 0.0; } @Override