Relocate Source to proper directory.
This commit is contained in:
@@ -0,0 +1,442 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.config.PowerUnits;
|
||||
import appeng.api.config.TunnelType;
|
||||
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.AppEng;
|
||||
import appeng.core.settings.TickRates;
|
||||
import appeng.integration.IntegrationType;
|
||||
import appeng.integration.abstraction.IMJ5;
|
||||
import appeng.integration.abstraction.IMJ6;
|
||||
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;
|
||||
import buildcraft.api.power.PowerHandler.Type;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@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
|
||||
{
|
||||
|
||||
BaseMJperdition pp;
|
||||
|
||||
public TunnelType getTunnelType()
|
||||
{
|
||||
return TunnelType.BC_POWER;
|
||||
}
|
||||
|
||||
public PartP2PBCPower(ItemStack is) {
|
||||
super( is );
|
||||
|
||||
if ( !AppEng.instance.isIntegrationEnabled( IntegrationType.MJ5 ) && !AppEng.instance.isIntegrationEnabled( IntegrationType.MJ6 ) )
|
||||
throw new RuntimeException( "MJ Not installed!" );
|
||||
|
||||
if ( AppEng.instance.isIntegrationEnabled( IntegrationType.MJ5 ) )
|
||||
{
|
||||
pp = (BaseMJperdition) ((IMJ5) AppEng.instance.getIntegration( IntegrationType.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() )
|
||||
{
|
||||
float totalRequiredPower = 0.0f;
|
||||
TunnelCollection<PartP2PBCPower> tunnelset;
|
||||
|
||||
try
|
||||
{
|
||||
tunnelset = getOutputs();
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
|
||||
for (PartP2PBCPower o : tunnelset)
|
||||
{
|
||||
IPowerReceptor target = o.getPowerTarget();
|
||||
if ( target != null )
|
||||
{
|
||||
PowerReceiver tp = target.getPowerReceiver( side.getOpposite() );
|
||||
if ( tp != null )
|
||||
{
|
||||
double howmuch = tp.powerRequest();
|
||||
|
||||
if ( howmuch > tp.getMaxEnergyReceived() )
|
||||
howmuch = tp.getMaxEnergyReceived();
|
||||
|
||||
if ( howmuch > 0.01 && howmuch > tp.getMinEnergyReceived() )
|
||||
{
|
||||
totalRequiredPower += howmuch;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( totalRequiredPower < 0.1 )
|
||||
return TickRateModulation.SLOWER;
|
||||
|
||||
double currentTotal = pp.getPowerReceiver().getEnergyStored();
|
||||
if ( currentTotal < 0.01 )
|
||||
return TickRateModulation.SLOWER;
|
||||
|
||||
for (PartP2PBCPower o : tunnelset)
|
||||
{
|
||||
IPowerReceptor target = o.getPowerTarget();
|
||||
if ( target != null )
|
||||
{
|
||||
PowerReceiver tp = target.getPowerReceiver( side.getOpposite() );
|
||||
if ( tp != null )
|
||||
{
|
||||
double howmuch = tp.powerRequest();
|
||||
|
||||
if ( howmuch > tp.getMaxEnergyReceived() )
|
||||
howmuch = tp.getMaxEnergyReceived();
|
||||
|
||||
if ( howmuch > 0.01 && howmuch > tp.getMinEnergyReceived() )
|
||||
{
|
||||
double toPull = currentTotal * (howmuch / totalRequiredPower);
|
||||
double pulled = pp.useEnergy( 0, toPull, true );
|
||||
QueueTunnelDrain( PowerUnits.MJ, pulled );
|
||||
|
||||
tp.receiveEnergy( Type.PIPE, pulled, o.side.getOpposite() );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return TickRateModulation.FASTER;
|
||||
}
|
||||
|
||||
return TickRateModulation.SLOWER;
|
||||
}
|
||||
|
||||
public float getPowerDrainPerTick()
|
||||
{
|
||||
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 )
|
||||
{
|
||||
IBatteryObject bo = MjAPI.getMjBattery( te, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite() );
|
||||
if ( bo != null )
|
||||
return bo;
|
||||
|
||||
return ((IMJ6) AppEng.instance.getIntegration( IntegrationType.MJ6 )).provider( te, side.getOpposite() );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Method(iname = "MJ5")
|
||||
private IPowerReceptor getPowerTarget()
|
||||
{
|
||||
TileEntity te = getWorld().getTileEntity( tile.xCoord + side.offsetX, tile.yCoord + side.offsetY, tile.zCoord + side.offsetZ );
|
||||
if ( te != null )
|
||||
{
|
||||
if ( te instanceof IPowerReceptor )
|
||||
return (IPowerReceptor) te;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.writeToNBT( tag );
|
||||
if ( pp != null )
|
||||
pp.writeToNBT( tag );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.readFromNBT( tag );
|
||||
if ( pp != null )
|
||||
pp.readFromNBT( tag );
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getTypeTexture()
|
||||
{
|
||||
return Blocks.emerald_block.getBlockTextureFromSide( 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(iname = "MJ5")
|
||||
public PowerReceiver getPowerReceiver(ForgeDirection side)
|
||||
{
|
||||
if ( side.equals( side ) )
|
||||
return ((BaseMJperdition) pp).getPowerReceiver();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(iname = "MJ5")
|
||||
public void doWork(PowerHandler workProvider)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld()
|
||||
{
|
||||
return tile.getWorldObj();
|
||||
}
|
||||
|
||||
@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 originalInput = 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 = originalInput / 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 originalInput - 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";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,232 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.config.PowerUnits;
|
||||
import appeng.api.config.TunnelType;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.integration.IntegrationType;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.cache.helpers.TunnelCollection;
|
||||
import appeng.transformer.annotations.integration.Interface;
|
||||
import appeng.transformer.annotations.integration.InterfaceList;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@InterfaceList(value = { @Interface(iface = "ic2.api.energy.tile.IEnergySink", iname = "IC2"),
|
||||
@Interface(iface = "ic2.api.energy.tile.IEnergySource", iname = "IC2") })
|
||||
public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements ic2.api.energy.tile.IEnergySink, ic2.api.energy.tile.IEnergySource
|
||||
{
|
||||
|
||||
public TunnelType getTunnelType()
|
||||
{
|
||||
return TunnelType.IC2_POWER;
|
||||
}
|
||||
|
||||
public PartP2PIC2Power(ItemStack is) {
|
||||
super( is );
|
||||
|
||||
if ( !AppEng.instance.isIntegrationEnabled( IntegrationType.IC2 ) )
|
||||
throw new RuntimeException( "IC2 Not installed!" );
|
||||
}
|
||||
|
||||
// two packet buffering...
|
||||
double OutputEnergyA;
|
||||
double OutputEnergyB;
|
||||
|
||||
// two packet buffering...
|
||||
double OutputVoltageA;
|
||||
double OutputVoltageB;
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.writeToNBT( tag );
|
||||
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 );
|
||||
OutputEnergyA = tag.getDouble( "OutputPacket" );
|
||||
OutputEnergyB = tag.getDouble( "OutputPacket2" );
|
||||
OutputVoltageA = tag.getDouble( "OutputVoltageA" );
|
||||
OutputVoltageB = tag.getDouble( "OutputVoltageB" );
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getTypeTexture()
|
||||
{
|
||||
return Blocks.diamond_block.getBlockTextureFromSide( 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
|
||||
{
|
||||
if ( !output )
|
||||
return direction.equals( side );
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean emitsEnergyTo(TileEntity receiver, ForgeDirection direction)
|
||||
{
|
||||
if ( output )
|
||||
return direction.equals( side );
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDemandedEnergy()
|
||||
{
|
||||
if ( output )
|
||||
return 0;
|
||||
|
||||
try
|
||||
{
|
||||
for (PartP2PIC2Power t : getOutputs())
|
||||
{
|
||||
if ( t.OutputEnergyA <= 0.0001 || t.OutputEnergyB <= 0.0001 )
|
||||
{
|
||||
return 2048;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelNetworkChange()
|
||||
{
|
||||
getHost().notifyNeighbors();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelConfigChange()
|
||||
{
|
||||
getHost().partChanged();
|
||||
}
|
||||
|
||||
public float getPowerDrainPerTick()
|
||||
{
|
||||
return 0.5f;
|
||||
};
|
||||
|
||||
@Override
|
||||
public double injectEnergy(ForgeDirection directionFrom, double amount, double voltage)
|
||||
{
|
||||
TunnelCollection<PartP2PIC2Power> outs;
|
||||
try
|
||||
{
|
||||
outs = getOutputs();
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
return amount;
|
||||
}
|
||||
|
||||
if ( outs.isEmpty() )
|
||||
return amount;
|
||||
|
||||
LinkedList<PartP2PIC2Power> Options = new LinkedList();
|
||||
for (PartP2PIC2Power o : outs)
|
||||
{
|
||||
if ( o.OutputEnergyA <= 0.01 )
|
||||
Options.add( o );
|
||||
}
|
||||
|
||||
if ( Options.isEmpty() )
|
||||
{
|
||||
for (PartP2PIC2Power o : outs)
|
||||
if ( o.OutputEnergyB <= 0.01 )
|
||||
Options.add( o );
|
||||
}
|
||||
|
||||
if ( Options.isEmpty() )
|
||||
{
|
||||
for (PartP2PIC2Power o : outs)
|
||||
Options.add( o );
|
||||
}
|
||||
|
||||
if ( Options.isEmpty() )
|
||||
return amount;
|
||||
|
||||
PartP2PIC2Power x = (PartP2PIC2Power) Platform.pickRandom( Options );
|
||||
|
||||
if ( x != null && x.OutputEnergyA <= 0.001 )
|
||||
{
|
||||
QueueTunnelDrain( PowerUnits.EU, amount );
|
||||
x.OutputEnergyA = amount;
|
||||
x.OutputVoltageA = voltage;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( x != null && x.OutputEnergyB <= 0.001 )
|
||||
{
|
||||
QueueTunnelDrain( PowerUnits.EU, amount );
|
||||
x.OutputEnergyB = amount;
|
||||
x.OutputVoltageB = voltage;
|
||||
return 0;
|
||||
}
|
||||
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSinkTier()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getOfferedEnergy()
|
||||
{
|
||||
if ( output )
|
||||
return OutputEnergyA;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEnergy(double amount)
|
||||
{
|
||||
OutputEnergyA -= amount;
|
||||
if ( OutputEnergyA < 0.001 )
|
||||
{
|
||||
OutputEnergyA = OutputEnergyB;
|
||||
OutputEnergyB = 0;
|
||||
|
||||
OutputVoltageA = OutputVoltageB;
|
||||
OutputVoltageB = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSourceTier()
|
||||
{
|
||||
if ( output )
|
||||
return calculateTierFromVoltage( OutputVoltageA );
|
||||
return 4;
|
||||
}
|
||||
|
||||
private int calculateTierFromVoltage(double voltage)
|
||||
{
|
||||
return ic2.api.energy.EnergyNet.instance.getTierFromPower( voltage );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,362 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.tileentity.TileEntityChest;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.config.TunnelType;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.events.MENetworkBootingStatusChange;
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.settings.TickRates;
|
||||
import appeng.integration.IntegrationType;
|
||||
import appeng.integration.abstraction.IBC;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.cache.helpers.TunnelCollection;
|
||||
import appeng.tile.inventory.AppEngNullInventory;
|
||||
import appeng.transformer.annotations.integration.Interface;
|
||||
import appeng.transformer.annotations.integration.Method;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.WrapperBCPipe;
|
||||
import appeng.util.inv.WrapperChainedInventory;
|
||||
import appeng.util.inv.WrapperMCISidedInventory;
|
||||
import buildcraft.api.transport.IPipeConnection;
|
||||
import buildcraft.api.transport.IPipeTile.PipeType;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@Interface(iface = "buildcraft.api.transport.IPipeConnection", iname = "BC")
|
||||
public class PartP2PItems extends PartP2PTunnel<PartP2PItems> implements IPipeConnection, IInventory, ISidedInventory, IGridTickable
|
||||
{
|
||||
|
||||
public TunnelType getTunnelType()
|
||||
{
|
||||
return TunnelType.ITEM;
|
||||
}
|
||||
|
||||
public PartP2PItems(ItemStack is) {
|
||||
super( is );
|
||||
}
|
||||
|
||||
int oldSize = 0;
|
||||
boolean requested;
|
||||
IInventory cachedInv;
|
||||
|
||||
LinkedList<IInventory> which = new LinkedList<IInventory>();
|
||||
|
||||
IInventory getOutputInv()
|
||||
{
|
||||
IInventory output = null;
|
||||
|
||||
if ( proxy.isActive() )
|
||||
{
|
||||
TileEntity te = tile.getWorldObj().getTileEntity( tile.xCoord + side.offsetX, tile.yCoord + side.offsetY, tile.zCoord + side.offsetZ );
|
||||
|
||||
if ( which.contains( this ) )
|
||||
return null;
|
||||
|
||||
which.add( this );
|
||||
|
||||
if ( AppEng.instance.isIntegrationEnabled( IntegrationType.BC ) )
|
||||
{
|
||||
IBC buildcraft = (IBC) AppEng.instance.getIntegration( IntegrationType.BC );
|
||||
if ( buildcraft != null )
|
||||
{
|
||||
if ( buildcraft.isPipe( te, side.getOpposite() ) )
|
||||
{
|
||||
try
|
||||
{
|
||||
output = new WrapperBCPipe( te, side.getOpposite() );
|
||||
}
|
||||
catch (Throwable ignore)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* if ( AppEng.instance.isIntegrationEnabled( "TE" ) ) { ITE thermal = (ITE) AppEng.instance.getIntegration(
|
||||
* "TE" ); if ( thermal != null ) { if ( thermal.isPipe( te, side.getOpposite() ) ) { try { output = new
|
||||
* WrapperTEPipe( te, side.getOpposite() ); } catch (Throwable ignore) { } } } }
|
||||
*/
|
||||
|
||||
if ( output == null )
|
||||
{
|
||||
if ( te instanceof TileEntityChest )
|
||||
{
|
||||
output = Platform.GetChestInv( te );
|
||||
}
|
||||
else if ( te instanceof ISidedInventory )
|
||||
{
|
||||
output = new WrapperMCISidedInventory( (ISidedInventory) te, side.getOpposite() );
|
||||
}
|
||||
else if ( te instanceof IInventory )
|
||||
{
|
||||
output = (IInventory) te;
|
||||
}
|
||||
}
|
||||
|
||||
which.pop();
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged()
|
||||
{
|
||||
cachedInv = null;
|
||||
PartP2PItems input = getInput();
|
||||
if ( input != null && output )
|
||||
input.onTunnelNetworkChange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node)
|
||||
{
|
||||
return new TickingRequest( TickRates.ItemTunnel.min, TickRates.ItemTunnel.max, false, false );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
|
||||
{
|
||||
boolean wasReq = requested;
|
||||
|
||||
if ( requested && cachedInv != null )
|
||||
((WrapperChainedInventory) cachedInv).cycleOrder();
|
||||
|
||||
requested = false;
|
||||
return wasReq ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
|
||||
}
|
||||
|
||||
IInventory getDest()
|
||||
{
|
||||
requested = true;
|
||||
|
||||
if ( cachedInv != null )
|
||||
return cachedInv;
|
||||
|
||||
List<IInventory> outs = new LinkedList<IInventory>();
|
||||
TunnelCollection<PartP2PItems> itemTunnels;
|
||||
|
||||
try
|
||||
{
|
||||
itemTunnels = getOutputs();
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
return new AppEngNullInventory();
|
||||
}
|
||||
|
||||
for (PartP2PItems t : itemTunnels)
|
||||
{
|
||||
IInventory inv = t.getOutputInv();
|
||||
if ( inv != null )
|
||||
{
|
||||
if ( Platform.getRandomInt() % 2 == 0 )
|
||||
outs.add( inv );
|
||||
else
|
||||
outs.add( 0, inv );
|
||||
}
|
||||
}
|
||||
|
||||
return cachedInv = new WrapperChainedInventory( outs );
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void changeStateA(MENetworkBootingStatusChange bs)
|
||||
{
|
||||
if ( !output )
|
||||
{
|
||||
cachedInv = null;
|
||||
int olderSize = oldSize;
|
||||
oldSize = getDest().getSizeInventory();
|
||||
if ( olderSize != oldSize )
|
||||
{
|
||||
getHost().notifyNeighbors();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void changeStateB(MENetworkChannelsChanged bs)
|
||||
{
|
||||
if ( !output )
|
||||
{
|
||||
cachedInv = null;
|
||||
int olderSize = oldSize;
|
||||
oldSize = getDest().getSizeInventory();
|
||||
if ( olderSize != oldSize )
|
||||
{
|
||||
getHost().notifyNeighbors();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void changeStateC(MENetworkPowerStatusChange bs)
|
||||
{
|
||||
if ( !output )
|
||||
{
|
||||
cachedInv = null;
|
||||
int olderSize = oldSize;
|
||||
oldSize = getDest().getSizeInventory();
|
||||
if ( olderSize != oldSize )
|
||||
{
|
||||
getHost().notifyNeighbors();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelNetworkChange()
|
||||
{
|
||||
if ( !output )
|
||||
{
|
||||
cachedInv = null;
|
||||
int olderSize = oldSize;
|
||||
oldSize = getDest().getSizeInventory();
|
||||
if ( olderSize != oldSize )
|
||||
{
|
||||
getHost().notifyNeighbors();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PartP2PItems input = getInput();
|
||||
if ( input != null )
|
||||
input.getHost().notifyNeighbors();
|
||||
}
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getTypeTexture()
|
||||
{
|
||||
return Blocks.hopper.getBlockTextureFromSide( 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return getDest().getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i)
|
||||
{
|
||||
return getDest().getStackInSlot( i );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j)
|
||||
{
|
||||
return getDest().decrStackSize( i, j );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int i)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack)
|
||||
{
|
||||
getDest().setInventorySlotContents( i, itemstack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return getDest().getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, net.minecraft.item.ItemStack itemstack)
|
||||
{
|
||||
return getDest().isItemValidForSlot( i, itemstack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int var1)
|
||||
{
|
||||
int[] slots = new int[getSizeInventory()];
|
||||
for (int x = 0; x < getSizeInventory(); x++)
|
||||
slots[x] = x;
|
||||
return slots;
|
||||
}
|
||||
|
||||
public float getPowerDrainPerTick()
|
||||
{
|
||||
return 2.0f;
|
||||
};
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem(int i, ItemStack itemstack, int j)
|
||||
{
|
||||
return getDest().isItemValidForSlot( i, itemstack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int i, ItemStack itemstack, int j)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Method(iname = "BC")
|
||||
public ConnectOverride overridePipeConnection(PipeType type, ForgeDirection with)
|
||||
{
|
||||
return side.equals( with ) && type == PipeType.ITEM ? ConnectOverride.CONNECT : ConnectOverride.DEFAULT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
// eh?
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import appeng.api.config.TunnelType;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.TickRateModulation;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.core.settings.TickRates;
|
||||
import appeng.me.GridAccessException;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartP2PLight extends PartP2PTunnel<PartP2PLight> implements IGridTickable
|
||||
{
|
||||
|
||||
public PartP2PLight(ItemStack is) {
|
||||
super( is );
|
||||
}
|
||||
|
||||
public TunnelType getTunnelType()
|
||||
{
|
||||
return TunnelType.LIGHT;
|
||||
}
|
||||
|
||||
int lastValue = 0;
|
||||
float opacity = -1;
|
||||
|
||||
public void setLightLevel(int out)
|
||||
{
|
||||
lastValue = out;
|
||||
getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLightLevel()
|
||||
{
|
||||
if ( output && isPowered() )
|
||||
return blockLight( lastValue );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private int blockLight(int emit)
|
||||
{
|
||||
if ( opacity < 0 )
|
||||
{
|
||||
TileEntity te = this.getTile();
|
||||
opacity = 255 - te.getWorldObj().getBlockLightOpacity( te.xCoord + side.offsetX, te.yCoord + side.offsetY, te.zCoord + side.offsetZ );
|
||||
}
|
||||
|
||||
return (int) (emit * (opacity / 255.0f));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void chanRender(MENetworkChannelsChanged c)
|
||||
{
|
||||
onTunnelNetworkChange();
|
||||
super.chanRender( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void powerRender(MENetworkPowerStatusChange c)
|
||||
{
|
||||
onTunnelNetworkChange();
|
||||
super.powerRender( c );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelNetworkChange()
|
||||
{
|
||||
if ( output )
|
||||
{
|
||||
PartP2PLight src = getInput();
|
||||
if ( src != null && src.proxy.isActive() )
|
||||
setLightLevel( src.lastValue );
|
||||
else
|
||||
getHost().markForUpdate();
|
||||
}
|
||||
else
|
||||
doWork();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelConfigChange()
|
||||
{
|
||||
onTunnelNetworkChange();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged()
|
||||
{
|
||||
opacity = -1;
|
||||
|
||||
doWork();
|
||||
|
||||
if ( output )
|
||||
getHost().markForUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.writeToNBT( tag );
|
||||
tag.setFloat( "opacity", opacity );
|
||||
tag.setInteger( "lastValue", lastValue );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.readFromNBT( tag );
|
||||
if ( tag.hasKey( "opacity" ) )
|
||||
opacity = tag.getFloat( "opacity" );
|
||||
lastValue = tag.getInteger( "lastValue" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean readFromStream(ByteBuf data) throws IOException
|
||||
{
|
||||
super.readFromStream( data );
|
||||
lastValue = data.readInt();
|
||||
output = lastValue > 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToStream(ByteBuf data) throws IOException
|
||||
{
|
||||
super.writeToStream( data );
|
||||
data.writeInt( output ? lastValue : 0 );
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getTypeTexture()
|
||||
{
|
||||
return Blocks.quartz_block.getBlockTextureFromSide( 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node)
|
||||
{
|
||||
return new TickingRequest( TickRates.LightTunnel.min, TickRates.LightTunnel.max, false, false );
|
||||
}
|
||||
|
||||
private boolean doWork()
|
||||
{
|
||||
if ( output )
|
||||
return false;
|
||||
|
||||
TileEntity te = getTile();
|
||||
World w = te.getWorldObj();
|
||||
|
||||
int newLevel = w.getBlockLightValue( te.xCoord + side.offsetX, te.yCoord + side.offsetY, te.zCoord + side.offsetZ );
|
||||
|
||||
if ( lastValue != newLevel && proxy.isActive() )
|
||||
{
|
||||
lastValue = newLevel;
|
||||
try
|
||||
{
|
||||
for (PartP2PLight out : getOutputs())
|
||||
out.setLightLevel( lastValue );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public float getPowerDrainPerTick()
|
||||
{
|
||||
return 0.5f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
|
||||
{
|
||||
return doWork() ? TickRateModulation.FASTER : TickRateModulation.SLOWER;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,264 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidHandler;
|
||||
import appeng.api.config.TunnelType;
|
||||
import appeng.me.GridAccessException;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartP2PLiquids extends PartP2PTunnel<PartP2PLiquids> implements IFluidHandler
|
||||
{
|
||||
|
||||
private final static FluidTankInfo[] activeTank = new FluidTankInfo[] { new FluidTankInfo( null, 10000 ) };
|
||||
private final static FluidTankInfo[] inactiveTank = new FluidTankInfo[] { new FluidTankInfo( null, 0 ) };
|
||||
|
||||
public TunnelType getTunnelType()
|
||||
{
|
||||
return TunnelType.FLUID;
|
||||
}
|
||||
|
||||
public PartP2PLiquids(ItemStack is) {
|
||||
super( is );
|
||||
}
|
||||
|
||||
private FluidTankInfo[] getTank()
|
||||
{
|
||||
if ( output )
|
||||
{
|
||||
PartP2PLiquids tun = getInput();
|
||||
if ( tun != null )
|
||||
return activeTank;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
if ( !getOutputs().isEmpty() )
|
||||
return activeTank;
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :(
|
||||
}
|
||||
}
|
||||
return inactiveTank;
|
||||
}
|
||||
|
||||
IFluidHandler cachedTank;
|
||||
|
||||
public float getPowerDrainPerTick()
|
||||
{
|
||||
return 2.0f;
|
||||
};
|
||||
|
||||
private int tmpUsed;
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.writeToNBT( tag );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.readFromNBT( tag );
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getTypeTexture()
|
||||
{
|
||||
return Blocks.lapis_block.getBlockTextureFromSide( 0 );
|
||||
}
|
||||
|
||||
List<PartP2PLiquids> getOutputs(Fluid input)
|
||||
{
|
||||
List<PartP2PLiquids> outs = new LinkedList<PartP2PLiquids>();
|
||||
|
||||
try
|
||||
{
|
||||
for (PartP2PLiquids l : getOutputs())
|
||||
{
|
||||
IFluidHandler targ = l.getTarget();
|
||||
if ( targ != null )
|
||||
{
|
||||
if ( targ.canFill( l.side.getOpposite(), input ) )
|
||||
outs.add( l );
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
return outs;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged()
|
||||
{
|
||||
cachedTank = null;
|
||||
if ( output )
|
||||
{
|
||||
PartP2PLiquids in = getInput();
|
||||
if ( in != null )
|
||||
in.onTunnelNetworkChange();
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onTunnelNetworkChange()
|
||||
{
|
||||
cachedTank = null;
|
||||
}
|
||||
|
||||
IFluidHandler getTarget()
|
||||
{
|
||||
if ( !proxy.isActive() )
|
||||
return null;
|
||||
|
||||
if ( cachedTank != null )
|
||||
return cachedTank;
|
||||
|
||||
TileEntity te = tile.getWorldObj().getTileEntity( tile.xCoord + side.offsetX, tile.yCoord + side.offsetY, tile.zCoord + side.offsetZ );
|
||||
if ( te instanceof IFluidHandler )
|
||||
return cachedTank = (IFluidHandler) te;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
static final ThreadLocal<Stack<PartP2PLiquids>> depth = new ThreadLocal<Stack<PartP2PLiquids>>();
|
||||
|
||||
private Stack<PartP2PLiquids> getDepth()
|
||||
{
|
||||
Stack<PartP2PLiquids> s = depth.get();
|
||||
|
||||
if ( s == null )
|
||||
depth.set( s = new Stack<PartP2PLiquids>() );
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill)
|
||||
{
|
||||
Stack<PartP2PLiquids> stack = getDepth();
|
||||
|
||||
for (PartP2PLiquids t : stack)
|
||||
if ( t == this )
|
||||
return 0;
|
||||
|
||||
stack.push( this );
|
||||
|
||||
List<PartP2PLiquids> list = getOutputs( resource.getFluid() );
|
||||
int requestTotal = 0;
|
||||
|
||||
Iterator<PartP2PLiquids> i = list.iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
PartP2PLiquids l = i.next();
|
||||
IFluidHandler tank = l.getTarget();
|
||||
if ( tank != null )
|
||||
l.tmpUsed = tank.fill( l.side.getOpposite(), resource.copy(), false );
|
||||
else
|
||||
l.tmpUsed = 0;
|
||||
|
||||
if ( l.tmpUsed <= 0 )
|
||||
i.remove();
|
||||
else
|
||||
requestTotal += l.tmpUsed;
|
||||
}
|
||||
|
||||
if ( requestTotal <= 0 )
|
||||
{
|
||||
if ( stack.pop() != this )
|
||||
throw new RuntimeException( "Invalid Recursion detected." );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( !doFill )
|
||||
{
|
||||
if ( stack.pop() != this )
|
||||
throw new RuntimeException( "Invalid Recursion detected." );
|
||||
|
||||
return Math.min( resource.amount, requestTotal );
|
||||
}
|
||||
|
||||
int available = resource.amount;
|
||||
int used = 0;
|
||||
|
||||
i = list.iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
PartP2PLiquids l = i.next();
|
||||
|
||||
FluidStack insert = resource.copy();
|
||||
insert.amount = (int) Math.ceil( insert.amount * ((double) l.tmpUsed / (double) requestTotal) );
|
||||
if ( insert.amount > available )
|
||||
insert.amount = available;
|
||||
|
||||
IFluidHandler tank = l.getTarget();
|
||||
if ( tank != null )
|
||||
l.tmpUsed = tank.fill( l.side.getOpposite(), insert.copy(), true );
|
||||
else
|
||||
l.tmpUsed = 0;
|
||||
|
||||
available -= insert.amount;
|
||||
used += insert.amount;
|
||||
}
|
||||
|
||||
if ( stack.pop() != this )
|
||||
throw new RuntimeException( "Invalid Recursion detected." );
|
||||
|
||||
return used;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill(ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
return !output && from.equals( side ) && !getOutputs( fluid ).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain(ForgeDirection from, Fluid fluid)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection from)
|
||||
{
|
||||
if ( from.equals( side ) )
|
||||
return getTank();
|
||||
return new FluidTankInfo[0];
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,253 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.config.PowerUnits;
|
||||
import appeng.api.config.TunnelType;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.integration.IntegrationType;
|
||||
import appeng.integration.modules.helpers.NullRFHandler;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.transformer.annotations.integration.Interface;
|
||||
import appeng.transformer.annotations.integration.InterfaceList;
|
||||
import appeng.util.Platform;
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@InterfaceList(value = { @Interface(iface = "cofh.api.energy.IEnergyHandler", iname = "RF") })
|
||||
public class PartP2PRFPower extends PartP2PTunnel<PartP2PRFPower> implements cofh.api.energy.IEnergyHandler
|
||||
{
|
||||
|
||||
private static final IEnergyHandler myNullHandler = new NullRFHandler();
|
||||
|
||||
boolean cachedTarget = false;
|
||||
IEnergyHandler outputTarget;
|
||||
|
||||
public TunnelType getTunnelType()
|
||||
{
|
||||
return TunnelType.RF_POWER;
|
||||
}
|
||||
|
||||
public PartP2PRFPower(ItemStack is) {
|
||||
super( is );
|
||||
|
||||
if ( !AppEng.instance.isIntegrationEnabled( IntegrationType.RF ) )
|
||||
throw new RuntimeException( "RF Not installed!" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.writeToNBT( tag );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.readFromNBT( tag );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged()
|
||||
{
|
||||
super.onNeighborChanged();
|
||||
cachedTarget = false;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getTypeTexture()
|
||||
{
|
||||
return Blocks.iron_block.getBlockTextureFromSide( 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelNetworkChange()
|
||||
{
|
||||
getHost().notifyNeighbors();
|
||||
}
|
||||
|
||||
public float getPowerDrainPerTick()
|
||||
{
|
||||
return 0.5f;
|
||||
}
|
||||
|
||||
static final ThreadLocal<Stack<PartP2PRFPower>> depth = new ThreadLocal<Stack<PartP2PRFPower>>();
|
||||
|
||||
private Stack<PartP2PRFPower> getDepth()
|
||||
{
|
||||
Stack<PartP2PRFPower> s = depth.get();
|
||||
|
||||
if ( s == null )
|
||||
depth.set( s = new Stack<PartP2PRFPower>() );
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate)
|
||||
{
|
||||
if ( output )
|
||||
return 0;
|
||||
|
||||
if ( isActive() )
|
||||
{
|
||||
Stack<PartP2PRFPower> stack = getDepth();
|
||||
|
||||
for (PartP2PRFPower t : stack)
|
||||
if ( t == this )
|
||||
return 0;
|
||||
|
||||
stack.push( this );
|
||||
|
||||
int total = 0;
|
||||
|
||||
try
|
||||
{
|
||||
for (PartP2PRFPower t : getOutputs())
|
||||
{
|
||||
if ( Platform.getRandomInt() % 2 > 0 )
|
||||
{
|
||||
int recv = t.getOutput().receiveEnergy( t.side.getOpposite(), maxReceive, simulate );
|
||||
maxReceive -= recv;
|
||||
total += recv;
|
||||
|
||||
if ( maxReceive <= 0 )
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if ( maxReceive > 0 )
|
||||
{
|
||||
for (PartP2PRFPower t : getOutputs())
|
||||
{
|
||||
int recv = t.getOutput().receiveEnergy( t.side.getOpposite(), maxReceive, simulate );
|
||||
maxReceive -= recv;
|
||||
total += recv;
|
||||
|
||||
if ( maxReceive <= 0 )
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QueueTunnelDrain( PowerUnits.RF, total );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
}
|
||||
|
||||
if ( stack.pop() != this )
|
||||
throw new RuntimeException( "Invalid Recursion detected." );
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored(ForgeDirection from)
|
||||
{
|
||||
if ( output || !isActive() )
|
||||
return 0;
|
||||
|
||||
int total = 0;
|
||||
|
||||
Stack<PartP2PRFPower> stack = getDepth();
|
||||
|
||||
for (PartP2PRFPower t : stack)
|
||||
if ( t == this )
|
||||
return 0;
|
||||
|
||||
stack.push( this );
|
||||
|
||||
try
|
||||
{
|
||||
for (PartP2PRFPower t : getOutputs())
|
||||
{
|
||||
total += t.getOutput().getEnergyStored( t.side.getOpposite() );
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( stack.pop() != this )
|
||||
throw new RuntimeException( "Invalid Recursion detected." );
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ForgeDirection from)
|
||||
{
|
||||
if ( output || !isActive() )
|
||||
return 0;
|
||||
|
||||
int total = 0;
|
||||
|
||||
Stack<PartP2PRFPower> stack = getDepth();
|
||||
|
||||
for (PartP2PRFPower t : stack)
|
||||
if ( t == this )
|
||||
return 0;
|
||||
|
||||
stack.push( this );
|
||||
|
||||
try
|
||||
{
|
||||
for (PartP2PRFPower t : getOutputs())
|
||||
{
|
||||
total += t.getOutput().getMaxEnergyStored( t.side.getOpposite() );
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if ( stack.pop() != this )
|
||||
throw new RuntimeException( "Invalid Recursion detected." );
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
private IEnergyHandler getOutput()
|
||||
{
|
||||
if ( output )
|
||||
{
|
||||
if ( !cachedTarget )
|
||||
{
|
||||
TileEntity self = getTile();
|
||||
TileEntity te = self.getWorldObj().getTileEntity( self.xCoord + side.offsetX, self.yCoord + side.offsetY, self.zCoord + side.offsetZ );
|
||||
outputTarget = te instanceof IEnergyHandler ? (IEnergyHandler) te : null;
|
||||
cachedTarget = true;
|
||||
}
|
||||
|
||||
if ( outputTarget == null || !outputTarget.canConnectEnergy( side.getOpposite() ) )
|
||||
return myNullHandler;
|
||||
|
||||
return outputTarget;
|
||||
}
|
||||
return myNullHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectEnergy(ForgeDirection from)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockRedstoneWire;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
import appeng.api.config.TunnelType;
|
||||
import appeng.api.networking.events.MENetworkBootingStatusChange;
|
||||
import appeng.api.networking.events.MENetworkChannelsChanged;
|
||||
import appeng.api.networking.events.MENetworkEventSubscribe;
|
||||
import appeng.api.networking.events.MENetworkPowerStatusChange;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartP2PRedstone extends PartP2PTunnel<PartP2PRedstone>
|
||||
{
|
||||
|
||||
public TunnelType getTunnelType()
|
||||
{
|
||||
return TunnelType.REDSTONE;
|
||||
}
|
||||
|
||||
public PartP2PRedstone(ItemStack is) {
|
||||
super( is );
|
||||
}
|
||||
|
||||
int power;
|
||||
|
||||
@Override
|
||||
public boolean canConnectRedstone()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingStrongPower()
|
||||
{
|
||||
return output ? power : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int isProvidingWeakPower()
|
||||
{
|
||||
return output ? power : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelNetworkChange()
|
||||
{
|
||||
setNetworkReady();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void changeStateA(MENetworkBootingStatusChange bs)
|
||||
{
|
||||
setNetworkReady();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void changeStateB(MENetworkChannelsChanged bs)
|
||||
{
|
||||
setNetworkReady();
|
||||
}
|
||||
|
||||
@MENetworkEventSubscribe
|
||||
public void changeStateC(MENetworkPowerStatusChange bs)
|
||||
{
|
||||
setNetworkReady();
|
||||
}
|
||||
|
||||
public void setNetworkReady()
|
||||
{
|
||||
if ( output )
|
||||
{
|
||||
PartP2PRedstone in = getInput();
|
||||
if ( in != null )
|
||||
putInput( ((PartP2PRedstone) in).power );
|
||||
}
|
||||
}
|
||||
|
||||
boolean recursive = false;
|
||||
|
||||
protected void putInput(Object o)
|
||||
{
|
||||
if ( recursive )
|
||||
return;
|
||||
|
||||
recursive = true;
|
||||
if ( output && proxy.isActive() )
|
||||
{
|
||||
int newPower = (Integer) o;
|
||||
if ( power != newPower )
|
||||
{
|
||||
power = newPower;
|
||||
notifyNeighbors();
|
||||
}
|
||||
}
|
||||
recursive = false;
|
||||
|
||||
}
|
||||
|
||||
public void notifyNeighbors()
|
||||
{
|
||||
World worldObj = tile.getWorldObj();
|
||||
|
||||
int xCoord = tile.xCoord;
|
||||
int yCoord = tile.yCoord;
|
||||
int zCoord = tile.zCoord;
|
||||
|
||||
Platform.notifyBlocksOfNeighbors( worldObj, xCoord, yCoord, zCoord );
|
||||
|
||||
// and this cause sometimes it can go thought walls.
|
||||
Platform.notifyBlocksOfNeighbors( worldObj, xCoord - 1, yCoord, zCoord );
|
||||
Platform.notifyBlocksOfNeighbors( worldObj, xCoord, yCoord - 1, zCoord );
|
||||
Platform.notifyBlocksOfNeighbors( worldObj, xCoord, yCoord, zCoord - 1 );
|
||||
Platform.notifyBlocksOfNeighbors( worldObj, xCoord, yCoord, zCoord + 1 );
|
||||
Platform.notifyBlocksOfNeighbors( worldObj, xCoord, yCoord + 1, zCoord );
|
||||
Platform.notifyBlocksOfNeighbors( worldObj, xCoord + 1, yCoord, zCoord );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.writeToNBT( tag );
|
||||
tag.setInteger( "power", power );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag)
|
||||
{
|
||||
super.readFromNBT( tag );
|
||||
power = tag.getInteger( "power" );
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getTypeTexture()
|
||||
{
|
||||
return Blocks.redstone_block.getBlockTextureFromSide( 0 );
|
||||
}
|
||||
|
||||
public float getPowerDrainPerTick()
|
||||
{
|
||||
return 0.5f;
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onNeighborChanged()
|
||||
{
|
||||
if ( !output )
|
||||
{
|
||||
int x = tile.xCoord + side.offsetX;
|
||||
int y = tile.yCoord + side.offsetY;
|
||||
int z = tile.zCoord + side.offsetZ;
|
||||
|
||||
Block b = tile.getWorldObj().getBlock( x, y, z );
|
||||
if ( b != null && !output )
|
||||
{
|
||||
int srcSide = side.ordinal();
|
||||
if ( b instanceof BlockRedstoneWire )
|
||||
srcSide = 1;
|
||||
power = b.isProvidingStrongPower( tile.getWorldObj(), x, y, z, srcSide );
|
||||
power = Math.max( power, b.isProvidingWeakPower( tile.getWorldObj(), x, y, z, srcSide ) );
|
||||
sendToOutput( power );
|
||||
}
|
||||
else
|
||||
sendToOutput( 0 );
|
||||
}
|
||||
}
|
||||
|
||||
private void sendToOutput(int power)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (PartP2PRedstone rs : getOutputs())
|
||||
{
|
||||
rs.putInput( power );
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,389 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.client.renderer.RenderBlocks;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.PowerMultiplier;
|
||||
import appeng.api.config.PowerUnits;
|
||||
import appeng.api.config.TunnelType;
|
||||
import appeng.api.implementations.items.IMemoryCard;
|
||||
import appeng.api.implementations.items.MemoryCardMessages;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.IPartCollisionHelper;
|
||||
import appeng.api.parts.IPartItem;
|
||||
import appeng.api.parts.IPartRenderHelper;
|
||||
import appeng.api.parts.PartItemStack;
|
||||
import appeng.client.texture.CableBusTextures;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.cache.P2PCache;
|
||||
import appeng.me.cache.helpers.TunnelCollection;
|
||||
import appeng.parts.PartBasicState;
|
||||
import appeng.util.Platform;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class PartP2PTunnel<T extends PartP2PTunnel> extends PartBasicState
|
||||
{
|
||||
|
||||
public boolean output;
|
||||
public long freq;
|
||||
TunnelCollection type = new TunnelCollection<T>( null, getClass() );
|
||||
|
||||
public PartP2PTunnel(ItemStack is) {
|
||||
super( PartP2PTunnel.class, is );
|
||||
if ( getClass() == PartP2PTunnel.class )
|
||||
throw new RuntimeException( "Don't construct the root tunnel!" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean useStandardMemoryCard()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data)
|
||||
{
|
||||
data.setBoolean( "output", output );
|
||||
data.setLong( "freq", freq );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data)
|
||||
{
|
||||
output = data.getBoolean( "output" );
|
||||
freq = data.getLong( "freq" );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartActivate(EntityPlayer player, Vec3 pos)
|
||||
{
|
||||
ItemStack is = player.inventory.getCurrentItem();
|
||||
|
||||
// UniqueIdentifier id = GameRegistry.findUniqueIdentifierFor( is.getItem() );
|
||||
// AELog.info( "ID:" + id.toString() + " : " + is.getItemDamage() );
|
||||
|
||||
TunnelType tt = AEApi.instance().registries().p2pTunnel().getTunnelTypeByItem( is );
|
||||
if ( is != null && is.getItem() instanceof IMemoryCard )
|
||||
{
|
||||
IMemoryCard mc = (IMemoryCard) is.getItem();
|
||||
NBTTagCompound data = mc.getData( is );
|
||||
|
||||
ItemStack newType = ItemStack.loadItemStackFromNBT( data );
|
||||
long freq = data.getLong( "freq" );
|
||||
|
||||
if ( newType != null )
|
||||
{
|
||||
if ( newType.getItem() instanceof IPartItem )
|
||||
{
|
||||
IPart testPart = ((IPartItem) newType.getItem()).createPartFromItemStack( newType );
|
||||
if ( testPart instanceof PartP2PTunnel )
|
||||
{
|
||||
getHost().removePart( side, true );
|
||||
ForgeDirection dir = getHost().addPart( newType, side, player );
|
||||
IPart newBus = getHost().getPart( dir );
|
||||
|
||||
if ( newBus instanceof PartP2PTunnel )
|
||||
{
|
||||
PartP2PTunnel newTunnel = (PartP2PTunnel) newBus;
|
||||
newTunnel.output = true;
|
||||
|
||||
try
|
||||
{
|
||||
P2PCache p2p = newTunnel.proxy.getP2P();
|
||||
p2p.updateFreq( newTunnel, freq );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
newTunnel.onTunnelNetworkChange();
|
||||
}
|
||||
|
||||
mc.notifyUser( player, MemoryCardMessages.SETTINGS_LOADED );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
mc.notifyUser( player, MemoryCardMessages.INVALID_MACHINE );
|
||||
}
|
||||
else if ( tt != null ) // attune-ment
|
||||
{
|
||||
ItemStack newType = null;
|
||||
|
||||
switch (tt)
|
||||
{
|
||||
case LIGHT:
|
||||
newType = AEApi.instance().parts().partP2PTunnelLight.stack( 1 );
|
||||
break;
|
||||
|
||||
case RF_POWER:
|
||||
newType = AEApi.instance().parts().partP2PTunnelRF.stack( 1 );
|
||||
break;
|
||||
|
||||
case BC_POWER:
|
||||
newType = AEApi.instance().parts().partP2PTunnelMJ.stack( 1 );
|
||||
break;
|
||||
|
||||
case FLUID:
|
||||
newType = AEApi.instance().parts().partP2PTunnelLiquids.stack( 1 );
|
||||
break;
|
||||
|
||||
case IC2_POWER:
|
||||
newType = AEApi.instance().parts().partP2PTunnelEU.stack( 1 );
|
||||
break;
|
||||
|
||||
case ITEM:
|
||||
newType = AEApi.instance().parts().partP2PTunnelItems.stack( 1 );
|
||||
break;
|
||||
|
||||
case ME:
|
||||
newType = AEApi.instance().parts().partP2PTunnelME.stack( 1 );
|
||||
break;
|
||||
|
||||
case REDSTONE:
|
||||
newType = AEApi.instance().parts().partP2PTunnelRedstone.stack( 1 );
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
||||
}
|
||||
|
||||
if ( newType != null && !Platform.isSameItem( newType, this.is ) )
|
||||
{
|
||||
boolean oldOutput = output;
|
||||
long myFreq = freq;
|
||||
|
||||
getHost().removePart( side, false );
|
||||
ForgeDirection dir = getHost().addPart( newType, side, player );
|
||||
IPart newBus = getHost().getPart( dir );
|
||||
|
||||
if ( newBus instanceof PartP2PTunnel )
|
||||
{
|
||||
PartP2PTunnel newTunnel = (PartP2PTunnel) newBus;
|
||||
newTunnel.output = oldOutput;
|
||||
newTunnel.onTunnelNetworkChange();
|
||||
|
||||
try
|
||||
{
|
||||
P2PCache p2p = newTunnel.proxy.getP2P();
|
||||
p2p.updateFreq( newTunnel, myFreq );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
Platform.notifyBlocksOfNeighbors( tile.getWorldObj(), tile.xCoord, tile.yCoord, tile.zCoord );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public TunnelType getTunnelType()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPartShiftActivate(EntityPlayer player, Vec3 pos)
|
||||
{
|
||||
ItemStack is = player.inventory.getCurrentItem();
|
||||
if ( is != null && is.getItem() instanceof IMemoryCard )
|
||||
{
|
||||
IMemoryCard mc = (IMemoryCard) is.getItem();
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
|
||||
long newFreq = freq;
|
||||
boolean wasOutput = output;
|
||||
output = false;
|
||||
|
||||
if ( wasOutput || freq == 0 )
|
||||
newFreq = System.currentTimeMillis();
|
||||
|
||||
try
|
||||
{
|
||||
proxy.getP2P().updateFreq( this, newFreq );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
onTunnelConfigChange();
|
||||
|
||||
ItemStack p2pItem = getItemStack( PartItemStack.Wrench );
|
||||
String type = p2pItem.getUnlocalizedName();
|
||||
|
||||
p2pItem.writeToNBT( data );
|
||||
data.setLong( "freq", freq );
|
||||
|
||||
mc.setMemoryCardContents( is, type + ".name", data );
|
||||
mc.notifyUser( player, MemoryCardMessages.SETTINGS_SAVED );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onTunnelConfigChange()
|
||||
{
|
||||
}
|
||||
|
||||
public ItemStack getItemStack(PartItemStack type)
|
||||
{
|
||||
if ( type == PartItemStack.World || type == PartItemStack.Network || type == PartItemStack.Wrench || type == PartItemStack.Pick )
|
||||
return super.getItemStack( type );
|
||||
|
||||
return AEApi.instance().parts().partP2PTunnelME.stack( 1 );
|
||||
}
|
||||
|
||||
public TunnelCollection<T> getCollection(Collection<PartP2PTunnel> collection, Class<? extends PartP2PTunnel> c)
|
||||
{
|
||||
if ( type.matches( c ) )
|
||||
{
|
||||
type.setSource( collection );
|
||||
return type;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public T getInput()
|
||||
{
|
||||
if ( freq == 0 )
|
||||
return null;
|
||||
|
||||
PartP2PTunnel tunn;
|
||||
try
|
||||
{
|
||||
tunn = proxy.getP2P().getInput( freq );
|
||||
if ( getClass().isInstance( tunn ) )
|
||||
return (T) tunn;
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public TunnelCollection<T> getOutputs() throws GridAccessException
|
||||
{
|
||||
if ( proxy.isActive() )
|
||||
return (TunnelCollection<T>) proxy.getP2P().getOutputs( freq, getClass() );
|
||||
return new TunnelCollection( new ArrayList(), getClass() );
|
||||
}
|
||||
|
||||
public void onTunnelNetworkChange()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderInventory(IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
rh.setTexture( getTypeTexture() );
|
||||
|
||||
rh.setBounds( 2, 2, 14, 14, 14, 16 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
|
||||
rh.setTexture( CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.BlockP2PTunnel2.getIcon(),
|
||||
is.getIconIndex(), CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.PartTunnelSides.getIcon() );
|
||||
|
||||
rh.setBounds( 2, 2, 14, 14, 14, 16 );
|
||||
rh.renderInventoryBox( renderer );
|
||||
}
|
||||
|
||||
protected IIcon getTypeTexture()
|
||||
{
|
||||
return AEApi.instance().blocks().blockQuartz.block().getIcon( 0, 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderStatic(int x, int y, int z, IPartRenderHelper rh, RenderBlocks renderer)
|
||||
{
|
||||
renderCache = rh.useSimplifiedRendering( x, y, z, this, renderCache );
|
||||
rh.setTexture( getTypeTexture() );
|
||||
|
||||
rh.setBounds( 2, 2, 14, 14, 14, 16 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
rh.setTexture( CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.BlockP2PTunnel2.getIcon(),
|
||||
is.getIconIndex(), CableBusTextures.PartTunnelSides.getIcon(), CableBusTextures.PartTunnelSides.getIcon() );
|
||||
|
||||
rh.setBounds( 2, 2, 14, 14, 14, 16 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
rh.setBounds( 3, 3, 13, 13, 13, 14 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
rh.setTexture( CableBusTextures.BlockP2PTunnel3.getIcon() );
|
||||
|
||||
rh.setBounds( 6, 5, 12, 10, 11, 13 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
rh.setBounds( 5, 6, 12, 11, 10, 13 );
|
||||
rh.renderBlock( x, y, z, renderer );
|
||||
|
||||
renderLights( x, y, z, rh, renderer );
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getBreakingTexture()
|
||||
{
|
||||
return CableBusTextures.BlockP2PTunnel2.getIcon();
|
||||
}
|
||||
|
||||
protected void QueueTunnelDrain(PowerUnits unit, double f)
|
||||
{
|
||||
double ae_to_tax = unit.convertTo( PowerUnits.AE, f * AEConfig.TunnelPowerLoss );
|
||||
|
||||
try
|
||||
{
|
||||
proxy.getEnergy().extractAEPower( ae_to_tax, Actionable.MODULATE, PowerMultiplier.ONE );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColors(boolean hasChan, boolean hasPower)
|
||||
{
|
||||
super.setColors( hasChan, hasPower );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getBoxes(IPartCollisionHelper bch)
|
||||
{
|
||||
bch.addBox( 5, 5, 12, 11, 11, 13 );
|
||||
bch.addBox( 3, 3, 13, 13, 13, 14 );
|
||||
bch.addBox( 2, 2, 14, 14, 14, 16 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int cableConnectionRenderTo()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,228 @@
|
||||
package appeng.parts.p2p;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.TunnelType;
|
||||
import appeng.api.exceptions.FailedConnection;
|
||||
import appeng.api.networking.GridFlags;
|
||||
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.api.parts.IPartHost;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.settings.TickRates;
|
||||
import appeng.hooks.TickHandler;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.cache.helpers.Connections;
|
||||
import appeng.me.cache.helpers.TunnelConnection;
|
||||
import appeng.me.helpers.AENetworkProxy;
|
||||
|
||||
public class PartP2PTunnelME extends PartP2PTunnel<PartP2PTunnelME> implements IGridTickable
|
||||
{
|
||||
|
||||
public TunnelType getTunnelType()
|
||||
{
|
||||
return TunnelType.ME;
|
||||
}
|
||||
|
||||
AENetworkProxy outerProxy = new AENetworkProxy( this, "outer", null, true );
|
||||
public Connections connection = new Connections( this );
|
||||
|
||||
public PartP2PTunnelME(ItemStack is) {
|
||||
super( is );
|
||||
proxy.setFlags( GridFlags.REQUIRE_CHANNEL, GridFlags.COMPRESSED_CHANNEL );
|
||||
outerProxy.setFlags( GridFlags.DENSE_CAPACITY, GridFlags.CANNOT_CARRY_COMPRESSED );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPartHostInfo(ForgeDirection side, IPartHost host, TileEntity tile)
|
||||
{
|
||||
super.setPartHostInfo( side, host, tile );
|
||||
outerProxy.setValidSides( EnumSet.of( side ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound extra)
|
||||
{
|
||||
super.readFromNBT( extra );
|
||||
outerProxy.readFromNBT( extra );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound extra)
|
||||
{
|
||||
super.writeToNBT( extra );
|
||||
outerProxy.writeToNBT( extra );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addToWorld()
|
||||
{
|
||||
super.addToWorld();
|
||||
outerProxy.onReady();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFromWorld()
|
||||
{
|
||||
super.removeFromWorld();
|
||||
outerProxy.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IGridNode getExternalFacingNode()
|
||||
{
|
||||
return outerProxy.getNode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public AECableType getCableConnectionType(ForgeDirection dir)
|
||||
{
|
||||
return AECableType.DENSE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelNetworkChange()
|
||||
{
|
||||
super.onTunnelNetworkChange();
|
||||
if ( !output )
|
||||
{
|
||||
try
|
||||
{
|
||||
proxy.getTick().wakeDevice( proxy.getNode() );
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickingRequest getTickingRequest(IGridNode node)
|
||||
{
|
||||
return new TickingRequest( TickRates.METunnel.min, TickRates.METunnel.max, true, false );
|
||||
}
|
||||
|
||||
@Override
|
||||
public TickRateModulation tickingRequest(IGridNode node, int TicksSinceLastCall)
|
||||
{
|
||||
// just move on...
|
||||
try
|
||||
{
|
||||
if ( !proxy.getPath().isNetworkBooting() )
|
||||
{
|
||||
if ( !proxy.getEnergy().isNetworkPowered() )
|
||||
{
|
||||
connection.markDestroy();
|
||||
TickHandler.instance.addCallable( tile.getWorldObj(), connection );
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( proxy.isActive() )
|
||||
{
|
||||
connection.markCreate();
|
||||
TickHandler.instance.addCallable( tile.getWorldObj(), connection );
|
||||
}
|
||||
else
|
||||
{
|
||||
connection.markDestroy();
|
||||
TickHandler.instance.addCallable( tile.getWorldObj(), connection );
|
||||
}
|
||||
}
|
||||
|
||||
return TickRateModulation.SLEEP;
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// meh?
|
||||
}
|
||||
|
||||
return TickRateModulation.IDLE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlacement(EntityPlayer player, ItemStack held, ForgeDirection side)
|
||||
{
|
||||
super.onPlacement( player, held, side );
|
||||
outerProxy.setOwner( player );
|
||||
}
|
||||
|
||||
public void updateConnections(Connections connections)
|
||||
{
|
||||
if ( connections.destroy )
|
||||
{
|
||||
for (TunnelConnection cw : connection.connections.values())
|
||||
cw.c.destroy();
|
||||
|
||||
connection.connections.clear();
|
||||
}
|
||||
else if ( connections.create )
|
||||
{
|
||||
|
||||
Iterator<TunnelConnection> i = connection.connections.values().iterator();
|
||||
while (i.hasNext())
|
||||
{
|
||||
TunnelConnection cw = i.next();
|
||||
try
|
||||
{
|
||||
if ( cw.tunnel.proxy.getGrid() != proxy.getGrid() )
|
||||
{
|
||||
cw.c.destroy();
|
||||
i.remove();
|
||||
}
|
||||
else if ( !cw.tunnel.proxy.isActive() )
|
||||
{
|
||||
cw.c.destroy();
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
// :P
|
||||
}
|
||||
}
|
||||
|
||||
LinkedList<PartP2PTunnelME> newSides = new LinkedList<PartP2PTunnelME>();
|
||||
try
|
||||
{
|
||||
for (PartP2PTunnelME me : getOutputs())
|
||||
{
|
||||
if ( me.proxy.isActive() && connections.connections.get( me.getGridNode() ) == null )
|
||||
{
|
||||
newSides.add( me );
|
||||
}
|
||||
}
|
||||
|
||||
for (PartP2PTunnelME me : newSides)
|
||||
{
|
||||
try
|
||||
{
|
||||
connections.connections.put( me.getGridNode(),
|
||||
new TunnelConnection( me, AEApi.instance().createGridConnection( outerProxy.getNode(), me.outerProxy.getNode() ) ) );
|
||||
}
|
||||
catch (FailedConnection e)
|
||||
{
|
||||
AELog.error( e );
|
||||
// :(
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
{
|
||||
AELog.error( e );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user