MJ 6 + MJ 5 Integration.

This commit is contained in:
AlgorithmX2 2014-05-11 16:13:37 -05:00
parent ce561ffbe3
commit be645f3e2f
7 changed files with 289 additions and 23 deletions

View file

@ -1,10 +1,9 @@
package appeng.integration.abstraction;
import appeng.tile.powersink.MinecraftJoules5;
public interface IMJ5
{
Object createPerdition(MinecraftJoules5 buildCraft);
Object createPerdition(Object buildCraft);
}

View file

@ -15,7 +15,7 @@ public abstract class BaseMJperdition extends AETileEventHandler
@Method(iname = "MJ5")
public abstract PowerReceiver getPowerReceiver();
public abstract double useEnergy(float f, float requred, boolean b);
public abstract double useEnergy(double f, double requred, boolean b);
public abstract void addEnergy(float failed);

View file

@ -3,7 +3,6 @@ package appeng.integration.modules;
import appeng.integration.BaseModule;
import appeng.integration.abstraction.IMJ5;
import appeng.integration.modules.helpers.MJPerdition;
import appeng.tile.powersink.MinecraftJoules5;
import buildcraft.api.power.IPowerReceptor;
public class MJ5 extends BaseModule implements IMJ5
@ -16,21 +15,23 @@ public class MJ5 extends BaseModule implements IMJ5
}
@Override
public Object createPerdition(MinecraftJoules5 buildCraft)
public Object createPerdition(Object buildCraft)
{
if ( buildCraft instanceof IPowerReceptor )
return new MJPerdition( buildCraft );
return new MJPerdition( (IPowerReceptor) buildCraft );
return null;
}
@Override
public void Init() throws Throwable
{
}
@Override
public void PostInit() throws Throwable
{
}
}

View file

@ -41,7 +41,7 @@ public class MJPerdition extends BaseMJperdition
}
@Override
public double useEnergy(float min, float max, boolean doUse)
public double useEnergy(double min, double max, boolean doUse)
{
return bcPowerHandler.useEnergy( min, max, doUse );
}

View file

