MechanicalGrid now triggers onTorqueChanged() and onVelocityChanged()
This commit is contained in:
parent
f039d282e1
commit
b9e53b59e8
5 changed files with 36 additions and 134 deletions
|
@ -1,17 +1,10 @@
|
|||
package resonantinduction.mechanical.mech
|
||||
|
||||
import java.util.{ArrayList, List}
|
||||
|
||||
import codechicken.lib.data.{MCDataInput, MCDataOutput}
|
||||
import codechicken.multipart._
|
||||
import net.minecraft.entity.player.EntityPlayer
|
||||
import net.minecraft.init.Items
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraft.util.MovingObjectPosition
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import resonant.engine.ResonantEngine
|
||||
import resonant.lib.transform.vector.VectorWorld
|
||||
import resonant.lib.transform.vector.{Vector3, VectorWorld}
|
||||
import resonantinduction.core.prefab.part.connector.{PartAbstract, TPartNodeProvider}
|
||||
import resonantinduction.mechanical.mech.grid.MechanicalNode
|
||||
|
||||
|
@ -28,17 +21,15 @@ abstract class PartMechanical extends PartAbstract with JNormalOcclusion with TF
|
|||
def mechanicalNode_=(mech: MechanicalNode)
|
||||
{
|
||||
_mechanicalNode = mech
|
||||
mechanicalNode.onVelocityChanged = () => sendVelocityPacket()
|
||||
nodes.add(mechanicalNode)
|
||||
}
|
||||
|
||||
protected var prevAngularVelocity: Double = .0
|
||||
/** Packets */
|
||||
private[mech] var markPacketUpdate: Boolean = false
|
||||
/** Simple debug external GUI */
|
||||
private[mech] var frame: DebugFrameMechanical = null
|
||||
/** Side of the block this is placed on */
|
||||
var placementSide: ForgeDirection = ForgeDirection.UNKNOWN
|
||||
var tier: Int = 0
|
||||
|
||||
/** The tier of this mechanical part */
|
||||
var tier = 0
|
||||
|
||||
def preparePlacement(side: Int, itemDamage: Int)
|
||||
{
|
||||
|
@ -46,59 +37,8 @@ abstract class PartMechanical extends PartAbstract with JNormalOcclusion with TF
|
|||
this.tier = itemDamage
|
||||
}
|
||||
|
||||
override def update()
|
||||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
checkClientUpdate()
|
||||
}
|
||||
|
||||
if (frame != null)
|
||||
{
|
||||
frame.update
|
||||
}
|
||||
|
||||
super.update()
|
||||
}
|
||||
|
||||
override def activate(player: EntityPlayer, hit: MovingObjectPosition, itemStack: ItemStack): Boolean =
|
||||
{
|
||||
if (ResonantEngine.runningAsDev)
|
||||
{
|
||||
if (itemStack != null && !world.isRemote)
|
||||
{
|
||||
if (itemStack.getItem eq Items.stick)
|
||||
{
|
||||
if (ControlKeyModifer.isControlDown(player))
|
||||
{
|
||||
if (frame == null)
|
||||
{
|
||||
frame = new DebugFrameMechanical(this)
|
||||
frame.showDebugFrame
|
||||
}
|
||||
else
|
||||
{
|
||||
frame.closeDebugFrame
|
||||
frame = null
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return super.activate(player, hit, itemStack)
|
||||
}
|
||||
|
||||
def checkClientUpdate()
|
||||
{
|
||||
if (Math.abs(prevAngularVelocity - mechanicalNode.angularVelocity) >= 0.1)
|
||||
{
|
||||
prevAngularVelocity = mechanicalNode.angularVelocity
|
||||
sendRotationPacket
|
||||
}
|
||||
}
|
||||
|
||||
/** Packet Code. */
|
||||
def sendRotationPacket()
|
||||
def sendVelocityPacket()
|
||||
{
|
||||
if (world != null && !world.isRemote)
|
||||
{
|
||||
|
@ -148,27 +88,7 @@ abstract class PartMechanical extends PartAbstract with JNormalOcclusion with TF
|
|||
nbt.setByte("tier", tier.asInstanceOf[Byte])
|
||||
}
|
||||
|
||||
protected def getItem: ItemStack
|
||||
def getPosition: VectorWorld = new VectorWorld(world, x, y, z)
|
||||
|
||||
override def getDrops: java.lang.Iterable[ItemStack] =
|
||||
{
|
||||
val drops: List[ItemStack] = new ArrayList[ItemStack]
|
||||
drops.add(getItem)
|
||||
return drops
|
||||
}
|
||||
|
||||
override def pickItem(hit: MovingObjectPosition): ItemStack =
|
||||
{
|
||||
return getItem
|
||||
}
|
||||
|
||||
def getPosition: VectorWorld =
|
||||
{
|
||||
return new VectorWorld(world, x, y, z)
|
||||
}
|
||||
|
||||
override def toString: String =
|
||||
{
|
||||
return "[" + getClass.getSimpleName + "]" + x + "x " + y + "y " + z + "z " + getSlotMask + "s "
|
||||
}
|
||||
override def toString: String = "[" + getClass.getSimpleName + "]" + x + "x " + y + "y " + z + "z " + getSlotMask + "s "
|
||||
}
|
|
@ -36,6 +36,7 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
|
|||
|
||||
//Constructor
|
||||
mechanicalNode = new GearNode(this)
|
||||
mechanicalNode.onVelocityChanged = () => if (getMultiBlock.isPrimary) sendVelocityPacket()
|
||||
|
||||
//TODO: Can we not have update ticks here?
|
||||
override def update()
|
||||
|
@ -54,11 +55,6 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
|
|||
getMultiBlock.update()
|
||||
}
|
||||
|
||||
override def checkClientUpdate()
|
||||
{
|
||||
if (getMultiBlock.isPrimary) super.checkClientUpdate
|
||||
}
|
||||
|
||||
override def activate(player: EntityPlayer, hit: MovingObjectPosition, itemStack: ItemStack): Boolean =
|
||||
{
|
||||
if (!world.isRemote)
|
||||
|
|
|
@ -2,35 +2,27 @@ package resonantinduction.mechanical.mech.gearshaft
|
|||
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import resonantinduction.mechanical.mech.gear.PartGear
|
||||
import resonant.api.grid.INodeProvider
|
||||
import resonant.lib.transform.vector.Vector3
|
||||
import resonantinduction.mechanical.mech.gear.PartGear
|
||||
import resonantinduction.mechanical.mech.grid.MechanicalNode
|
||||
|
||||
class GearShaftNode(parent: INodeProvider) extends MechanicalNode(parent)
|
||||
class GearShaftNode(parent: PartGearShaft) extends MechanicalNode(parent)
|
||||
{
|
||||
override def getTorqueLoad: Double =
|
||||
{
|
||||
shaft.tier match
|
||||
return shaft.tier match
|
||||
{
|
||||
case 1 =>
|
||||
return 0.02
|
||||
case 2 =>
|
||||
return 0.01
|
||||
case _ =>
|
||||
return 0.03
|
||||
case 0 => 0.03
|
||||
case 1 => 0.02
|
||||
case 2 => 0.01
|
||||
}
|
||||
}
|
||||
|
||||
override def getAngularVelocityLoad: Double =
|
||||
{
|
||||
return 0
|
||||
}
|
||||
override def getAngularVelocityLoad: Double = 0
|
||||
|
||||
override def reconstruct()
|
||||
override def rebuild()
|
||||
{
|
||||
connections.clear
|
||||
|
||||
for (ch <- List(shaft.placementSide, shaft.placementSide.getOpposite))
|
||||
{
|
||||
val checkDir: ForgeDirection = ch
|
||||
|
@ -81,13 +73,10 @@ class GearShaftNode(parent: INodeProvider) extends MechanicalNode(parent)
|
|||
{
|
||||
if (shaft.placementSide.offsetY != 0 || shaft.placementSide.offsetZ != 0)
|
||||
{
|
||||
return dir eq shaft.placementSide.getOpposite
|
||||
return dir == shaft.placementSide.getOpposite
|
||||
}
|
||||
return dir eq shaft.placementSide
|
||||
return dir == shaft.placementSide
|
||||
}
|
||||
|
||||
def shaft: PartGearShaft =
|
||||
{
|
||||
return this.getParent.asInstanceOf[PartGearShaft]
|
||||
}
|
||||
def shaft: PartGearShaft = getParent.asInstanceOf[PartGearShaft]
|
||||
}
|
|
@ -41,31 +41,21 @@ class PartGearShaft extends PartMechanical
|
|||
tier = itemDamage
|
||||
}
|
||||
|
||||
protected def getItem: ItemStack =
|
||||
{
|
||||
return new ItemStack(MechanicalContent.itemGearShaft, 1, tier)
|
||||
}
|
||||
protected def getItem: ItemStack = new ItemStack(MechanicalContent.itemGearShaft, 1, tier)
|
||||
|
||||
@SideOnly(Side.CLIENT) override def renderDynamic(pos: Vector3, frame: Float, pass: Int)
|
||||
@SideOnly(Side.CLIENT)
|
||||
override def renderDynamic(pos: Vector3, frame: Float, pass: Int)
|
||||
{
|
||||
if (pass == 0)
|
||||
{
|
||||
RenderGearShaft.INSTANCE.renderDynamic(this, pos.x, pos.y, pos.z, frame)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Multipart Bounds
|
||||
*/
|
||||
def getSlotMask: Int =
|
||||
{
|
||||
return PartMap.CENTER.mask
|
||||
}
|
||||
def getSlotMask: Int = PartMap.CENTER.mask
|
||||
|
||||
def getOcclusionBoxes: java.lang.Iterable[Cuboid6] =
|
||||
{
|
||||
return getCollisionBoxes
|
||||
}
|
||||
def getOcclusionBoxes: java.lang.Iterable[Cuboid6] = getCollisionBoxes
|
||||
|
||||
override def getCollisionBoxes: java.lang.Iterable[Cuboid6] =
|
||||
{
|
||||
|
@ -92,8 +82,5 @@ class PartGearShaft extends PartMechanical
|
|||
return subParts
|
||||
}
|
||||
|
||||
def getBounds: Cuboid6 =
|
||||
{
|
||||
return new Cuboid6(0.375, 0.375, 0.375, 0.625, 0.625, 0.625)
|
||||
}
|
||||
def getBounds: Cuboid6 = new Cuboid6(0.375, 0.375, 0.375, 0.625, 0.625, 0.625)
|
||||
}
|
|
@ -77,9 +77,19 @@ class MechanicalGrid extends GridNode[MechanicalNode](classOf[MechanicalNode]) w
|
|||
//Set torque and angular velocity of all nodes
|
||||
getNodes.foreach(n =>
|
||||
{
|
||||
val prevTorque = n.torque
|
||||
val prevAngularVelocity = n.angularVelocity
|
||||
|
||||
val inversion = if (spinMap(n)) 1 else -1
|
||||
n.torque = delta._1 * n.ratio * inversion
|
||||
n.angularVelocity = delta._2 / n.ratio * inversion
|
||||
|
||||
if (Math.abs(prevTorque - n.torque) >= 0.1)
|
||||
n.onTorqueChanged()
|
||||
|
||||
if (Math.abs(prevAngularVelocity - n.angularVelocity) >= 0.1)
|
||||
n.onVelocityChanged()
|
||||
|
||||
})
|
||||
|
||||
//Clear buffers
|
||||
|
|
Loading…
Add table
Reference in a new issue