Finished initial gear energy algorithm
This commit is contained in:
parent
ba19eff873
commit
274442fb31
|
@ -20,6 +20,12 @@ trait TMechanicalNode extends INode with IVectorWorld
|
|||
*/
|
||||
def getRadius(side: ForgeDirection, from: TMechanicalNode): Double = 0.5
|
||||
|
||||
/**
|
||||
* The mechanical ratio. The higher the ratio, the more torque but less angular velocity.
|
||||
* @return A double greater than zero
|
||||
*/
|
||||
def ratio = 1D
|
||||
|
||||
/**
|
||||
* Gets the angular velocity of the mechanical device from a specific side
|
||||
*
|
||||
|
@ -51,5 +57,5 @@ trait TMechanicalNode extends INode with IVectorWorld
|
|||
* @param torque - force at an angle
|
||||
* @param angularVelocity - speed of rotation
|
||||
*/
|
||||
def apply(source: AnyRef, torque: Double, angularVelocity: Double)
|
||||
def rotate(source: AnyRef, torque: Double, angularVelocity: Double)
|
||||
}
|
|
@ -2,6 +2,7 @@ package resonantinduction.core.prefab.part.connector
|
|||
|
||||
import java.util
|
||||
|
||||
import codechicken.multipart.TMultiPart
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import resonant.api.ISave
|
||||
|
@ -38,6 +39,12 @@ trait TPartNodeProvider extends PartAbstract with INodeProvider
|
|||
nodes.foreach(_.reconstruct())
|
||||
}
|
||||
|
||||
override def onPartChanged(part: TMultiPart)
|
||||
{
|
||||
if (!world.isRemote)
|
||||
nodes.foreach(_.reconstruct())
|
||||
}
|
||||
|
||||
override def onWorldSeparate()
|
||||
{
|
||||
nodes.foreach(_.deconstruct())
|
||||
|
|
|
@ -8,7 +8,7 @@ import resonant.api.grid.INode;
|
|||
import resonant.api.grid.INodeProvider;
|
||||
|
||||
/**
|
||||
* TNodeProvider Trait.
|
||||
* TNodeProvider multipart Trait.
|
||||
* Keep this in Java for smoother ASM.
|
||||
* @author Calclavia
|
||||
*/
|
||||
|
@ -31,13 +31,11 @@ public class TNodeProvider extends TileMultipart implements INodeProvider
|
|||
if (nodePart == null)
|
||||
{
|
||||
nodePart = partMap(i);
|
||||
System.out.println(nodePart);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (nodePart instanceof INodeProvider)
|
||||
{
|
||||
return ((INodeProvider) nodePart).getNode(nodeType, from);
|
||||
|
|
|
@ -65,7 +65,7 @@ class TileMotor extends TileNode(Material.iron) with TElectric with IRotatable
|
|||
if (receive > 0)
|
||||
{
|
||||
val percentageUsed: Double = receive / power
|
||||
mechNode.apply(this, -mechNode.torque(ForgeDirection.UNKNOWN) * percentageUsed, -mechNode.angularVelocity(ForgeDirection.UNKNOWN) * percentageUsed)
|
||||
mechNode.rotate(this, -mechNode.torque(ForgeDirection.UNKNOWN) * percentageUsed, -mechNode.angularVelocity(ForgeDirection.UNKNOWN) * percentageUsed)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ class TileMotor extends TileNode(Material.iron) with TElectric with IRotatable
|
|||
{setTorque = Math.min(setTorque, maxTorque) * (mechNode.torque(ForgeDirection.UNKNOWN) / currentTorque)}
|
||||
val currentVelo: Double = Math.abs(mechNode.angularVelocity(ForgeDirection.UNKNOWN))
|
||||
if (currentVelo != 0) setAngularVelocity = Math.min(+setAngularVelocity, maxAngularVelocity) * (mechNode.angularVelocity(ForgeDirection.UNKNOWN) / currentVelo)
|
||||
mechNode.apply(this, setTorque - mechNode.torque(ForgeDirection.UNKNOWN), setAngularVelocity - mechNode.angularVelocity(ForgeDirection.UNKNOWN))
|
||||
mechNode.rotate(this, setTorque - mechNode.torque(ForgeDirection.UNKNOWN), setAngularVelocity - mechNode.angularVelocity(ForgeDirection.UNKNOWN))
|
||||
// dcNode.removeEnergy(ForgeDirection.UNKNOWN, Math.abs(setTorque * setAngularVelocity).asInstanceOf[Long], true)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,13 +26,12 @@ object TilePump
|
|||
|
||||
class TilePump extends TileMechanical(Material.iron) with IRotatable with IFluidHandler
|
||||
{
|
||||
var pressureNode: PumpNode = null
|
||||
val pressureNode = new PumpNode(this)
|
||||
|
||||
//Constructor
|
||||
normalRender = false
|
||||
isOpaqueCube = false
|
||||
setTextureName("material_steel")
|
||||
pressureNode = new PumpNode(this)
|
||||
|
||||
override def update()
|
||||
{
|
||||
|
|
|
@ -10,19 +10,27 @@ import net.minecraft.item.ItemStack
|
|||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.util.MovingObjectPosition
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import resonant.api.grid.{INode, INodeProvider}
|
||||
import resonant.engine.ResonantEngine
|
||||
import resonant.lib.transform.vector.VectorWorld
|
||||
import resonantinduction.core.prefab.part.connector.PartAbstract
|
||||
import resonantinduction.core.prefab.part.connector.{PartAbstract, TPartNodeProvider}
|
||||
import resonantinduction.mechanical.mech.grid.MechanicalNode
|
||||
|
||||
/** We assume all the force acting on the gear is 90 degrees.
|
||||
*
|
||||
* @author Calclavia */
|
||||
abstract class PartMechanical extends PartAbstract with JNormalOcclusion with TFacePart with INodeProvider with TCuboidPart
|
||||
abstract class PartMechanical extends PartAbstract with JNormalOcclusion with TFacePart with TPartNodeProvider with TCuboidPart
|
||||
{
|
||||
/** Node that handles resonantinduction.mechanical action of the machine */
|
||||
var mechanicalNode: MechanicalNode = null
|
||||
private var _mechanicalNode: MechanicalNode = null
|
||||
|
||||
def mechanicalNode = _mechanicalNode
|
||||
|
||||
def mechanicalNode_=(mech: MechanicalNode)
|
||||
{
|
||||
_mechanicalNode = mech
|
||||
nodes.add(mechanicalNode)
|
||||
}
|
||||
|
||||
protected var prevAngularVelocity: Double = .0
|
||||
/** Packets */
|
||||
private[mech] var markPacketUpdate: Boolean = false
|
||||
|
@ -38,21 +46,6 @@ abstract class PartMechanical extends PartAbstract with JNormalOcclusion with TF
|
|||
this.tier = itemDamage
|
||||
}
|
||||
|
||||
override def onNeighborChanged()
|
||||
{
|
||||
super.onNeighborChanged()
|
||||
mechanicalNode.reconstruct()
|
||||
}
|
||||
|
||||
override def onPartChanged(part: TMultiPart)
|
||||
{
|
||||
super.onPartChanged(part)
|
||||
if (part.isInstanceOf[INodeProvider])
|
||||
{
|
||||
mechanicalNode.reconstruct
|
||||
}
|
||||
}
|
||||
|
||||
override def update()
|
||||
{
|
||||
if (!world.isRemote)
|
||||
|
@ -104,29 +97,6 @@ abstract class PartMechanical extends PartAbstract with JNormalOcclusion with TF
|
|||
}
|
||||
}
|
||||
|
||||
override def getNode[N <: INode](nodeType: Class[_ <: N], from: ForgeDirection): N =
|
||||
{
|
||||
if (classOf[MechanicalNode].isAssignableFrom(nodeType))
|
||||
return mechanicalNode.asInstanceOf[N]
|
||||
|
||||
return null.asInstanceOf[N]
|
||||
}
|
||||
|
||||
override def onWorldJoin()
|
||||
{
|
||||
mechanicalNode.reconstruct()
|
||||
}
|
||||
|
||||
override def onWorldSeparate()
|
||||
{
|
||||
mechanicalNode.deconstruct()
|
||||
|
||||
if (frame != null)
|
||||
{
|
||||
frame.closeDebugFrame()
|
||||
}
|
||||
}
|
||||
|
||||
/** Packet Code. */
|
||||
def sendRotationPacket()
|
||||
{
|
||||
|
@ -136,12 +106,6 @@ abstract class PartMechanical extends PartAbstract with JNormalOcclusion with TF
|
|||
}
|
||||
}
|
||||
|
||||
/** Packet Code. */
|
||||
override def read(packet: MCDataInput)
|
||||
{
|
||||
read(packet, packet.readUByte)
|
||||
}
|
||||
|
||||
override def read(packet: MCDataInput, packetID: Int)
|
||||
{
|
||||
if (packetID == 0)
|
||||
|
@ -168,15 +132,9 @@ abstract class PartMechanical extends PartAbstract with JNormalOcclusion with TF
|
|||
packet.writeNBTTagCompound(nbt)
|
||||
}
|
||||
|
||||
override def redstoneConductionMap: Int =
|
||||
{
|
||||
return 0
|
||||
}
|
||||
override def redstoneConductionMap: Int = 0
|
||||
|
||||
override def solid(arg0: Int): Boolean =
|
||||
{
|
||||
return true
|
||||
}
|
||||
override def solid(arg0: Int): Boolean = true
|
||||
|
||||
override def load(nbt: NBTTagCompound)
|
||||
{
|
||||
|
|
|
@ -17,26 +17,23 @@ import resonantinduction.mechanical.mech.grid.MechanicalNode
|
|||
*/
|
||||
class GearNode(parent: PartGear) extends MechanicalNode(parent: PartGear)
|
||||
{
|
||||
protected def gear: PartGear = getParent.asInstanceOf[PartGear]
|
||||
|
||||
protected def gear: PartGear =
|
||||
{
|
||||
return this.getParent.asInstanceOf[PartGear]
|
||||
}
|
||||
|
||||
override def update(deltaTime: Double)
|
||||
{
|
||||
super.update(deltaTime)
|
||||
if (!gear.getMultiBlock.isPrimary)
|
||||
/*
|
||||
override def update(deltaTime: Double)
|
||||
{
|
||||
torque = 0
|
||||
angularVelocity = 0
|
||||
}
|
||||
else if (gear.tier == 10)
|
||||
{
|
||||
torque = 100
|
||||
angularVelocity = 100
|
||||
}
|
||||
}
|
||||
super.update(deltaTime)
|
||||
if (!gear.getMultiBlock.isPrimary)
|
||||
{
|
||||
torque = 0
|
||||
angularVelocity = 0
|
||||
}
|
||||
else if (gear.tier == 10)
|
||||
{
|
||||
torque = 100
|
||||
angularVelocity = 100
|
||||
}
|
||||
}*/
|
||||
|
||||
override def getTorqueLoad: Double =
|
||||
{
|
||||
|
@ -58,13 +55,13 @@ class GearNode(parent: PartGear) extends MechanicalNode(parent: PartGear)
|
|||
}
|
||||
}
|
||||
|
||||
override def reconstruct()
|
||||
override def rebuild()
|
||||
{
|
||||
connections.clear
|
||||
if (!gear.getMultiBlock.isPrimary || world == null)
|
||||
{
|
||||
return
|
||||
}
|
||||
|
||||
val tileBehind: TileEntity = new Vector3(gear.tile).add(gear.placementSide).getTileEntity(world)
|
||||
if (tileBehind.isInstanceOf[INodeProvider])
|
||||
{
|
||||
|
@ -211,16 +208,16 @@ class GearNode(parent: PartGear) extends MechanicalNode(parent: PartGear)
|
|||
return false
|
||||
}
|
||||
|
||||
override def getRadius(dir: ForgeDirection, `with`: TMechanicalNode): Double =
|
||||
override def getRadius(dir: ForgeDirection, other: TMechanicalNode): Double =
|
||||
{
|
||||
val deltaPos: Vector3 = new VectorWorld(`with`.asInstanceOf[IVectorWorld]).subtract(toVectorWorld)
|
||||
val caseX: Boolean = gear.placementSide.offsetX != 0 && deltaPos.y == 0 && deltaPos.z == 0
|
||||
val caseY: Boolean = gear.placementSide.offsetY != 0 && deltaPos.x == 0 && deltaPos.z == 0
|
||||
val caseZ: Boolean = gear.placementSide.offsetZ != 0 && deltaPos.x == 0 && deltaPos.y == 0
|
||||
val deltaPos: Vector3 = new VectorWorld(other.asInstanceOf[IVectorWorld]).subtract(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, `with`)
|
||||
}
|
||||
return if (gear.getMultiBlock.isConstructed) 1.5f else super.getRadius(dir, `with`)
|
||||
return super.getRadius(dir, other)
|
||||
|
||||
return if (gear.getMultiBlock.isConstructed) 1.5f else super.getRadius(dir, other)
|
||||
}
|
||||
}
|
|
@ -29,7 +29,7 @@ import resonantinduction.mechanical.mech.PartMechanical
|
|||
class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
|
||||
{
|
||||
var isClockwiseCrank: Boolean = true
|
||||
var manualCrankTime: Int = 0
|
||||
var manualCrankTime = 0D
|
||||
var multiBlockRadius: Int = 1
|
||||
/** Multiblock */
|
||||
var multiBlock: GearMultiBlockHandler = null
|
||||
|
@ -37,27 +37,36 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
|
|||
//Constructor
|
||||
mechanicalNode = new GearNode(this)
|
||||
|
||||
override def update
|
||||
//TODO: Can we not have update ticks here?
|
||||
override def update()
|
||||
{
|
||||
super.update
|
||||
super.update()
|
||||
|
||||
if (!this.world.isRemote)
|
||||
{
|
||||
if (manualCrankTime > 0)
|
||||
{
|
||||
mechanicalNode.apply(this, if (isClockwiseCrank) 15 else -15, if (isClockwiseCrank) 0.025f else -0.025f)
|
||||
manualCrankTime -= 1
|
||||
mechanicalNode.rotate(this, if (isClockwiseCrank) 15 else -15, if (isClockwiseCrank) 0.025f else -0.025f)
|
||||
manualCrankTime -= 0.1
|
||||
}
|
||||
}
|
||||
getMultiBlock.update
|
||||
|
||||
getMultiBlock.update()
|
||||
}
|
||||
|
||||
override def checkClientUpdate
|
||||
override def checkClientUpdate()
|
||||
{
|
||||
if (getMultiBlock.isPrimary) super.checkClientUpdate
|
||||
}
|
||||
|
||||
override def activate(player: EntityPlayer, hit: MovingObjectPosition, itemStack: ItemStack): Boolean =
|
||||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
println(mechanicalNode)
|
||||
println(mechanicalNode.getMechanicalGrid)
|
||||
}
|
||||
|
||||
if (itemStack != null && itemStack.getItem.isInstanceOf[ItemHandCrank])
|
||||
{
|
||||
if (!world.isRemote && ControlKeyModifer.isControlDown(player))
|
||||
|
@ -68,7 +77,7 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
|
|||
}
|
||||
isClockwiseCrank = player.isSneaking
|
||||
//TODO fix;
|
||||
// getMultiBlock.get.manualCrankTime = 20
|
||||
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)
|
||||
player.addExhaustion(0.01f)
|
||||
return true
|
||||
|
|
|
@ -1,18 +1,15 @@
|
|||
package resonantinduction.mechanical.mech.gearshaft
|
||||
|
||||
import java.util.Collection
|
||||
import java.util.HashSet
|
||||
import java.util.Set
|
||||
import resonantinduction.mechanical.MechanicalContent
|
||||
import resonantinduction.mechanical.mech.PartMechanical
|
||||
import java.util.{Collection, HashSet, Set}
|
||||
|
||||
import codechicken.lib.raytracer.IndexedCuboid6
|
||||
import codechicken.lib.vec.{Cuboid6, Vector3}
|
||||
import codechicken.multipart.PartMap
|
||||
import cpw.mods.fml.relauncher.{Side, SideOnly}
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import codechicken.lib.raytracer.IndexedCuboid6
|
||||
import codechicken.lib.vec.Cuboid6
|
||||
import codechicken.lib.vec.Vector3
|
||||
import codechicken.multipart.PartMap
|
||||
import cpw.mods.fml.relauncher.Side
|
||||
import cpw.mods.fml.relauncher.SideOnly
|
||||
import resonantinduction.mechanical.MechanicalContent
|
||||
import resonantinduction.mechanical.mech.PartMechanical
|
||||
|
||||
/**
|
||||
* We assume all the force acting on the gear is 90 degrees.
|
||||
|
@ -21,83 +18,82 @@ import cpw.mods.fml.relauncher.SideOnly
|
|||
*/
|
||||
object PartGearShaft
|
||||
{
|
||||
var sides: Array[IndexedCuboid6] = new Array[IndexedCuboid6](7)
|
||||
var sides: Array[IndexedCuboid6] = new Array[IndexedCuboid6](7)
|
||||
|
||||
//Bound boxes for each side Sides
|
||||
sides(0) = new IndexedCuboid6(0, new Cuboid6(0.36, 0.000, 0.36, 0.64, 0.36, 0.64))
|
||||
sides(1) = new IndexedCuboid6(1, new Cuboid6(0.36, 0.64, 0.36, 0.64, 1.000, 0.64))
|
||||
sides(2) = new IndexedCuboid6(2, new Cuboid6(0.36, 0.36, 0.000, 0.64, 0.64, 0.36))
|
||||
sides(3) = new IndexedCuboid6(3, new Cuboid6(0.36, 0.36, 0.64, 0.64, 0.64, 1.000))
|
||||
sides(4) = new IndexedCuboid6(4, new Cuboid6(0.000, 0.36, 0.36, 0.36, 0.64, 0.64))
|
||||
sides(5) = new IndexedCuboid6(5, new Cuboid6(0.64, 0.36, 0.36, 1.000, 0.64, 0.64))
|
||||
sides(6) = new IndexedCuboid6(6, new Cuboid6(0.36, 0.36, 0.36, 0.64, 0.64, 0.64))
|
||||
//Bound boxes for each side Sides
|
||||
sides(0) = new IndexedCuboid6(0, new Cuboid6(0.36, 0.000, 0.36, 0.64, 0.36, 0.64))
|
||||
sides(1) = new IndexedCuboid6(1, new Cuboid6(0.36, 0.64, 0.36, 0.64, 1.000, 0.64))
|
||||
sides(2) = new IndexedCuboid6(2, new Cuboid6(0.36, 0.36, 0.000, 0.64, 0.64, 0.36))
|
||||
sides(3) = new IndexedCuboid6(3, new Cuboid6(0.36, 0.36, 0.64, 0.64, 0.64, 1.000))
|
||||
sides(4) = new IndexedCuboid6(4, new Cuboid6(0.000, 0.36, 0.36, 0.36, 0.64, 0.64))
|
||||
sides(5) = new IndexedCuboid6(5, new Cuboid6(0.64, 0.36, 0.36, 1.000, 0.64, 0.64))
|
||||
sides(6) = new IndexedCuboid6(6, new Cuboid6(0.36, 0.36, 0.36, 0.64, 0.64, 0.64))
|
||||
}
|
||||
|
||||
class PartGearShaft extends PartMechanical
|
||||
{
|
||||
//Constructor
|
||||
mechanicalNode = new GearShaftNode(this)
|
||||
mechanicalNode = new GearShaftNode(this)
|
||||
|
||||
override def preparePlacement(side: Int, itemDamage: Int)
|
||||
override def preparePlacement(side: Int, itemDamage: Int)
|
||||
{
|
||||
val dir: ForgeDirection = ForgeDirection.getOrientation((side ^ 1).asInstanceOf[Byte])
|
||||
this.placementSide = ForgeDirection.getOrientation(if (!(dir.ordinal % 2 == 0)) dir.ordinal - 1 else dir.ordinal)
|
||||
tier = itemDamage
|
||||
}
|
||||
|
||||
protected def getItem: ItemStack =
|
||||
{
|
||||
return new ItemStack(MechanicalContent.itemGearShaft, 1, tier)
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT) override def renderDynamic(pos: Vector3, frame: Float, pass: Int)
|
||||
{
|
||||
if (pass == 0)
|
||||
{
|
||||
val dir: ForgeDirection = ForgeDirection.getOrientation((side ^ 1).asInstanceOf[Byte])
|
||||
this.placementSide = ForgeDirection.getOrientation(if (!(dir.ordinal % 2 == 0)) dir.ordinal - 1 else dir.ordinal)
|
||||
tier = itemDamage
|
||||
RenderGearShaft.INSTANCE.renderDynamic(this, pos.x, pos.y, pos.z, frame)
|
||||
}
|
||||
}
|
||||
|
||||
protected def getItem: ItemStack =
|
||||
{
|
||||
return new ItemStack(MechanicalContent.itemGearShaft, 1, tier)
|
||||
}
|
||||
/**
|
||||
* Multipart Bounds
|
||||
*/
|
||||
def getSlotMask: Int =
|
||||
{
|
||||
return PartMap.CENTER.mask
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT) override def renderDynamic(pos: Vector3, frame: Float, pass: Int)
|
||||
def getOcclusionBoxes: java.lang.Iterable[Cuboid6] =
|
||||
{
|
||||
return getCollisionBoxes
|
||||
}
|
||||
|
||||
override def getCollisionBoxes: java.lang.Iterable[Cuboid6] =
|
||||
{
|
||||
val collisionBoxes: Set[Cuboid6] = new HashSet[Cuboid6]
|
||||
collisionBoxes.addAll(getSubParts.asInstanceOf[Collection[_ <: Cuboid6]])
|
||||
return collisionBoxes
|
||||
}
|
||||
|
||||
override def getSubParts: java.lang.Iterable[IndexedCuboid6] =
|
||||
{
|
||||
val subParts: Set[IndexedCuboid6] = new HashSet[IndexedCuboid6]
|
||||
val currentSides: Array[IndexedCuboid6] = PartGearShaft.sides
|
||||
if (tile != null)
|
||||
{
|
||||
if (pass == 0)
|
||||
for (side <- ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
if (side == placementSide || side == placementSide.getOpposite)
|
||||
{
|
||||
RenderGearShaft.INSTANCE.renderDynamic(this, pos.x, pos.y, pos.z, frame)
|
||||
subParts.add(currentSides(side.ordinal))
|
||||
}
|
||||
}
|
||||
}
|
||||
subParts.add(currentSides(6))
|
||||
return subParts
|
||||
}
|
||||
|
||||
/**
|
||||
* Multipart Bounds
|
||||
*/
|
||||
def getSlotMask: Int =
|
||||
{
|
||||
return PartMap.CENTER.mask
|
||||
}
|
||||
|
||||
def getOcclusionBoxes: java.lang.Iterable[Cuboid6] =
|
||||
{
|
||||
return getCollisionBoxes
|
||||
}
|
||||
|
||||
override def getCollisionBoxes: java.lang.Iterable[Cuboid6] =
|
||||
{
|
||||
val collisionBoxes: Set[Cuboid6] = new HashSet[Cuboid6]
|
||||
collisionBoxes.addAll(getSubParts.asInstanceOf[Collection[_ <: Cuboid6]])
|
||||
return collisionBoxes
|
||||
}
|
||||
|
||||
override def getSubParts: java.lang.Iterable[IndexedCuboid6] =
|
||||
{
|
||||
val subParts: Set[IndexedCuboid6] = new HashSet[IndexedCuboid6]
|
||||
val currentSides: Array[IndexedCuboid6] = PartGearShaft.sides
|
||||
if (tile != null)
|
||||
{
|
||||
for (side <- ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
if (side == placementSide || side == placementSide.getOpposite)
|
||||
{
|
||||
subParts.add(currentSides(side.ordinal))
|
||||
}
|
||||
}
|
||||
}
|
||||
subParts.add(currentSides(6))
|
||||
return subParts
|
||||
}
|
||||
|
||||
def getBounds: Cuboid6 =
|
||||
{
|
||||
return new Cuboid6(0.375, 0.375, 0.375, 0.625, 0.625, 0.625)
|
||||
}
|
||||
def getBounds: Cuboid6 =
|
||||
{
|
||||
return new Cuboid6(0.375, 0.375, 0.375, 0.625, 0.625, 0.625)
|
||||
}
|
||||
}
|
|
@ -2,7 +2,6 @@ package resonantinduction.mechanical.mech.grid
|
|||
|
||||
import resonant.api.grid.IUpdate
|
||||
import resonant.lib.grid.{GridNode, UpdateTicker}
|
||||
import resonantinduction.core.interfaces.TMechanicalNode
|
||||
|
||||
import scala.collection.convert.wrapAll._
|
||||
import scala.collection.mutable
|
||||
|
@ -28,32 +27,64 @@ class MechanicalGrid extends GridNode[MechanicalNode](classOf[MechanicalNode]) w
|
|||
|
||||
def power = _power
|
||||
|
||||
override def reconstruct()
|
||||
/**
|
||||
* Rebuild the node list starting from the first node and recursively iterating through its connections.
|
||||
*/
|
||||
override def reconstruct(first: MechanicalNode)
|
||||
{
|
||||
//Populate spin map
|
||||
spinMap.clear()
|
||||
populateSpinMap(getNodes.head)
|
||||
|
||||
super.reconstruct(first)
|
||||
UpdateTicker.addUpdater(this)
|
||||
}
|
||||
|
||||
private def populateSpinMap(node: MechanicalNode, inverse: Boolean = false)
|
||||
override protected def populateNode(node: MechanicalNode, prev: MechanicalNode)
|
||||
{
|
||||
spinMap += (node -> inverse)
|
||||
node.connections.foreach(n => populateSpinMap(n, !inverse))
|
||||
super.populateNode(node, prev)
|
||||
spinMap += (node -> (if (prev != null) !spinMap(prev) else false))
|
||||
}
|
||||
|
||||
override def update(deltaTime: Double)
|
||||
{
|
||||
//Find all nodes that are currently producing energy
|
||||
val inputs = getNodes.filter(n => n.bufferTorque != 0 && n.bufferAngle != 0)
|
||||
|
||||
}
|
||||
//Calculate the total input equivalent torque and angular velocity
|
||||
val input = inputs
|
||||
.map(
|
||||
n =>
|
||||
{
|
||||
val inversion = if (spinMap(n)) 1 else -1
|
||||
(n.bufferTorque * n.ratio * inversion, n.bufferAngle / deltaTime / n.ratio * inversion)
|
||||
})
|
||||
.foldLeft((0D, 0D))((b, a) => (a._1 + b._1, a._2 + b._2))
|
||||
|
||||
/**
|
||||
* Propogates the buffer from this specific device
|
||||
*/
|
||||
private def propogate()
|
||||
{
|
||||
if (input._1 != 0 && input._2 != 0)
|
||||
{
|
||||
//Calculate the total resistance of all nodes
|
||||
//TODO: Cache this
|
||||
val resistance = getNodes.view
|
||||
.map(n => (n.getTorqueLoad, n.getAngularVelocityLoad))
|
||||
.foldLeft((0D, 0D))((b, a) => (a._1 + b._1, a._2 + b._2))
|
||||
|
||||
//Calculate the total change in torque and angular velocity
|
||||
val delta = (input._1 - input._1 * resistance._1, input._2 - input._2 * resistance._2)
|
||||
|
||||
//Calculate power
|
||||
_power = delta._1 * delta._2
|
||||
|
||||
//Set torque and angular velocity of all nodes
|
||||
getNodes.foreach(n =>
|
||||
{
|
||||
n.torque = delta._1 * n.ratio
|
||||
n.angularVelocity = delta._2 / n.ratio
|
||||
})
|
||||
|
||||
//Clear buffers
|
||||
inputs.foreach(n =>
|
||||
{
|
||||
n.bufferTorque = 0
|
||||
n.bufferAngle = 0
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
override def continueUpdate = getNodes.size > 0
|
||||
|
|
|
@ -3,6 +3,7 @@ package resonantinduction.mechanical.mech.grid
|
|||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import resonant.api.grid.{INodeProvider, IUpdate}
|
||||
import resonant.lib.grid.GridNode
|
||||
import resonant.lib.grid.node.NodeGrid
|
||||
import resonant.lib.transform.vector.IVectorWorld
|
||||
import resonant.lib.utility.nbt.ISaveObj
|
||||
|
@ -14,7 +15,7 @@ import resonantinduction.core.prefab.node.TMultipartNode
|
|||
*
|
||||
* @author Calclavia, Darkguardsman
|
||||
*/
|
||||
class MechanicalNode(parent: INodeProvider) extends NodeGrid[MechanicalNode](parent) with TMultipartNode[MechanicalNode] with TMechanicalNode with ISaveObj with IVectorWorld with IUpdate
|
||||
class MechanicalNode(parent: INodeProvider) extends NodeGrid[MechanicalNode](parent) with TMultipartNode[MechanicalNode] with TMechanicalNode with ISaveObj with IVectorWorld
|
||||
{
|
||||
/**
|
||||
* Allows the node to share its power with other nodes
|
||||
|
@ -25,7 +26,7 @@ class MechanicalNode(parent: INodeProvider) extends NodeGrid[MechanicalNode](par
|
|||
var angularVelocity: Double = 0
|
||||
|
||||
protected[grid] var bufferTorque = 0D
|
||||
protected[grid] var bufferVelocity = 0D
|
||||
protected[grid] var bufferAngle = 0D
|
||||
|
||||
/**
|
||||
* Current angle of rotation, mainly used for rendering
|
||||
|
@ -52,89 +53,86 @@ class MechanicalNode(parent: INodeProvider) extends NodeGrid[MechanicalNode](par
|
|||
|
||||
override def inverseRotation(side: ForgeDirection): Boolean = false
|
||||
|
||||
override def update(deltaTime: Double)
|
||||
/*
|
||||
override def update(deltaTime: Double)
|
||||
{
|
||||
if (angularVelocity >= 0)
|
||||
{
|
||||
/*
|
||||
if (angularVelocity >= 0)
|
||||
renderAngle += Math.min(angularVelocity, this.maxDeltaAngle) * deltaTime
|
||||
}
|
||||
else
|
||||
{
|
||||
renderAngle += Math.max(angularVelocity, -this.maxDeltaAngle) * deltaTime
|
||||
}
|
||||
if (renderAngle >= Math.PI * 2)
|
||||
{
|
||||
revolve
|
||||
renderAngle = renderAngle % (Math.PI * 2)
|
||||
}
|
||||
if (world != null && !world.isRemote)
|
||||
{
|
||||
val acceleration: Double = this.acceleration * deltaTime
|
||||
if (Math.abs(prevAngularVelocity - angularVelocity) > 0.01f)
|
||||
{
|
||||
renderAngle += Math.min(angularVelocity, this.maxDeltaAngle) * deltaTime
|
||||
prevAngularVelocity = angularVelocity
|
||||
onStateChanged()
|
||||
}
|
||||
else
|
||||
if (Math.abs(prevTorque - torque) > 0.01f)
|
||||
{
|
||||
renderAngle += Math.max(angularVelocity, -this.maxDeltaAngle) * deltaTime
|
||||
prevTorque = torque
|
||||
onStateChanged()
|
||||
}
|
||||
if (renderAngle >= Math.PI * 2)
|
||||
val torqueLoss: Double = Math.min(Math.abs(getTorque), (Math.abs(getTorque * getTorqueLoad) + getTorqueLoad / 10) * deltaTime)
|
||||
torque += (if (torque > 0) -torqueLoss else torqueLoss)
|
||||
val velocityLoss: Double = Math.min(Math.abs(getAngularSpeed), (Math.abs(getAngularSpeed * getAngularVelocityLoad) + getAngularVelocityLoad / 10) * deltaTime)
|
||||
angularVelocity += (if (angularVelocity > 0) -velocityLoss else velocityLoss)
|
||||
if (getEnergy <= 0)
|
||||
{
|
||||
revolve
|
||||
renderAngle = renderAngle % (Math.PI * 2)
|
||||
angularVelocity = ({torque = 0; torque})
|
||||
}
|
||||
if (world != null && !world.isRemote)
|
||||
{
|
||||
val acceleration: Double = this.acceleration * deltaTime
|
||||
if (Math.abs(prevAngularVelocity - angularVelocity) > 0.01f)
|
||||
{
|
||||
prevAngularVelocity = angularVelocity
|
||||
onStateChanged()
|
||||
}
|
||||
if (Math.abs(prevTorque - torque) > 0.01f)
|
||||
{
|
||||
prevTorque = torque
|
||||
onStateChanged()
|
||||
}
|
||||
val torqueLoss: Double = Math.min(Math.abs(getTorque), (Math.abs(getTorque * getTorqueLoad) + getTorqueLoad / 10) * deltaTime)
|
||||
torque += (if (torque > 0) -torqueLoss else torqueLoss)
|
||||
val velocityLoss: Double = Math.min(Math.abs(getAngularSpeed), (Math.abs(getAngularSpeed * getAngularVelocityLoad) + getAngularVelocityLoad / 10) * deltaTime)
|
||||
angularVelocity += (if (angularVelocity > 0) -velocityLoss else velocityLoss)
|
||||
if (getEnergy <= 0)
|
||||
{
|
||||
angularVelocity = ({torque = 0; torque})
|
||||
}
|
||||
power = getEnergy / deltaTime
|
||||
power = getEnergy / deltaTime
|
||||
|
||||
if (sharePower)
|
||||
if (sharePower)
|
||||
{
|
||||
directionMap.foreach
|
||||
{
|
||||
directionMap.foreach
|
||||
case (adjacentMech: MechanicalNode, dir: ForgeDirection) =>
|
||||
{
|
||||
case (adjacentMech: MechanicalNode, dir: ForgeDirection) =>
|
||||
if (adjacentMech != null)
|
||||
{
|
||||
if (adjacentMech != null)
|
||||
val ratio: Double = adjacentMech.getRadius(dir.getOpposite, this) / getRadius(dir, adjacentMech)
|
||||
val inverseRotation: Boolean = this.inverseRotation(dir) && adjacentMech.inverseRotation(dir.getOpposite)
|
||||
val inversion: Int = if (inverseRotation) -1 else 1
|
||||
val targetTorque: Double = inversion * adjacentMech.getTorque / ratio
|
||||
val applyTorque: Double = targetTorque * acceleration
|
||||
if (Math.abs(torque + applyTorque) < Math.abs(targetTorque))
|
||||
{
|
||||
val ratio: Double = adjacentMech.getRadius(dir.getOpposite, this) / getRadius(dir, adjacentMech)
|
||||
val inverseRotation: Boolean = this.inverseRotation(dir) && adjacentMech.inverseRotation(dir.getOpposite)
|
||||
val inversion: Int = if (inverseRotation) -1 else 1
|
||||
val targetTorque: Double = inversion * adjacentMech.getTorque / ratio
|
||||
val applyTorque: Double = targetTorque * acceleration
|
||||
if (Math.abs(torque + applyTorque) < Math.abs(targetTorque))
|
||||
{
|
||||
torque += applyTorque
|
||||
}
|
||||
else if (Math.abs(torque - applyTorque) > Math.abs(targetTorque))
|
||||
{
|
||||
torque -= applyTorque
|
||||
}
|
||||
val targetVelocity: Double = inversion * adjacentMech.getAngularSpeed * ratio
|
||||
val applyVelocity: Double = targetVelocity * acceleration
|
||||
if (Math.abs(angularVelocity + applyVelocity) < Math.abs(targetVelocity))
|
||||
{
|
||||
angularVelocity += applyVelocity
|
||||
}
|
||||
else if (Math.abs(angularVelocity - applyVelocity) > Math.abs(targetVelocity))
|
||||
{
|
||||
angularVelocity -= applyVelocity
|
||||
}
|
||||
torque += applyTorque
|
||||
}
|
||||
else if (Math.abs(torque - applyTorque) > Math.abs(targetTorque))
|
||||
{
|
||||
torque -= applyTorque
|
||||
}
|
||||
val targetVelocity: Double = inversion * adjacentMech.getAngularSpeed * ratio
|
||||
val applyVelocity: Double = targetVelocity * acceleration
|
||||
if (Math.abs(angularVelocity + applyVelocity) < Math.abs(targetVelocity))
|
||||
{
|
||||
angularVelocity += applyVelocity
|
||||
}
|
||||
else if (Math.abs(angularVelocity - applyVelocity) > Math.abs(targetVelocity))
|
||||
{
|
||||
angularVelocity -= applyVelocity
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
prev_angle = renderAngle
|
||||
*/
|
||||
}
|
||||
|
||||
override def canUpdate: Boolean = true
|
||||
prev_angle = renderAngle
|
||||
|
||||
override def continueUpdate: Boolean = true
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Called when one revolution is made.
|
||||
|
@ -143,10 +141,10 @@ class MechanicalNode(parent: INodeProvider) extends NodeGrid[MechanicalNode](par
|
|||
{
|
||||
}
|
||||
|
||||
override def apply(from: AnyRef, torque: Double, angularVelocity: Double)
|
||||
override def rotate(from: AnyRef, torque: Double, angle: Double)
|
||||
{
|
||||
bufferTorque += torque
|
||||
bufferVelocity += angularVelocity
|
||||
bufferAngle += angle
|
||||
}
|
||||
|
||||
private def getTorque: Double = if (angularVelocity != 0) torque else 0
|
||||
|
@ -170,7 +168,7 @@ class MechanicalNode(parent: INodeProvider) extends NodeGrid[MechanicalNode](par
|
|||
|
||||
def getPower: Double =
|
||||
{
|
||||
return getMechanicalGrid.power
|
||||
return 0//getMechanicalGrid.power
|
||||
}
|
||||
|
||||
def load(nbt: NBTTagCompound)
|
||||
|
@ -187,6 +185,8 @@ class MechanicalNode(parent: INodeProvider) extends NodeGrid[MechanicalNode](par
|
|||
|
||||
def getMechanicalGrid: MechanicalGrid = super.getGrid.asInstanceOf[MechanicalGrid]
|
||||
|
||||
override def newGrid: GridNode[MechanicalNode] = new MechanicalGrid
|
||||
|
||||
override def isValidConnection(other: AnyRef): Boolean =
|
||||
{
|
||||
return other.isInstanceOf[MechanicalNode]
|
||||
|
|
Loading…
Reference in a new issue