2013-12-27 23:59:59 +01:00
|
|
|
package appeng.tile.networking;
|
|
|
|
|
|
|
|
import java.util.EnumSet;
|
|
|
|
|
|
|
|
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.networking.GridFlags;
|
|
|
|
import appeng.api.networking.energy.IAEPowerStorage;
|
|
|
|
import appeng.api.networking.events.MENetworkControllerChange;
|
|
|
|
import appeng.api.networking.events.MENetworkEventSubscribe;
|
|
|
|
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
|
|
|
import appeng.api.networking.events.MENetworkPowerStorage;
|
|
|
|
import appeng.api.networking.events.MENetworkPowerStorage.PowerEventType;
|
|
|
|
import appeng.api.networking.pathing.ControllerState;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.api.util.AECableType;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.me.GridAccessException;
|
|
|
|
import appeng.tile.grid.AENetworkPowerTile;
|
|
|
|
import appeng.tile.inventory.AppEngInternalInventory;
|
|
|
|
import appeng.tile.inventory.InvOperation;
|
|
|
|
|
|
|
|
public class TileController extends AENetworkPowerTile implements IAEPowerStorage
|
|
|
|
{
|
|
|
|
|
|
|
|
boolean isValid = false;
|
|
|
|
|
|
|
|
public TileController() {
|
|
|
|
internalMaxPower = 8000;
|
|
|
|
internalPublicPowerStorage = true;
|
|
|
|
gridProxy.setIdlePowerUsage( 6 );
|
2014-02-04 05:23:14 +01:00
|
|
|
gridProxy.setFlags( GridFlags.CANNOT_CARRY, GridFlags.TIER_2_CAPACITY );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
@Override
|
|
|
|
public AECableType getCableConnectionType(ForgeDirection dir)
|
|
|
|
{
|
|
|
|
return AECableType.DENSE;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
2014-06-04 03:33:04 +02:00
|
|
|
protected double getFunnelPowerDemand(double maxRecived)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
return gridProxy.getEnergy().getEnergyDemand( 8000 );
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
// no grid? use local...
|
2014-06-04 03:33:04 +02:00
|
|
|
return super.getFunnelPowerDemand( maxRecived );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected double funnelPowerIntoStorage(double AEUnits, Actionable mode)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
double ret = gridProxy.getEnergy().injectPower( AEUnits, mode );
|
|
|
|
if ( mode == Actionable.SIMULATE )
|
|
|
|
return ret;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
// no grid? use local...
|
|
|
|
return super.funnelPowerIntoStorage( AEUnits, mode );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void PowerEvent(PowerEventType x)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
gridProxy.getGrid().postEvent( new MENetworkPowerStorage( this, x ) );
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
// not ready!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@MENetworkEventSubscribe
|
2014-04-23 04:49:03 +02:00
|
|
|
public void onControllerChange(MENetworkControllerChange status)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
updateMeta();
|
|
|
|
}
|
|
|
|
|
|
|
|
@MENetworkEventSubscribe
|
|
|
|
public void onPowerChange(MENetworkPowerStatusChange status)
|
|
|
|
{
|
|
|
|
updateMeta();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onReady()
|
|
|
|
{
|
|
|
|
onNeighborChange( true );
|
|
|
|
super.onReady();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void onNeighborChange(boolean force)
|
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
boolean xx = worldObj.getTileEntity( xCoord - 1, yCoord, zCoord ) instanceof TileController
|
|
|
|
&& worldObj.getTileEntity( xCoord + 1, yCoord, zCoord ) instanceof TileController;
|
|
|
|
boolean yy = worldObj.getTileEntity( xCoord, yCoord - 1, zCoord ) instanceof TileController
|
|
|
|
&& worldObj.getTileEntity( xCoord, yCoord + 1, zCoord ) instanceof TileController;
|
|
|
|
boolean zz = worldObj.getTileEntity( xCoord, yCoord, zCoord - 1 ) instanceof TileController
|
|
|
|
&& worldObj.getTileEntity( xCoord, yCoord, zCoord + 1 ) instanceof TileController;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
// int meta = world.getBlockMetadata( xCoord, yCoord, zCoord );
|
|
|
|
// boolean hasPower = meta > 0;
|
|
|
|
// boolean isConflict = meta == 2;
|
|
|
|
|
|
|
|
boolean oldValid = isValid;
|
|
|
|
|
|
|
|
isValid = (xx && !yy && !zz) || (!xx && yy && !zz) || (!xx && !yy && zz) || ((xx ? 1 : 0) + (yy ? 1 : 0) + (zz ? 1 : 0) <= 1);
|
|
|
|
|
|
|
|
if ( oldValid != isValid || force )
|
|
|
|
{
|
|
|
|
if ( isValid )
|
|
|
|
gridProxy.setValidSides( EnumSet.allOf( ForgeDirection.class ) );
|
|
|
|
else
|
|
|
|
gridProxy.setValidSides( EnumSet.noneOf( ForgeDirection.class ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
updateMeta();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateMeta()
|
|
|
|
{
|
|
|
|
if ( !gridProxy.isReady() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
int meta = 0;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if ( gridProxy.getEnergy().isNetworkPowered() )
|
|
|
|
{
|
|
|
|
meta = 1;
|
|
|
|
|
|
|
|
if ( gridProxy.getPath().getControllerState() == ControllerState.CONTROLLER_CONFLICT )
|
|
|
|
meta = 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
meta = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
worldObj.setBlockMetadataWithNotify( xCoord, yCoord, zCoord, meta, 2 );
|
|
|
|
}
|
|
|
|
|
2014-07-17 22:14:44 +02:00
|
|
|
final int sides[] = new int[] {};
|
|
|
|
static final AppEngInternalInventory inv = new AppEngInternalInventory( null, 0 );
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|