Initial 1.7.10 IC2 API Update.

This commit is contained in:
AlgorithmX2 2014-06-28 17:32:40 -05:00
parent 1cbda9e7ae
commit 6718fae629
5 changed files with 89 additions and 40 deletions

View file

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

View file

@ -112,7 +112,7 @@ public class LayerIEnergySink extends LayerBase implements IEnergySink
}
@Override
public double demandedEnergyUnits()
public double getDemandedEnergy()
{
if ( !isInIC2() )
return 0;
@ -125,7 +125,7 @@ public class LayerIEnergySink extends LayerBase implements IEnergySink
if ( part instanceof IEnergySink )
{
// 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
public double injectEnergyUnits(ForgeDirection directionFrom, double amount)
public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage)
{
if ( !isInIC2() )
return amount;
@ -143,7 +143,7 @@ public class LayerIEnergySink extends LayerBase implements IEnergySink
IPart part = getPart( dir );
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
public int getMaxSafeInput()
public int getSinkTier()
{
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...
double OutputPacketA;
double OutputPacketB;
double OutputEnergyA;
double OutputEnergyB;
// two packet buffering...
double OutputVoltageA;
double OutputVoltageB;
@Override
public void writeToNBT(NBTTagCompound tag)
{
super.writeToNBT( tag );
tag.setDouble( "OutputPacket", OutputPacketA );
tag.setDouble( "OutputPacket2", OutputPacketB );
tag.setDouble( "OutputPacket", OutputEnergyA );
tag.setDouble( "OutputPacket2", OutputEnergyB );
tag.setDouble( "OutputVoltageA", OutputVoltageA );
tag.setDouble( "OutputVoltageB", OutputVoltageB );
}
@Override
public void readFromNBT(NBTTagCompound tag)
{
super.readFromNBT( tag );
OutputPacketA = tag.getDouble( "OutputPacket" );
OutputPacketB = tag.getDouble( "OutputPacket2" );
OutputEnergyA = tag.getDouble( "OutputPacket" );
OutputEnergyB = tag.getDouble( "OutputPacket2" );
OutputVoltageA = tag.getDouble( "OutputVoltageA" );
OutputVoltageB = tag.getDouble( "OutputVoltageB" );
}
@SideOnly(Side.CLIENT)
@ -79,7 +87,7 @@ public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements i
}
@Override
public double demandedEnergyUnits()
public double getDemandedEnergy()
{
if ( output )
return 0;
@ -88,7 +96,7 @@ public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements i
{
for (PartP2PIC2Power t : getOutputs())
{
if ( t.OutputPacketA <= 0.0001 || t.OutputPacketB <= 0.0001 )
if ( t.OutputEnergyA <= 0.0001 || t.OutputEnergyB <= 0.0001 )
{
return 2048;
}
@ -120,7 +128,7 @@ public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements i
};
@Override
public double injectEnergyUnits(ForgeDirection directionFrom, double amount)
public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage)
{
TunnelCollection<PartP2PIC2Power> outs;
try
@ -138,14 +146,14 @@ public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements i
LinkedList<PartP2PIC2Power> Options = new LinkedList();
for (PartP2PIC2Power o : outs)
{
if ( o.OutputPacketA <= 0.01 )
if ( o.OutputEnergyA <= 0.01 )
Options.add( o );
}
if ( Options.isEmpty() )
{
for (PartP2PIC2Power o : outs)
if ( o.OutputPacketB <= 0.01 )
if ( o.OutputEnergyB <= 0.01 )
Options.add( o );
}
@ -160,17 +168,19 @@ public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements i
PartP2PIC2Power x = (PartP2PIC2Power) Platform.pickRandom( Options );
if ( x != null && x.OutputPacketA <= 0.001 )
if ( x != null && x.OutputEnergyA <= 0.001 )
{
QueueTunnelDrain( PowerUnits.EU, amount );
x.OutputPacketA = amount;
x.OutputEnergyA = amount;
x.OutputVoltageA = voltage;
return 0;
}
if ( x != null && x.OutputPacketB <= 0.001 )
if ( x != null && x.OutputEnergyB <= 0.001 )
{
QueueTunnelDrain( PowerUnits.EU, amount );
x.OutputPacketB = amount;
x.OutputEnergyB = amount;
x.OutputVoltageB = voltage;
return 0;
}
@ -178,28 +188,50 @@ public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements i
}
@Override
public int getMaxSafeInput()
public int getSinkTier()
{
return Integer.MAX_VALUE;
return 4;
}
@Override
public double getOfferedEnergy()
{
if ( output )
return OutputPacketA;
return OutputEnergyA;
return 0;
}
@Override
public void drawEnergy(double amount)
{
OutputPacketA -= amount;
if ( OutputPacketA < 0.001 )
OutputEnergyA -= amount;
if ( OutputEnergyA < 0.001 )
{
OutputPacketA = OutputPacketB;
OutputPacketB = 0;
OutputEnergyA = OutputEnergyB;
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
final public double demandedEnergyUnits()
final public double getDemandedEnergy()
{
return getExternalPowerDemand( PowerUnits.EU, Double.MAX_VALUE );
}
@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,
// IC2 will just disintegrate it - Oct 20th 2013
@ -41,7 +41,7 @@ public abstract class IC2 extends MinecraftJoules6 implements IEnergySink
}
@Override
final public int getMaxSafeInput()
final public int getSinkTier()
{
return Integer.MAX_VALUE;
}