Attempt to fix gear teeth alignment
This commit is contained in:
parent
eed96732fa
commit
c6e4437199
5 changed files with 31 additions and 23 deletions
|
@ -49,7 +49,10 @@ abstract class PartMechanical extends PartAbstract with JNormalOcclusion with TF
|
|||
save(tag)
|
||||
packet.writeNBTTagCompound(tag)
|
||||
case 1 => packet.writeFloat(mechanicalNode.angularVelocity.toFloat)
|
||||
case 2 => packet.writeFloat(mechanicalNode.angle.toFloat)
|
||||
case 2 =>
|
||||
if (mechanicalNode.connections.size() > 0)
|
||||
mechanicalNode.resetAngle()
|
||||
// packet.writeFloat(mechanicalNode.angle.toFloat)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -63,8 +66,8 @@ abstract class PartMechanical extends PartAbstract with JNormalOcclusion with TF
|
|||
load(packet.readNBTTagCompound())
|
||||
case 1 => mechanicalNode.angularVelocity = packet.readFloat()
|
||||
case 2 =>
|
||||
mechanicalNode.prevAngle = packet.readFloat()
|
||||
mechanicalNode.prevTime = System.currentTimeMillis()
|
||||
// mechanicalNode.prevAngle = packet.readFloat()
|
||||
// mechanicalNode.prevTime = System.currentTimeMillis()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@ import resonant.lib.network.handle.{TPacketReceiver, TPacketSender}
|
|||
import resonant.lib.transform.vector.Vector3
|
||||
import resonantinduction.mechanical.mech.grid.NodeMechanical
|
||||
|
||||
import scala.collection.convert.wrapAll._
|
||||
|
||||
/** Prefab for resonantinduction.mechanical tiles
|
||||
*
|
||||
* @author Calclavia */
|
||||
|
@ -30,6 +32,7 @@ abstract class TileMechanical(material: Material) extends SpatialTile(material:
|
|||
{
|
||||
_mechanicalNode = newNode
|
||||
mechanicalNode.onVelocityChanged = () => sendPacket(1)
|
||||
nodes.remove(nodes.filter(_.isInstanceOf[NodeMechanical]))
|
||||
nodes.add(mechanicalNode)
|
||||
}
|
||||
|
||||
|
|
|
@ -26,14 +26,14 @@ import resonantinduction.mechanical.mech.PartMechanical
|
|||
*/
|
||||
class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
|
||||
{
|
||||
var isClockwiseCrank: Boolean = true
|
||||
var isClockwiseCrank = true
|
||||
var manualCrankTime = 0
|
||||
var multiBlockRadius: Int = 1
|
||||
/** Multiblock */
|
||||
var multiBlockRadius = 1
|
||||
val multiBlock = new GearMultiBlockHandler(this)
|
||||
|
||||
//Constructor
|
||||
mechanicalNode = new NodeGear(this)
|
||||
|
||||
mechanicalNode.onVelocityChanged = () =>
|
||||
{
|
||||
if (getMultiBlock.isPrimary)
|
||||
|
|
|
@ -20,23 +20,9 @@ class MechanicalGrid extends GridNode[NodeMechanical](classOf[NodeMechanical]) w
|
|||
{
|
||||
super.reconstruct(first)
|
||||
UpdateTicker.world.addUpdater(this)
|
||||
|
||||
load = getNodes.map(n => n.getLoad).foldLeft(0D)(_ + _)
|
||||
}
|
||||
|
||||
override protected def populateNode(node: NodeMechanical, prev: NodeMechanical)
|
||||
{
|
||||
super.populateNode(node, prev)
|
||||
|
||||
//TODO: Check if gears are LOCKED (when two nodes obtain undesirable spins)
|
||||
// val dir = if (prev != null) if (node.inverseRotation(prev)) !spinMap(prev) else spinMap(prev) else false
|
||||
// spinMap += (node -> dir)
|
||||
|
||||
//Set mechanical node's initial angle
|
||||
if (prev != null)
|
||||
node.prevAngle = (prev.prevAngle + prev.angleDisplacement) % (2 * Math.PI)
|
||||
}
|
||||
|
||||
override def update(deltaTime: Double)
|
||||
{
|
||||
getNodes synchronized
|
||||
|
@ -81,7 +67,7 @@ class MechanicalGrid extends GridNode[NodeMechanical](classOf[NodeMechanical]) w
|
|||
|
||||
def recurse(deltaTime: Double, torque: Double, angularVelocity: Double, passed: Seq[NodeMechanical])
|
||||
{
|
||||
val curr = passed(passed.size - 1)
|
||||
val curr = passed.last
|
||||
|
||||
if (passed.size > 1)
|
||||
{
|
||||
|
|
|
@ -8,6 +8,7 @@ import resonantinduction.core.interfaces.TNodeMechanical
|
|||
import resonantinduction.core.prefab.node.TMultipartNode
|
||||
|
||||
import scala.beans.BeanProperty
|
||||
import scala.collection.convert.wrapAll._
|
||||
|
||||
/**
|
||||
* Prefab node for the mechanical system used by almost ever mechanical object in Resonant Induction. Handles connections to other tiles, and shares power with them
|
||||
|
@ -75,7 +76,22 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par
|
|||
return prevAngle
|
||||
}
|
||||
|
||||
override def rotate(torque: Double, angularVelocity : Double)
|
||||
/**
|
||||
* Sets the mechanical node's angle based on its connections
|
||||
*/
|
||||
def resetAngle()
|
||||
{
|
||||
connections.foreach(
|
||||
n =>
|
||||
{
|
||||
val diff = Math.round((n.prevAngle - prevAngle) * angleDisplacement)
|
||||
n.prevAngle = (prevAngle + diff) % (Math.PI * 2)
|
||||
}
|
||||
)
|
||||
prevTime = System.currentTimeMillis()
|
||||
}
|
||||
|
||||
override def rotate(torque: Double, angularVelocity: Double)
|
||||
{
|
||||
bufferTorque += torque
|
||||
bufferAngularVelocity += angularVelocity
|
||||
|
@ -89,5 +105,5 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par
|
|||
|
||||
override def isValidConnection(other: AnyRef): Boolean = other.isInstanceOf[NodeMechanical]
|
||||
|
||||
override def toString = "NodeMechanical[Connections: "+connections.size() + " Torque: " + torque + " Angular Velocity:" + angularVelocity+"]"
|
||||
override def toString = "NodeMechanical[Connections: " + connections.size() + " Torque: " + torque + " Angular Velocity:" + angularVelocity + "]"
|
||||
}
|
Loading…
Add table
Reference in a new issue