ME Tunnel + Network Tool
This commit is contained in:
@@ -34,10 +34,10 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IMEMonito
|
||||
final IMEMonitor<IAEItemStack> monitor;
|
||||
final IItemList<IAEItemStack> items = new ItemList<IAEItemStack>();
|
||||
|
||||
public ContainerMEMonitorable(InventoryPlayer ip, IStorageMonitorable montiorable) {
|
||||
protected ContainerMEMonitorable(InventoryPlayer ip, IStorageMonitorable montiorable, boolean isServer) {
|
||||
super( ip, montiorable instanceof TileEntity ? (TileEntity) montiorable : null, montiorable instanceof IPart ? (IPart) montiorable : null );
|
||||
|
||||
if ( Platform.isServer() )
|
||||
if ( isServer )
|
||||
{
|
||||
monitor = montiorable.getItemInventory();
|
||||
monitor.addListener( this, null );
|
||||
@@ -61,7 +61,10 @@ public class ContainerMEMonitorable extends AEBaseContainer implements IMEMonito
|
||||
}
|
||||
else
|
||||
monitor = null;
|
||||
}
|
||||
|
||||
public ContainerMEMonitorable(InventoryPlayer ip, IStorageMonitorable montiorable) {
|
||||
this( ip, montiorable, Platform.isServer() );
|
||||
bindPlayerInventory( ip, 0, 0 );
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,8 @@ public class ContainerMEPortableCell extends ContainerMEMonitorable
|
||||
ICellItemViewer civ;
|
||||
|
||||
public ContainerMEPortableCell(InventoryPlayer ip, ICellItemViewer montiorable) {
|
||||
super( ip, (IStorageMonitorable) montiorable );
|
||||
super( ip, (IStorageMonitorable) montiorable, Platform.isServer() );
|
||||
lockPlayerInventorySlot( ip.currentItem );
|
||||
civ = montiorable;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,24 +1,160 @@
|
||||
package appeng.container.implementations;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridBlock;
|
||||
import appeng.api.networking.IGridHost;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.energy.IEnergyGrid;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.core.sync.packets.PacketMEInventoryUpdate;
|
||||
import appeng.helpers.INetworkTool;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class ContainerNetworkStatus extends AEBaseContainer
|
||||
{
|
||||
|
||||
TileEntity myte;
|
||||
IGrid network;
|
||||
|
||||
public ContainerNetworkStatus(InventoryPlayer ip, TileEntity te) {
|
||||
super( ip, te, null );
|
||||
myte = te;
|
||||
public ContainerNetworkStatus(InventoryPlayer ip, INetworkTool te) {
|
||||
super( ip, null, null );
|
||||
IGridHost host = te.getGridHost();
|
||||
|
||||
// addSlotToContainer( new SlotRestrictedInput(
|
||||
// PlaceableItemType.WIRELESS_TERMINAL, te, 0, 71, 14 ) );
|
||||
// addSlotToContainer( new SlotOutput( te, 1, 71, 14,
|
||||
// PlaceableItemType.WIRELESS_TERMINAL.icon ) );
|
||||
if ( host != null )
|
||||
{
|
||||
findNode( host, ForgeDirection.UNKNOWN );
|
||||
for (ForgeDirection d : ForgeDirection.VALID_DIRECTIONS)
|
||||
findNode( host, d );
|
||||
}
|
||||
|
||||
bindPlayerInventory( ip, 0, 199 - /* height of playerinventory */82 );
|
||||
if ( network == null )
|
||||
ip.player.closeScreen();
|
||||
}
|
||||
|
||||
private void findNode(IGridHost host, ForgeDirection d)
|
||||
{
|
||||
if ( network == null )
|
||||
{
|
||||
IGridNode node = host.getGridNode( d );
|
||||
if ( node != null )
|
||||
network = node.getGrid();
|
||||
}
|
||||
}
|
||||
|
||||
int delay = 0;
|
||||
|
||||
public long avgAddition;
|
||||
public long powerUsage;
|
||||
|
||||
int lo_avgAddition, hi_avgAddition;
|
||||
int lo_powerUsage, hi_powerUsage;
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void updateProgressBar(int idx, int value)
|
||||
{
|
||||
switch (idx)
|
||||
{
|
||||
case 0:
|
||||
lo_avgAddition = value;
|
||||
break;
|
||||
case 1:
|
||||
hi_avgAddition = value;
|
||||
break;
|
||||
case 2:
|
||||
lo_powerUsage = value;
|
||||
break;
|
||||
case 3:
|
||||
hi_powerUsage = value;
|
||||
break;
|
||||
}
|
||||
|
||||
avgAddition = ((long) hi_avgAddition) << 32 | lo_avgAddition;
|
||||
powerUsage = ((long) hi_powerUsage) << 32 | lo_powerUsage;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges()
|
||||
{
|
||||
delay++;
|
||||
if ( Platform.isServer() && delay > 1 && network != null )
|
||||
{
|
||||
delay = 0;
|
||||
|
||||
IEnergyGrid eg = network.getCache( IEnergyGrid.class );
|
||||
if ( eg != null )
|
||||
{
|
||||
avgAddition = (long) (100.0 * eg.getAvgPowerInjection());
|
||||
powerUsage = (long) (100.0 * eg.getAvgPowerUsage());
|
||||
|
||||
lo_avgAddition = (int) (avgAddition & 0xffffffffL);
|
||||
hi_avgAddition = (int) (avgAddition >> 32L);
|
||||
|
||||
lo_powerUsage = (int) (powerUsage & 0xffffffffL);
|
||||
hi_powerUsage = (int) (powerUsage >> 32L);
|
||||
|
||||
for (Object c : this.crafters)
|
||||
{
|
||||
ICrafting icrafting = (ICrafting) c;
|
||||
icrafting.sendProgressBarUpdate( this, 0, (int) lo_avgAddition );
|
||||
icrafting.sendProgressBarUpdate( this, 1, (int) hi_avgAddition );
|
||||
icrafting.sendProgressBarUpdate( this, 2, (int) lo_powerUsage );
|
||||
icrafting.sendProgressBarUpdate( this, 3, (int) hi_powerUsage );
|
||||
}
|
||||
}
|
||||
|
||||
PacketMEInventoryUpdate piu;
|
||||
try
|
||||
{
|
||||
piu = new PacketMEInventoryUpdate();
|
||||
|
||||
for (Class<? extends IGridHost> machineClass : network.getMachinesClasses())
|
||||
{
|
||||
IItemList<IAEItemStack> list = AEApi.instance().storage().createItemList();
|
||||
for (IGridNode machine : network.getMachines( machineClass ))
|
||||
{
|
||||
IGridBlock blk = machine.getGridBlock();
|
||||
ItemStack is = blk.getMachineRepresentation();
|
||||
if ( is != null )
|
||||
{
|
||||
IAEItemStack ais = AEItemStack.create( is );
|
||||
ais.setStackSize( 1 );
|
||||
ais.setCountRequestable( (long) (blk.getIdlePowerUsage() * 100.0) );
|
||||
list.add( ais );
|
||||
}
|
||||
}
|
||||
|
||||
for (IAEItemStack ais : list)
|
||||
piu.appendItem( ais );
|
||||
}
|
||||
|
||||
Packet p = piu.getPacket();
|
||||
for (Object c : this.crafters)
|
||||
{
|
||||
if ( c instanceof Player )
|
||||
PacketDispatcher.sendPacketToPlayer( p, (Player) c );
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
}
|
||||
super.detectAndSendChanges();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package appeng.container.implementations;
|
||||
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.slot.SlotRestrictedInput;
|
||||
import appeng.container.slot.SlotRestrictedInput.PlaceableItemType;
|
||||
import appeng.helpers.INetworkTool;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class ContainerNetworkTool extends AEBaseContainer
|
||||
{
|
||||
|
||||
INetworkTool toolInv;
|
||||
|
||||
public ContainerNetworkTool(InventoryPlayer ip, INetworkTool te) {
|
||||
super( ip, null, null );
|
||||
toolInv = te;
|
||||
|
||||
lockPlayerInventorySlot( ip.currentItem );
|
||||
|
||||
for (int y = 0; y < 3; y++)
|
||||
for (int x = 0; x < 3; x++)
|
||||
addSlotToContainer( (new SlotRestrictedInput( PlaceableItemType.UPGRADES, te, y * 3 + x, 80 - 18 + x * 18, 37 - 18 + y * 18 )) );
|
||||
|
||||
bindPlayerInventory( ip, 0, 166 - /* height of playerinventory */82 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges()
|
||||
{
|
||||
ItemStack currentItem = getPlayerInv().getCurrentItem();
|
||||
|
||||
if ( currentItem != toolInv.getItemStack() )
|
||||
{
|
||||
if ( currentItem != null )
|
||||
{
|
||||
if ( Platform.isSameItem( toolInv.getItemStack(), currentItem ) )
|
||||
getPlayerInv().setInventorySlotContents( getPlayerInv().currentItem, toolInv.getItemStack() );
|
||||
else
|
||||
getPlayerInv().player.closeScreen();
|
||||
}
|
||||
else
|
||||
getPlayerInv().player.closeScreen();
|
||||
}
|
||||
|
||||
super.detectAndSendChanges();
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,9 @@ package appeng.container.implementations;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.config.RedstoneMode;
|
||||
import appeng.api.config.Settings;
|
||||
@@ -17,7 +19,8 @@ import appeng.container.slot.OptionalSlotFakeTypeOnly;
|
||||
import appeng.container.slot.SlotFakeTypeOnly;
|
||||
import appeng.container.slot.SlotRestrictedInput;
|
||||
import appeng.container.slot.SlotRestrictedInput.PlaceableItemType;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.helpers.NetworkToolInv;
|
||||
import appeng.items.tools.ToolNetworkTool;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
@@ -26,17 +29,54 @@ public class ContainerUpgradeable extends AEBaseContainer implements IOptionalSl
|
||||
{
|
||||
|
||||
IBusCommon myte;
|
||||
IInventory toolbox = new AppEngInternalInventory( null, 9 );
|
||||
|
||||
int tbslot;
|
||||
NetworkToolInv tbinv;
|
||||
|
||||
public ContainerUpgradeable(InventoryPlayer ip, IBusCommon te) {
|
||||
super( ip, (TileEntity) (te instanceof TileEntity ? te : null), (IPart) (te instanceof IPart ? te : null) );
|
||||
myte = te;
|
||||
|
||||
World w = null;
|
||||
int xCoor = 0, yCoor = 0, zCoor = 0;
|
||||
|
||||
if ( te instanceof TileEntity )
|
||||
{
|
||||
TileEntity myTile = (TileEntity) te;
|
||||
w = myTile.getWorldObj();
|
||||
xCoor = myTile.xCoord;
|
||||
yCoor = myTile.yCoord;
|
||||
zCoor = myTile.zCoord;
|
||||
}
|
||||
|
||||
if ( te instanceof IPart )
|
||||
{
|
||||
IBusCommon myTile = (IBusCommon) te;
|
||||
TileEntity mk = myTile.getTile();
|
||||
w = mk.getWorldObj();
|
||||
xCoor = mk.xCoord;
|
||||
yCoor = mk.yCoord;
|
||||
zCoor = mk.zCoord;
|
||||
}
|
||||
|
||||
IInventory pi = getPlayerInv();
|
||||
for (int x = 0; x < pi.getSizeInventory(); x++)
|
||||
{
|
||||
ItemStack pii = pi.getStackInSlot( x );
|
||||
if ( pii != null && pii.getItem() instanceof ToolNetworkTool )
|
||||
{
|
||||
lockPlayerInventorySlot( x );
|
||||
tbslot = x;
|
||||
tbinv = (NetworkToolInv) ((ToolNetworkTool) pii.getItem()).getGuiObject( pii, w, xCoor, yCoor, zCoor );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( hasToolbox() )
|
||||
{
|
||||
for (int v = 0; v < 3; v++)
|
||||
for (int u = 0; u < 3; u++)
|
||||
addSlotToContainer( (new SlotRestrictedInput( PlaceableItemType.UPGRADES, toolbox, u + v * 3, 186 + u * 18, getHeight() - 82 + v * 18 ))
|
||||
addSlotToContainer( (new SlotRestrictedInput( PlaceableItemType.UPGRADES, tbinv, u + v * 3, 186 + u * 18, getHeight() - 82 + v * 18 ))
|
||||
.setPlayerSide() );
|
||||
}
|
||||
|
||||
@@ -95,6 +135,27 @@ public class ContainerUpgradeable extends AEBaseContainer implements IOptionalSl
|
||||
public RedstoneMode rsMode = RedstoneMode.IGNORE;
|
||||
public FuzzyMode fzMode = FuzzyMode.IGNORE_ALL;
|
||||
|
||||
public void checkToolbox()
|
||||
{
|
||||
if ( hasToolbox() )
|
||||
{
|
||||
ItemStack currentItem = getPlayerInv().getStackInSlot( tbslot );
|
||||
|
||||
if ( currentItem != tbinv.getItemStack() )
|
||||
{
|
||||
if ( currentItem != null )
|
||||
{
|
||||
if ( Platform.isSameItem( tbinv.getItemStack(), currentItem ) )
|
||||
getPlayerInv().setInventorySlotContents( tbslot, tbinv.getItemStack() );
|
||||
else
|
||||
getPlayerInv().player.closeScreen();
|
||||
}
|
||||
else
|
||||
getPlayerInv().player.closeScreen();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges()
|
||||
{
|
||||
@@ -119,6 +180,8 @@ public class ContainerUpgradeable extends AEBaseContainer implements IOptionalSl
|
||||
this.rsMode = (RedstoneMode) this.myte.getConfigManager().getSetting( Settings.REDSTONE_CONTROLLED );
|
||||
}
|
||||
|
||||
checkToolbox();
|
||||
|
||||
for (Object o : inventorySlots)
|
||||
{
|
||||
if ( o instanceof OptionalSlotFake )
|
||||
@@ -152,8 +215,7 @@ public class ContainerUpgradeable extends AEBaseContainer implements IOptionalSl
|
||||
|
||||
public boolean hasToolbox()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
return tbinv != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user