All Terminals now can be opened in low power / channel state and show dark slots.
This commit is contained in:
parent
5e36754cfd
commit
c40c81070c
18 changed files with 204 additions and 38 deletions
|
@ -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;
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -526,7 +526,7 @@ public abstract class AEBaseGui extends GuiContainer
|
|||
|
||||
AppEngRenderItem aeri = new AppEngRenderItem();
|
||||
|
||||
private boolean isPowered()
|
||||
protected boolean isPowered()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -28,4 +28,9 @@ public class InternalSlotME
|
|||
{
|
||||
return repo.getRefrenceItem( offset );
|
||||
}
|
||||
|
||||
public boolean hasPower()
|
||||
{
|
||||
return repo.hasPower();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -115,8 +115,8 @@ public abstract class AEBaseContainer extends Container
|
|||
public ContainerOpenContext openContext;
|
||||
|
||||
protected IMEInventoryHandler<IAEItemStack> cellInv;
|
||||
protected IEnergySource powerSrc;
|
||||
protected HashSet<Integer> locked = new HashSet();
|
||||
protected IEnergySource powerSrc;
|
||||
|
||||
public void lockPlayerInventorySlot(int idx)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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, "" );
|
||||
|
|
1
me/cache/GridStorageCache.java
vendored
1
me/cache/GridStorageCache.java
vendored
|
@ -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;
|
||||
|
||||
|
|
15
me/cache/NetworkMonitor.java
vendored
15
me/cache/NetworkMonitor.java
vendored
|
@ -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<T extends IAEStack<T>> extends MEMonitorHandler<T>
|
|||
public void forceUpdate()
|
||||
{
|
||||
hasChanged = true;
|
||||
|
||||
Iterator<Entry<IMEMonitorHandlerReceiver<T>, Object>> i = getListeners();
|
||||
while (i.hasNext())
|
||||
{
|
||||
Entry<IMEMonitorHandlerReceiver<T>, Object> o = i.next();
|
||||
IMEMonitorHandlerReceiver<T> recv = o.getKey();
|
||||
|
||||
if ( recv.isValid( o.getValue() ) )
|
||||
recv.onListUpdate();
|
||||
else
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
|
||||
public NetworkMonitor(GridStorageCache cache, StorageChannel chan) {
|
||||
|
|
27
me/helpers/ChannelPowerSrc.java
Normal file
27
me/helpers/ChannelPowerSrc.java
Normal file
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -22,7 +22,7 @@ public class MEMonitorPassthu<T extends IAEStack<T>> extends MEPassthru<T> imple
|
|||
public BaseActionSource changeSource;
|
||||
|
||||
public MEMonitorPassthu(IMEInventory<T> i, Class<? extends IAEStack> cla) {
|
||||
super( i,cla );
|
||||
super( i, cla );
|
||||
if ( i instanceof IMEMonitor )
|
||||
monitor = (IMEMonitor<T>) i;
|
||||
}
|
||||
|
@ -34,13 +34,13 @@ public class MEMonitorPassthu<T extends IAEStack<T>> extends MEPassthru<T> imple
|
|||
monitor.removeListener( this );
|
||||
|
||||
monitor = null;
|
||||
IItemList<T> before = getInternal() == null ? new ItemList(clz) : getInternal().getAvailableItems( new ItemList(clz) );
|
||||
IItemList<T> before = getInternal() == null ? new ItemList( clz ) : getInternal().getAvailableItems( new ItemList( clz ) );
|
||||
|
||||
super.setInternal( i );
|
||||
if ( i instanceof IMEMonitor )
|
||||
monitor = (IMEMonitor<T>) i;
|
||||
|
||||
IItemList<T> after = getInternal() == null ? new ItemList(clz) : getInternal().getAvailableItems( new ItemList(clz) );
|
||||
IItemList<T> 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<T extends IAEStack<T>> extends MEPassthru<T> imple
|
|||
public IItemList<T> getStorageList()
|
||||
{
|
||||
if ( monitor == null )
|
||||
return getInternal().getAvailableItems( new ItemList<T>(clz) );
|
||||
return getInternal().getAvailableItems( new ItemList<T>( clz ) );
|
||||
return monitor.getStorageList();
|
||||
}
|
||||
|
||||
|
@ -88,4 +88,19 @@ public class MEMonitorPassthu<T extends IAEStack<T>> extends MEPassthru<T> imple
|
|||
i.remove();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListUpdate()
|
||||
{
|
||||
Iterator<Entry<IMEMonitorHandlerReceiver<T>, Object>> i = listeners.entrySet().iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
Entry<IMEMonitorHandlerReceiver<T>, Object> e = i.next();
|
||||
IMEMonitorHandlerReceiver<T> recv = e.getKey();
|
||||
if ( recv.isValid( e.getValue() ) )
|
||||
recv.onListUpdate();
|
||||
else
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -319,6 +319,12 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, IFluidHan
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onListUpdate()
|
||||
{
|
||||
// not used here
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
class ChestMonitorHandler<T extends IAEStack> extends MEMonitorHandler<T>
|
||||
|
|
Loading…
Reference in a new issue