Fixed gears and grinder not rotating the same way
This commit is contained in:
parent
5bc9257ba7
commit
a6f635d704
|
@ -38,10 +38,17 @@ trait TNodeMechanical extends INode with IVectorWorld
|
||||||
/**
|
/**
|
||||||
* Does the direction flip on this side for rotation
|
* Does the direction flip on this side for rotation
|
||||||
*
|
*
|
||||||
* @param other - The other mechanical node
|
* @param prev - The other mechanical node
|
||||||
* @return boolean, true = flipped, false = not
|
* @return boolean, true = flipped, false = not
|
||||||
*/
|
*/
|
||||||
def inverseRotation(other: TNodeMechanical): Boolean = true
|
def inverseRotation(prev: TNodeMechanical): Boolean = true
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does this node flip the next node's rotation?
|
||||||
|
* @param next - The next node
|
||||||
|
* @return True to flip the next node
|
||||||
|
*/
|
||||||
|
def inverseNext(next: TNodeMechanical): Boolean = true
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies rotational force and velocity to this node increasing its current rotation value
|
* Applies rotational force and velocity to this node increasing its current rotation value
|
||||||
|
|
|
@ -232,7 +232,15 @@ class NodeGear(parent: PartGear) extends NodeMechanical(parent: PartGear)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
override def inverseRotation(other: TNodeMechanical): Boolean = !other.isInstanceOf[NodeGearShaft] || (other.isInstanceOf[NodeGearShaft] && parent.placementSide.offset < Vector3.zero)
|
override def inverseRotation(other: TNodeMechanical): Boolean =
|
||||||
|
{
|
||||||
|
if (other.isInstanceOf[NodeGearShaft])
|
||||||
|
{
|
||||||
|
return parent.placementSide.offset < Vector3.zero
|
||||||
|
}
|
||||||
|
|
||||||
|
return !other.isInstanceOf[NodeGearShaft]
|
||||||
|
}
|
||||||
|
|
||||||
override def radius(other: TNodeMechanical): Double =
|
override def radius(other: TNodeMechanical): Double =
|
||||||
{
|
{
|
||||||
|
|
|
@ -76,7 +76,7 @@ class MechanicalGrid extends GridNode[NodeMechanical](classOf[NodeMechanical]) w
|
||||||
//Pass energy to every single node
|
//Pass energy to every single node
|
||||||
val prev = passed(passed.size - 2)
|
val prev = passed(passed.size - 2)
|
||||||
val ratio = curr.radius(prev) / prev.radius(curr)
|
val ratio = curr.radius(prev) / prev.radius(curr)
|
||||||
val invert = if (curr.inverseRotation(prev)) -1 else 1
|
val invert = if (curr.inverseRotation(prev) && prev.inverseNext(curr)) -1 else 1
|
||||||
val addTorque = torque * ratio * invert
|
val addTorque = torque * ratio * invert
|
||||||
val addVel = angularVelocity / ratio * invert
|
val addVel = angularVelocity / ratio * invert
|
||||||
curr.torque += addTorque
|
curr.torque += addTorque
|
||||||
|
|
|
@ -2,6 +2,7 @@ package resonantinduction.mechanical.mech.process.grinder
|
||||||
|
|
||||||
import net.minecraftforge.common.util.ForgeDirection
|
import net.minecraftforge.common.util.ForgeDirection
|
||||||
import resonantinduction.core.interfaces.TNodeMechanical
|
import resonantinduction.core.interfaces.TNodeMechanical
|
||||||
|
import resonantinduction.mechanical.mech.gear.NodeGear
|
||||||
import resonantinduction.mechanical.mech.grid.NodeMechanical
|
import resonantinduction.mechanical.mech.grid.NodeMechanical
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,15 +12,9 @@ class NodeGrinder(parent: TileGrindingWheel) extends NodeMechanical(parent: Tile
|
||||||
{
|
{
|
||||||
override def getLoad = 1000d * angularVelocity
|
override def getLoad = 1000d * angularVelocity
|
||||||
|
|
||||||
override def canConnect[B <: NodeMechanical](other: B, from: ForgeDirection): Boolean =
|
override def canConnect[B <: NodeMechanical](other: B, from: ForgeDirection): Boolean = parent.getDirection == from || parent.getDirection.getOpposite == from
|
||||||
{
|
|
||||||
if (parent.getDirection == ForgeDirection.UP || parent.getDirection == ForgeDirection.DOWN)
|
|
||||||
{
|
|
||||||
return parent.getDirection == from || parent.getDirection.getOpposite == from
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent.getDirection != from && parent.getDirection.getOpposite != from
|
override def inverseRotation(other: TNodeMechanical): Boolean = if (other.isInstanceOf[NodeGear]) (toVector3 - other.asInstanceOf[NodeMechanical].toVector3).toArray.sum < 0 else false
|
||||||
}
|
|
||||||
|
|
||||||
override def inverseRotation(other: TNodeMechanical) = (toVector3 - other.asInstanceOf[NodeMechanical].toVector3).toArray.sum < 0
|
override def inverseNext(other: TNodeMechanical): Boolean = if (other.isInstanceOf[NodeGear]) (toVector3 - other.asInstanceOf[NodeMechanical].toVector3).toArray.sum < 0 else super.inverseNext(other)
|
||||||
}
|
}
|
|
@ -14,12 +14,14 @@ import resonant.content.factory.resources.RecipeType
|
||||||
import resonant.lib.prefab.damage.CustomDamageSource
|
import resonant.lib.prefab.damage.CustomDamageSource
|
||||||
import resonant.lib.render.RenderUtility
|
import resonant.lib.render.RenderUtility
|
||||||
import resonant.lib.transform.region.Cuboid
|
import resonant.lib.transform.region.Cuboid
|
||||||
|
import resonant.lib.transform.rotation.AngleAxis
|
||||||
import resonant.lib.transform.vector.Vector3
|
import resonant.lib.transform.vector.Vector3
|
||||||
import resonant.lib.utility.{MathUtility, Timer}
|
import resonant.lib.utility.Timer
|
||||||
import resonantinduction.core.{Reference, ResonantInduction}
|
import resonantinduction.core.{Reference, ResonantInduction}
|
||||||
import resonantinduction.mechanical.mech.TileMechanical
|
import resonantinduction.mechanical.mech.TileMechanical
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The grinding wheel. This block will face the direction in which it can rotate.
|
||||||
* @author Calclavia
|
* @author Calclavia
|
||||||
*/
|
*/
|
||||||
object TileGrindingWheel
|
object TileGrindingWheel
|
||||||
|
@ -45,6 +47,7 @@ class TileGrindingWheel extends TileMechanical(Material.rock)
|
||||||
isOpaqueCube = false
|
isOpaqueCube = false
|
||||||
normalRender = false
|
normalRender = false
|
||||||
textureName = "material_steel_dark"
|
textureName = "material_steel_dark"
|
||||||
|
rotationMask = 0x3F
|
||||||
|
|
||||||
override def update()
|
override def update()
|
||||||
{
|
{
|
||||||
|
@ -84,15 +87,15 @@ class TileGrindingWheel extends TileMechanical(Material.rock)
|
||||||
|
|
||||||
if (mechanicalNode.angularVelocity != 0)
|
if (mechanicalNode.angularVelocity != 0)
|
||||||
{
|
{
|
||||||
|
//The velocity added should be tangent to the circle
|
||||||
|
val deltaVector = new Vector3(entity) - center
|
||||||
|
val deltaAngle = Math.toDegrees(mechanicalNode.angularVelocity / 20)
|
||||||
var dir = getDirection
|
var dir = getDirection
|
||||||
dir = ForgeDirection.getOrientation(if (dir.ordinal % 2 != 0) dir.ordinal - 1 else dir.ordinal).getOpposite
|
dir = ForgeDirection.getOrientation(if (dir.ordinal() % 2 != 0) dir.ordinal() - 1 else dir.ordinal()).getOpposite
|
||||||
|
val deltaEulerAngle = new AngleAxis(deltaAngle, new Vector3(dir))
|
||||||
val speed = mechanicalNode.angularVelocity / 20
|
val deltaPos = deltaVector.transform(deltaEulerAngle)
|
||||||
val speedX = MathUtility.absCap(dir.offsetX * speed, 1)
|
val velocity = deltaPos / 20
|
||||||
val speedZ = MathUtility.absCap(dir.offsetZ * speed, 1)
|
entity.addVelocity(velocity.x, velocity.y, velocity.z)
|
||||||
val speedY = MathUtility.absCap(dir.offsetY * speed, 1)
|
|
||||||
|
|
||||||
entity.addVelocity(speedX, speedY, speedZ)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,7 +195,15 @@ class TileGrindingWheel extends TileMechanical(Material.rock)
|
||||||
glPushMatrix()
|
glPushMatrix()
|
||||||
glTranslated(pos.x + 0.5, pos.y + 0.5, pos.z + 0.5)
|
glTranslated(pos.x + 0.5, pos.y + 0.5, pos.z + 0.5)
|
||||||
glScalef(0.51f, 0.5f, 0.5f)
|
glScalef(0.51f, 0.5f, 0.5f)
|
||||||
val dir = getDirection
|
|
||||||
|
var dir = getDirection
|
||||||
|
dir = ForgeDirection.getOrientation(if (dir.ordinal() % 2 != 0) dir.ordinal() - 1 else dir.ordinal())
|
||||||
|
|
||||||
|
if (dir.offsetY == 0)
|
||||||
|
glRotated(90, 0, 1, 0)
|
||||||
|
else
|
||||||
|
glRotated(90, 0, 1, 0)
|
||||||
|
|
||||||
RenderUtility.rotateBlockBasedOnDirection(dir)
|
RenderUtility.rotateBlockBasedOnDirection(dir)
|
||||||
glRotated(Math.toDegrees(mechanicalNode.angle), 0, 0, 1)
|
glRotated(Math.toDegrees(mechanicalNode.angle), 0, 0, 1)
|
||||||
RenderUtility.bind(Reference.blockTextureDirectory + "planks_oak.png")
|
RenderUtility.bind(Reference.blockTextureDirectory + "planks_oak.png")
|
||||||
|
|
Loading…
Reference in a new issue