From a90702fa273fbc2b243c1937e73c9b4d6fc0a3c0 Mon Sep 17 00:00:00 2001 From: Robert S Date: Tue, 10 Jun 2014 10:14:59 -0400 Subject: [PATCH] Added torque syncing to client in TileMechanical --- .../mechanical/energy/grid/MechanicalNode.java | 9 ++++++++- .../mechanical/energy/grid/TileMechanical.java | 6 ++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/mechanical/src/main/scala/resonantinduction/mechanical/energy/grid/MechanicalNode.java b/mechanical/src/main/scala/resonantinduction/mechanical/energy/grid/MechanicalNode.java index 6a3e5f97..2b657a4e 100644 --- a/mechanical/src/main/scala/resonantinduction/mechanical/energy/grid/MechanicalNode.java +++ b/mechanical/src/main/scala/resonantinduction/mechanical/energy/grid/MechanicalNode.java @@ -26,11 +26,12 @@ public class MechanicalNode implements IMechanicalNode, ISaveObj, IVectorWorld public boolean doDebug = false; /** Used to note that you should trigger a packet update for rotation */ public boolean markRotationUpdate = false; + public boolean markTorqueUpdate = false; /** Which section of debug is enabled */ public int debugCue = 0, maxDebugCue = 1, minDebugCue = 0; public static final int UPDATE_DEBUG = 0, CONNECTION_DEBUG = 1; /** Rotational Force */ - public double torque = 0; + public double torque = 0, prevTorque; /** Rotational speed */ public double prevAngularVelocity, angularVelocity = 0; /** Rotational acceleration */ @@ -123,6 +124,12 @@ public class MechanicalNode implements IMechanicalNode, ISaveObj, IVectorWorld prevAngularVelocity = angularVelocity; markRotationUpdate = true; } + + if (Math.abs(prevTorque - torque) > 0.01f) + { + prevTorque = torque; + markTorqueUpdate = true; + } //----------------------------------- // Loss calculations diff --git a/mechanical/src/main/scala/resonantinduction/mechanical/energy/grid/TileMechanical.java b/mechanical/src/main/scala/resonantinduction/mechanical/energy/grid/TileMechanical.java index 87742e65..af5ee3e1 100644 --- a/mechanical/src/main/scala/resonantinduction/mechanical/energy/grid/TileMechanical.java +++ b/mechanical/src/main/scala/resonantinduction/mechanical/energy/grid/TileMechanical.java @@ -63,10 +63,11 @@ public abstract class TileMechanical extends TileBase implements INodeProvider, mechanicalNode.update(); if (!this.getWorldObj().isRemote) { - if (mechanicalNode.markRotationUpdate && ticks % 3 == 0) + if (ticks % 3 == 0 && (mechanicalNode.markTorqueUpdate || mechanicalNode.markRotationUpdate)) { sendRotationPacket(); mechanicalNode.markRotationUpdate = false; + mechanicalNode.markTorqueUpdate = false; } } } @@ -89,7 +90,7 @@ public abstract class TileMechanical extends TileBase implements INodeProvider, private void sendRotationPacket() { - PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_VELOCITY, this, mechanicalNode.angularVelocity), worldObj, new Vector3(this), 20); + PacketHandler.sendPacketToClients(ResonantInduction.PACKET_TILE.getPacketWithID(PACKET_VELOCITY, this, mechanicalNode.angularVelocity, mechanicalNode.torque), worldObj, new Vector3(this), 20); } @Override @@ -107,6 +108,7 @@ public abstract class TileMechanical extends TileBase implements INodeProvider, else if (id == PACKET_VELOCITY) { mechanicalNode.angularVelocity = data.readDouble(); + mechanicalNode.torque = data.readDouble(); return true; } }