@ -13,11 +13,19 @@ import appeng.api.networking.IGridNode;
import appeng.api.networking.ticking.IGridTickable;
import appeng.api.networking.ticking.TickRateModulation;
import appeng.api.networking.ticking.TickingRequest;
import appeng.core.AELog;
import appeng.core.AppEng;
import appeng.core.settings.TickRates;
import appeng.integration.abstraction.IMJ5;
import appeng.integration.abstraction.helpers.BaseMJperdition;
import appeng.me.GridAccessException;
import appeng.me.cache.helpers.TunnelCollection;
import appeng.transformer.annotations.integration.Interface;
import appeng.transformer.annotations.integration.InterfaceList;
import appeng.transformer.annotations.integration.Method;
import buildcraft.api.mj.IBatteryObject;
import buildcraft.api.mj.ISidedBatteryProvider;
import buildcraft.api.mj.MjAPI;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
@ -25,11 +33,13 @@ import buildcraft.api.power.PowerHandler.Type;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@Interface(iface = "buildcraft.api.power.IPowerReceptor", iname = "MJ5")
public class PartP2PBCPower extends PartP2PTunnel<PartP2PBCPower> implements IPowerReceptor, IGridTickable
@InterfaceList(value = { @Interface(iface = "buildcraft.api.mj.ISidedBatteryProvider", iname = "MJ6"),
@Interface(iface = "buildcraft.api.power.IPowerReceptor", iname = "MJ5"),
@Interface(iface = "appeng.api.networking.ticking.IGridTickable", iname = "MJ5") })
public class PartP2PBCPower extends PartP2PTunnel<PartP2PBCPower> implements IPowerReceptor, ISidedBatteryProvider, IBatteryObject, IGridTickable
{
PowerHandler pp;
BaseMJperdition pp;
public TunnelType getTunnelType()
{
@ -42,17 +52,23 @@ public class PartP2PBCPower extends PartP2PTunnel<PartP2PBCPower> implements IPo
if ( !AppEng.instance.isIntegrationEnabled( "MJ5" ) && !AppEng.instance.isIntegrationEnabled( "MJ6" ) )
throw new RuntimeException( "MJ Not installed!" );
pp = new PowerHandler( this, Type.MACHINE );
pp.configure( 1f, 320f, 800f, 640f );
if ( AppEng.instance.isIntegrationEnabled( "MJ5" ) )
{
pp = (BaseMJperdition) ((IMJ5) AppEng.instance.getIntegration( "MJ5" )).createPerdition( this );
if ( pp != null )
pp.configure( 1, 380, 1.0f / 5.0f, 1000 );
}
}
@Override
@Method(iname = "MJ5")
public TickingRequest getTickingRequest(IGridNode node)
{
return new TickingRequest( TickRates.MJTunnel.min, TickRates.MJTunnel.max, false, false );
}
@Override
@Method(iname = "MJ5")
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
{
if ( !output && proxy.isActive() )
@ -93,7 +109,8 @@ public class PartP2PBCPower extends PartP2PTunnel<PartP2PBCPower> implements IPo
if ( totalRequiredPower < 0.1 )
return TickRateModulation.SLOWER;
double currentTotal = pp.getEnergyStored();
double currentTotal = pp.getPowerReceiver().getEnergyStored();
AELog.info( "currentTotal: " + currentTotal );
if ( currentTotal < 0.01 )
return TickRateModulation.SLOWER;
@ -106,16 +123,19 @@ public class PartP2PBCPower extends PartP2PTunnel<PartP2PBCPower> implements IPo
if ( tp != null )
{
double howmuch = tp.powerRequest(); // orientation.getOpposite()
// );
AELog.info( "pulled: " + howmuch );
// );
if ( howmuch > tp.getMaxEnergyReceived() )
howmuch = tp.getMaxEnergyReceived();
AELog.info( "howmuch: " + howmuch );
if ( howmuch > 0.01 && howmuch > tp.getMinEnergyReceived() )
{
double toPull = currentTotal * (howmuch / totalRequiredPower);
double pulled = pp.useEnergy( 0, toPull, true );
QueueTunnelDrain( PowerUnits.MJ, pulled );
AELog.info( "pulled: " + pulled );
tp.receiveEnergy( Type.PIPE, pulled, o.side.getOpposite() );
}
}
@ -133,6 +153,16 @@ public class PartP2PBCPower extends PartP2PTunnel<PartP2PBCPower> implements IPo
return 0.5f;
};
@Method(iname = "MJ6")
private IBatteryObject getTargetBattery()
{
TileEntity te = getWorld().getTileEntity( tile.xCoord + side.offsetX, tile.yCoord + side.offsetY, tile.zCoord + side.offsetZ );
if ( te != null )
return MjAPI.getMjBattery( te );
return null;
}
@Method(iname = "MJ5")
private IPowerReceptor getPowerTarget()
{
TileEntity te = getWorld().getTileEntity( tile.xCoord + side.offsetX, tile.yCoord + side.offsetY, tile.zCoord + side.offsetZ );
@ -148,14 +178,16 @@ public class PartP2PBCPower extends PartP2PTunnel<PartP2PBCPower> implements IPo
public void writeToNBT(NBTTagCompound tag)
{
super.writeToNBT( tag );
pp.writeToNBT( tag );
if ( pp != null )
pp.writeToNBT( tag );
}
@Override
public void readFromNBT(NBTTagCompound tag)
{
super.readFromNBT( tag );
pp.readFromNBT( tag );
if ( pp != null )
pp.readFromNBT( tag );
}
@SideOnly(Side.CLIENT)
@ -165,14 +197,16 @@ public class PartP2PBCPower extends PartP2PTunnel<PartP2PBCPower> implements IPo
}
@Override
@Method(iname = "MJ5")
public PowerReceiver getPowerReceiver(ForgeDirection side)
{
if ( side.equals( side ) )
return pp.getPowerReceiver();
return ((BaseMJperdition) pp).getPowerReceiver();
return null;
}
@Override
@Method(iname = "MJ5")
public void doWork(PowerHandler workProvider)
{
@ -184,4 +218,229 @@ public class PartP2PBCPower extends PartP2PTunnel<PartP2PBCPower> implements IPo
return tile.getWorldObj();
}
@Override
@Method(iname = "MJ6")
public IBatteryObject getMjBattery(String kind)
{
return this;
}
@Override
@Method(iname = "MJ6")
public IBatteryObject getMjBattery(String kind, ForgeDirection direction)
{
return this;
}
@Override
@Method(iname = "MJ6")
public double getEnergyRequested()
{
try
{
double totalRequiredPower = 0.0f;
for (PartP2PBCPower g : getOutputs())
{
IBatteryObject o = g.getTargetBattery();
if ( o != null )
totalRequiredPower += o.getEnergyRequested();
}
return totalRequiredPower;
}
catch (GridAccessException e)
{
return 0;
}
}
@Override
@Method(iname = "MJ6")
public double addEnergy(double mj)
{
return addEnergyInternal( mj, false, false );
}
@Override
@Method(iname = "MJ6")
public double addEnergy(double mj, boolean ignoreCycleLimit)
{
return addEnergyInternal( mj, true, ignoreCycleLimit );
}
@Method(iname = "MJ6")
private double addEnergyInternal(double mj, boolean cycleLimitMode, boolean ignoreCycleLimit)
{
if ( !output && proxy.isActive() )
return 0;
double originaInput = mj;
try
{
TunnelCollection<PartP2PBCPower> outs = getOutputs();
double outputs = 0;
for (PartP2PBCPower g : outs)
{
IBatteryObject o = g.getTargetBattery();
if ( o != null )
{
outputs = outputs + 1.0;
}
}
if ( outputs < 0.0000001 )
return 0;
for (PartP2PBCPower g : outs)
{
IBatteryObject o = g.getTargetBattery();
if ( o != null )
{
double fraction = originaInput / outputs;
if ( cycleLimitMode )
fraction = o.addEnergy( fraction );
else
fraction = o.addEnergy( fraction, ignoreCycleLimit );
mj -= fraction;
}
}
if ( mj > 0 )
{
for (PartP2PBCPower g : outs)
{
IBatteryObject o = g.getTargetBattery();
if ( o != null )
{
if ( cycleLimitMode )
mj = mj - o.addEnergy( mj );
else
mj = mj - o.addEnergy( mj, ignoreCycleLimit );
}
}
}
return originaInput - mj;
}
catch (GridAccessException e)
{
return 0;
}
}
@Override
@Method(iname = "MJ6")
public double getEnergyStored()
{
try
{
double totalRequiredPower = 0.0f;
for (PartP2PBCPower g : getOutputs())
{
IBatteryObject o = g.getTargetBattery();
if ( o != null )
totalRequiredPower += o.getEnergyStored();
}
return totalRequiredPower;
}
catch (GridAccessException e)
{
return 0;
}
}
@Override
@Method(iname = "MJ6")
public void setEnergyStored(double mj)
{
// EHh?!
}
@Override
public double maxCapacity()
{
try
{
double totalRequiredPower = 0.0f;
for (PartP2PBCPower g : getOutputs())
{
IBatteryObject o = g.getTargetBattery();
if ( o != null )
totalRequiredPower += o.maxCapacity();
}
return totalRequiredPower;
}
catch (GridAccessException e)
{
return 0;
}
}
@Override
@Method(iname = "MJ6")
public double minimumConsumption()
{
try
{
double totalRequiredPower = 1000000000000.0;
for (PartP2PBCPower g : getOutputs())
{
IBatteryObject o = g.getTargetBattery();
if ( o != null )
totalRequiredPower = Math.min( totalRequiredPower, o.minimumConsumption() );
}
return totalRequiredPower;
}
catch (GridAccessException e)
{
return 0;
}
}
@Override
@Method(iname = "MJ6")
public double maxReceivedPerCycle()
{
try
{
double totalRequiredPower = 1000000.0;
for (PartP2PBCPower g : getOutputs())
{
IBatteryObject o = g.getTargetBattery();
if ( o != null )
totalRequiredPower = Math.min( totalRequiredPower, o.maxReceivedPerCycle() );
}
return totalRequiredPower;
}
catch (GridAccessException e)
{
return 0;
}
}
@Override
@Method(iname = "MJ6")
public IBatteryObject reconfigure(double maxCapacity, double maxReceivedPerCycle, double minimumConsumption)
{
return this;
}
@Override
@Method(iname = "MJ6")
public String kind()
{
return "tunnel";
}
}

