2014-01-20 17:41:37 +01:00
|
|
|
package appeng.parts.p2p;
|
|
|
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraft.init.Blocks;
|
2014-01-20 17:41:37 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraft.util.IIcon;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-05-02 07:40:46 +02:00
|
|
|
import appeng.api.config.PowerUnits;
|
2014-01-27 05:00:36 +01:00
|
|
|
import appeng.api.config.TunnelType;
|
2014-04-06 08:55:24 +02:00
|
|
|
import appeng.core.AppEng;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.me.GridAccessException;
|
|
|
|
import appeng.me.cache.helpers.TunnelCollection;
|
2014-04-06 08:55:24 +02:00
|
|
|
import appeng.transformer.annotations.integration.Interface;
|
|
|
|
import appeng.transformer.annotations.integration.InterfaceList;
|
2014-01-20 17:41:37 +01:00
|
|
|
import appeng.util.Platform;
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
|
2014-04-06 08:55:24 +02:00
|
|
|
@InterfaceList(value = { @Interface(iface = "ic2.api.energy.tile.IEnergySink", iname = "IC2"),
|
|
|
|
@Interface(iface = "ic2.api.energy.tile.IEnergySource", iname = "IC2") })
|
2014-01-20 17:41:37 +01:00
|
|
|
public class PartP2PIC2Power extends PartP2PTunnel<PartP2PIC2Power> implements ic2.api.energy.tile.IEnergySink, ic2.api.energy.tile.IEnergySource
|
|
|
|
{
|
|
|
|
|
2014-01-27 05:00:36 +01:00
|
|
|
public TunnelType getTunnelType()
|
|
|
|
{
|
|
|
|
return TunnelType.IC2_POWER;
|
|
|
|
}
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
public PartP2PIC2Power(ItemStack is) {
|
|
|
|
super( is );
|
2014-04-06 08:55:24 +02:00
|
|
|
|
|
|
|
if ( !AppEng.instance.isIntegrationEnabled( "IC2" ) )
|
|
|
|
throw new RuntimeException( "IC2 Not installed!" );
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
2014-05-19 04:36:32 +02:00
|
|
|
// two packet buffering...
|
|
|
|
double OutputPacketA;
|
|
|
|
double OutputPacketB;
|
2014-01-20 17:41:37 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToNBT(NBTTagCompound tag)
|
|
|
|
{
|
|
|
|
super.writeToNBT( tag );
|
2014-05-19 04:36:32 +02:00
|
|
|
tag.setDouble( "OutputPacket", OutputPacketA );
|
|
|
|
tag.setDouble( "OutputPacket2", OutputPacketB );
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readFromNBT(NBTTagCompound tag)
|
|
|
|
{
|
|
|
|
super.readFromNBT( tag );
|
2014-05-19 04:36:32 +02:00
|
|
|
OutputPacketA = tag.getDouble( "OutputPacket" );
|
|
|
|
OutputPacketB = tag.getDouble( "OutputPacket2" );
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
2014-02-09 02:34:52 +01:00
|
|
|
public IIcon getTypeTexture()
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
return Blocks.diamond_block.getBlockTextureFromSide( 0 );
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@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 demandedEnergyUnits()
|
|
|
|
{
|
|
|
|
if ( output )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
for (PartP2PIC2Power t : getOutputs())
|
|
|
|
{
|
2014-05-19 04:36:32 +02:00
|
|
|
if ( t.OutputPacketA <= 0.0001 || t.OutputPacketB <= 0.0001 )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
|
|
|
return 2048;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (GridAccessException e)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-09 01:10:19 +02:00
|
|
|
public void onTunnelNetworkChange()
|
|
|
|
{
|
|
|
|
getHost().notifyNeighbors();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onTunnelConfigChange()
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
2014-02-26 16:17:39 +01:00
|
|
|
getHost().partChanged();
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public float getPowerDrainPerTick()
|
|
|
|
{
|
|
|
|
return 0.5f;
|
|
|
|
};
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double injectEnergyUnits(ForgeDirection directionFrom, double amount)
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
2014-05-19 04:36:32 +02:00
|
|
|
if ( o.OutputPacketA <= 0.01 )
|
2014-01-20 17:41:37 +01:00
|
|
|
Options.add( o );
|
|
|
|
}
|
|
|
|
|
2014-05-19 04:36:32 +02:00
|
|
|
if ( Options.isEmpty() )
|
|
|
|
{
|
|
|
|
for (PartP2PIC2Power o : outs)
|
|
|
|
if ( o.OutputPacketB <= 0.01 )
|
|
|
|
Options.add( o );
|
|
|
|
}
|
|
|
|
|
2014-04-08 04:31:36 +02:00
|
|
|
if ( Options.isEmpty() )
|
|
|
|
{
|
|
|
|
for (PartP2PIC2Power o : outs)
|
|
|
|
Options.add( o );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( Options.isEmpty() )
|
|
|
|
return amount;
|
|
|
|
|
2014-01-20 17:41:37 +01:00
|
|
|
PartP2PIC2Power x = (PartP2PIC2Power) Platform.pickRandom( Options );
|
2014-05-19 04:36:32 +02:00
|
|
|
|
|
|
|
if ( x != null && x.OutputPacketA <= 0.001 )
|
2014-01-20 17:41:37 +01:00
|
|
|
{
|
2014-05-02 07:40:46 +02:00
|
|
|
QueueTunnelDrain( PowerUnits.EU, amount );
|
2014-05-19 04:36:32 +02:00
|
|
|
x.OutputPacketA = amount;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( x != null && x.OutputPacketB <= 0.001 )
|
|
|
|
{
|
|
|
|
QueueTunnelDrain( PowerUnits.EU, amount );
|
|
|
|
x.OutputPacketB = amount;
|
2014-01-20 17:41:37 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return amount;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getMaxSafeInput()
|
|
|
|
{
|
|
|
|
return Integer.MAX_VALUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double getOfferedEnergy()
|
|
|
|
{
|
|
|
|
if ( output )
|
2014-05-19 04:36:32 +02:00
|
|
|
return OutputPacketA;
|
2014-01-20 17:41:37 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void drawEnergy(double amount)
|
|
|
|
{
|
2014-05-19 04:36:32 +02:00
|
|
|
OutputPacketA -= amount;
|
|
|
|
if ( OutputPacketA < 0.001 )
|
|
|
|
{
|
|
|
|
OutputPacketA = OutputPacketB;
|
|
|
|
OutputPacketB = 0;
|
|
|
|
}
|
2014-01-20 17:41:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|