This commit is contained in:
AlgorithmX2 2014-06-28 17:34:03 -05:00
commit e5e373ce10
7 changed files with 91 additions and 41 deletions

View file

@ -669,7 +669,7 @@ public class AEBaseBlock extends BlockContainer implements IAEFeature
} }
} }
if ( id.removedByPlayer( w, player, x, y, z ) ) if ( id.removedByPlayer( w, player, x, y, z, false ) )
{ {
List<ItemStack> l = new ArrayList<ItemStack>(); List<ItemStack> l = new ArrayList<ItemStack>();
for (ItemStack iss : drops) for (ItemStack iss : drops)

View file

@ -271,6 +271,7 @@ public class BlockCableBus extends AEBaseBlock implements IRedNetConnection
return cb( world, x, y, z ).isEmpty(); return cb( world, x, y, z ).isEmpty();
} }
@SuppressWarnings("deprecation")
@Override @Override
public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z) public boolean removedByPlayer(World world, EntityPlayer player, int x, int y, int z)
{ {

View file

@ -20,10 +20,10 @@ public class IC2 extends AERootPoweredItem implements IElectricItemManager, ISpe
} }
@Override @Override
public int charge(ItemStack is, int amount, int tier, boolean ignoreTransferLimit, boolean simulate) public double charge(ItemStack is, double amount, int tier, boolean ignoreTransferLimit, boolean simulate)
{ {
int addedAmt = amount; double addedAmt = amount;
int limit = getTransferLimit( is ); double limit = getTransferLimit( is );
if ( !ignoreTransferLimit && amount > limit ) if ( !ignoreTransferLimit && amount > limit )
addedAmt = limit; addedAmt = limit;
@ -32,25 +32,25 @@ public class IC2 extends AERootPoweredItem implements IElectricItemManager, ISpe
} }
@Override @Override
public int discharge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate) public double discharge(ItemStack itemStack, double amount, int tier, boolean ignoreTransferLimit, boolean externaly, boolean simulate)
{ {
return 0; return 0;
} }
@Override @Override
public int getCharge(ItemStack is) public double getCharge(ItemStack is)
{ {
return (int) PowerUnits.AE.convertTo( PowerUnits.EU, getAECurrentPower( is ) ); return (int) PowerUnits.AE.convertTo( PowerUnits.EU, getAECurrentPower( is ) );
} }
@Override @Override
public boolean canUse(ItemStack is, int amount) public boolean canUse(ItemStack is, double amount)
{ {
return getCharge( is ) > amount; return getCharge( is ) > amount;
} }
@Override @Override
public boolean use(ItemStack is, int amount, EntityLivingBase entity) public boolean use(ItemStack is, double amount, EntityLivingBase entity)
{ {
if ( canUse( is, amount ) ) if ( canUse( is, amount ) )
{ {
@ -92,9 +92,9 @@ public class IC2 extends AERootPoweredItem implements IElectricItemManager, ISpe
} }
@Override @Override
public int getMaxCharge(ItemStack itemStack) public double getMaxCharge(ItemStack itemStack)
{ {
return (int) PowerUnits.AE.convertTo( PowerUnits.EU, getAEMaxPower( itemStack ) ); return PowerUnits.AE.convertTo( PowerUnits.EU, getAEMaxPower( itemStack ) );
} }
@Override @Override
@ -104,7 +104,7 @@ public class IC2 extends AERootPoweredItem implements IElectricItemManager, ISpe
} }
@Override @Override
public int getTransferLimit(ItemStack itemStack) public double getTransferLimit(ItemStack itemStack)
{ {
return Math.max( 32, getMaxCharge( itemStack ) / 200 ); return Math.max( 32, getMaxCharge( itemStack ) / 200 );
} }

View file