View file

@ -13,7 +13,7 @@ import appeng.transformer.annotations.integration.Interface;
import appeng.util.Platform;
@Interface(iname = "IC2", iface = "ic2.api.energy.tile.IEnergySink")
public abstract class IC2 extends MinecraftJoules5 implements IEnergySink
public abstract class IC2 extends MinecraftJoules6 implements IEnergySink
{
boolean isInIC2 = false;

View file

@ -9,9 +9,16 @@ import buildcraft.api.mj.IBatteryProvider;
@InterfaceList(value = { @Interface(iname = "MJ6", iface = "buildcraft.api.mj.IBatteryProvider"),
@Interface(iname = "MJ6", iface = "buildcraft.api.mj.IBatteryObject") })
public abstract class MinecraftJoules6 extends AERootPoweredTile implements IBatteryProvider, IBatteryObject
public abstract class MinecraftJoules6 extends MinecraftJoules5 implements IBatteryProvider, IBatteryObject
{
@Override
@Method(iname = "MJ6")
public String kind()
{
return null;
}
@Override
@Method(iname = "MJ6")
public double getEnergyRequested()
@ -23,7 +30,7 @@ public abstract class MinecraftJoules6 extends AERootPoweredTile implements IBat
@Method(iname = "MJ6")
public double addEnergy(double amount)
{
double overflow = PowerUnits.MJ.convertTo( PowerUnits.AE, injectExternalPower( PowerUnits.MJ, amount ) );
double overflow = injectExternalPower( PowerUnits.MJ, amount );
return amount - overflow;
}
@ -31,7 +38,7 @@ public abstract class MinecraftJoules6 extends AERootPoweredTile implements IBat
@Method(iname = "MJ6")
public double addEnergy(double amount, boolean ignoreCycleLimit)
{
double overflow = PowerUnits.MJ.convertTo( PowerUnits.AE, injectExternalPower( PowerUnits.MJ, amount ) );
double overflow = injectExternalPower( PowerUnits.MJ, amount );
return amount - overflow;
}
@ -74,12 +81,12 @@ public abstract class MinecraftJoules6 extends AERootPoweredTile implements IBat
@Method(iname = "MJ6")
public IBatteryObject reconfigure(double maxCapacity, double maxReceivedPerCycle, double minimumConsumption)
{
return getMjBattery();
return getMjBattery( "" );
}
@Override
@Method(iname = "MJ6")
public IBatteryObject getMjBattery()
public IBatteryObject getMjBattery(String kind)
{
return this;
}