From a5c124eeac26d140fd191b089e9ef51f2e9800a7 Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sat, 18 Jan 2014 12:43:41 +0800 Subject: [PATCH] Added ability to change torque to velocity ratio in generator --- .../electrical/generator/BlockGenerator.java | 17 +++++++++++++++++ .../electrical/generator/TileGenerator.java | 15 +++++++++++++-- .../mechanical/gear/PartGear.java | 19 ++++++------------- .../mechanical/network/MechanicalNetwork.java | 6 +++++- 4 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/main/java/resonantinduction/electrical/generator/BlockGenerator.java b/src/main/java/resonantinduction/electrical/generator/BlockGenerator.java index bcf18e40..da91a35a 100644 --- a/src/main/java/resonantinduction/electrical/generator/BlockGenerator.java +++ b/src/main/java/resonantinduction/electrical/generator/BlockGenerator.java @@ -35,6 +35,23 @@ public class BlockGenerator extends BlockRIRotatable return false; } + @Override + public boolean onSneakUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ) + { + TileEntity tileEntity = world.getBlockTileEntity(x, y, z); + + if (tileEntity instanceof TileGenerator) + { + if (!world.isRemote) + { + entityPlayer.addChatMessage("Generator torque ratio: " + ((TileGenerator) tileEntity).toggleRatio()); + } + + return true; + } + return false; + } + @Override public TileEntity createNewTileEntity(World world) { diff --git a/src/main/java/resonantinduction/electrical/generator/TileGenerator.java b/src/main/java/resonantinduction/electrical/generator/TileGenerator.java index 275db150..2d701802 100644 --- a/src/main/java/resonantinduction/electrical/generator/TileGenerator.java +++ b/src/main/java/resonantinduction/electrical/generator/TileGenerator.java @@ -19,12 +19,19 @@ public class TileGenerator extends TileElectrical implements IMechanical /** Generator turns KE -> EE. Inverted one will turn EE -> KE. */ public boolean isInversed = false; + private float torqueRatio = 500; + public TileGenerator() { - energy = new EnergyStorageHandler(10000, 1000); + energy = new EnergyStorageHandler(10000); this.ioMap = 728; } + public float toggleRatio() + { + return torqueRatio = (torqueRatio + 100) % energy.getMaxExtract(); + } + @Override public void updateEntity() { @@ -44,7 +51,11 @@ public class TileGenerator extends TileElectrical implements IMechanical long extract = energy.extractEnergy(); if (extract > 0) - ((IMechanical) mechanical).onReceiveEnergy(getOuputDirection().getOpposite(), (long) (500), extract / 500f); + { + float angularVelocity = extract / torqueRatio; + long torque = (long) (extract / angularVelocity); + ((IMechanical) mechanical).onReceiveEnergy(getOuputDirection().getOpposite(), torque, angularVelocity); + } } } } diff --git a/src/main/java/resonantinduction/mechanical/gear/PartGear.java b/src/main/java/resonantinduction/mechanical/gear/PartGear.java index 8e62d086..3aa407c1 100644 --- a/src/main/java/resonantinduction/mechanical/gear/PartGear.java +++ b/src/main/java/resonantinduction/mechanical/gear/PartGear.java @@ -81,6 +81,11 @@ public class PartGear extends JCuboidPart implements JNormalOcclusion, TFacePart @Override public void update() { + if (markRotationUpdate) + { + updateRotations(); + } + if (!this.world().isRemote) { if (manualCrankTime > 0) @@ -91,11 +96,6 @@ public class PartGear extends JCuboidPart implements JNormalOcclusion, TFacePart } else { - if (markRotationUpdate) - { - updateRotations(); - } - /** * Update angle rotation. */ @@ -110,13 +110,6 @@ public class PartGear extends JCuboidPart implements JNormalOcclusion, TFacePart @Override public void onNetworkChanged() { - if (world() != null) - { - if (markRotationUpdate) - { - updateRotations(); - } - } } /** @@ -338,7 +331,7 @@ public class PartGear extends JCuboidPart implements JNormalOcclusion, TFacePart @Override public void sendNetworkPacket(long torque, float angularVelocity) - {System.out.println("SEND"); + { tile().getWriteStream(this).writeByte(0).writeLong(torque).writeFloat(angularVelocity).writeBoolean(isClockwise); } diff --git a/src/main/java/resonantinduction/mechanical/network/MechanicalNetwork.java b/src/main/java/resonantinduction/mechanical/network/MechanicalNetwork.java index 40edc372..dc62d6c5 100644 --- a/src/main/java/resonantinduction/mechanical/network/MechanicalNetwork.java +++ b/src/main/java/resonantinduction/mechanical/network/MechanicalNetwork.java @@ -55,7 +55,7 @@ public class MechanicalNetwork extends Network