Applied-Energistics-2-tiler.../src/main/java/appeng/container/implementations/ContainerSpatialIOPort.java

93 lines
3 KiB
Java
Raw Normal View History

2014-11-14 12:02:52 +01:00
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
2014-09-24 02:26:27 +02:00
package appeng.container.implementations;
2014-09-24 02:26:27 +02:00
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraftforge.common.util.ForgeDirection;
2014-12-29 21:59:05 +01:00
2014-09-24 02:26:27 +02:00
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;
2014-09-24 02:26:27 +02:00
public class ContainerSpatialIOPort extends AEBaseContainer
{
final TileSpatialIOPort spatialIOPort;
@GuiSync( 0 )
2014-09-24 02:26:27 +02:00
public long currentPower;
@GuiSync( 1 )
2014-09-24 02:26:27 +02:00
public long maxPower;
@GuiSync( 2 )
2014-09-24 02:26:27 +02:00
public long reqPower;
@GuiSync( 3 )
2014-09-24 02:26:27 +02:00
public long eff;
IGrid network;
2014-09-24 02:26:27 +02:00
int delay = 40;
public ContainerSpatialIOPort( InventoryPlayer ip, TileSpatialIOPort spatialIOPort )
{
super( ip, spatialIOPort, null );
this.spatialIOPort = spatialIOPort;
2014-09-24 02:26:27 +02:00
if( Platform.isServer() )
2014-12-29 15:13:47 +01:00
this.network = spatialIOPort.getGridNode( ForgeDirection.UNKNOWN ).getGrid();
2014-09-24 02:26:27 +02:00
2014-12-29 15:13:47 +01:00
this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.SPATIAL_STORAGE_CELLS, spatialIOPort, 0, 52, 48, this.invPlayer ) );
this.addSlotToContainer( new SlotOutput( spatialIOPort, 1, 113, 48, SlotRestrictedInput.PlacableItemType.SPATIAL_STORAGE_CELLS.IIcon ) );
2014-09-24 02:26:27 +02:00
2014-12-29 15:13:47 +01:00
this.bindPlayerInventory( ip, 0, 197 - /* height of player inventory */82 );
2014-09-24 02:26:27 +02:00
}
@Override
public void detectAndSendChanges()
{
2014-12-29 15:13:47 +01:00
this.verifyPermissions( SecurityPermissions.BUILD, false );
2014-09-24 02:26:27 +02:00
if( Platform.isServer() )
2014-09-24 02:26:27 +02:00
{
2014-12-29 15:13:47 +01:00
this.delay++;
if( this.delay > 15 && this.network != null )
2014-09-24 02:26:27 +02:00
{
2014-12-29 15:13:47 +01:00
this.delay = 0;
2014-09-24 02:26:27 +02:00
2014-12-29 15:13:47 +01:00
IEnergyGrid eg = this.network.getCache( IEnergyGrid.class );
ISpatialCache sc = this.network.getCache( ISpatialCache.class );
if( eg != null )
2014-09-24 02:26:27 +02:00
{
this.currentPower = (long) ( 100.0 * eg.getStoredPower() );
this.maxPower = (long) ( 100.0 * eg.getMaxStoredPower() );
this.reqPower = (long) ( 100.0 * sc.requiredPower() );
this.eff = (long) ( 100.0f * sc.currentEfficiency() );
2014-09-24 02:26:27 +02:00
}
}
}
super.detectAndSendChanges();
}
}