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 );
// }
//}