From c40c81070c98e1ad35dd6f17ea35a3329fd7a8a6 Mon Sep 17 00:00:00 2001 From: AlgorithmX2 Date: Thu, 27 Mar 2014 23:31:06 -0500 Subject: [PATCH] All Terminals now can be opened in low power / channel state and show dark slots. --- block/misc/BlockSecurity.java | 14 ++--- block/storage/BlockChest.java | 4 +- client/gui/AEBaseGui.java | 2 +- .../gui/implementations/GuiMEMonitorable.java | 15 ++++- client/me/InternalSlotME.java | 5 ++ client/me/ItemRepo.java | 12 ++++ client/me/SlotME.java | 12 +++- container/AEBaseContainer.java | 2 +- .../ContainerMEMonitorable.java | 62 ++++++++++++++++++- .../implementations/ContainerSecurity.java | 12 ++-- me/cache/GridStorageCache.java | 1 + me/cache/NetworkMonitor.java | 15 +++++ me/helpers/ChannelPowerSrc.java | 27 ++++++++ me/storage/MEMonitorPassthu.java | 23 +++++-- parts/automation/PartLevelEmitter.java | 13 ++++ parts/misc/PartStorageBus.java | 6 ++ parts/reporting/PartTerminal.java | 11 +--- tile/storage/TileChest.java | 6 ++ 18 files changed, 204 insertions(+), 38 deletions(-) create mode 100644 me/helpers/ChannelPowerSrc.java diff --git a/block/misc/BlockSecurity.java b/block/misc/BlockSecurity.java index d2c9f1838..b214a9f32 100644 --- a/block/misc/BlockSecurity.java +++ b/block/misc/BlockSecurity.java @@ -10,7 +10,6 @@ import appeng.block.AEBaseBlock; import appeng.client.render.BaseBlockRender; import appeng.client.render.blocks.RendererSecurity; import appeng.core.features.AEFeature; -import appeng.core.localization.PlayerMessages; import appeng.core.sync.GuiBridge; import appeng.tile.misc.TileSecurity; import appeng.util.Platform; @@ -39,15 +38,10 @@ public class BlockSecurity extends AEBaseBlock TileSecurity tg = getTileEntity( w, x, y, z ); if ( tg != null ) { - if ( Platform.isServer() ) - { - if ( tg.isPowered() ) - { - Platform.openGUI( p, tg, ForgeDirection.getOrientation( side ), GuiBridge.GUI_SECURITY ); - } - else - p.addChatMessage( PlayerMessages.MachineNotPowered.get() ); - } + if ( Platform.isClient() ) + return true; + + Platform.openGUI( p, tg, ForgeDirection.getOrientation( side ), GuiBridge.GUI_SECURITY ); return true; } diff --git a/block/storage/BlockChest.java b/block/storage/BlockChest.java index be336b1c7..27553fdd6 100644 --- a/block/storage/BlockChest.java +++ b/block/storage/BlockChest.java @@ -46,7 +46,7 @@ public class BlockChest extends AEBaseBlock { Platform.openGUI( p, tg, ForgeDirection.getOrientation( side ), GuiBridge.GUI_CHEST ); } - else if ( tg.isPowered() ) + else { ItemStack cell = tg.getStackInSlot( 1 ); if ( cell != null ) @@ -58,8 +58,6 @@ public class BlockChest extends AEBaseBlock else p.addChatMessage( PlayerMessages.ChestCannotReadStorageCell.get() ); } - else - p.addChatMessage( PlayerMessages.MachineNotPowered.get() ); return true; } diff --git a/client/gui/AEBaseGui.java b/client/gui/AEBaseGui.java index 04832566a..4481a2c37 100644 --- a/client/gui/AEBaseGui.java +++ b/client/gui/AEBaseGui.java @@ -526,7 +526,7 @@ public abstract class AEBaseGui extends GuiContainer AppEngRenderItem aeri = new AppEngRenderItem(); - private boolean isPowered() + protected boolean isPowered() { return true; } diff --git a/client/gui/implementations/GuiMEMonitorable.java b/client/gui/implementations/GuiMEMonitorable.java index 66a4983f5..f1214cf07 100644 --- a/client/gui/implementations/GuiMEMonitorable.java +++ b/client/gui/implementations/GuiMEMonitorable.java @@ -79,6 +79,7 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi super( c ); myScrollBar = new GuiScrollbar(); repo = new ItemRepo( myScrollBar, this ); + xSize = 195; ySize = 204; @@ -156,7 +157,7 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi this.xSize = standardSize + ((perRow - 9) * 18); else this.xSize = standardSize; - + super.initGui(); // full size : 204 // extra slots : 72 @@ -280,6 +281,13 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi } } + @Override + public void updateScreen() + { + repo.setPower( mecontainer.hasPower ); + super.updateScreen(); + } + @Override public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) { @@ -354,4 +362,9 @@ public class GuiMEMonitorable extends AEBaseMEGui implements ISortSource, IConfi repo.updateView(); } + protected boolean isPowered() + { + return repo.hasPower(); + } + } diff --git a/client/me/InternalSlotME.java b/client/me/InternalSlotME.java index ac79879c7..4f1046c1e 100644 --- a/client/me/InternalSlotME.java +++ b/client/me/InternalSlotME.java @@ -28,4 +28,9 @@ public class InternalSlotME { return repo.getRefrenceItem( offset ); } + + public boolean hasPower() + { + return repo.hasPower(); + } } diff --git a/client/me/ItemRepo.java b/client/me/ItemRepo.java index 4fd5970e5..914b1f7a7 100644 --- a/client/me/ItemRepo.java +++ b/client/me/ItemRepo.java @@ -241,4 +241,16 @@ public class ItemRepo list.resetStatus(); } + private boolean hasPower; + + public boolean hasPower() + { + return hasPower; + } + + public void setPower(boolean hasPower) + { + this.hasPower = hasPower; + } + } diff --git a/client/me/SlotME.java b/client/me/SlotME.java index 180ca510a..f227dfc12 100644 --- a/client/me/SlotME.java +++ b/client/me/SlotME.java @@ -19,12 +19,16 @@ public class SlotME extends Slot @Override public ItemStack getStack() { - return mySlot.getStack(); + if ( mySlot.hasPower() ) + return mySlot.getStack(); + return null; } public IAEItemStack getAEStack() { - return mySlot.getAEStack(); + if ( mySlot.hasPower() ) + return mySlot.getAEStack(); + return null; } @Override @@ -48,7 +52,9 @@ public class SlotME extends Slot @Override public boolean getHasStack() { - return getStack() != null; + if ( mySlot.hasPower() ) + return getStack() != null; + return false; } @Override diff --git a/container/AEBaseContainer.java b/container/AEBaseContainer.java index b2513422a..967c12014 100644 --- a/container/AEBaseContainer.java +++ b/container/AEBaseContainer.java @@ -115,8 +115,8 @@ public abstract class AEBaseContainer extends Container public ContainerOpenContext openContext; protected IMEInventoryHandler cellInv; - protected IEnergySource powerSrc; protected HashSet locked = new HashSet(); + protected IEnergySource powerSrc; public void lockPlayerInventorySlot(int idx) { diff --git a/container/implementations/ContainerMEMonitorable.java b/container/implementations/ContainerMEMonitorable.java index 68d363aba..679597c6b 100644 --- a/container/implementations/ContainerMEMonitorable.java +++ b/container/implementations/ContainerMEMonitorable.java @@ -10,6 +10,8 @@ import net.minecraft.inventory.ICrafting; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; import appeng.api.AEApi; +import appeng.api.config.Actionable; +import appeng.api.config.PowerMultiplier; import appeng.api.config.SecurityPermissions; import appeng.api.config.Settings; import appeng.api.config.SortDir; @@ -38,6 +40,7 @@ import appeng.core.AELog; import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.packets.PacketMEInventoryUpdate; import appeng.core.sync.packets.PacketValueConfig; +import appeng.me.helpers.ChannelPowerSrc; import appeng.util.ConfigManager; import appeng.util.IConfigManagerHost; import appeng.util.Platform; @@ -52,9 +55,12 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa IConfigManager clientCM; public boolean canAccessViewCells = false; + public boolean hasPower = false; + public SlotRestrictedInput cellView[] = new SlotRestrictedInput[5]; public IConfigManagerHost gui; + private IGridNode networkNode; protected ContainerMEMonitorable(InventoryPlayer ip, ITerminalHost montiorable, boolean bindInventory) { super( ip, montiorable instanceof TileEntity ? (TileEntity) montiorable : null, montiorable instanceof IPart ? (IPart) montiorable : null ); @@ -85,9 +91,10 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa IGridNode node = ((IGridHost) montiorable).getGridNode( ForgeDirection.UNKNOWN ); if ( node != null ) { + networkNode = node; IGrid g = node.getGrid(); if ( g != null ) - powerSrc = g.getCache( IEnergyGrid.class ); + powerSrc = new ChannelPowerSrc( networkNode, (IEnergyGrid) g.getCache( IEnergyGrid.class ) ); } } } @@ -180,6 +187,8 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa } } + updatePowerStatus(); + boolean oldCanAccessViewCells = canAccessViewCells; canAccessViewCells = hasAccess( SecurityPermissions.BUILD, false ); if ( canAccessViewCells != oldCanAccessViewCells ) @@ -201,11 +210,46 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa } } + protected void updatePowerStatus() + { + boolean oldHasPower = hasPower; + try + { + if ( networkNode != null ) + hasPower = networkNode.isActive(); + else if ( powerSrc instanceof IEnergyGrid ) + hasPower = ((IEnergyGrid) powerSrc).isNetworkPowered(); + else + hasPower = powerSrc.extractAEPower( 1, Actionable.SIMULATE, PowerMultiplier.CONFIG ) > 0.8; + } + catch (Throwable t) + { + // :P + } + + if ( hasPower != oldHasPower ) + { + for (Object c : this.crafters) + { + if ( c instanceof ICrafting ) + { + ICrafting cr = (ICrafting) c; + cr.sendProgressBarUpdate( this, 98, hasPower ? 1 : 0 ); + } + } + } + + } + @Override public void addCraftingToCrafters(ICrafting c) { super.addCraftingToCrafters( c ); + queueInventory( c ); + } + public void queueInventory(ICrafting c) + { if ( Platform.isServer() && c instanceof EntityPlayer && monitor != null ) { try @@ -238,11 +282,27 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IConfigMa } } + @Override + public void onListUpdate() + { + for (Object c : this.crafters) + { + if ( c instanceof ICrafting ) + { + ICrafting cr = (ICrafting) c; + queueInventory( cr ); + } + } + } + @Override public void updateProgressBar(int idx, int value) { super.updateProgressBar( idx, value ); + if ( idx == 98 ) + hasPower = value == 1; + if ( idx == 99 ) canAccessViewCells = value == 1; diff --git a/container/implementations/ContainerSecurity.java b/container/implementations/ContainerSecurity.java index 3d1b63d53..251c7e460 100644 --- a/container/implementations/ContainerSecurity.java +++ b/container/implementations/ContainerSecurity.java @@ -85,6 +85,8 @@ public class ContainerSecurity extends ContainerMEMonitorable implements IAEAppE @Override public void updateProgressBar(int key, int value) { + super.updateProgressBar( key, value ); + if ( key == 0 ) security = value; } @@ -92,7 +94,7 @@ public class ContainerSecurity extends ContainerMEMonitorable implements IAEAppE @Override public void detectAndSendChanges() { - verifyPermissions( SecurityPermissions.SECURITY, true ); + verifyPermissions( SecurityPermissions.SECURITY, false ); int newSecurity = 0; @@ -105,6 +107,8 @@ public class ContainerSecurity extends ContainerMEMonitorable implements IAEAppE newSecurity = newSecurity | (1 << sp.ordinal()); } + updatePowerStatus(); + if ( newSecurity != security ) { if ( Platform.isServer() ) @@ -138,14 +142,14 @@ public class ContainerSecurity extends ContainerMEMonitorable implements IAEAppE { ItemStack term = wirelessIn.getStack().copy(); INetworkEncodable netEncodeable = null; - + if ( term.getItem() instanceof INetworkEncodable ) netEncodeable = (INetworkEncodable) term.getItem(); - + IWirelessTermHandler wTermHandler = AEApi.instance().registries().wireless().getWirelessTerminalHandler( term ); if ( wTermHandler != null ) netEncodeable = wTermHandler; - + if ( netEncodeable != null ) { netEncodeable.setEncryptionKey( term, "" + securityBox.securityKey, "" ); diff --git a/me/cache/GridStorageCache.java b/me/cache/GridStorageCache.java index 435042f38..5802bb2cb 100644 --- a/me/cache/GridStorageCache.java +++ b/me/cache/GridStorageCache.java @@ -27,6 +27,7 @@ import appeng.api.storage.data.IAEStack; import appeng.api.storage.data.IItemList; import appeng.me.storage.ItemWatcher; import appeng.me.storage.NetworkInventoryHandler; + import com.google.common.collect.HashMultimap; import com.google.common.collect.SetMultimap; diff --git a/me/cache/NetworkMonitor.java b/me/cache/NetworkMonitor.java index e23024588..9fe06d5b4 100644 --- a/me/cache/NetworkMonitor.java +++ b/me/cache/NetworkMonitor.java @@ -1,11 +1,14 @@ package appeng.me.cache; +import java.util.Iterator; import java.util.LinkedList; +import java.util.Map.Entry; import java.util.Set; import appeng.api.networking.events.MENetworkStorageEvent; import appeng.api.networking.security.BaseActionSource; import appeng.api.storage.IMEInventoryHandler; +import appeng.api.storage.IMEMonitorHandlerReceiver; import appeng.api.storage.MEMonitorHandler; import appeng.api.storage.StorageChannel; import appeng.api.storage.data.IAEStack; @@ -23,6 +26,18 @@ public class NetworkMonitor> extends MEMonitorHandler public void forceUpdate() { hasChanged = true; + + Iterator, Object>> i = getListeners(); + while (i.hasNext()) + { + Entry, Object> o = i.next(); + IMEMonitorHandlerReceiver recv = o.getKey(); + + if ( recv.isValid( o.getValue() ) ) + recv.onListUpdate(); + else + i.remove(); + } } public NetworkMonitor(GridStorageCache cache, StorageChannel chan) { diff --git a/me/helpers/ChannelPowerSrc.java b/me/helpers/ChannelPowerSrc.java new file mode 100644 index 000000000..43d5dda2c --- /dev/null +++ b/me/helpers/ChannelPowerSrc.java @@ -0,0 +1,27 @@ +package appeng.me.helpers; + +import appeng.api.config.Actionable; +import appeng.api.config.PowerMultiplier; +import appeng.api.networking.IGridNode; +import appeng.api.networking.energy.IEnergySource; + +public class ChannelPowerSrc implements IEnergySource +{ + + IGridNode node; + IEnergySource realSrc; + + public ChannelPowerSrc(IGridNode networkNode, IEnergySource src) { + node = networkNode; + realSrc = src; + } + + @Override + public double extractAEPower(double amt, Actionable mode, PowerMultiplier usePowerMultiplier) + { + if ( node.isActive() ) + return realSrc.extractAEPower( amt, mode, usePowerMultiplier ); + return 0.0; + } + +} diff --git a/me/storage/MEMonitorPassthu.java b/me/storage/MEMonitorPassthu.java index 6c7302cb2..08b6fe2f2 100644 --- a/me/storage/MEMonitorPassthu.java +++ b/me/storage/MEMonitorPassthu.java @@ -22,7 +22,7 @@ public class MEMonitorPassthu> extends MEPassthru imple public BaseActionSource changeSource; public MEMonitorPassthu(IMEInventory i, Class cla) { - super( i,cla ); + super( i, cla ); if ( i instanceof IMEMonitor ) monitor = (IMEMonitor) i; } @@ -34,13 +34,13 @@ public class MEMonitorPassthu> extends MEPassthru imple monitor.removeListener( this ); monitor = null; - IItemList before = getInternal() == null ? new ItemList(clz) : getInternal().getAvailableItems( new ItemList(clz) ); + IItemList before = getInternal() == null ? new ItemList( clz ) : getInternal().getAvailableItems( new ItemList( clz ) ); super.setInternal( i ); if ( i instanceof IMEMonitor ) monitor = (IMEMonitor) i; - IItemList after = getInternal() == null ? new ItemList(clz) : getInternal().getAvailableItems( new ItemList(clz) ); + IItemList after = getInternal() == null ? new ItemList( clz ) : getInternal().getAvailableItems( new ItemList( clz ) ); if ( monitor != null ) monitor.addListener( this, monitor ); @@ -64,7 +64,7 @@ public class MEMonitorPassthu> extends MEPassthru imple public IItemList getStorageList() { if ( monitor == null ) - return getInternal().getAvailableItems( new ItemList(clz) ); + return getInternal().getAvailableItems( new ItemList( clz ) ); return monitor.getStorageList(); } @@ -88,4 +88,19 @@ public class MEMonitorPassthu> extends MEPassthru imple i.remove(); } } + + @Override + public void onListUpdate() + { + Iterator, Object>> i = listeners.entrySet().iterator(); + while (i.hasNext()) + { + Entry, Object> e = i.next(); + IMEMonitorHandlerReceiver recv = e.getKey(); + if ( recv.isValid( e.getValue() ) ) + recv.onListUpdate(); + else + i.remove(); + } + } } diff --git a/parts/automation/PartLevelEmitter.java b/parts/automation/PartLevelEmitter.java index b4cf21a17..4711d8e3d 100644 --- a/parts/automation/PartLevelEmitter.java +++ b/parts/automation/PartLevelEmitter.java @@ -576,4 +576,17 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH return super.getInventoryByName( name ); } + @Override + public void onListUpdate() + { + try + { + updateReportingValue( proxy.getStorage().getItemInventory() ); + } + catch (GridAccessException e) + { + // ;P + } + } + } diff --git a/parts/misc/PartStorageBus.java b/parts/misc/PartStorageBus.java index 4d239cfdc..54e58fde8 100644 --- a/parts/misc/PartStorageBus.java +++ b/parts/misc/PartStorageBus.java @@ -411,4 +411,10 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC return type == PipeType.ITEM && with == side ? ConnectOverride.CONNECT : ConnectOverride.DISCONNECT; } + @Override + public void onListUpdate() + { + // not used here. + } + } diff --git a/parts/reporting/PartTerminal.java b/parts/reporting/PartTerminal.java index cfb70716c..5e0be23e3 100644 --- a/parts/reporting/PartTerminal.java +++ b/parts/reporting/PartTerminal.java @@ -14,7 +14,6 @@ import appeng.api.storage.IMEMonitor; import appeng.api.storage.ITerminalHost; import appeng.api.util.IConfigManager; import appeng.client.texture.CableBusTextures; -import appeng.core.localization.PlayerMessages; import appeng.core.sync.GuiBridge; import appeng.me.GridAccessException; import appeng.tile.inventory.AppEngInternalInventory; @@ -79,15 +78,7 @@ public class PartTerminal extends PartMonitor implements ITerminalHost, IConfigM if ( Platform.isClient() ) return true; - if ( proxy.isActive() ) - Platform.openGUI( player, getHost().getTile(), side, getGui() ); - else - { - if ( proxy.isPowered() ) - player.addChatMessage( PlayerMessages.CommunicationError.get() ); - else - player.addChatMessage( PlayerMessages.MachineNotPowered.get() ); - } + Platform.openGUI( player, getHost().getTile(), side, getGui() ); return true; } diff --git a/tile/storage/TileChest.java b/tile/storage/TileChest.java index 1adfec8ff..8fc320066 100644 --- a/tile/storage/TileChest.java +++ b/tile/storage/TileChest.java @@ -319,6 +319,12 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, IFluidHan return false; } + @Override + public void onListUpdate() + { + // not used here + } + }; class ChestMonitorHandler extends MEMonitorHandler