Package appeng.container.implementations

Source Code of appeng.container.implementations.ContainerSpatialIOPort

package appeng.container.implementations;

import net.minecraft.entity.player.InventoryPlayer;
import net.minecraftforge.common.util.ForgeDirection;
import appeng.api.config.SecurityPermissions;
import appeng.api.networking.IGrid;
import appeng.api.networking.energy.IEnergyGrid;
import appeng.api.networking.spatial.ISpatialCache;
import appeng.container.AEBaseContainer;
import appeng.container.guisync.GuiSync;
import appeng.container.slot.SlotOutput;
import appeng.container.slot.SlotRestrictedInput;
import appeng.tile.spatial.TileSpatialIOPort;
import appeng.util.Platform;

public class ContainerSpatialIOPort extends AEBaseContainer
{

  final TileSpatialIOPort spatialIOPort;

  IGrid network;

  @GuiSync(0)
  public long currentPower;
  @GuiSync(1)
  public long maxPower;
  @GuiSync(2)
  public long reqPower;
  @GuiSync(3)
  public long eff;

  int delay = 40;

  public ContainerSpatialIOPort(InventoryPlayer ip, TileSpatialIOPort spatialIOPort) {
    super( ip, spatialIOPort, null );
    this.spatialIOPort = spatialIOPort;

    if ( Platform.isServer() )
      network = spatialIOPort.getGridNode( ForgeDirection.UNKNOWN ).getGrid();

    addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.SPATIAL_STORAGE_CELLS, spatialIOPort, 0, 52, 48, invPlayer ) );
    addSlotToContainer( new SlotOutput( spatialIOPort, 1, 113, 48, SlotRestrictedInput.PlacableItemType.SPATIAL_STORAGE_CELLS.IIcon ) );

    bindPlayerInventory( ip, 0, 197 - /* height of player inventory */82 );
  }

  @Override
  public void detectAndSendChanges()
  {
    verifyPermissions( SecurityPermissions.BUILD, false );

    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.currentEfficiency());
        }
      }
    }

    super.detectAndSendChanges();
  }
TOP

Related Classes of appeng.container.implementations.ContainerSpatialIOPort

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.