Basic reformat, hit once, hope never again
This commit is contained in:
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.tile.powersink;
|
||||
|
||||
|
||||
public abstract class AEBasePoweredTile extends MekJoules
|
||||
{
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.tile.powersink;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@@ -33,86 +34,85 @@ import appeng.tile.AEBaseInvTile;
|
||||
import appeng.tile.TileEvent;
|
||||
import appeng.tile.events.TileEventType;
|
||||
|
||||
|
||||
public abstract class AERootPoweredTile extends AEBaseInvTile implements IAEPowerStorage
|
||||
{
|
||||
|
||||
protected final boolean internalCanAcceptPower = true;
|
||||
// values that determine general function, are set by inheriting classes if
|
||||
// needed. These should generally remain static.
|
||||
protected double internalMaxPower = 10000;
|
||||
protected final boolean internalCanAcceptPower = true;
|
||||
protected boolean internalPublicPowerStorage = false;
|
||||
private EnumSet<ForgeDirection> internalPowerSides = EnumSet.allOf( ForgeDirection.class );
|
||||
|
||||
protected AccessRestriction internalPowerFlow = AccessRestriction.READ_WRITE;
|
||||
|
||||
// the current power buffer.
|
||||
protected double internalCurrentPower = 0;
|
||||
|
||||
protected void setPowerSides(EnumSet<ForgeDirection> sides)
|
||||
{
|
||||
this.internalPowerSides = sides;
|
||||
// trigger re-calc!
|
||||
}
|
||||
private EnumSet<ForgeDirection> internalPowerSides = EnumSet.allOf( ForgeDirection.class );
|
||||
|
||||
protected EnumSet<ForgeDirection> getPowerSides()
|
||||
{
|
||||
return this.internalPowerSides.clone();
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_WRITE)
|
||||
public void writeToNBT_AERootPoweredTile(NBTTagCompound data)
|
||||
protected void setPowerSides( EnumSet<ForgeDirection> sides )
|
||||
{
|
||||
this.internalPowerSides = sides;
|
||||
// trigger re-calc!
|
||||
}
|
||||
|
||||
@TileEvent( TileEventType.WORLD_NBT_WRITE )
|
||||
public void writeToNBT_AERootPoweredTile( NBTTagCompound data )
|
||||
{
|
||||
data.setDouble( "internalCurrentPower", this.internalCurrentPower );
|
||||
}
|
||||
|
||||
@TileEvent(TileEventType.WORLD_NBT_READ)
|
||||
public void readFromNBT_AERootPoweredTile(NBTTagCompound data)
|
||||
@TileEvent( TileEventType.WORLD_NBT_READ )
|
||||
public void readFromNBT_AERootPoweredTile( NBTTagCompound data )
|
||||
{
|
||||
this.internalCurrentPower = data.getDouble( "internalCurrentPower" );
|
||||
}
|
||||
|
||||
final protected double getExternalPowerDemand(PowerUnits externalUnit, double maxPowerRequired)
|
||||
final protected double getExternalPowerDemand( PowerUnits externalUnit, double maxPowerRequired )
|
||||
{
|
||||
return PowerUnits.AE.convertTo( externalUnit, Math.max( 0.0, this.getFunnelPowerDemand( externalUnit.convertTo( PowerUnits.AE, maxPowerRequired ) ) ) );
|
||||
}
|
||||
|
||||
protected double getFunnelPowerDemand(double maxRequired)
|
||||
protected double getFunnelPowerDemand( double maxRequired )
|
||||
{
|
||||
return this.internalMaxPower - this.internalCurrentPower;
|
||||
}
|
||||
|
||||
final public double injectExternalPower(PowerUnits input, double amt)
|
||||
final public double injectExternalPower( PowerUnits input, double amt )
|
||||
{
|
||||
return PowerUnits.AE.convertTo( input, this.funnelPowerIntoStorage( input.convertTo( PowerUnits.AE, amt ), Actionable.MODULATE ) );
|
||||
}
|
||||
|
||||
protected double funnelPowerIntoStorage(double AEUnits, Actionable mode)
|
||||
protected double funnelPowerIntoStorage( double AEUnits, Actionable mode )
|
||||
{
|
||||
return this.injectAEPower( AEUnits, mode );
|
||||
}
|
||||
|
||||
@Override
|
||||
final public double injectAEPower(double amt, Actionable mode)
|
||||
final public double injectAEPower( double amt, Actionable mode )
|
||||
{
|
||||
if ( amt < 0.000001 )
|
||||
if( amt < 0.000001 )
|
||||
return 0;
|
||||
|
||||
if ( mode == Actionable.SIMULATE )
|
||||
if( mode == Actionable.SIMULATE )
|
||||
{
|
||||
double fakeBattery = this.internalCurrentPower + amt;
|
||||
|
||||
if ( fakeBattery > this.internalMaxPower )
|
||||
if( fakeBattery > this.internalMaxPower )
|
||||
return fakeBattery - this.internalMaxPower;
|
||||
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( this.internalCurrentPower < 0.01 && amt > 0.01 )
|
||||
if( this.internalCurrentPower < 0.01 && amt > 0.01 )
|
||||
this.PowerEvent( PowerEventType.PROVIDE_POWER );
|
||||
|
||||
this.internalCurrentPower += amt;
|
||||
if ( this.internalCurrentPower > this.internalMaxPower )
|
||||
if( this.internalCurrentPower > this.internalMaxPower )
|
||||
{
|
||||
amt = this.internalCurrentPower - this.internalMaxPower;
|
||||
this.internalCurrentPower = this.internalMaxPower;
|
||||
@@ -123,43 +123,11 @@ public abstract class AERootPoweredTile extends AEBaseInvTile implements IAEPowe
|
||||
}
|
||||
}
|
||||
|
||||
protected void PowerEvent(PowerEventType x)
|
||||
protected void PowerEvent( PowerEventType x )
|
||||
{
|
||||
// nothing.
|
||||
}
|
||||
|
||||
protected double extractAEPower(double amt, Actionable mode)
|
||||
{
|
||||
if ( mode == Actionable.SIMULATE )
|
||||
{
|
||||
if ( this.internalCurrentPower > amt )
|
||||
return amt;
|
||||
return this.internalCurrentPower;
|
||||
}
|
||||
|
||||
boolean wasFull = this.internalCurrentPower >= this.internalMaxPower - 0.001;
|
||||
if ( wasFull && amt > 0.001 )
|
||||
{
|
||||
this.PowerEvent( PowerEventType.REQUEST_POWER );
|
||||
}
|
||||
|
||||
if ( this.internalCurrentPower > amt )
|
||||
{
|
||||
this.internalCurrentPower -= amt;
|
||||
return amt;
|
||||
}
|
||||
|
||||
amt = this.internalCurrentPower;
|
||||
this.internalCurrentPower = 0;
|
||||
return amt;
|
||||
}
|
||||
|
||||
@Override
|
||||
final public double extractAEPower(double amt, Actionable mode, PowerMultiplier multiplier)
|
||||
{
|
||||
return multiplier.divide( this.extractAEPower( multiplier.multiply( amt ), mode ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
final public double getAEMaxPower()
|
||||
{
|
||||
@@ -183,4 +151,36 @@ public abstract class AERootPoweredTile extends AEBaseInvTile implements IAEPowe
|
||||
{
|
||||
return this.internalPowerFlow;
|
||||
}
|
||||
|
||||
@Override
|
||||
final public double extractAEPower( double amt, Actionable mode, PowerMultiplier multiplier )
|
||||
{
|
||||
return multiplier.divide( this.extractAEPower( multiplier.multiply( amt ), mode ) );
|
||||
}
|
||||
|
||||
protected double extractAEPower( double amt, Actionable mode )
|
||||
{
|
||||
if( mode == Actionable.SIMULATE )
|
||||
{
|
||||
if( this.internalCurrentPower > amt )
|
||||
return amt;
|
||||
return this.internalCurrentPower;
|
||||
}
|
||||
|
||||
boolean wasFull = this.internalCurrentPower >= this.internalMaxPower - 0.001;
|
||||
if( wasFull && amt > 0.001 )
|
||||
{
|
||||
this.PowerEvent( PowerEventType.REQUEST_POWER );
|
||||
}
|
||||
|
||||
if( this.internalCurrentPower > amt )
|
||||
{
|
||||
this.internalCurrentPower -= amt;
|
||||
return amt;
|
||||
}
|
||||
|
||||
amt = this.internalCurrentPower;
|
||||
this.internalCurrentPower = 0;
|
||||
return amt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.tile.powersink;
|
||||
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
@@ -32,14 +33,15 @@ import appeng.integration.abstraction.IIC2;
|
||||
import appeng.transformer.annotations.Integration.Interface;
|
||||
import appeng.util.Platform;
|
||||
|
||||
@Interface(iname = "IC2", iface = "ic2.api.energy.tile.IEnergySink")
|
||||
|
||||
@Interface( iname = "IC2", iface = "ic2.api.energy.tile.IEnergySink" )
|
||||
public abstract class IC2 extends AERootPoweredTile implements IEnergySink
|
||||
{
|
||||
|
||||
boolean isInIC2 = false;
|
||||
|
||||
@Override
|
||||
final public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
|
||||
final public boolean acceptsEnergyFrom( TileEntity emitter, ForgeDirection direction )
|
||||
{
|
||||
return this.getPowerSides().contains( direction );
|
||||
}
|
||||
@@ -51,7 +53,13 @@ public abstract class IC2 extends AERootPoweredTile implements IEnergySink
|
||||
}
|
||||
|
||||
@Override
|
||||
final public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage)
|
||||
final public int getSinkTier()
|
||||
{
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
final public double injectEnergy( ForgeDirection directionFrom, double amount, double voltage )
|
||||
{
|
||||
// just store the excess in the current block, if I return the waste,
|
||||
// IC2 will just disintegrate it - Oct 20th 2013
|
||||
@@ -60,12 +68,6 @@ public abstract class IC2 extends AERootPoweredTile implements IEnergySink
|
||||
return 0; // see above comment.
|
||||
}
|
||||
|
||||
@Override
|
||||
final public int getSinkTier()
|
||||
{
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
@@ -73,6 +75,19 @@ public abstract class IC2 extends AERootPoweredTile implements IEnergySink
|
||||
this.removeFromENet();
|
||||
}
|
||||
|
||||
private void removeFromENet()
|
||||
{
|
||||
if( AppEng.instance.isIntegrationEnabled( IntegrationType.IC2 ) )
|
||||
{
|
||||
IIC2 ic2Integration = (IIC2) AppEng.instance.getIntegration( IntegrationType.IC2 );
|
||||
if( this.isInIC2 && Platform.isServer() && ic2Integration != null )
|
||||
{
|
||||
ic2Integration.removeFromEnergyNet( this );
|
||||
this.isInIC2 = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload()
|
||||
{
|
||||
@@ -87,20 +102,12 @@ public abstract class IC2 extends AERootPoweredTile implements IEnergySink
|
||||
this.addToENet();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setPowerSides(EnumSet<ForgeDirection> sides)
|
||||
{
|
||||
super.setPowerSides( sides );
|
||||
this.removeFromENet();
|
||||
this.addToENet();
|
||||
}
|
||||
|
||||
private void addToENet()
|
||||
{
|
||||
if ( AppEng.instance.isIntegrationEnabled( IntegrationType.IC2 ) )
|
||||
if( AppEng.instance.isIntegrationEnabled( IntegrationType.IC2 ) )
|
||||
{
|
||||
IIC2 ic2Integration = (IIC2) AppEng.instance.getIntegration( IntegrationType.IC2 );
|
||||
if ( !this.isInIC2 && Platform.isServer() && ic2Integration != null )
|
||||
if( !this.isInIC2 && Platform.isServer() && ic2Integration != null )
|
||||
{
|
||||
ic2Integration.addToEnergyNet( this );
|
||||
this.isInIC2 = true;
|
||||
@@ -108,17 +115,11 @@ public abstract class IC2 extends AERootPoweredTile implements IEnergySink
|
||||
}
|
||||
}
|
||||
|
||||
private void removeFromENet()
|
||||
@Override
|
||||
protected void setPowerSides( EnumSet<ForgeDirection> sides )
|
||||
{
|
||||
if ( AppEng.instance.isIntegrationEnabled( IntegrationType.IC2 ) )
|
||||
{
|
||||
IIC2 ic2Integration = (IIC2) AppEng.instance.getIntegration( IntegrationType.IC2 );
|
||||
if ( this.isInIC2 && Platform.isServer() && ic2Integration != null )
|
||||
{
|
||||
ic2Integration.removeFromEnergyNet( this );
|
||||
this.isInIC2 = false;
|
||||
}
|
||||
}
|
||||
super.setPowerSides( sides );
|
||||
this.removeFromENet();
|
||||
this.addToENet();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.tile.powersink;
|
||||
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import mekanism.api.energy.IStrictEnergyAcceptor;
|
||||
@@ -25,30 +26,35 @@ import mekanism.api.energy.IStrictEnergyAcceptor;
|
||||
import appeng.api.config.PowerUnits;
|
||||
import appeng.transformer.annotations.Integration.Interface;
|
||||
|
||||
@Interface(iname = "Mekanism", iface = "mekanism.api.energy.IStrictEnergyAcceptor")
|
||||
public abstract class MekJoules extends RedstoneFlux implements IStrictEnergyAcceptor {
|
||||
|
||||
@Interface( iname = "Mekanism", iface = "mekanism.api.energy.IStrictEnergyAcceptor" )
|
||||
public abstract class MekJoules extends RedstoneFlux implements IStrictEnergyAcceptor
|
||||
{
|
||||
|
||||
@Override
|
||||
public double getEnergy() {
|
||||
public double getEnergy()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEnergy(double energy) {
|
||||
public void setEnergy( double energy )
|
||||
{
|
||||
double extra = this.injectExternalPower( PowerUnits.MK, energy );
|
||||
this.internalCurrentPower += PowerUnits.MK.convertTo(PowerUnits.AE, extra );
|
||||
this.internalCurrentPower += PowerUnits.MK.convertTo( PowerUnits.AE, extra );
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getMaxEnergy() {
|
||||
public double getMaxEnergy()
|
||||
{
|
||||
return this.getExternalPowerDemand( PowerUnits.MK, 100000 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public double transferEnergyToAcceptor(ForgeDirection side, double amount)
|
||||
public double transferEnergyToAcceptor( ForgeDirection side, double amount )
|
||||
{
|
||||
double demand = this.getExternalPowerDemand( PowerUnits.MK, Double.MAX_VALUE );
|
||||
if ( amount > demand )
|
||||
if( amount > demand )
|
||||
amount = demand;
|
||||
|
||||
double overflow = this.injectExternalPower( PowerUnits.MK, amount );
|
||||
@@ -56,8 +62,8 @@ public abstract class MekJoules extends RedstoneFlux implements IStrictEnergyAcc
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReceiveEnergy(ForgeDirection side) {
|
||||
return this.getPowerSides().contains(side);
|
||||
public boolean canReceiveEnergy( ForgeDirection side )
|
||||
{
|
||||
return this.getPowerSides().contains( side );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,10 +33,10 @@ public abstract class RedstoneFlux extends RotaryCraft implements IEnergyReceive
|
||||
@Override
|
||||
final public int receiveEnergy( ForgeDirection from, int maxReceive, boolean simulate )
|
||||
{
|
||||
final int networkRFDemand = ( int ) Math.floor( this.getExternalPowerDemand( PowerUnits.RF, maxReceive ) );
|
||||
final int networkRFDemand = (int) Math.floor( this.getExternalPowerDemand( PowerUnits.RF, maxReceive ) );
|
||||
final int usedRF = Math.min( maxReceive, networkRFDemand );
|
||||
|
||||
if ( !simulate )
|
||||
if( !simulate )
|
||||
{
|
||||
this.injectExternalPower( PowerUnits.RF, usedRF );
|
||||
}
|
||||
@@ -47,13 +47,13 @@ public abstract class RedstoneFlux extends RotaryCraft implements IEnergyReceive
|
||||
@Override
|
||||
final public int getEnergyStored( ForgeDirection from )
|
||||
{
|
||||
return ( int ) Math.floor( PowerUnits.AE.convertTo( PowerUnits.RF, this.getAECurrentPower() ) );
|
||||
return (int) Math.floor( PowerUnits.AE.convertTo( PowerUnits.RF, this.getAECurrentPower() ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
final public int getMaxEnergyStored( ForgeDirection from )
|
||||
{
|
||||
return ( int ) Math.floor( PowerUnits.AE.convertTo( PowerUnits.RF, this.getAEMaxPower() ) );
|
||||
return (int) Math.floor( PowerUnits.AE.convertTo( PowerUnits.RF, this.getAEMaxPower() ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.tile.powersink;
|
||||
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import Reika.RotaryCraft.API.Power.ShaftPowerReceiver;
|
||||
@@ -29,7 +30,8 @@ import appeng.transformer.annotations.Integration.Interface;
|
||||
import appeng.transformer.annotations.Integration.Method;
|
||||
import appeng.util.Platform;
|
||||
|
||||
@Interface(iname = "RotaryCraft", iface = "Reika.RotaryCraft.API.Power.ShaftPowerReceiver")
|
||||
|
||||
@Interface( iname = "RotaryCraft", iface = "Reika.RotaryCraft.API.Power.ShaftPowerReceiver" )
|
||||
public abstract class RotaryCraft extends IC2 implements ShaftPowerReceiver
|
||||
{
|
||||
|
||||
@@ -38,11 +40,11 @@ public abstract class RotaryCraft extends IC2 implements ShaftPowerReceiver
|
||||
private long power = 0;
|
||||
private int alpha = 0;
|
||||
|
||||
@TileEvent(TileEventType.TICK)
|
||||
@Method(iname = "RotaryCraft")
|
||||
@TileEvent( TileEventType.TICK )
|
||||
@Method( iname = "RotaryCraft" )
|
||||
public void Tick_RotaryCraft()
|
||||
{
|
||||
if ( this.worldObj != null && !this.worldObj.isRemote && this.power > 0 )
|
||||
if( this.worldObj != null && !this.worldObj.isRemote && this.power > 0 )
|
||||
this.injectExternalPower( PowerUnits.WA, this.power );
|
||||
}
|
||||
|
||||
@@ -77,58 +79,20 @@ public abstract class RotaryCraft extends IC2 implements ShaftPowerReceiver
|
||||
}
|
||||
|
||||
@Override
|
||||
final public void setIORenderAlpha(int io)
|
||||
final public void setIORenderAlpha( int io )
|
||||
{
|
||||
this.alpha = io;
|
||||
}
|
||||
|
||||
@Override
|
||||
final public void setOmega(int o)
|
||||
final public void setPower( long p )
|
||||
{
|
||||
this.omega = o;
|
||||
}
|
||||
|
||||
@Override
|
||||
final public void setTorque(int t)
|
||||
{
|
||||
this.torque = t;
|
||||
}
|
||||
|
||||
@Override
|
||||
final public void setPower(long p)
|
||||
{
|
||||
if ( Platform.isClient() )
|
||||
if( Platform.isClient() )
|
||||
return;
|
||||
|
||||
this.power = p;
|
||||
}
|
||||
|
||||
final public boolean canReadFromBlock(int x, int y, int z)
|
||||
{
|
||||
ForgeDirection side = ForgeDirection.UNKNOWN;
|
||||
|
||||
if ( x == this.xCoord - 1 )
|
||||
side = ForgeDirection.WEST;
|
||||
else if ( x == this.xCoord + 1 )
|
||||
side = ForgeDirection.EAST;
|
||||
else if ( z == this.zCoord - 1 )
|
||||
side = ForgeDirection.NORTH;
|
||||
else if ( z == this.zCoord + 1 )
|
||||
side = ForgeDirection.SOUTH;
|
||||
else if ( y == this.yCoord - 1 )
|
||||
side = ForgeDirection.DOWN;
|
||||
else if ( y == this.yCoord + 1 )
|
||||
side = ForgeDirection.UP;
|
||||
|
||||
return this.getPowerSides().contains( side );
|
||||
}
|
||||
|
||||
@Override
|
||||
final public boolean isReceiving()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
final public void noInputMachine()
|
||||
{
|
||||
@@ -138,15 +102,52 @@ public abstract class RotaryCraft extends IC2 implements ShaftPowerReceiver
|
||||
}
|
||||
|
||||
@Override
|
||||
final public boolean canReadFrom(ForgeDirection side)
|
||||
final public void setTorque( int t )
|
||||
{
|
||||
this.torque = t;
|
||||
}
|
||||
|
||||
@Override
|
||||
final public void setOmega( int o )
|
||||
{
|
||||
this.omega = o;
|
||||
}
|
||||
|
||||
final public boolean canReadFromBlock( int x, int y, int z )
|
||||
{
|
||||
ForgeDirection side = ForgeDirection.UNKNOWN;
|
||||
|
||||
if( x == this.xCoord - 1 )
|
||||
side = ForgeDirection.WEST;
|
||||
else if( x == this.xCoord + 1 )
|
||||
side = ForgeDirection.EAST;
|
||||
else if( z == this.zCoord - 1 )
|
||||
side = ForgeDirection.NORTH;
|
||||
else if( z == this.zCoord + 1 )
|
||||
side = ForgeDirection.SOUTH;
|
||||
else if( y == this.yCoord - 1 )
|
||||
side = ForgeDirection.DOWN;
|
||||
else if( y == this.yCoord + 1 )
|
||||
side = ForgeDirection.UP;
|
||||
|
||||
return this.getPowerSides().contains( side );
|
||||
}
|
||||
|
||||
@Override
|
||||
final public boolean canReadFrom( ForgeDirection side )
|
||||
{
|
||||
return this.getPowerSides().contains( side );
|
||||
}
|
||||
|
||||
@Override
|
||||
final public int getMinTorque(int available)
|
||||
final public boolean isReceiving()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
final public int getMinTorque( int available )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user