Merge pull request #595 from thatsIch/e-593-newrfapi
Closes #593 Updating RF Integration to use version 1.7.10R1.0.2
This commit is contained in:
commit
fc07acbced
7 changed files with 133 additions and 134 deletions
|
@ -36,6 +36,6 @@ api_mekansim_version=1
|
|||
api_mfr_version=1
|
||||
api_railcraft_version=1
|
||||
api_rblocks_version=1
|
||||
api_rf_version=1
|
||||
api_rf_version=2
|
||||
api_rotarycraft_version=1
|
||||
dev_buildcraft_version=1
|
||||
|
|
|
@ -560,7 +560,7 @@ public class Registration
|
|||
ph.registerNewLayer( "appeng.parts.layers.LayerIBatteryProvider", "buildcraft.api.mj.IBatteryProvider" );
|
||||
|
||||
if ( AppEng.instance.isIntegrationEnabled( IntegrationType.RF ) )
|
||||
ph.registerNewLayer( "appeng.parts.layers.LayerIEnergyHandler", "cofh.api.energy.IEnergyHandler" );
|
||||
ph.registerNewLayer( "appeng.parts.layers.LayerIEnergyHandler", "cofh.api.energy.IEnergyReceiver" );
|
||||
|
||||
FMLCommonHandler.instance().bus().register( TickHandler.instance );
|
||||
MinecraftForge.EVENT_BUS.register( TickHandler.instance );
|
||||
|
|
|
@ -31,6 +31,8 @@ public class RF extends BaseModule
|
|||
public static RF instance;
|
||||
|
||||
public RF() {
|
||||
TestClass( cofh.api.energy.IEnergyReceiver.class );
|
||||
TestClass( cofh.api.energy.IEnergyProvider.class );
|
||||
TestClass( cofh.api.energy.IEnergyHandler.class );
|
||||
TestClass( cofh.api.energy.IEnergyConnection.class );
|
||||
}
|
||||
|
|
|
@ -18,40 +18,36 @@
|
|||
|
||||
package appeng.integration.modules.helpers;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
|
||||
public class NullRFHandler implements IEnergyHandler
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
|
||||
|
||||
public class NullRFHandler implements IEnergyReceiver
|
||||
{
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate)
|
||||
public int receiveEnergy( ForgeDirection from, int maxReceive, boolean simulate )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate)
|
||||
public int getEnergyStored( ForgeDirection from )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored(ForgeDirection from)
|
||||
public int getMaxEnergyStored( ForgeDirection from )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ForgeDirection from)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canConnectEnergy(ForgeDirection from)
|
||||
public boolean canConnectEnergy( ForgeDirection from )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,7 +21,12 @@ package appeng.parts.layers;
|
|||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.api.parts.LayerBase;
|
||||
|
||||
import cofh.api.energy.IEnergyConnection;
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
import cofh.api.energy.IEnergyProvider;
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
|
||||
|
||||
public class LayerIEnergyHandler extends LayerBase implements IEnergyHandler
|
||||
{
|
||||
|
@ -29,9 +34,9 @@ public class LayerIEnergyHandler extends LayerBase implements IEnergyHandler
|
|||
@Override
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate)
|
||||
{
|
||||
IPart part = getPart( from );
|
||||
if ( part instanceof IEnergyHandler )
|
||||
return ((IEnergyHandler) part).receiveEnergy( from, maxReceive, simulate );
|
||||
IPart part = this.getPart( from );
|
||||
if ( part instanceof IEnergyReceiver )
|
||||
return ((IEnergyReceiver) part).receiveEnergy( from, maxReceive, simulate );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -39,9 +44,9 @@ public class LayerIEnergyHandler extends LayerBase implements IEnergyHandler
|
|||
@Override
|
||||
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate)
|
||||
{
|
||||
IPart part = getPart( from );
|
||||
if ( part instanceof IEnergyHandler )
|
||||
return ((IEnergyHandler) part).extractEnergy( from, maxExtract, simulate );
|
||||
IPart part = this.getPart( from );
|
||||
if ( part instanceof IEnergyProvider )
|
||||
return ((IEnergyProvider) part).extractEnergy( from, maxExtract, simulate );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -49,9 +54,9 @@ public class LayerIEnergyHandler extends LayerBase implements IEnergyHandler
|
|||
@Override
|
||||
public int getEnergyStored(ForgeDirection from)
|
||||
{
|
||||
IPart part = getPart( from );
|
||||
if ( part instanceof IEnergyHandler )
|
||||
return ((IEnergyHandler) part).getEnergyStored( from );
|
||||
IPart part = this.getPart( from );
|
||||
if ( part instanceof IEnergyProvider )
|
||||
return ((IEnergyProvider) part).getEnergyStored( from );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -59,9 +64,9 @@ public class LayerIEnergyHandler extends LayerBase implements IEnergyHandler
|
|||
@Override
|
||||
public int getMaxEnergyStored(ForgeDirection from)
|
||||
{
|
||||
IPart part = getPart( from );
|
||||
if ( part instanceof IEnergyHandler )
|
||||
return ((IEnergyHandler) part).getMaxEnergyStored( from );
|
||||
IPart part = this.getPart( from );
|
||||
if ( part instanceof IEnergyProvider )
|
||||
return ((IEnergyProvider) part).getMaxEnergyStored( from );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -69,9 +74,9 @@ public class LayerIEnergyHandler extends LayerBase implements IEnergyHandler
|
|||
@Override
|
||||
public boolean canConnectEnergy(ForgeDirection from)
|
||||
{
|
||||
IPart part = getPart( from );
|
||||
if ( part instanceof IEnergyHandler )
|
||||
return ((IEnergyHandler) part).canConnectEnergy( from );
|
||||
IPart part = this.getPart( from );
|
||||
if ( part instanceof IEnergyConnection )
|
||||
return ((IEnergyConnection) part).canConnectEnergy( from );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
package appeng.parts.p2p;
|
||||
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
|
@ -25,6 +26,12 @@ 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.api.config.TunnelType;
|
||||
import appeng.core.AppEng;
|
||||
|
@ -34,18 +41,28 @@ 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
|
||||
|
||||
@InterfaceList( value = { @Interface( iface = "cofh.api.energy.IEnergyReceiver", iname = "RF" ) } )
|
||||
public 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;
|
||||
|
||||
private static final IEnergyHandler myNullHandler = new NullRFHandler();
|
||||
public PartP2PRFPower( ItemStack is )
|
||||
{
|
||||
super( is );
|
||||
|
||||
boolean cachedTarget = false;
|
||||
IEnergyHandler outputTarget;
|
||||
if ( !AppEng.instance.isIntegrationEnabled( IntegrationType.RF ) )
|
||||
{
|
||||
throw new RuntimeException( "RF Not installed!" );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TunnelType getTunnelType()
|
||||
|
@ -53,61 +70,38 @@ public class PartP2PRFPower extends PartP2PTunnel<PartP2PRFPower> implements cof
|
|||
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 onNeighborChanged()
|
||||
public void onTunnelNetworkChange()
|
||||
{
|
||||
super.onNeighborChanged();
|
||||
cachedTarget = false;
|
||||
this.getHost().notifyNeighbors();
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
@SideOnly( Side.CLIENT )
|
||||
public IIcon getTypeTexture()
|
||||
{
|
||||
return Blocks.iron_block.getBlockTextureFromSide( 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTunnelNetworkChange()
|
||||
public void onNeighborChanged()
|
||||
{
|
||||
getHost().notifyNeighbors();
|
||||
}
|
||||
super.onNeighborChanged();
|
||||
|
||||
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;
|
||||
this.cachedTarget = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate)
|
||||
public int receiveEnergy( ForgeDirection from, int maxReceive, boolean simulate )
|
||||
{
|
||||
if ( output )
|
||||
if ( this.output )
|
||||
return 0;
|
||||
|
||||
if ( isActive() )
|
||||
if ( this.isActive() )
|
||||
{
|
||||
Stack<PartP2PRFPower> stack = getDepth();
|
||||
Stack<PartP2PRFPower> stack = this.getDepth();
|
||||
|
||||
for (PartP2PRFPower t : stack)
|
||||
for ( PartP2PRFPower t : stack )
|
||||
if ( t == this )
|
||||
return 0;
|
||||
|
||||
|
@ -117,7 +111,7 @@ public class PartP2PRFPower extends PartP2PTunnel<PartP2PRFPower> implements cof
|
|||
|
||||
try
|
||||
{
|
||||
for (PartP2PRFPower t : getOutputs())
|
||||
for ( PartP2PRFPower t : this.getOutputs() )
|
||||
{
|
||||
if ( Platform.getRandomInt() % 2 > 0 )
|
||||
{
|
||||
|
@ -132,7 +126,7 @@ public class PartP2PRFPower extends PartP2PTunnel<PartP2PRFPower> implements cof
|
|||
|
||||
if ( maxReceive > 0 )
|
||||
{
|
||||
for (PartP2PRFPower t : getOutputs())
|
||||
for ( PartP2PRFPower t : this.getOutputs() )
|
||||
{
|
||||
int receiver = t.getOutput().receiveEnergy( t.side.getOpposite(), maxReceive, simulate );
|
||||
maxReceive -= receiver;
|
||||
|
@ -143,9 +137,9 @@ public class PartP2PRFPower extends PartP2PTunnel<PartP2PRFPower> implements cof
|
|||
}
|
||||
}
|
||||
|
||||
QueueTunnelDrain( PowerUnits.RF, total );
|
||||
this.QueueTunnelDrain( PowerUnits.RF, total );
|
||||
}
|
||||
catch (GridAccessException ignored)
|
||||
catch ( GridAccessException ignored )
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -158,23 +152,47 @@ public class PartP2PRFPower extends PartP2PTunnel<PartP2PRFPower> implements cof
|
|||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate)
|
||||
private Stack<PartP2PRFPower> getDepth()
|
||||
{
|
||||
return 0;
|
||||
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.getWorldObj().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)
|
||||
public int getEnergyStored( ForgeDirection from )
|
||||
{
|
||||
if ( output || !isActive() )
|
||||
if ( this.output || !this.isActive() )
|
||||
return 0;
|
||||
|
||||
int total = 0;
|
||||
|
||||
Stack<PartP2PRFPower> stack = getDepth();
|
||||
Stack<PartP2PRFPower> stack = this.getDepth();
|
||||
|
||||
for (PartP2PRFPower t : stack)
|
||||
for ( PartP2PRFPower t : stack )
|
||||
if ( t == this )
|
||||
return 0;
|
||||
|
||||
|
@ -182,12 +200,12 @@ public class PartP2PRFPower extends PartP2PTunnel<PartP2PRFPower> implements cof
|
|||
|
||||
try
|
||||
{
|
||||
for (PartP2PRFPower t : getOutputs())
|
||||
for ( PartP2PRFPower t : this.getOutputs() )
|
||||
{
|
||||
total += t.getOutput().getEnergyStored( t.side.getOpposite() );
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
catch ( GridAccessException e )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -199,16 +217,16 @@ public class PartP2PRFPower extends PartP2PTunnel<PartP2PRFPower> implements cof
|
|||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ForgeDirection from)
|
||||
public int getMaxEnergyStored( ForgeDirection from )
|
||||
{
|
||||
if ( output || !isActive() )
|
||||
if ( this.output || !this.isActive() )
|
||||
return 0;
|
||||
|
||||
int total = 0;
|
||||
|
||||
Stack<PartP2PRFPower> stack = getDepth();
|
||||
Stack<PartP2PRFPower> stack = this.getDepth();
|
||||
|
||||
for (PartP2PRFPower t : stack)
|
||||
for ( PartP2PRFPower t : stack )
|
||||
if ( t == this )
|
||||
return 0;
|
||||
|
||||
|
@ -216,12 +234,12 @@ public class PartP2PRFPower extends PartP2PTunnel<PartP2PRFPower> implements cof
|
|||
|
||||
try
|
||||
{
|
||||
for (PartP2PRFPower t : getOutputs())
|
||||
for ( PartP2PRFPower t : this.getOutputs() )
|
||||
{
|
||||
total += t.getOutput().getMaxEnergyStored( t.side.getOpposite() );
|
||||
}
|
||||
}
|
||||
catch (GridAccessException e)
|
||||
catch ( GridAccessException e )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
@ -232,28 +250,8 @@ public class PartP2PRFPower extends PartP2PTunnel<PartP2PRFPower> implements cof
|
|||
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)
|
||||
public boolean canConnectEnergy( ForgeDirection from )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -18,18 +18,22 @@
|
|||
|
||||
package appeng.tile.powersink;
|
||||
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
|
||||
import appeng.api.config.PowerUnits;
|
||||
import appeng.transformer.annotations.integration.Interface;
|
||||
import cofh.api.energy.IEnergyHandler;
|
||||
|
||||
@Interface(iname = "RF", iface = "cofh.api.energy.IEnergyHandler")
|
||||
public abstract class RedstoneFlux extends RotaryCraft implements IEnergyHandler
|
||||
|
||||
@Interface( iname = "RF", iface = "cofh.api.energy.IEnergyReceiver" )
|
||||
public abstract class RedstoneFlux extends RotaryCraft implements IEnergyReceiver
|
||||
{
|
||||
@Override
|
||||
final public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate)
|
||||
final public int receiveEnergy( ForgeDirection from, int maxReceive, boolean simulate )
|
||||
{
|
||||
final int networkRFDemand = (int) Math.floor( this.getExternalPowerDemand( PowerUnits.RF, maxReceive ) );
|
||||
final int networkRFDemand = ( int ) Math.floor( this.getExternalPowerDemand( PowerUnits.RF, maxReceive ) );
|
||||
final int usedRF = Math.min( maxReceive, networkRFDemand );
|
||||
|
||||
if ( !simulate )
|
||||
|
@ -41,26 +45,20 @@ public abstract class RedstoneFlux extends RotaryCraft implements IEnergyHandler
|
|||
}
|
||||
|
||||
@Override
|
||||
final public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate)
|
||||
final public int getEnergyStored( ForgeDirection from )
|
||||
{
|
||||
return 0;
|
||||
return ( int ) Math.floor( PowerUnits.AE.convertTo( PowerUnits.RF, this.getAECurrentPower() ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
final public boolean canConnectEnergy(ForgeDirection from)
|
||||
final public int getMaxEnergyStored( ForgeDirection from )
|
||||
{
|
||||
return ( int ) Math.floor( PowerUnits.AE.convertTo( PowerUnits.RF, this.getAEMaxPower() ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
final public boolean canConnectEnergy( ForgeDirection from )
|
||||
{
|
||||
return this.getPowerSides().contains( from );
|
||||
}
|
||||
|
||||
@Override
|
||||
final public int getEnergyStored(ForgeDirection from)
|
||||
{
|
||||
return (int) Math.floor( PowerUnits.AE.convertTo( PowerUnits.RF, this.getAECurrentPower() ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
final public int getMaxEnergyStored(ForgeDirection from)
|
||||
{
|
||||
return (int) Math.floor( PowerUnits.AE.convertTo( PowerUnits.RF, this.getAEMaxPower() ) );
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue