Re-enabled the RF and IC2 handler, as well as their P2P tunnels. Added Forge Energy P2P tunnel.

This commit is contained in:
Gunther De Wachter
2017-07-14 21:52:04 +02:00
parent fdab91323c
commit 66c87a2fa2
26 changed files with 1776 additions and 1241 deletions
+193 -256
View File
@@ -18,260 +18,197 @@
package appeng.parts.p2p;
import java.util.List;
import java.util.Stack;
//import java.util.Stack;
//
//import net.minecraft.init.Blocks;
//import net.minecraft.item.ItemStack;
//import net.minecraft.tileentity.TileEntity;
//import net.minecraft.util.IIcon;
//import net.minecraftforge.common.util.ForgeDirection;
//
//import cpw.mods.fml.relauncher.Side;
//import cpw.mods.fml.relauncher.SideOnly;
//
//import cofh.api.energy.IEnergyReceiver;
//
//import appeng.api.config.PowerUnits;
//import appeng.integration.IntegrationType;
//import appeng.integration.modules.helpers.NullRFHandler;
//import appeng.me.GridAccessException;
//import appeng.coremod.annotations.Integration.Interface;
//import appeng.coremod.annotations.Integration.InterfaceList;
//import appeng.util.Platform;
//
//
//@InterfaceList( value = { @Interface( iface = "cofh.api.energy.IEnergyReceiver", iname = IntegrationType.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 IIcon 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.x + this.side.offsetX, self.y + this.side.offsetY, self.z + 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;
// }
// }
import appeng.api.parts.IPartModel;
import appeng.items.parts.PartModels;
import cofh.redstoneflux.api.IEnergyReceiver;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import appeng.api.config.PowerUnits;
import appeng.integration.IntegrationType;
import appeng.me.GridAccessException;
import appeng.coremod.annotations.Integration.Interface;
import appeng.coremod.annotations.Integration.InterfaceList;
import appeng.util.Platform;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
@InterfaceList( value = { @Interface( iface = "cofh.redstoneflux.api.IEnergyReceiver", iname = IntegrationType.RF ) } )
public final class PartP2PRFPower extends PartP2PTunnel<PartP2PRFPower> implements IEnergyReceiver
{
private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_rf" );
private boolean cachedTarget = false;
private IEnergyReceiver outputTarget;
public PartP2PRFPower( ItemStack is )
{
super( is );
}
@PartModels
public static List<IPartModel> getModels()
{
return MODELS.getModels();
}
@Override
public IPartModel getStaticModels()
{
return MODELS.getModel( isPowered(), isActive() );
}
@Override
public void onTunnelNetworkChange()
{
this.getHost().notifyNeighbors();
}
@Override
public void onNeighborChanged()
{
super.onNeighborChanged();
this.cachedTarget = false;
}
@Override
public int receiveEnergy( EnumFacing from, int maxReceive, boolean simulate )
{
if( this.isOutput() )
{
return 0;
}
if( this.isActive() )
{
int total = 0;
try
{
for( PartP2PRFPower t : this.getOutputs() )
{
if( Platform.getRandomInt() % 2 > 0 )
{
int receiver = t.getOutput().receiveEnergy( t.getSide().getFacing().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.getSide().getFacing().getOpposite(), maxReceive, simulate );
maxReceive -= receiver;
total += receiver;
if( maxReceive <= 0 )
{
break;
}
}
}
this.queueTunnelDrain( PowerUnits.RF, total );
}
catch( GridAccessException ignored )
{
}
return total;
}
return 0;
}
private IEnergyReceiver getOutput()
{
if( this.isOutput() )
{
if( !this.cachedTarget )
{
TileEntity self = this.getTile();
TileEntity te = self.getWorld().getTileEntity( new BlockPos( self.getPos().getX() + this.getSide().xOffset, self.getPos().getY() + this.getSide().yOffset, self.getPos().getZ() + this.getSide().zOffset ) );
this.outputTarget = te instanceof IEnergyReceiver ? (IEnergyReceiver) te : null;
this.cachedTarget = true;
}
if( this.outputTarget == null || !this.outputTarget.canConnectEnergy( this.getSide().getOpposite().getFacing() ) )
{
return null;
}
return this.outputTarget;
}
return null;
}
@Override
public int getEnergyStored( EnumFacing from )
{
if( this.isOutput() || !this.isActive() )
{
return 0;
}
int total = 0;
try
{
for( PartP2PRFPower t : this.getOutputs() )
{
total += t.getOutput().getEnergyStored( this.getSide().getOpposite().getFacing() );
}
}
catch( GridAccessException e )
{
return 0;
}
return total;
}
@Override
public int getMaxEnergyStored( EnumFacing from )
{
if( this.isOutput() || !this.isActive() )
{
return 0;
}
int total = 0;
try
{
for( PartP2PRFPower t : this.getOutputs() )
{
total += t.getOutput().getMaxEnergyStored( this.getSide().getOpposite().getFacing() );
}
}
catch( GridAccessException e )
{
return 0;
}
return total;
}
@Override
public boolean canConnectEnergy( EnumFacing from )
{
return true;
}
}