Fixed gears and grinder not rotating the same way
This commit is contained in:
parent
5bc9257ba7
commit
a6f635d704
5 changed files with 44 additions and 23 deletions
|
@ -38,10 +38,17 @@ trait TNodeMechanical extends INode with IVectorWorld
|
|||
/**
|
||||
* 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
|
||||
*/
|
||||
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
|
||||
|
|
|
@ -232,7 +232,15 @@ class NodeGear(parent: PartGear) extends NodeMechanical(parent: PartGear)
|
|||
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 =
|
||||
{
|
||||
|
|
|
@ -76,7 +76,7 @@ class MechanicalGrid extends GridNode[NodeMechanical](classOf[NodeMechanical]) w
|
|||
//Pass energy to every single node
|
||||
val prev = passed(passed.size - 2)
|
||||
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 addVel = angularVelocity / ratio * invert
|
||||
curr.torque += addTorque
|
||||
|
|
|
@ -2,6 +2,7 @@ package resonantinduction.mechanical.mech.process.grinder
|
|||
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import resonantinduction.core.interfaces.TNodeMechanical
|
||||
import resonantinduction.mechanical.mech.gear.NodeGear
|
||||
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 canConnect[B <: NodeMechanical](other: B, from: ForgeDirection): Boolean =
|
||||
{
|
||||
if (parent.getDirection == ForgeDirection.UP || parent.getDirection == ForgeDirection.DOWN)
|
||||
{
|
||||
return parent.getDirection == from || parent.getDirection.getOpposite == from
|
||||
}
|
||||
override def canConnect[B <: NodeMechanical](other: B, from: ForgeDirection): Boolean = 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.render.RenderUtility
|
||||
import resonant.lib.transform.region.Cuboid
|
||||
import resonant.lib.transform.rotation.AngleAxis
|
||||
import resonant.lib.transform.vector.Vector3
|
||||
import resonant.lib.utility.{MathUtility, Timer}
|
||||
import resonant.lib.utility.Timer
|
||||
import resonantinduction.core.{Reference, ResonantInduction}
|
||||
import resonantinduction.mechanical.mech.TileMechanical
|
||||
|
||||
/**
|
||||
* The grinding wheel. This block will face the direction in which it can rotate.
|
||||
* @author Calclavia
|
||||
*/
|
||||
object TileGrindingWheel
|
||||
|
@ -45,6 +47,7 @@ class TileGrindingWheel extends TileMechanical(Material.rock)
|
|||
isOpaqueCube = false
|
||||
normalRender = false
|
||||
textureName = "material_steel_dark"
|
||||
rotationMask = 0x3F
|
||||
|
||||
override def update()
|
||||
{
|
||||
|
@ -84,15 +87,15 @@ class TileGrindingWheel extends TileMechanical(Material.rock)
|
|||
|
||||
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
|
||||
dir = ForgeDirection.getOrientation(if (dir.ordinal % 2 != 0) dir.ordinal - 1 else dir.ordinal).getOpposite
|
||||
|
||||
val speed = mechanicalNode.angularVelocity / 20
|
||||
val speedX = MathUtility.absCap(dir.offsetX * speed, 1)
|
||||
val speedZ = MathUtility.absCap(dir.offsetZ * speed, 1)
|
||||
val speedY = MathUtility.absCap(dir.offsetY * speed, 1)
|
||||
|
||||
entity.addVelocity(speedX, speedY, speedZ)
|
||||
dir = ForgeDirection.getOrientation(if (dir.ordinal() % 2 != 0) dir.ordinal() - 1 else dir.ordinal()).getOpposite
|
||||
val deltaEulerAngle = new AngleAxis(deltaAngle, new Vector3(dir))
|
||||
val deltaPos = deltaVector.transform(deltaEulerAngle)
|
||||
val velocity = deltaPos / 20
|
||||
entity.addVelocity(velocity.x, velocity.y, velocity.z)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -192,7 +195,15 @@ class TileGrindingWheel extends TileMechanical(Material.rock)
|
|||
glPushMatrix()
|
||||
glTranslated(pos.x + 0.5, pos.y + 0.5, pos.z + 0.5)
|
||||
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)
|
||||
glRotated(Math.toDegrees(mechanicalNode.angle), 0, 0, 1)
|
||||
RenderUtility.bind(Reference.blockTextureDirectory + "planks_oak.png")
|
||||
|
|
Loading…
Reference in a new issue