Adjusted the way how load works
This commit is contained in:
parent
03e04b3ae3
commit
8b7ae367e6
3 changed files with 30 additions and 26 deletions
|
@ -29,7 +29,7 @@ import resonantinduction.mechanical.mech.PartMechanical
|
||||||
class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
|
class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
|
||||||
{
|
{
|
||||||
var isClockwiseCrank: Boolean = true
|
var isClockwiseCrank: Boolean = true
|
||||||
var manualCrankTime = 0D
|
var manualCrankTime = 0
|
||||||
var multiBlockRadius: Int = 1
|
var multiBlockRadius: Int = 1
|
||||||
/** Multiblock */
|
/** Multiblock */
|
||||||
val multiBlock = new GearMultiBlockHandler(this)
|
val multiBlock = new GearMultiBlockHandler(this)
|
||||||
|
@ -53,8 +53,9 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
|
||||||
{
|
{
|
||||||
if (manualCrankTime > 0)
|
if (manualCrankTime > 0)
|
||||||
{
|
{
|
||||||
|
//A punch his around 5000 Newtons
|
||||||
mechanicalNode.rotate(if (isClockwiseCrank) 50 else -50)
|
mechanicalNode.rotate(if (isClockwiseCrank) 50 else -50)
|
||||||
manualCrankTime -= 0.1
|
manualCrankTime -= 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,8 +76,8 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
|
||||||
}
|
}
|
||||||
|
|
||||||
isClockwiseCrank = player.isSneaking
|
isClockwiseCrank = player.isSneaking
|
||||||
|
getMultiBlock.get.manualCrankTime = 40
|
||||||
|
|
||||||
getMultiBlock.get.manualCrankTime = 2
|
|
||||||
world.playSoundEffect(x + 0.5, y + 0.5, z + 0.5, Reference.prefix + "gearCrank", 0.5f, 0.9f + world.rand.nextFloat * 0.2f)
|
world.playSoundEffect(x + 0.5, y + 0.5, z + 0.5, Reference.prefix + "gearCrank", 0.5f, 0.9f + world.rand.nextFloat * 0.2f)
|
||||||
player.addExhaustion(0.01f)
|
player.addExhaustion(0.01f)
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -19,7 +19,7 @@ class MechanicalGrid extends GridNode[NodeMechanical](classOf[NodeMechanical]) w
|
||||||
*/
|
*/
|
||||||
val spinMap = mutable.WeakHashMap.empty[NodeMechanical, Boolean]
|
val spinMap = mutable.WeakHashMap.empty[NodeMechanical, Boolean]
|
||||||
|
|
||||||
private var friction = 0D
|
private var load = 0D
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rebuild the node list starting from the first node and recursively iterating through its connections.
|
* Rebuild the node list starting from the first node and recursively iterating through its connections.
|
||||||
|
@ -29,7 +29,7 @@ class MechanicalGrid extends GridNode[NodeMechanical](classOf[NodeMechanical]) w
|
||||||
super.reconstruct(first)
|
super.reconstruct(first)
|
||||||
UpdateTicker.addUpdater(this)
|
UpdateTicker.addUpdater(this)
|
||||||
|
|
||||||
friction = getNodes.map(n => n.getLoad).foldLeft(0D)(_ + _)
|
load = getNodes.map(n => n.getLoad).foldLeft(0D)(_ + _)
|
||||||
}
|
}
|
||||||
|
|
||||||
override protected def populateNode(node: NodeMechanical, prev: NodeMechanical)
|
override protected def populateNode(node: NodeMechanical, prev: NodeMechanical)
|
||||||
|
@ -54,32 +54,31 @@ class MechanicalGrid extends GridNode[NodeMechanical](classOf[NodeMechanical]) w
|
||||||
|
|
||||||
//Calculate the total input equivalent torque
|
//Calculate the total input equivalent torque
|
||||||
val inputTorque = inputs
|
val inputTorque = inputs
|
||||||
.map(n => n.bufferTorque * (if (spinMap(n)) 1 else -1))
|
.map(n => n.bufferTorque * (if (spinMap(n)) 1 else -1))
|
||||||
.foldLeft(0D)(_ + _)
|
.foldLeft(0D)(_ + _)
|
||||||
|
|
||||||
val deltaTorque = inputTorque - friction * inputTorque
|
val deltaTorque = if (inputTorque != 0) Math.max(Math.abs(inputTorque) - load * deltaTime, 0) * inputTorque / Math.abs(inputTorque) else 0
|
||||||
|
|
||||||
//Set torque and angular velocity of all nodes
|
//Set torque and angular velocity of all nodes
|
||||||
getNodes.foreach(
|
getNodes.foreach(n =>
|
||||||
n =>
|
{
|
||||||
{
|
val prevTorque = n.torque
|
||||||
val prevTorque = n.torque
|
val prevAngularVelocity = n.angularVelocity
|
||||||
val prevAngularVelocity = n.angularVelocity
|
|
||||||
|
|
||||||
val inversion = if (spinMap(n)) 1 else -1
|
val inversion = if (spinMap(n)) 1 else -1
|
||||||
n.torque = deltaTorque * n.ratio * inversion
|
n.torque = deltaTorque * n.ratio * inversion
|
||||||
val angularAcceleration = deltaTorque / n.momentOfInertia
|
val angularAcceleration = deltaTorque / n.momentOfInertia
|
||||||
n.angularVelocity = angularAcceleration / n.ratio * deltaTime * inversion
|
n.angularVelocity = angularAcceleration / n.ratio * deltaTime * inversion
|
||||||
|
|
||||||
if (Math.abs(prevTorque - n.torque) >= 0.1)
|
if (Math.abs(prevTorque - n.torque) >= 0.1)
|
||||||
n.onTorqueChanged()
|
n.onTorqueChanged()
|
||||||
|
|
||||||
if (Math.abs(prevAngularVelocity - n.angularVelocity) >= 0.1)
|
if (Math.abs(prevAngularVelocity - n.angularVelocity) >= 0.01)
|
||||||
n.onVelocityChanged()
|
n.onVelocityChanged()
|
||||||
|
|
||||||
//Clear buffers
|
//Clear buffers
|
||||||
n.bufferTorque = 0
|
n.bufferTorque = 0
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,9 +26,9 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par
|
||||||
protected[grid] var bufferTorque = 0D
|
protected[grid] var bufferTorque = 0D
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A percentage value indicating how much friction the loss.
|
* The mechanical load
|
||||||
*/
|
*/
|
||||||
var load = 0.1D
|
var load = 10D
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Angle calculations
|
* Angle calculations
|
||||||
|
@ -70,6 +70,10 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par
|
||||||
//Moment of inertia = m * r ^ 2
|
//Moment of inertia = m * r ^ 2
|
||||||
def momentOfInertia = 1d
|
def momentOfInertia = 1d
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The mechanical load
|
||||||
|
* @return Torque in Newton meters per second
|
||||||
|
*/
|
||||||
def getLoad = load
|
def getLoad = load
|
||||||
|
|
||||||
override def rotate(torque: Double)
|
override def rotate(torque: Double)
|
||||||
|
|
Loading…
Reference in a new issue