2013-12-27 23:59:59 +01:00
|
|
|
package appeng.container.implementations;
|
|
|
|
|
2014-03-06 06:45:14 +01:00
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayerMP;
|
2013-12-27 23:59:59 +01:00
|
|
|
import net.minecraft.entity.player.InventoryPlayer;
|
2014-03-06 06:45:14 +01:00
|
|
|
import net.minecraft.inventory.ICrafting;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.api.config.SecurityPermissions;
|
2014-03-06 06:45:14 +01:00
|
|
|
import appeng.api.networking.IGrid;
|
|
|
|
import appeng.api.networking.energy.IEnergyGrid;
|
|
|
|
import appeng.api.networking.spatial.ISpatialCache;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.container.AEBaseContainer;
|
|
|
|
import appeng.container.slot.SlotOutput;
|
|
|
|
import appeng.container.slot.SlotRestrictedInput;
|
|
|
|
import appeng.container.slot.SlotRestrictedInput.PlaceableItemType;
|
2014-03-06 06:45:14 +01:00
|
|
|
import appeng.core.AELog;
|
|
|
|
import appeng.core.sync.network.NetworkHandler;
|
|
|
|
import appeng.core.sync.packets.PacketProgressBar;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.tile.spatial.TileSpatialIOPort;
|
2014-03-06 06:45:14 +01:00
|
|
|
import appeng.util.Platform;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
public class ContainerSpatialIOPort extends AEBaseContainer
|
|
|
|
{
|
|
|
|
|
|
|
|
TileSpatialIOPort myte;
|
|
|
|
|
2014-03-06 06:45:14 +01:00
|
|
|
IGrid network;
|
|
|
|
|
|
|
|
public long reqPower;
|
|
|
|
public long currentPower;
|
|
|
|
public long maxPower;
|
|
|
|
public long eff;
|
|
|
|
|
|
|
|
int delay = 40;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateFullProgressBar(int id, long value)
|
|
|
|
{
|
|
|
|
if ( id == 0 )
|
|
|
|
currentPower = value;
|
|
|
|
|
|
|
|
if ( id == 1 )
|
|
|
|
maxPower = value;
|
|
|
|
|
|
|
|
if ( id == 2 )
|
|
|
|
reqPower = value;
|
|
|
|
|
|
|
|
if ( id == 3 )
|
|
|
|
eff = value;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
public ContainerSpatialIOPort(InventoryPlayer ip, TileSpatialIOPort te) {
|
2014-01-02 06:51:41 +01:00
|
|
|
super( ip, te, null );
|
2013-12-27 23:59:59 +01:00
|
|
|
myte = te;
|
|
|
|
|
2014-03-06 06:45:14 +01:00
|
|
|
if ( Platform.isServer() )
|
|
|
|
network = te.getGridNode( ForgeDirection.UNKNOWN ).getGrid();
|
|
|
|
|
|
|
|
addSlotToContainer( new SlotRestrictedInput( PlaceableItemType.SPATIAL_STORAGE_CELLS, te, 0, 52, 48 ) );
|
|
|
|
addSlotToContainer( new SlotOutput( te, 1, 113, 48, PlaceableItemType.SPATIAL_STORAGE_CELLS.IIcon ) );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-03-05 08:27:42 +01:00
|
|
|
bindPlayerInventory( ip, 0, 197 - /* height of playerinventory */82 );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-01-27 05:00:36 +01:00
|
|
|
@Override
|
|
|
|
public void detectAndSendChanges()
|
|
|
|
{
|
|
|
|
verifyPermissions( SecurityPermissions.BUILD, false );
|
|
|
|
|
2014-03-06 06:45:14 +01:00
|
|
|
if ( Platform.isServer() )
|
|
|
|
{
|
|
|
|
delay++;
|
|
|
|
if ( delay > 15 && network != null )
|
|
|
|
{
|
|
|
|
delay = 0;
|
|
|
|
|
|
|
|
IEnergyGrid eg = network.getCache( IEnergyGrid.class );
|
|
|
|
ISpatialCache sc = network.getCache( ISpatialCache.class );
|
|
|
|
if ( eg != null )
|
|
|
|
{
|
|
|
|
currentPower = (long) (100.0 * eg.getStoredPower());
|
|
|
|
maxPower = (long) (100.0 * eg.getMaxStoredPower());
|
|
|
|
reqPower = (long) (100.0 * sc.requiredPower());
|
|
|
|
eff = (long) (100.0f * sc.currentEffiency());
|
|
|
|
|
|
|
|
for (Object c : this.crafters)
|
|
|
|
{
|
|
|
|
ICrafting icrafting = (ICrafting) c;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
NetworkHandler.instance.sendTo( new PacketProgressBar( 0, currentPower ), (EntityPlayerMP) icrafting );
|
|
|
|
NetworkHandler.instance.sendTo( new PacketProgressBar( 1, maxPower ), (EntityPlayerMP) icrafting );
|
|
|
|
NetworkHandler.instance.sendTo( new PacketProgressBar( 2, reqPower ), (EntityPlayerMP) icrafting );
|
|
|
|
NetworkHandler.instance.sendTo( new PacketProgressBar( 3, eff ), (EntityPlayerMP) icrafting );
|
|
|
|
}
|
|
|
|
catch (IOException e)
|
|
|
|
{
|
|
|
|
AELog.error( e );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-27 05:00:36 +01:00
|
|
|
super.detectAndSendChanges();
|
|
|
|
}
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|