@ -112,7 +112,7 @@ public class LayerIEnergySink extends LayerBase implements IEnergySink
} }
@Override @Override
public double demandedEnergyUnits() public double getDemandedEnergy()
{ {
if ( !isInIC2() ) if ( !isInIC2() )
return 0; return 0;
@ -125,7 +125,7 @@ public class LayerIEnergySink extends LayerBase implements IEnergySink
if ( part instanceof IEnergySink ) if ( part instanceof IEnergySink )
{ {
// use lower number cause ic2 deletes power it sends that isn't recieved. // use lower number cause ic2 deletes power it sends that isn't recieved.
return ((IEnergySink) part).demandedEnergyUnits(); return ((IEnergySink) part).getDemandedEnergy();
} }
} }
@ -133,7 +133,7 @@ public class LayerIEnergySink extends LayerBase implements IEnergySink
} }
@Override @Override
public double injectEnergyUnits(ForgeDirection directionFrom, double amount) public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage)
{ {
if ( !isInIC2() ) if ( !isInIC2() )
return amount; return amount;
@ -143,7 +143,7 @@ public class LayerIEnergySink extends LayerBase implements IEnergySink
IPart part = getPart( dir ); IPart part = getPart( dir );
if ( part instanceof IEnergySink ) if ( part instanceof IEnergySink )
{ {
return ((IEnergySink) part).injectEnergyUnits( directionFrom, amount ); return ((IEnergySink) part).injectEnergy( directionFrom, amount, voltage );
} }
} }
@ -151,7 +151,7 @@ public class LayerIEnergySink extends LayerBase implements IEnergySink
} }
@Override @Override
public int getMaxSafeInput() public int getSinkTier()
{ {
return Integer.MAX_VALUE; // no real options here... return Integer.MAX_VALUE; // no real options here...
} }

View file

@ -147,4 +147,21 @@ public class LayerIEnergySource extends LayerBase implements IEnergySource
} }
} }
@Override
public int getSourceTier()
{
// this is a flawed implementation, that requires a change to the IC2 API.
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
IPart part = getPart( dir );
if ( part instanceof IEnergySource )
{
return ((IEnergySource) part).getSourceTier();
}
}
return 0;
}
} }

View file

