2013-12-27 23:59:59 +01:00
|
|
|
package appeng.tile.networking;
|
|
|
|
|
|
|
|
import net.minecraft.inventory.IInventory;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.config.Actionable;
|
|
|
|
import appeng.api.config.PowerMultiplier;
|
|
|
|
import appeng.api.networking.energy.IEnergyGrid;
|
|
|
|
import appeng.api.util.AECableType;
|
|
|
|
import appeng.me.GridAccessException;
|
|
|
|
import appeng.tile.events.AETileEventHandler;
|
|
|
|
import appeng.tile.events.TileEventType;
|
|
|
|
import appeng.tile.grid.AENetworkPowerTile;
|
|
|
|
import appeng.tile.inventory.AppEngInternalInventory;
|
|
|
|
import appeng.tile.inventory.InvOperation;
|
|
|
|
|
|
|
|
public class TileEnergyAcceptor extends AENetworkPowerTile
|
|
|
|
{
|
|
|
|
|
|
|
|
final int sides[] = new int[] {};
|
2014-07-17 22:14:44 +02:00
|
|
|
final static AppEngInternalInventory inv = new AppEngInternalInventory( null, 0 );
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public AECableType getCableConnectionType(ForgeDirection dir)
|
|
|
|
{
|
|
|
|
return AECableType.COVERED;
|
|
|
|
}
|
|
|
|
|
|
|
|
private class TilePowerRelayHandler extends AETileEventHandler
|
|
|
|
{
|
|
|
|
|
|
|
|
public TilePowerRelayHandler() {
|
2014-01-26 07:46:16 +01:00
|
|
|
super( TileEventType.TICK );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void Tick()
|
|
|
|
{
|
|
|
|
if ( internalCurrentPower > 0 )
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
IEnergyGrid eg = gridProxy.getEnergy();
|
|
|
|
double powerRequested = internalCurrentPower - eg.injectPower( internalCurrentPower, Actionable.SIMULATE );
|
2014-01-26 07:46:16 +01:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
if ( powerRequested > 0 )
|
|
|
|
{
|
2014-03-12 02:54:04 +01:00
|
|
|
eg.injectPower( extractAEPower( powerRequested, Actionable.MODULATE, PowerMultiplier.ONE ), Actionable.MODULATE );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
// null net, probably bads.
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-06-04 03:33:04 +02:00
|
|
|
@Override
|
|
|
|
protected double getFunnelPowerDemand(double maxRequired)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
IEnergyGrid grid = gridProxy.getEnergy();
|
|
|
|
return grid.getEnergyDemand( maxRequired );
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
return super.getFunnelPowerDemand( maxRequired );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-12 02:54:04 +01:00
|
|
|
@Override
|
|
|
|
protected double funnelPowerIntoStorage(double newPower, Actionable mode)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
IEnergyGrid grid = gridProxy.getEnergy();
|
2014-06-08 02:23:31 +02:00
|
|
|
double leftOver = grid.injectPower( newPower, mode );
|
|
|
|
if ( mode == Actionable.SIMULATE )
|
|
|
|
return leftOver;
|
|
|
|
return 0.0;
|
2014-03-12 02:54:04 +01:00
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
return super.funnelPowerIntoStorage( newPower, mode );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
public TileEnergyAcceptor() {
|
2014-03-12 02:54:04 +01:00
|
|
|
gridProxy.setIdlePowerUsage( 0.0 );
|
2013-12-27 23:59:59 +01:00
|
|
|
addNewHandler( new TilePowerRelayHandler() );
|
2014-03-12 02:54:04 +01:00
|
|
|
internalMaxPower = 100;
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IInventory getInternalInventory()
|
|
|
|
{
|
|
|
|
return inv;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onChangeInventory(IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-03-14 03:59:37 +01:00
|
|
|
public int[] getAccessibleSlotsBySide(ForgeDirection side)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
return sides;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|