From e8a68cc5311a44c42a172f2c3a33e0ec61c5359c Mon Sep 17 00:00:00 2001 From: Jeremiah Winsley Date: Mon, 11 May 2015 19:54:52 -0400 Subject: [PATCH] Fixes #1384 - implement AdvancedShaftPowerReceiver for RotaryCraft powersink --- .../integration/modules/RotaryCraft.java | 3 +- .../appeng/tile/powersink/RotaryCraft.java | 91 +++++++++++-------- 2 files changed, 56 insertions(+), 38 deletions(-) diff --git a/src/main/java/appeng/integration/modules/RotaryCraft.java b/src/main/java/appeng/integration/modules/RotaryCraft.java index 71383e65..d67af81e 100644 --- a/src/main/java/appeng/integration/modules/RotaryCraft.java +++ b/src/main/java/appeng/integration/modules/RotaryCraft.java @@ -28,7 +28,8 @@ public class RotaryCraft extends BaseModule public RotaryCraft() { - this.testClassExistence( Reika.RotaryCraft.API.Power.ShaftPowerReceiver.class ); + this.testClassExistence( Reika.RotaryCraft.API.Power.AdvancedShaftPowerReceiver.class ); + this.testClassExistence( Reika.RotaryCraft.API.Interfaces.Transducerable.class ); } @Override diff --git a/src/main/java/appeng/tile/powersink/RotaryCraft.java b/src/main/java/appeng/tile/powersink/RotaryCraft.java index b8ffbbb3..79d6d42d 100644 --- a/src/main/java/appeng/tile/powersink/RotaryCraft.java +++ b/src/main/java/appeng/tile/powersink/RotaryCraft.java @@ -19,20 +19,25 @@ package appeng.tile.powersink; +import appeng.transformer.annotations.Integration; +import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -import Reika.RotaryCraft.API.Power.ShaftPowerReceiver; +import Reika.RotaryCraft.API.Interfaces.Transducerable; +import Reika.RotaryCraft.API.Power.AdvancedShaftPowerReceiver; import appeng.api.config.PowerUnits; import appeng.tile.TileEvent; import appeng.tile.events.TileEventType; import appeng.transformer.annotations.Integration.Interface; +import appeng.transformer.annotations.Integration.InterfaceList; import appeng.transformer.annotations.Integration.Method; import appeng.util.Platform; +import java.util.ArrayList; -@Interface( iname = "RotaryCraft", iface = "Reika.RotaryCraft.API.Power.ShaftPowerReceiver" ) -public abstract class RotaryCraft extends IC2 implements ShaftPowerReceiver +@InterfaceList( value = { @Interface( iname = "RotaryCraft", iface = "Reika.RotaryCraft.API.Power.AdvancedShaftPowerReceiver" ), @Interface( iname = "RotaryCraft", iface = "Reika.RotaryCraft.API.Interfaces.Transducerable") } ) +public abstract class RotaryCraft extends IC2 implements AdvancedShaftPowerReceiver, Transducerable { private int omega = 0; @@ -40,16 +45,32 @@ public abstract class RotaryCraft extends IC2 implements ShaftPowerReceiver private long power = 0; private int alpha = 0; + private long currentPower = 0; + @TileEvent( TileEventType.TICK ) @Method( iname = "RotaryCraft" ) public void Tick_RotaryCraft() { - if( this.worldObj != null && !this.worldObj.isRemote && this.power > 0 ) + if( this.worldObj != null && !this.worldObj.isRemote && this.currentPower > 0 ) { - this.injectExternalPower( PowerUnits.WA, this.power ); + this.injectExternalPower( PowerUnits.WA, this.currentPower ); + this.currentPower = 0; } } + @Override + public final boolean addPower( int torque, int omega, long power, ForgeDirection side ) + { + this.omega = omega; + this.torque = torque; + this.power = power; + + this.currentPower += power; + + return true; + + } + @Override public final int getOmega() { @@ -86,37 +107,6 @@ public abstract class RotaryCraft extends IC2 implements ShaftPowerReceiver this.alpha = io; } - @Override - public final void setPower( long p ) - { - if( Platform.isClient() ) - { - return; - } - - this.power = p; - } - - @Override - public final void noInputMachine() - { - this.power = 0; - this.torque = 0; - this.omega = 0; - } - - @Override - public final void setTorque( int t ) - { - this.torque = t; - } - - @Override - public final void setOmega( int o ) - { - this.omega = o; - } - public final boolean canReadFromBlock( int x, int y, int z ) { ForgeDirection side = ForgeDirection.UNKNOWN; @@ -164,6 +154,33 @@ public abstract class RotaryCraft extends IC2 implements ShaftPowerReceiver @Override public final int getMinTorque( int available ) { - return 0; + return 1; + } + + @Override + public final ArrayList getMessages( World world, int x, int y, int z, int side ) + { + String out; + if( power >= 1000000000 ) + { + out = String.format( "Receiving %.3f GW @ %d rad/s.", power / 1000000000.0D, omega ); + } + else if( power >= 1000000 ) + { + out = String.format( "Receiving %.3f MW @ %d rad/s.", power / 1000000.0D, omega ); + } + else if( power >= 1000 ) + { + out = String.format( "Receiving %.3f kW @ %d rad/s.", power / 1000.0D, omega ); + } + else + { + out = String.format( "Receiving %d W @ %d rad/s.", power, omega ); + } + + + ArrayList messages = new ArrayList( 1 ); + messages.add( out ); + return messages; } }