More work on the large gear

This commit is contained in:
Calclavia 2014-11-13 23:04:21 +08:00
parent 109b2c89c7
commit 6ba88e0a8d
10 changed files with 72 additions and 101 deletions

View file

@ -1,6 +1,5 @@
package resonantinduction.core.interfaces
import net.minecraftforge.common.util.ForgeDirection
import resonant.api.grid.INode
import resonant.lib.transform.vector.IVectorWorld
@ -25,6 +24,18 @@ trait TMechanicalNode extends INode with IVectorWorld
*/
def torque: Double
/**
* The mechanical load
* @return Torque in Newton meters per second
*/
def getLoad = 10D
/**
* Moment of inertia = m * r * r
* Where "m" is the mass and "r" is the radius of the object.
*/
def momentOfInertia = 2 * 0.5 * 0.5
/**
* Does the direction flip on this side for rotation
*

View file

@ -26,7 +26,7 @@ class NodeFluidPressure(parent: INodeProvider, volume: Int = FluidContainerRegis
override def reconstruct()
{
super.reconstruct()
UpdateTicker.addUpdater(this)
UpdateTicker.threaded.addUpdater(this)
}
def update(deltaTime: Double)

View file

@ -129,7 +129,7 @@ class MultimeterGrid extends Grid[PartMultimeter](classOf[PartMultimeter]) with
size = new Vector3(Math.abs(upperBound.x) + Math.abs(lowerBound.x), Math.abs(upperBound.y) + Math.abs(lowerBound.y), Math.abs(upperBound.z) + Math.abs(lowerBound.z))
val area: Double = (if (size.x != 0) size.x else 1) * (if (size.y != 0) size.y else 1) * (if (size.z != 0) size.z else 1)
isEnabled = area == getNodes.size
UpdateTicker.addUpdater(this)
UpdateTicker.threaded.addUpdater(this)
getNodes foreach (c =>
{

View file

@ -347,7 +347,7 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
{
override def reconstruct()
{
UpdateTicker.addUpdater(this)
UpdateTicker.threaded.addUpdater(this)
if (!world.isRemote)
{

View file

@ -2,11 +2,9 @@ package resonantinduction.mechanical.mech
import codechicken.lib.data.{MCDataInput, MCDataOutput}
import codechicken.multipart._
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.util.MovingObjectPosition
import net.minecraftforge.common.util.ForgeDirection
import resonant.lib.grid.UpdateTicker
import resonant.lib.transform.vector.VectorWorld
import resonantinduction.core.prefab.part.connector.{PartAbstract, TPartNodeProvider}
import resonantinduction.mechanical.mech.grid.NodeMechanical
@ -19,14 +17,12 @@ abstract class PartMechanical extends PartAbstract with JNormalOcclusion with TF
/** Node that handles resonantinduction.mechanical action of the machine */
private var _mechanicalNode: NodeMechanical = null
protected var markVelocityUpdate = false
def mechanicalNode = _mechanicalNode
def mechanicalNode_=(mech: NodeMechanical)
{
_mechanicalNode = mech
mechanicalNode.onVelocityChanged = () => markVelocityUpdate = true
mechanicalNode.onVelocityChanged = () => UpdateTicker.world.enqueue(() => sendPacket(1))
nodes.add(mechanicalNode)
}
@ -36,17 +32,6 @@ abstract class PartMechanical extends PartAbstract with JNormalOcclusion with TF
/** The tier of this mechanical part */
var tier = 0
override def update()
{
super.update()
if (markVelocityUpdate)
{
sendPacket(1)
markVelocityUpdate = false
}
}
def preparePlacement(side: Int, itemDamage: Int)
{
this.placementSide = ForgeDirection.getOrientation((side).asInstanceOf[Byte])

View file

@ -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.{IVectorWorld, Vector3, VectorWorld}
import resonant.lib.transform.vector.Vector3
import resonant.lib.wrapper.ForgeDirectionWrapper._
import resonantinduction.core.interfaces.TMechanicalNode
import resonantinduction.mechanical.mech.gearshaft.{GearShaftNode, PartGearShaft}
@ -49,7 +49,7 @@ class NodeGear(parent: PartGear) extends NodeMechanical(parent: PartGear)
return
}
val tileBehind: TileEntity = new Vector3(gear.tile).add(gear.placementSide).getTileEntity(world)
val tileBehind = new Vector3(gear.tile).add(gear.placementSide).getTileEntity(world)
if (tileBehind.isInstanceOf[INodeProvider])
{
val instance: NodeMechanical = (tileBehind.asInstanceOf[INodeProvider]).getNode(classOf[NodeMechanical], gear.placementSide.getOpposite)
@ -75,21 +75,23 @@ class NodeGear(parent: PartGear) extends NodeMechanical(parent: PartGear)
}
}
}
var displaceCheck: Int = 1
if (gear.getMultiBlock.isPrimary && gear.getMultiBlock.isConstructed)
{
displaceCheck = 2
}
//TODO: Change this to the radius of the gear
val checkDisplacement = if (gear.getMultiBlock.isPrimary && gear.getMultiBlock.isConstructed) 2 else 1
//Check the sides of the gear for any other gear connections
for (i <- 0 until 4)
{
val checkDir: ForgeDirection = ForgeDirection.getOrientation(Rotation.rotateSide(gear.placementSide.ordinal, i))
val checkTile: TileEntity = new Vector3(gear.tile).add(checkDir).getTileEntity(world)
if (!directionMap.containsValue(checkDir) && checkTile.isInstanceOf[INodeProvider])
val toDir = ForgeDirection.getOrientation(Rotation.rotateSide(gear.placementSide.ordinal, i))
val checkTile = (new Vector3(gear.tile) + (new Vector3(toDir) * checkDisplacement)).getTileEntity(world)
if (!directionMap.containsValue(toDir) && checkTile.isInstanceOf[INodeProvider])
{
val instance: NodeMechanical = (checkTile.asInstanceOf[INodeProvider]).getNode(classOf[NodeMechanical], gear.placementSide)
if (instance != null && instance != this && instance.canConnect(this, checkDir.getOpposite) && !(instance.getParent.isInstanceOf[PartGearShaft]))
val instance = checkTile.asInstanceOf[INodeProvider].getNode(classOf[NodeMechanical], gear.placementSide)
if (instance != null && instance != this && instance.canConnect(this, toDir.getOpposite) && !instance.isInstanceOf[GearShaftNode])
{
connect(instance, checkDir)
connect(instance, toDir)
}
}
}
@ -102,35 +104,38 @@ class NodeGear(parent: PartGear) extends NodeMechanical(parent: PartGear)
* @param other - The source of the connection.
* @return True is so.
*/
override def canConnect[B](other: B, from: ForgeDirection): Boolean =
override def canConnect[B <: NodeMechanical](other: B, from: ForgeDirection): Boolean =
{
if (!gear.getMultiBlock.isPrimary)
{
return false
}
if (other.isInstanceOf[NodeMechanical])
{
val parent: INodeProvider = other.asInstanceOf[NodeMechanical].getParent
val otherParent = other.getParent
if (from == gear.placementSide.getOpposite)
{
if (parent.isInstanceOf[PartGear] || parent.isInstanceOf[PartGearShaft])
//This object is coming from the front of the gear
if (otherParent.isInstanceOf[PartGear] || otherParent.isInstanceOf[PartGearShaft])
{
if (parent.isInstanceOf[PartGearShaft])
if (otherParent.isInstanceOf[PartGearShaft])
{
//We are connecting to a shaft.
val shaft = parent.asInstanceOf[PartGearShaft]
val shaft = otherParent.asInstanceOf[PartGearShaft]
//Check if the shaft is directing connected to the center of the gear (multiblock cases) and also its direction to make sure the shaft is facing the gear itself
return /*shaft.tile.partMap(from.getOpposite.ordinal) != gear && */ Math.abs(shaft.placementSide.offsetX) == Math.abs(gear.placementSide.offsetX) && Math.abs(shaft.placementSide.offsetY) == Math.abs(gear.placementSide.offsetY) && Math.abs(shaft.placementSide.offsetZ) == Math.abs(gear.placementSide.offsetZ)
}
else if (parent.isInstanceOf[PartGear])
else if (otherParent.isInstanceOf[PartGear])
{
if ((parent.asInstanceOf[PartGear]).tile == gear.tile && !gear.getMultiBlock.isConstructed)
if ((otherParent.asInstanceOf[PartGear]).tile == gear.tile && !gear.getMultiBlock.isConstructed)
{
return true
}
if ((parent.asInstanceOf[PartGear]).placementSide ne gear.placementSide)
if ((otherParent.asInstanceOf[PartGear]).placementSide != gear.placementSide)
{
val part: TMultiPart = gear.tile.partMap((parent.asInstanceOf[PartGear]).placementSide.ordinal)
val part = gear.tile.partMap((otherParent.asInstanceOf[PartGear]).placementSide.ordinal)
if (part.isInstanceOf[PartGear])
{
val sourceGear: PartGear = part.asInstanceOf[PartGear]
@ -143,11 +148,11 @@ class NodeGear(parent: PartGear) extends NodeMechanical(parent: PartGear)
{
if (gear.getMultiBlock.isConstructed)
{
val checkPart: TMultiPart = (parent.asInstanceOf[PartGear]).tile.partMap(gear.placementSide.ordinal)
val checkPart: TMultiPart = (otherParent.asInstanceOf[PartGear]).tile.partMap(gear.placementSide.ordinal)
if (checkPart.isInstanceOf[PartGear])
{
val requiredDirection: ForgeDirection = (checkPart.asInstanceOf[PartGear]).getPosition.subtract(toVectorWorld).toForgeDirection
return (checkPart.asInstanceOf[PartGear]).isCenterMultiBlock && (parent.asInstanceOf[PartGear]).placementSide == requiredDirection
return (checkPart.asInstanceOf[PartGear]).isCenterMultiBlock && (otherParent.asInstanceOf[PartGear]).placementSide == requiredDirection
}
}
}
@ -157,12 +162,13 @@ class NodeGear(parent: PartGear) extends NodeMechanical(parent: PartGear)
val sourceTile: TileEntity = toVectorWorld.add(from.getOpposite).getTileEntity(world)
if (sourceTile.isInstanceOf[INodeProvider])
{
val sourceInstance: NodeMechanical = (sourceTile.asInstanceOf[INodeProvider]).getNode(classOf[NodeMechanical], from)
val sourceInstance = sourceTile.asInstanceOf[INodeProvider].getNode(classOf[NodeMechanical], from)
return sourceInstance == other
}
}
else if (from == gear.placementSide)
{
//This object is from the back of the gear
val sourceTile: TileEntity = toVectorWorld.add(from).getTileEntity(world)
if (sourceTile.isInstanceOf[INodeProvider])
{
@ -172,15 +178,18 @@ class NodeGear(parent: PartGear) extends NodeMechanical(parent: PartGear)
}
else
{
val destinationTile: TileEntity = other.asInstanceOf[NodeMechanical].toVectorWorld.add(from.getOpposite).getTileEntity(world)
if (destinationTile.isInstanceOf[INodeProvider] && destinationTile.isInstanceOf[TileMultipart])
//This object is from the sides of the gear
val otherTile = other.asInstanceOf[NodeMechanical].toVectorWorld.add(from.getOpposite).getTileEntity
if (otherTile.isInstanceOf[INodeProvider] && otherTile.isInstanceOf[TileMultipart])
{
val destinationPart: TMultiPart = destinationTile.asInstanceOf[TileMultipart].partMap(gear.placementSide.ordinal)
if (destinationPart.isInstanceOf[PartGear])
val otherPart = otherTile.asInstanceOf[TileMultipart].partMap(gear.placementSide.ordinal)
if (otherPart.isInstanceOf[PartGear])
{
if (gear ne destinationPart)
if (gear != otherPart)
{
return destinationPart.asInstanceOf[PartGear].isCenterMultiBlock
return otherPart.asInstanceOf[PartGear].isCenterMultiBlock
}
else
{
@ -199,7 +208,7 @@ class NodeGear(parent: PartGear) extends NodeMechanical(parent: PartGear)
override def inverseRotation(other: TMechanicalNode): Boolean = !other.isInstanceOf[GearShaftNode] || (other.isInstanceOf[GearShaftNode] && parent.placementSide.offset < Vector3.zero)
override def momentOfInertia = if (gear.getMultiBlock.isConstructed) 1.5f else super.momentOfInertia
override def momentOfInertia = if (gear.getMultiBlock.isConstructed) 1.5 * 1.5 else super.momentOfInertia
/*
override def getRadius(dir: ForgeDirection, other: TMechanicalNode): Double =

View file

@ -13,8 +13,8 @@ import net.minecraft.util.MovingObjectPosition
import net.minecraft.world.World
import net.minecraftforge.common.util.ForgeDirection
import resonant.api.grid.INode
import resonant.lib.grid.UpdateTicker
import resonant.lib.multiblock.reference.IMultiBlockStructure
import resonant.lib.transform.vector.VectorWorld
import resonant.lib.utility.WrenchUtility
import resonantinduction.core.Reference
import resonantinduction.core.prefab.part.CuboidShapes
@ -39,12 +39,10 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
mechanicalNode.onVelocityChanged = () =>
{
if (getMultiBlock.isPrimary)
markVelocityUpdate = true
UpdateTicker.world.enqueue(() => if (world != null) sendPacket(1))
if(mechanicalNode.angularVelocity == 0)
{
//mark
}
if (mechanicalNode.angularVelocity == 0)
UpdateTicker.world.enqueue(() => if (world != null) sendPacket(2))
}
mechanicalNode.onGridReconstruct = () => if (world != null && !world.isRemote) sendPacket(2)
@ -59,7 +57,7 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
if (manualCrankTime > 0)
{
//A punch his around 5000 Newtons
mechanicalNode.rotate((if (isClockwiseCrank) 3 else -3) * manualCrankTime)
mechanicalNode.rotate((if (isClockwiseCrank) 2 else -2) * manualCrankTime)
manualCrankTime -= 1
}
}
@ -104,30 +102,18 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
getMultiBlock.deconstruct()
}
/** Is this gear block the one in the center-edge of the multiblock that can interact with other
* gears?
*
* @return*/
/**
* Is this gear block the one in the center-edge of the multiblock that can interact with other gears?
* @return Returning true implies that this gear is able to connect to other ones side-by-side.
*/
def isCenterMultiBlock: Boolean =
{
if (!getMultiBlock.isConstructed)
{
return true
}
val primaryPos: VectorWorld = getMultiBlock.getPrimary.getPosition
if (primaryPos.xi == x && placementSide.offsetX == 0)
{
return true
}
if (primaryPos.yi == y && placementSide.offsetY == 0)
{
return true
}
if (primaryPos.zi == z && placementSide.offsetZ == 0)
{
return true
}
return false
val primaryPos = getMultiBlock.getPrimary.getPosition
return (primaryPos.xi == x && placementSide.offsetX == 0) || (primaryPos.yi == y && placementSide.offsetY == 0) || (primaryPos.zi == z && placementSide.offsetZ == 0)
}
protected def getItem: ItemStack =

View file

@ -27,7 +27,7 @@ class MechanicalGrid extends GridNode[NodeMechanical](classOf[NodeMechanical]) w
override def reconstruct(first: NodeMechanical)
{
super.reconstruct(first)
UpdateTicker.addUpdater(this)
UpdateTicker.threaded.addUpdater(this)
load = getNodes.map(n => n.getLoad).foldLeft(0D)(_ + _)
}
@ -73,7 +73,7 @@ class MechanicalGrid extends GridNode[NodeMechanical](classOf[NodeMechanical]) w
if (Math.abs(n.torque - prevTorque) >= 0.1)
n.onTorqueChanged()
if (Math.abs(n.angularVelocity - prevAngularVelocity) >= 0.001)
if (Math.abs(n.angularVelocity - prevAngularVelocity) >= 0.01)
n.onVelocityChanged()
//Clear buffers

View file

@ -1,6 +1,5 @@
package resonantinduction.mechanical.mech.grid
import net.minecraftforge.common.util.ForgeDirection
import resonant.api.grid.INodeProvider
import resonant.lib.grid.GridNode
import resonant.lib.grid.node.NodeGrid
@ -25,11 +24,6 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par
*/
protected[grid] var bufferTorque = 0D
/**
* The mechanical load
*/
var load = 10D
/**
* Angle calculations
*/
@ -61,20 +55,6 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par
return prevAngle
}
@deprecated
protected def revolve()
{
}
//Moment of inertia = m * r ^ 2
def momentOfInertia = 1d
/**
* The mechanical load
* @return Torque in Newton meters per second
*/
def getLoad = load
override def rotate(torque: Double)
{

View file

@ -13,7 +13,7 @@ class NodeMechanicalPiston(parent: TileMechanicalPiston) extends NodeMechanical(
return dir ne (getParent.asInstanceOf[TileMechanicalPiston]).getDirection
}
protected override def revolve
protected def revolve
{
getParent.asInstanceOf[TileMechanicalPiston].markRevolve = true
}