make it runnable

This commit is contained in:
thatsIch
2015-06-17 19:39:18 +02:00
parent 38afde724b
commit a95b9962b9
17 changed files with 1422 additions and 1583 deletions
@@ -19,244 +19,226 @@
package appeng.parts.p2p;
import java.util.LinkedList;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import appeng.api.config.PowerUnits;
import appeng.api.util.ForgeDirection;
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;
@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
{
// two packet buffering...
double OutputEnergyA;
double OutputEnergyB;
// two packet buffering...
double OutputVoltageA;
double OutputVoltageB;
public PartP2PIC2Power( ItemStack is )
{
super( is );
}
@Override
@SideOnly( Side.CLIENT )
public TextureAtlasSprite getTypeTexture()
{
return Blocks.diamond_block.getBlockTextureFromSide( 0 );
}
@Override
public void readFromNBT( NBTTagCompound tag )
{
super.readFromNBT( tag );
this.OutputEnergyA = tag.getDouble( "OutputPacket" );
this.OutputEnergyB = tag.getDouble( "OutputPacket2" );
this.OutputVoltageA = tag.getDouble( "OutputVoltageA" );
this.OutputVoltageB = tag.getDouble( "OutputVoltageB" );
}
@Override
public void writeToNBT( NBTTagCompound tag )
{
super.writeToNBT( tag );
tag.setDouble( "OutputPacket", this.OutputEnergyA );
tag.setDouble( "OutputPacket2", this.OutputEnergyB );
tag.setDouble( "OutputVoltageA", this.OutputVoltageA );
tag.setDouble( "OutputVoltageB", this.OutputVoltageB );
}
@Override
public void onTunnelConfigChange()
{
this.getHost().partChanged();
}
@Override
public void onTunnelNetworkChange()
{
this.getHost().notifyNeighbors();
}
@Override
public boolean acceptsEnergyFrom( TileEntity emitter, ForgeDirection direction )
{
if( !this.output )
{
return direction == this.side;
}
return false;
}
@Override
public boolean emitsEnergyTo( TileEntity receiver, ForgeDirection direction )
{
if( this.output )
{
return direction == this.side;
}
return false;
}
@Override
public double getDemandedEnergy()
{
if( this.output )
{
return 0;
}
try
{
for( PartP2PIC2Power t : this.getOutputs() )
{
if( t.OutputEnergyA <= 0.0001 || t.OutputEnergyB <= 0.0001 )
{
return 2048;
}
}
}
catch( GridAccessException e )
{
return 0;
}
return 0;
}
@Override
public int getSinkTier()
{
return 4;
}
@Override
public double injectEnergy( ForgeDirection directionFrom, double amount, double voltage )
{
TunnelCollection<PartP2PIC2Power> outs;
try
{
outs = this.getOutputs();
}
catch( GridAccessException e )
{
return amount;
}
if( outs.isEmpty() )
{
return amount;
}
LinkedList<PartP2PIC2Power> options = new LinkedList<PartP2PIC2Power>();
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 = Platform.pickRandom( options );
if( x != null && x.OutputEnergyA <= 0.001 )
{
this.queueTunnelDrain( PowerUnits.EU, amount );
x.OutputEnergyA = amount;
x.OutputVoltageA = voltage;
return 0;
}
if( x != null && x.OutputEnergyB <= 0.001 )
{
this.queueTunnelDrain( PowerUnits.EU, amount );
x.OutputEnergyB = amount;
x.OutputVoltageB = voltage;
return 0;
}
return amount;
}
public float getPowerDrainPerTick()
{
return 0.5f;
}
@Override
public double getOfferedEnergy()
{
if( this.output )
{
return this.OutputEnergyA;
}
return 0;
}
@Override
public void drawEnergy( double amount )
{
this.OutputEnergyA -= amount;
if( this.OutputEnergyA < 0.001 )
{
this.OutputEnergyA = this.OutputEnergyB;
this.OutputEnergyB = 0;
this.OutputVoltageA = this.OutputVoltageB;
this.OutputVoltageB = 0;
}
}
@Override
public int getSourceTier()
{
if( this.output )
{
return this.calculateTierFromVoltage( this.OutputVoltageA );
}
return 4;
}
private int calculateTierFromVoltage( double voltage )
{
return ic2.api.energy.EnergyNet.instance.getTierFromPower( voltage );
}
}
//@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
//{
//
// // two packet buffering...
// double OutputEnergyA;
// double OutputEnergyB;
// // two packet buffering...
// double OutputVoltageA;
// double OutputVoltageB;
//
// public PartP2PIC2Power( ItemStack is )
// {
// super( is );
// }
//
// @Override
// @SideOnly( Side.CLIENT )
// public TextureAtlasSprite getTypeTexture()
// {
// return Blocks.diamond_block.getBlockTextureFromSide( 0 );
// }
//
// @Override
// public void readFromNBT( NBTTagCompound tag )
// {
// super.readFromNBT( tag );
// this.OutputEnergyA = tag.getDouble( "OutputPacket" );
// this.OutputEnergyB = tag.getDouble( "OutputPacket2" );
// this.OutputVoltageA = tag.getDouble( "OutputVoltageA" );
// this.OutputVoltageB = tag.getDouble( "OutputVoltageB" );
// }
//
// @Override
// public void writeToNBT( NBTTagCompound tag )
// {
// super.writeToNBT( tag );
// tag.setDouble( "OutputPacket", this.OutputEnergyA );
// tag.setDouble( "OutputPacket2", this.OutputEnergyB );
// tag.setDouble( "OutputVoltageA", this.OutputVoltageA );
// tag.setDouble( "OutputVoltageB", this.OutputVoltageB );
// }
//
// @Override
// public void onTunnelConfigChange()
// {
// this.getHost().partChanged();
// }
//
// @Override
// public void onTunnelNetworkChange()
// {
// this.getHost().notifyNeighbors();
// }
//
// @Override
// public boolean acceptsEnergyFrom( TileEntity emitter, ForgeDirection direction )
// {
// if( !this.output )
// {
// return direction == this.side;
// }
// return false;
// }
//
// @Override
// public boolean emitsEnergyTo( TileEntity receiver, ForgeDirection direction )
// {
// if( this.output )
// {
// return direction == this.side;
// }
// return false;
// }
//
// @Override
// public double getDemandedEnergy()
// {
// if( this.output )
// {
// return 0;
// }
//
// try
// {
// for( PartP2PIC2Power t : this.getOutputs() )
// {
// if( t.OutputEnergyA <= 0.0001 || t.OutputEnergyB <= 0.0001 )
// {
// return 2048;
// }
// }
// }
// catch( GridAccessException e )
// {
// return 0;
// }
//
// return 0;
// }
//
// @Override
// public int getSinkTier()
// {
// return 4;
// }
//
// @Override
// public double injectEnergy( ForgeDirection directionFrom, double amount, double voltage )
// {
// TunnelCollection<PartP2PIC2Power> outs;
// try
// {
// outs = this.getOutputs();
// }
// catch( GridAccessException e )
// {
// return amount;
// }
//
// if( outs.isEmpty() )
// {
// return amount;
// }
//
// LinkedList<PartP2PIC2Power> options = new LinkedList<PartP2PIC2Power>();
// 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 = Platform.pickRandom( options );
//
// if( x != null && x.OutputEnergyA <= 0.001 )
// {
// this.queueTunnelDrain( PowerUnits.EU, amount );
// x.OutputEnergyA = amount;
// x.OutputVoltageA = voltage;
// return 0;
// }
//
// if( x != null && x.OutputEnergyB <= 0.001 )
// {
// this.queueTunnelDrain( PowerUnits.EU, amount );
// x.OutputEnergyB = amount;
// x.OutputVoltageB = voltage;
// return 0;
// }
//
// return amount;
// }
//
// public float getPowerDrainPerTick()
// {
// return 0.5f;
// }
//
// @Override
// public double getOfferedEnergy()
// {
// if( this.output )
// {
// return this.OutputEnergyA;
// }
// return 0;
// }
//
// @Override
// public void drawEnergy( double amount )
// {
// this.OutputEnergyA -= amount;
// if( this.OutputEnergyA < 0.001 )
// {
// this.OutputEnergyA = this.OutputEnergyB;
// this.OutputEnergyB = 0;
//
// this.OutputVoltageA = this.OutputVoltageB;
// this.OutputVoltageB = 0;
// }
// }
//
// @Override
// public int getSourceTier()
// {
// if( this.output )
// {
// return this.calculateTierFromVoltage( this.OutputVoltageA );
// }
// return 4;
// }
//
// private int calculateTierFromVoltage( double voltage )
// {
// return ic2.api.energy.EnergyNet.instance.getTierFromPower( voltage );
// }
//}
@@ -19,229 +19,197 @@
package appeng.parts.p2p;
import java.util.concurrent.Callable;
import javax.annotation.Nullable;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import li.cil.oc.api.API;
import li.cil.oc.api.Items;
import li.cil.oc.api.Network;
import li.cil.oc.api.network.Environment;
import li.cil.oc.api.network.Message;
import li.cil.oc.api.network.Node;
import li.cil.oc.api.network.SidedEnvironment;
import li.cil.oc.api.network.Visibility;
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.util.ForgeDirection;
import appeng.core.AELog;
import appeng.core.settings.TickRates;
import appeng.hooks.TickHandler;
import appeng.integration.IntegrationRegistry;
import appeng.integration.IntegrationType;
import appeng.me.GridAccessException;
import appeng.transformer.annotations.Integration.Interface;
import appeng.transformer.annotations.Integration.InterfaceList;
@InterfaceList(value = { @Interface(iface = "li.cil.oc.api.network.Environment", iname = "OpenComputers"), @Interface(iface = "li.cil.oc.api.network.SidedEnvironment", iname = "OpenComputers") })
public final class PartP2POpenComputers extends PartP2PTunnel<PartP2POpenComputers> implements IGridTickable, Environment, SidedEnvironment
{
@Nullable
private final Node node;
private final Callable<Void> updateCallback;
public PartP2POpenComputers(ItemStack is)
{
super( is );
if ( !IntegrationRegistry.INSTANCE.isEnabled( IntegrationType.OpenComputers ) )
{
throw new RuntimeException( "OpenComputers is not installed!" );
}
// Avoid NPE when called in pre-init phase (part population).
if ( API.network != null )
{
this.node = Network.newNode( this, Visibility.None ).create();
}
else
{
this.node = null; // to satisfy final
}
this.updateCallback = new UpdateCallback();
}
@Override
@SideOnly(Side.CLIENT)
public TextureAtlasSprite getTypeTexture()
{
return Items.get( "adapter" ).block().getBlockTextureFromSide( 2 );
}
@Override
public void removeFromWorld()
{
super.removeFromWorld();
if ( this.node != null)
{
this.node.remove();
}
}
@Override
public void onTunnelNetworkChange()
{
super.onTunnelNetworkChange();
try
{
this.proxy.getTick().wakeDevice( this.proxy.getNode() );
}
catch( GridAccessException e )
{
// ignore
}
}
@Override
public void readFromNBT(NBTTagCompound data)
{
super.readFromNBT( data );
if ( this.node != null)
{
this.node.load( data );
}
}
@Override
public void writeToNBT(NBTTagCompound data)
{
super.writeToNBT( data );
if ( this.node != null)
{
this.node.save( data );
}
}
@Override
public TickingRequest getTickingRequest( IGridNode node )
{
return new TickingRequest( TickRates.OpenComputersTunnel.min, TickRates.OpenComputersTunnel.max, true, false );
}
@Override
public TickRateModulation tickingRequest( IGridNode node, int ticksSinceLastCall )
{
try
{
if( !this.proxy.getPath().isNetworkBooting() )
{
if ( this.node() != null ) // Client side doesn't have nodes.
{
TickHandler.INSTANCE.addCallable( this.tile.getWorld(), this.updateCallback );
}
return TickRateModulation.SLEEP;
}
}
catch( GridAccessException e )
{
// ignore
}
return TickRateModulation.IDLE;
}
private void updateConnections()
{
if ( this.proxy.isPowered() && this.proxy.isActive() )
{
// Make sure we're connected to existing OC nodes in the world.
Network.joinOrCreateNetwork( this.getTile() );
if ( this.output )
{
if ( this.getInput() != null && this.node != null )
{
Network.joinOrCreateNetwork( this.getInput().getTile() );
this.node.connect( this.getInput().node() );
}
}
else
{
try
{
for ( PartP2POpenComputers output : this.getOutputs() )
{
if ( this.node != null )
{
Network.joinOrCreateNetwork( output.getTile() );
this.node.connect( output.node() );
}
}
}
catch ( GridAccessException e )
{
AELog.error( e );
}
}
}
else if ( this.node != null )
{
this.node.remove();
}
}
@Nullable
@Override
public Node node()
{
return this.node;
}
@Override
public void onConnect(Node node) {
}
@Override
public void onDisconnect(Node node) {
}
@Override
public void onMessage(Message message) {
}
@Nullable
@Override
public Node sidedNode(ForgeDirection side)
{
return side == this.side ? this.node : null;
}
@Override
public boolean canConnect(ForgeDirection side)
{
return side == this.side;
}
private final class UpdateCallback implements Callable<Void>
{
@Nullable
@Override
public Void call() throws Exception
{
PartP2POpenComputers.this.updateConnections();
return null;
}
}
}
//@InterfaceList(value = { @Interface(iface = "li.cil.oc.api.network.Environment", iname = "OpenComputers"), @Interface(iface = "li.cil.oc.api.network.SidedEnvironment", iname = "OpenComputers") })
//public final class PartP2POpenComputers extends PartP2PTunnel<PartP2POpenComputers> implements IGridTickable, Environment, SidedEnvironment
//{
// @Nullable
// private final Node node;
//
// private final Callable<Void> updateCallback;
//
// public PartP2POpenComputers(ItemStack is)
// {
// super( is );
//
// if ( !IntegrationRegistry.INSTANCE.isEnabled( IntegrationType.OpenComputers ) )
// {
// throw new RuntimeException( "OpenComputers is not installed!" );
// }
//
// // Avoid NPE when called in pre-init phase (part population).
// if ( API.network != null )
// {
// this.node = Network.newNode( this, Visibility.None ).create();
// }
// else
// {
// this.node = null; // to satisfy final
// }
//
// this.updateCallback = new UpdateCallback();
// }
//
// @Override
// @SideOnly(Side.CLIENT)
// public TextureAtlasSprite getTypeTexture()
// {
// return Items.get( "adapter" ).block().getBlockTextureFromSide( 2 );
// }
//
// @Override
// public void removeFromWorld()
// {
// super.removeFromWorld();
// if ( this.node != null)
// {
// this.node.remove();
// }
// }
//
// @Override
// public void onTunnelNetworkChange()
// {
// super.onTunnelNetworkChange();
// try
// {
// this.proxy.getTick().wakeDevice( this.proxy.getNode() );
// }
// catch( GridAccessException e )
// {
// // ignore
// }
// }
//
// @Override
// public void readFromNBT(NBTTagCompound data)
// {
// super.readFromNBT( data );
// if ( this.node != null)
// {
// this.node.load( data );
// }
// }
//
// @Override
// public void writeToNBT(NBTTagCompound data)
// {
// super.writeToNBT( data );
// if ( this.node != null)
// {
// this.node.save( data );
// }
// }
//
// @Override
// public TickingRequest getTickingRequest( IGridNode node )
// {
// return new TickingRequest( TickRates.OpenComputersTunnel.min, TickRates.OpenComputersTunnel.max, true, false );
// }
//
// @Override
// public TickRateModulation tickingRequest( IGridNode node, int ticksSinceLastCall )
// {
// try
// {
// if( !this.proxy.getPath().isNetworkBooting() )
// {
// if ( this.node() != null ) // Client side doesn't have nodes.
// {
// TickHandler.INSTANCE.addCallable( this.tile.getWorld(), this.updateCallback );
// }
//
// return TickRateModulation.SLEEP;
// }
// }
// catch( GridAccessException e )
// {
// // ignore
// }
//
// return TickRateModulation.IDLE;
// }
//
// private void updateConnections()
// {
// if ( this.proxy.isPowered() && this.proxy.isActive() )
// {
// // Make sure we're connected to existing OC nodes in the world.
// Network.joinOrCreateNetwork( this.getTile() );
//
// if ( this.output )
// {
// if ( this.getInput() != null && this.node != null )
// {
// Network.joinOrCreateNetwork( this.getInput().getTile() );
// this.node.connect( this.getInput().node() );
// }
// }
// else
// {
// try
// {
// for ( PartP2POpenComputers output : this.getOutputs() )
// {
// if ( this.node != null )
// {
// Network.joinOrCreateNetwork( output.getTile() );
// this.node.connect( output.node() );
// }
// }
// }
// catch ( GridAccessException e )
// {
// AELog.error( e );
// }
// }
// }
// else if ( this.node != null )
// {
// this.node.remove();
// }
// }
//
// @Nullable
// @Override
// public Node node()
// {
// return this.node;
// }
//
// @Override
// public void onConnect(Node node) {
// }
//
// @Override
// public void onDisconnect(Node node) {
// }
//
// @Override
// public void onMessage(Message message) {
// }
//
// @Nullable
// @Override
// public Node sidedNode(ForgeDirection side)
// {
// return side == this.side ? this.node : null;
// }
//
// @Override
// public boolean canConnect(ForgeDirection side)
// {
// return side == this.side;
// }
//
// private final class UpdateCallback implements Callable<Void>
// {
// @Nullable
// @Override
// public Void call() throws Exception
// {
// PartP2POpenComputers.this.updateConnections();
//
// return null;
// }
// }
//}
+234 -252
View File
@@ -19,255 +19,237 @@
package appeng.parts.p2p;
import java.util.Stack;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import cofh.api.energy.IEnergyReceiver;
import appeng.api.config.PowerUnits;
import appeng.api.util.ForgeDirection;
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;
@InterfaceList( value = { @Interface( iface = "cofh.api.energy.IEnergyReceiver", iname = "RF" ) } )
public final class PartP2PRFPower extends PartP2PTunnel<PartP2PRFPower> implements IEnergyReceiver
{
private static final ThreadLocal<Stack<PartP2PRFPower>> THREAD_STACK = new ThreadLocal<Stack<PartP2PRFPower>>();
/**
* Default element based on the null element pattern
*/
private static final IEnergyReceiver NULL_HANDLER = new NullRFHandler();
private boolean cachedTarget = false;
private IEnergyReceiver outputTarget;
public PartP2PRFPower( ItemStack is )
{
super( is );
}
@Override
@SideOnly( Side.CLIENT )
public TextureAtlasSprite getTypeTexture()
{
return Blocks.iron_block.getBlockTextureFromSide( 0 );
}
@Override
public void onTunnelNetworkChange()
{
this.getHost().notifyNeighbors();
}
@Override
public void onNeighborChanged()
{
super.onNeighborChanged();
this.cachedTarget = false;
}
@Override
public int receiveEnergy( ForgeDirection from, int maxReceive, boolean simulate )
{
if( this.output )
{
return 0;
}
if( this.isActive() )
{
Stack<PartP2PRFPower> stack = this.getDepth();
for( PartP2PRFPower t : stack )
{
if( t == this )
{
return 0;
}
}
stack.push( this );
int total = 0;
try
{
for( PartP2PRFPower t : this.getOutputs() )
{
if( Platform.getRandomInt() % 2 > 0 )
{
int receiver = t.getOutput().receiveEnergy( t.side.getOpposite(), maxReceive, simulate );
maxReceive -= receiver;
total += receiver;
if( maxReceive <= 0 )
{
break;
}
}
}
if( maxReceive > 0 )
{
for( PartP2PRFPower t : this.getOutputs() )
{
int receiver = t.getOutput().receiveEnergy( t.side.getOpposite(), maxReceive, simulate );
maxReceive -= receiver;
total += receiver;
if( maxReceive <= 0 )
{
break;
}
}
}
this.queueTunnelDrain( PowerUnits.RF, total );
}
catch( GridAccessException ignored )
{
}
if( stack.pop() != this )
{
throw new IllegalStateException( "Invalid Recursion detected." );
}
return total;
}
return 0;
}
private Stack<PartP2PRFPower> getDepth()
{
Stack<PartP2PRFPower> s = THREAD_STACK.get();
if( s == null )
{
THREAD_STACK.set( s = new Stack<PartP2PRFPower>() );
}
return s;
}
private IEnergyReceiver getOutput()
{
if( this.output )
{
if( !this.cachedTarget )
{
TileEntity self = this.getTile();
TileEntity te = self.getWorld().getTileEntity( self.xCoord + this.side.offsetX, self.yCoord + this.side.offsetY, self.zCoord + this.side.offsetZ );
this.outputTarget = te instanceof IEnergyReceiver ? (IEnergyReceiver) te : null;
this.cachedTarget = true;
}
if( this.outputTarget == null || !this.outputTarget.canConnectEnergy( this.side.getOpposite() ) )
{
return NULL_HANDLER;
}
return this.outputTarget;
}
return NULL_HANDLER;
}
@Override
public int getEnergyStored( ForgeDirection from )
{
if( this.output || !this.isActive() )
{
return 0;
}
int total = 0;
Stack<PartP2PRFPower> stack = this.getDepth();
for( PartP2PRFPower t : stack )
{
if( t == this )
{
return 0;
}
}
stack.push( this );
try
{
for( PartP2PRFPower t : this.getOutputs() )
{
total += t.getOutput().getEnergyStored( t.side.getOpposite() );
}
}
catch( GridAccessException e )
{
return 0;
}
if( stack.pop() != this )
{
throw new IllegalStateException( "Invalid Recursion detected." );
}
return total;
}
@Override
public int getMaxEnergyStored( ForgeDirection from )
{
if( this.output || !this.isActive() )
{
return 0;
}
int total = 0;
Stack<PartP2PRFPower> stack = this.getDepth();
for( PartP2PRFPower t : stack )
{
if( t == this )
{
return 0;
}
}
stack.push( this );
try
{
for( PartP2PRFPower t : this.getOutputs() )
{
total += t.getOutput().getMaxEnergyStored( t.side.getOpposite() );
}
}
catch( GridAccessException e )
{
return 0;
}
if( stack.pop() != this )
{
throw new IllegalStateException( "Invalid Recursion detected." );
}
return total;
}
@Override
public boolean canConnectEnergy( ForgeDirection from )
{
return true;
}
}
//@InterfaceList( value = { @Interface( iface = "cofh.api.energy.IEnergyReceiver", iname = "RF" ) } )
//public final class PartP2PRFPower extends PartP2PTunnel<PartP2PRFPower> implements IEnergyReceiver
//{
// private static final ThreadLocal<Stack<PartP2PRFPower>> THREAD_STACK = new ThreadLocal<Stack<PartP2PRFPower>>();
// /**
// * Default element based on the null element pattern
// */
// private static final IEnergyReceiver NULL_HANDLER = new NullRFHandler();
// private boolean cachedTarget = false;
// private IEnergyReceiver outputTarget;
//
// public PartP2PRFPower( ItemStack is )
// {
// super( is );
// }
//
// @Override
// @SideOnly( Side.CLIENT )
// public TextureAtlasSprite getTypeTexture()
// {
// return Blocks.iron_block.getBlockTextureFromSide( 0 );
// }
//
// @Override
// public void onTunnelNetworkChange()
// {
// this.getHost().notifyNeighbors();
// }
//
// @Override
// public void onNeighborChanged()
// {
// super.onNeighborChanged();
//
// this.cachedTarget = false;
// }
//
// @Override
// public int receiveEnergy( ForgeDirection from, int maxReceive, boolean simulate )
// {
// if( this.output )
// {
// return 0;
// }
//
// if( this.isActive() )
// {
// Stack<PartP2PRFPower> stack = this.getDepth();
//
// for( PartP2PRFPower t : stack )
// {
// if( t == this )
// {
// return 0;
// }
// }
//
// stack.push( this );
//
// int total = 0;
//
// try
// {
// for( PartP2PRFPower t : this.getOutputs() )
// {
// if( Platform.getRandomInt() % 2 > 0 )
// {
// int receiver = t.getOutput().receiveEnergy( t.side.getOpposite(), maxReceive, simulate );
// maxReceive -= receiver;
// total += receiver;
//
// if( maxReceive <= 0 )
// {
// break;
// }
// }
// }
//
// if( maxReceive > 0 )
// {
// for( PartP2PRFPower t : this.getOutputs() )
// {
// int receiver = t.getOutput().receiveEnergy( t.side.getOpposite(), maxReceive, simulate );
// maxReceive -= receiver;
// total += receiver;
//
// if( maxReceive <= 0 )
// {
// break;
// }
// }
// }
//
// this.queueTunnelDrain( PowerUnits.RF, total );
// }
// catch( GridAccessException ignored )
// {
// }
//
// if( stack.pop() != this )
// {
// throw new IllegalStateException( "Invalid Recursion detected." );
// }
//
// return total;
// }
//
// return 0;
// }
//
// private Stack<PartP2PRFPower> getDepth()
// {
// Stack<PartP2PRFPower> s = THREAD_STACK.get();
//
// if( s == null )
// {
// THREAD_STACK.set( s = new Stack<PartP2PRFPower>() );
// }
//
// return s;
// }
//
// private IEnergyReceiver getOutput()
// {
// if( this.output )
// {
// if( !this.cachedTarget )
// {
// TileEntity self = this.getTile();
// TileEntity te = self.getWorld().getTileEntity( self.xCoord + this.side.offsetX, self.yCoord + this.side.offsetY, self.zCoord + this.side.offsetZ );
// this.outputTarget = te instanceof IEnergyReceiver ? (IEnergyReceiver) te : null;
// this.cachedTarget = true;
// }
//
// if( this.outputTarget == null || !this.outputTarget.canConnectEnergy( this.side.getOpposite() ) )
// {
// return NULL_HANDLER;
// }
//
// return this.outputTarget;
// }
// return NULL_HANDLER;
// }
//
// @Override
// public int getEnergyStored( ForgeDirection from )
// {
// if( this.output || !this.isActive() )
// {
// return 0;
// }
//
// int total = 0;
//
// Stack<PartP2PRFPower> stack = this.getDepth();
//
// for( PartP2PRFPower t : stack )
// {
// if( t == this )
// {
// return 0;
// }
// }
//
// stack.push( this );
//
// try
// {
// for( PartP2PRFPower t : this.getOutputs() )
// {
// total += t.getOutput().getEnergyStored( t.side.getOpposite() );
// }
// }
// catch( GridAccessException e )
// {
// return 0;
// }
//
// if( stack.pop() != this )
// {
// throw new IllegalStateException( "Invalid Recursion detected." );
// }
//
// return total;
// }
//
// @Override
// public int getMaxEnergyStored( ForgeDirection from )
// {
// if( this.output || !this.isActive() )
// {
// return 0;
// }
//
// int total = 0;
//
// Stack<PartP2PRFPower> stack = this.getDepth();
//
// for( PartP2PRFPower t : stack )
// {
// if( t == this )
// {
// return 0;
// }
// }
//
// stack.push( this );
//
// try
// {
// for( PartP2PRFPower t : this.getOutputs() )
// {
// total += t.getOutput().getMaxEnergyStored( t.side.getOpposite() );
// }
// }
// catch( GridAccessException e )
// {
// return 0;
// }
//
// if( stack.pop() != this )
// {
// throw new IllegalStateException( "Invalid Recursion detected." );
// }
//
// return total;
// }
//
// @Override
// public boolean canConnectEnergy( ForgeDirection from )
// {
// return true;
// }
//}