Some mechanical grid fixes
This commit is contained in:
parent
1c832ea241
commit
88316d9b6c
|
@ -33,7 +33,7 @@ trait TNodeMechanical extends INode with IVectorWorld
|
|||
/**
|
||||
* The radius of rotation
|
||||
*/
|
||||
def radius = 0.5
|
||||
def radius(other: TNodeMechanical) = 0.5
|
||||
|
||||
/**
|
||||
* Does the direction flip on this side for rotation
|
||||
|
@ -48,5 +48,5 @@ trait TNodeMechanical extends INode with IVectorWorld
|
|||
*
|
||||
* @param torque - force at an angle
|
||||
*/
|
||||
def rotate(torque: Double, angularVelocity : Double)
|
||||
def rotate(torque: Double, angularVelocity: Double)
|
||||
}
|
|
@ -5,7 +5,7 @@ import codechicken.multipart.{TMultiPart, TileMultipart}
|
|||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import resonant.api.grid.INodeProvider
|
||||
import resonant.lib.transform.vector.Vector3
|
||||
import resonant.lib.transform.vector.{VectorWorld, Vector3}
|
||||
import resonant.lib.wrapper.ForgeDirectionWrapper._
|
||||
import resonantinduction.core.interfaces.TNodeMechanical
|
||||
import resonantinduction.mechanical.mech.gearshaft.{GearShaftNode, PartGearShaft}
|
||||
|
@ -208,20 +208,16 @@ class NodeGear(parent: PartGear) extends NodeMechanical(parent: PartGear)
|
|||
|
||||
override def inverseRotation(other: TNodeMechanical): Boolean = !other.isInstanceOf[GearShaftNode] || (other.isInstanceOf[GearShaftNode] && parent.placementSide.offset < Vector3.zero)
|
||||
|
||||
override def radius = if (gear.getMultiBlock.isConstructed) 1.5 * 1.5 else super.radius
|
||||
|
||||
/*
|
||||
override def getRadius(dir: ForgeDirection, other: TMechanicalNode): Double =
|
||||
override def radius( other: TNodeMechanical): Double =
|
||||
{
|
||||
//The ratio is the same if it is a gear placed back to back with each other OR a shaft
|
||||
val deltaPos: Vector3 = new VectorWorld(other.asInstanceOf[IVectorWorld]).subtract(toVectorWorld)
|
||||
val deltaPos = other.asInstanceOf[NodeMechanical].toVectorWorld - toVectorWorld
|
||||
val caseX = gear.placementSide.offsetX != 0 && deltaPos.y == 0 && deltaPos.z == 0
|
||||
val caseY = gear.placementSide.offsetY != 0 && deltaPos.x == 0 && deltaPos.z == 0
|
||||
val caseZ = gear.placementSide.offsetZ != 0 && deltaPos.x == 0 && deltaPos.y == 0
|
||||
|
||||
if (caseX || caseY || caseZ)
|
||||
return super.getRadius(dir, other)
|
||||
return super.radius( other)
|
||||
|
||||
return if (gear.getMultiBlock.isConstructed) 1.5f else super.getRadius(dir, other)
|
||||
}*/
|
||||
if (gear.getMultiBlock.isConstructed) 1.5 else super.radius(other)
|
||||
}
|
||||
}
|
|
@ -55,10 +55,12 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
|
|||
{
|
||||
if (manualCrankTime > 0)
|
||||
{
|
||||
//A punch his around 5000 Newtons
|
||||
mechanicalNode.rotate((if (isClockwiseCrank) 2 else -2) * manualCrankTime, (if (isClockwiseCrank) 2 else -2) * manualCrankTime)
|
||||
//A punch has around 5000 Newtons
|
||||
mechanicalNode.rotate((if (isClockwiseCrank) 2 else -2) * manualCrankTime, (if (isClockwiseCrank) 0.5 else -0.5) * manualCrankTime)
|
||||
manualCrankTime -= 1
|
||||
}
|
||||
mechanicalNode.bufferDefaultTorque = (if (isClockwiseCrank) 2 else -2) * manualCrankTime
|
||||
mechanicalNode.bufferDefaultAngularVelocity = (if (isClockwiseCrank) 0.5 else -0.5) * manualCrankTime
|
||||
}
|
||||
|
||||
getMultiBlock.update()
|
||||
|
|
|
@ -68,8 +68,12 @@ class MechanicalGrid extends GridNode[NodeMechanical](classOf[NodeMechanical]) w
|
|||
if (n.prevTorque != n.torque)
|
||||
n.onTorqueChanged()
|
||||
|
||||
if (n.prevAngularVelocity != n.angularVelocity)
|
||||
// if (n.prevAngularVelocity != n.angularVelocity)
|
||||
n.onVelocityChanged()
|
||||
|
||||
//TODO: Solve problem with "buffer" not syncing up with this thread.
|
||||
n.bufferTorque = n.bufferDefaultTorque
|
||||
n.bufferAngularVelocity = n.bufferDefaultAngularVelocity
|
||||
}
|
||||
)
|
||||
}
|
||||
|
@ -84,15 +88,13 @@ class MechanicalGrid extends GridNode[NodeMechanical](classOf[NodeMechanical]) w
|
|||
val prev = passed(passed.size - 2)
|
||||
val ratio = curr.radius / prev.radius
|
||||
val invert = if (curr.inverseRotation(prev)) -1 else 1
|
||||
curr._torque += prev.torque * ratio * invert
|
||||
curr._angularVelocity += prev.angularVelocity / ratio * invert
|
||||
curr._torque += Math.abs(passed(0).bufferTorque) * ratio * invert * Math.signum(prev.torque)
|
||||
curr._angularVelocity += Math.abs(passed(0).bufferAngularVelocity) * deltaTime / ratio * invert * Math.signum(prev.angularVelocity)
|
||||
}
|
||||
else
|
||||
{
|
||||
curr._torque += curr.bufferTorque
|
||||
curr._angularVelocity += curr.bufferAngularVelocity * deltaTime
|
||||
curr.bufferTorque = 0
|
||||
curr.bufferAngularVelocity = 0
|
||||
}
|
||||
|
||||
if (curr.power > 0)
|
||||
|
|
|
@ -44,6 +44,7 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par
|
|||
protected[grid] var bufferTorque = 0D
|
||||
protected[grid] var bufferAngularVelocity = 0D
|
||||
var bufferDefaultTorque = 0D
|
||||
var bufferDefaultAngularVelocity = 0D
|
||||
|
||||
/**
|
||||
* Angle calculations
|
||||
|
@ -79,7 +80,7 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par
|
|||
override def rotate(torque: Double, angularVelocity : Double)
|
||||
{
|
||||
bufferTorque += torque
|
||||
bufferAngularVelocity += torque
|
||||
bufferAngularVelocity += angularVelocity
|
||||
}
|
||||
|
||||
def power: Double = torque * angularVelocity
|
||||
|
|
Loading…
Reference in a new issue