@ -37,23 +37,31 @@ public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements i
} }
// two packet buffering... // two packet buffering...
double OutputPacketA; double OutputEnergyA;
double OutputPacketB; double OutputEnergyB;
// two packet buffering...
double OutputVoltageA;
double OutputVoltageB;
@Override @Override
public void writeToNBT(NBTTagCompound tag) public void writeToNBT(NBTTagCompound tag)
{ {
super.writeToNBT( tag ); super.writeToNBT( tag );
tag.setDouble( "OutputPacket", OutputPacketA ); tag.setDouble( "OutputPacket", OutputEnergyA );
tag.setDouble( "OutputPacket2", OutputPacketB ); tag.setDouble( "OutputPacket2", OutputEnergyB );
tag.setDouble( "OutputVoltageA", OutputVoltageA );
tag.setDouble( "OutputVoltageB", OutputVoltageB );
} }
@Override @Override
public void readFromNBT(NBTTagCompound tag) public void readFromNBT(NBTTagCompound tag)
{ {
super.readFromNBT( tag ); super.readFromNBT( tag );
OutputPacketA = tag.getDouble( "OutputPacket" ); OutputEnergyA = tag.getDouble( "OutputPacket" );
OutputPacketB = tag.getDouble( "OutputPacket2" ); OutputEnergyB = tag.getDouble( "OutputPacket2" );
OutputVoltageA = tag.getDouble( "OutputVoltageA" );
OutputVoltageB = tag.getDouble( "OutputVoltageB" );
} }
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
@ -79,7 +87,7 @@ public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements i
} }
@Override @Override
public double demandedEnergyUnits() public double getDemandedEnergy()
{ {
if ( output ) if ( output )
return 0; return 0;
@ -88,7 +96,7 @@ public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements i
{ {
for (PartP2PIC2Power t : getOutputs()) for (PartP2PIC2Power t : getOutputs())
{ {
if ( t.OutputPacketA <= 0.0001 || t.OutputPacketB <= 0.0001 ) if ( t.OutputEnergyA <= 0.0001 || t.OutputEnergyB <= 0.0001 )
{ {
return 2048; return 2048;
} }
@ -120,7 +128,7 @@ public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements i
}; };
@Override @Override
public double injectEnergyUnits(ForgeDirection directionFrom, double amount) public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage)
{ {
TunnelCollection<PartP2PIC2Power> outs; TunnelCollection<PartP2PIC2Power> outs;
try try
@ -138,14 +146,14 @@ public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements i
LinkedList<PartP2PIC2Power> Options = new LinkedList(); LinkedList<PartP2PIC2Power> Options = new LinkedList();
for (PartP2PIC2Power o : outs) for (PartP2PIC2Power o : outs)
{ {
if ( o.OutputPacketA <= 0.01 ) if ( o.OutputEnergyA <= 0.01 )
Options.add( o ); Options.add( o );
} }
if ( Options.isEmpty() ) if ( Options.isEmpty() )
{ {
for (PartP2PIC2Power o : outs) for (PartP2PIC2Power o : outs)
if ( o.OutputPacketB <= 0.01 ) if ( o.OutputEnergyB <= 0.01 )
Options.add( o ); Options.add( o );
} }
@ -160,17 +168,19 @@ public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements i
PartP2PIC2Power x = (PartP2PIC2Power) Platform.pickRandom( Options ); PartP2PIC2Power x = (PartP2PIC2Power) Platform.pickRandom( Options );
if ( x != null && x.OutputPacketA <= 0.001 ) if ( x != null && x.OutputEnergyA <= 0.001 )
{ {
QueueTunnelDrain( PowerUnits.EU, amount ); QueueTunnelDrain( PowerUnits.EU, amount );
x.OutputPacketA = amount; x.OutputEnergyA = amount;
x.OutputVoltageA = voltage;
return 0; return 0;
} }
if ( x != null && x.OutputPacketB <= 0.001 ) if ( x != null && x.OutputEnergyB <= 0.001 )
{ {
QueueTunnelDrain( PowerUnits.EU, amount ); QueueTunnelDrain( PowerUnits.EU, amount );
x.OutputPacketB = amount; x.OutputEnergyB = amount;
x.OutputVoltageB = voltage;
return 0; return 0;
} }
@ -178,28 +188,50 @@ public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements i
} }
@Override @Override
public int getMaxSafeInput() public int getSinkTier()
{ {
return Integer.MAX_VALUE; return 4;
} }
@Override @Override
public double getOfferedEnergy() public double getOfferedEnergy()
{ {
if ( output ) if ( output )
return OutputPacketA; return OutputEnergyA;
return 0; return 0;
} }
@Override @Override
public void drawEnergy(double amount) public void drawEnergy(double amount)
{ {
OutputPacketA -= amount; OutputEnergyA -= amount;
if ( OutputPacketA < 0.001 ) if ( OutputEnergyA < 0.001 )
{ {
OutputPacketA = OutputPacketB; OutputEnergyA = OutputEnergyB;
OutputPacketB = 0; OutputEnergyB = 0;
OutputVoltageA = OutputVoltageB;
OutputVoltageB = 0;
} }
} }
@Override
public int getSourceTier()
{
if ( output )
return calculateTierFromVoltage( OutputVoltageA );
return 4;
}
private int calculateTierFromVoltage(double outputVoltageA2)
{
for (int x = 8; x >= 0; x--)
{
double top = ic2.api.energy.EnergyNet.instance.getPowerFromTier( x );
if ( outputVoltageA2 > top && top > 0 )
return x + 1;
}
return 0;
}
} }

View file

@ -25,13 +25,13 @@ public abstract class IC2 extends MinecraftJoules6 implements IEnergySink
} }
@Override @Override
final public double demandedEnergyUnits() final public double getDemandedEnergy()
{ {
return getExternalPowerDemand( PowerUnits.EU, Double.MAX_VALUE ); return getExternalPowerDemand( PowerUnits.EU, Double.MAX_VALUE );
} }
@Override @Override
final public double injectEnergyUnits(ForgeDirection directionFrom, double amount) final public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage)
{ {
// just store the excess in the current block, if I return the waste, // just store the excess in the current block, if I return the waste,
// IC2 will just disintegrate it - Oct 20th 2013 // IC2 will just disintegrate it - Oct 20th 2013
@ -41,7 +41,7 @@ public abstract class IC2 extends MinecraftJoules6 implements IEnergySink
} }
@Override @Override
final public int getMaxSafeInput() final public int getSinkTier()
{ {
return Integer.MAX_VALUE; return Integer.MAX_VALUE;
} }