Added torque syncing to client in TileMechanical

This commit is contained in:
Robert S 2014-06-10 10:14:59 -04:00
parent f02912e7a4
commit a90702fa27
2 changed files with 12 additions and 3 deletions

View file

@ -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

View file

@ -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;
}
}