Merge branch 'master' of https://bitbucket.org/AlgorithmX2/appliedenergistics2 into rv1
Conflicts: container/AEBaseContainer.java core/sync/AppEngPacketHandlerBase.java
This commit is contained in:
@@ -79,6 +79,23 @@ public class CableBusContainer implements AEMultiTile, ICableBusContainer
|
||||
return sides[side.ordinal()];
|
||||
}
|
||||
|
||||
public void rotateLeft()
|
||||
{
|
||||
IPart newSides[] = new IPart[6];
|
||||
|
||||
newSides[ForgeDirection.UP.ordinal()] = sides[ForgeDirection.UP.ordinal()];
|
||||
newSides[ForgeDirection.DOWN.ordinal()] = sides[ForgeDirection.DOWN.ordinal()];
|
||||
|
||||
newSides[ForgeDirection.EAST.ordinal()] = sides[ForgeDirection.NORTH.ordinal()];
|
||||
newSides[ForgeDirection.SOUTH.ordinal()] = sides[ForgeDirection.EAST.ordinal()];
|
||||
newSides[ForgeDirection.WEST.ordinal()] = sides[ForgeDirection.SOUTH.ordinal()];
|
||||
newSides[ForgeDirection.NORTH.ordinal()] = sides[ForgeDirection.WEST.ordinal()];
|
||||
|
||||
sides = newSides;
|
||||
|
||||
fc.rotateLeft();
|
||||
}
|
||||
|
||||
public void updateDynamicRender()
|
||||
{
|
||||
requiresDynamicRender = false;
|
||||
|
||||
+266
-12
@@ -15,9 +15,16 @@ import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
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 +32,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 = "BC")
|
||||
public class PartP2PBCPower extends PartP2PTunnel<PartP2PBCPower> implements IPowerReceptor, IGridTickable
|
||||
@InterfaceList(value = { @Interface(iface = "buildcraft.api.mj.ISidedBatteryProvider", iname = "MJ6"),
|
||||
@Interface(iface = "buildcraft.api.mj.IBatteryObject", 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()
|
||||
{
|
||||
@@ -39,20 +48,26 @@ public class PartP2PBCPower extends PartP2PTunnel<PartP2PBCPower> implements IPo
|
||||
public PartP2PBCPower(ItemStack is) {
|
||||
super( is );
|
||||
|
||||
if ( !AppEng.instance.isIntegrationEnabled( "MJ" ) )
|
||||
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 +108,7 @@ public class PartP2PBCPower extends PartP2PTunnel<PartP2PBCPower> implements IPo
|
||||
if ( totalRequiredPower < 0.1 )
|
||||
return TickRateModulation.SLOWER;
|
||||
|
||||
double currentTotal = pp.getEnergyStored();
|
||||
double currentTotal = pp.getPowerReceiver().getEnergyStored();
|
||||
if ( currentTotal < 0.01 )
|
||||
return TickRateModulation.SLOWER;
|
||||
|
||||
@@ -105,8 +120,8 @@ public class PartP2PBCPower extends PartP2PTunnel<PartP2PBCPower> implements IPo
|
||||
PowerReceiver tp = target.getPowerReceiver( side.getOpposite() );
|
||||
if ( tp != null )
|
||||
{
|
||||
double howmuch = tp.powerRequest(); // orientation.getOpposite()
|
||||
// );
|
||||
double howmuch = tp.powerRequest();
|
||||
|
||||
if ( howmuch > tp.getMaxEnergyReceived() )
|
||||
howmuch = tp.getMaxEnergyReceived();
|
||||
|
||||
@@ -133,6 +148,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 +173,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 +192,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 +213,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";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user