Fixed graph and mechanical node errors
This commit is contained in:
parent
65c3661f90
commit
16561c9d32
|
@ -91,12 +91,11 @@ class TileMotor extends SpatialTile(Material.iron) with TIO with TElectric with
|
||||||
* Produce torque based on current.
|
* Produce torque based on current.
|
||||||
* T = NBA * I / (2pi)
|
* T = NBA * I / (2pi)
|
||||||
*/
|
*/
|
||||||
val power = electricNode.power
|
|
||||||
val torque = TileMotor.motorConstant * electricNode.current / (2 * Math.PI)
|
val torque = TileMotor.motorConstant * electricNode.current / (2 * Math.PI)
|
||||||
|
|
||||||
//TODO: Check if angular velocity should be generated based on torque
|
//TODO: Check if angular velocity should be generated based on torque
|
||||||
if (torque != 0)
|
if (torque != 0)
|
||||||
mechNode.rotate(torque, power / torque)
|
mechNode.accelerate(torque)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Motors produce emf or counter-emf by Lenz's law based on angular velocity
|
* Motors produce emf or counter-emf by Lenz's law based on angular velocity
|
||||||
|
|
|
@ -28,11 +28,16 @@ class Graph[V](val name: String, val maxPoints: Int = 0)(implicit n: Numeric[V])
|
||||||
|
|
||||||
def head: V = apply(0)
|
def head: V = apply(0)
|
||||||
|
|
||||||
def apply(x: Int): V = if (points.size > x) points.get(x) else default
|
def apply(x: Int = 0): V = if (points.size > x) points.get(x) else default
|
||||||
|
|
||||||
def default: V = n.zero
|
def default: V = n.zero
|
||||||
|
|
||||||
def queue(value: V) = queue = value
|
def getDouble(x: Int = 0) = n.toDouble(this(x))
|
||||||
|
|
||||||
|
def queue(value: V)
|
||||||
|
{
|
||||||
|
queue = value
|
||||||
|
}
|
||||||
|
|
||||||
def doneQueue = this += queue
|
def doneQueue = this += queue
|
||||||
|
|
||||||
|
@ -46,12 +51,13 @@ class Graph[V](val name: String, val maxPoints: Int = 0)(implicit n: Numeric[V])
|
||||||
def load(nbt: NBTTagCompound)
|
def load(nbt: NBTTagCompound)
|
||||||
{
|
{
|
||||||
points.clear()
|
points.clear()
|
||||||
points.addAll(nbt.getArray("DataPoints").toList)
|
val array = nbt.getArray[Double]("DataPoints")
|
||||||
|
points.addAll(array.map(_.asInstanceOf[V]).toList)
|
||||||
}
|
}
|
||||||
|
|
||||||
def save(nbt: NBTTagCompound)
|
def save(nbt: NBTTagCompound)
|
||||||
{
|
{
|
||||||
nbt.setArray("DataPoints", points.toArray)
|
nbt.setArray("DataPoints", points.map(n.toDouble).toArray)
|
||||||
}
|
}
|
||||||
|
|
||||||
def getAverage: Double = if (points.size > 0) n.toDouble(points.foldLeft(n.zero)((b, a) => n.plus(b, a))) / points.size else 0
|
def getAverage: Double = if (points.size > 0) n.toDouble(points.foldLeft(n.zero)((b, a) => n.plus(b, a))) / points.size else 0
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
package edx.electrical.multimeter
|
package edx.electrical.multimeter
|
||||||
|
|
||||||
import net.minecraft.nbt.{NBTTagCompound, NBTTagList}
|
import net.minecraft.nbt.{NBTTagCompound, NBTTagList}
|
||||||
import resonant.api.IUpdate
|
import resonant.lib.grid.core.Grid
|
||||||
import resonant.lib.grid.core.{Grid, UpdateTicker}
|
|
||||||
import resonant.lib.transform.vector.Vector3
|
import resonant.lib.transform.vector.Vector3
|
||||||
import resonant.lib.utility.LanguageUtility
|
import resonant.lib.utility.LanguageUtility
|
||||||
import resonant.lib.utility.science.UnitDisplay
|
import resonant.lib.utility.science.UnitDisplay
|
||||||
|
@ -10,7 +9,7 @@ import resonant.lib.utility.science.UnitDisplay
|
||||||
import scala.collection.convert.wrapAll._
|
import scala.collection.convert.wrapAll._
|
||||||
import scala.collection.mutable.ArrayBuffer
|
import scala.collection.mutable.ArrayBuffer
|
||||||
|
|
||||||
class GridMultimeter extends Grid[PartMultimeter] with IUpdate
|
class GridMultimeter extends Grid[PartMultimeter]
|
||||||
{
|
{
|
||||||
final val displayInformation = new ArrayBuffer[String]
|
final val displayInformation = new ArrayBuffer[String]
|
||||||
/**
|
/**
|
||||||
|
@ -53,7 +52,6 @@ class GridMultimeter extends Grid[PartMultimeter] with IUpdate
|
||||||
|
|
||||||
graphs += energyGraph
|
graphs += energyGraph
|
||||||
graphs += powerGraph
|
graphs += powerGraph
|
||||||
graphs += energyCapacityGraph
|
|
||||||
graphs += voltageGraph
|
graphs += voltageGraph
|
||||||
graphs += torqueGraph
|
graphs += torqueGraph
|
||||||
graphs += angularVelocityGraph
|
graphs += angularVelocityGraph
|
||||||
|
@ -65,15 +63,14 @@ class GridMultimeter extends Grid[PartMultimeter] with IUpdate
|
||||||
{
|
{
|
||||||
val graph = graphs(graphID)
|
val graph = graphs(graphID)
|
||||||
var graphValue: String = ""
|
var graphValue: String = ""
|
||||||
if (graph == energyGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.JOULES, energyGraph.get).toString
|
if (graph == energyGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.JOULES, energyGraph()).toString
|
||||||
if (graph == powerGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.WATT, powerGraph.get).toString
|
if (graph == powerGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.WATT, powerGraph()).toString
|
||||||
if (graph == energyCapacityGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.JOULES, energyCapacityGraph.get).toString
|
if (graph == voltageGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.VOLTAGE, voltageGraph()).toString
|
||||||
if (graph == voltageGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.VOLTAGE, voltageGraph.get).toString
|
if (graph == torqueGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.NEWTON_METER, torqueGraph(), true).toString
|
||||||
if (graph == torqueGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.NEWTON_METER, torqueGraph.get, true).toString
|
if (graph == angularVelocityGraph) graphValue = UnitDisplay.roundDecimals(angularVelocityGraph()) + " rad/s"
|
||||||
if (graph == angularVelocityGraph) graphValue = UnitDisplay.roundDecimals(angularVelocityGraph.get) + " rad/s"
|
if (graph == fluidGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.LITER, fluidGraph()).toString
|
||||||
if (graph == fluidGraph) graphValue = new UnitDisplay(UnitDisplay.Unit.LITER, fluidGraph.get.toInt).toString
|
if (graph == thermalGraph) graphValue = UnitDisplay.roundDecimals(thermalGraph()) + " K"
|
||||||
if (graph == thermalGraph) graphValue = UnitDisplay.roundDecimals(thermalGraph.get.toFloat) + " K"
|
if (graph == pressureGraph) graphValue = UnitDisplay.roundDecimals(pressureGraph()) + " Pa"
|
||||||
if (graph == pressureGraph) graphValue = UnitDisplay.roundDecimals(pressureGraph.get.toInt) + " Pa"
|
|
||||||
return getLocalized(graph) + ": " + graphValue
|
return getLocalized(graph) + ": " + graphValue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,22 +84,11 @@ class GridMultimeter extends Grid[PartMultimeter] with IUpdate
|
||||||
return primaryMultimeter == check
|
return primaryMultimeter == check
|
||||||
}
|
}
|
||||||
|
|
||||||
def update(delta: Double)
|
|
||||||
{
|
|
||||||
if (doUpdate)
|
|
||||||
{
|
|
||||||
graphs.foreach(_.doneQueue())
|
|
||||||
doUpdate = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def markUpdate
|
def markUpdate
|
||||||
{
|
{
|
||||||
doUpdate = true
|
doUpdate = true
|
||||||
}
|
}
|
||||||
|
|
||||||
override def updatePeriod: Int = if (getNodes.size > 0) 50 else 0
|
|
||||||
|
|
||||||
override def isValidNode(node: AnyRef): Boolean =
|
override def isValidNode(node: AnyRef): Boolean =
|
||||||
{
|
{
|
||||||
return node.isInstanceOf[PartMultimeter] && node.asInstanceOf[PartMultimeter].world != null && node.asInstanceOf[PartMultimeter].tile != null
|
return node.isInstanceOf[PartMultimeter] && node.asInstanceOf[PartMultimeter].world != null && node.asInstanceOf[PartMultimeter].tile != null
|
||||||
|
@ -138,7 +124,6 @@ class GridMultimeter extends Grid[PartMultimeter] with IUpdate
|
||||||
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))
|
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)
|
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
|
isEnabled = area == getNodes.size
|
||||||
UpdateTicker.threaded.addUpdater(this)
|
|
||||||
|
|
||||||
getNodes foreach (c =>
|
getNodes foreach (c =>
|
||||||
{
|
{
|
||||||
|
@ -163,9 +148,16 @@ class GridMultimeter extends Grid[PartMultimeter] with IUpdate
|
||||||
|
|
||||||
def save: NBTTagCompound =
|
def save: NBTTagCompound =
|
||||||
{
|
{
|
||||||
val nbt: NBTTagCompound = new NBTTagCompound
|
val nbt = new NBTTagCompound
|
||||||
val data: NBTTagList = new NBTTagList
|
val data = new NBTTagList
|
||||||
graphs.foreach(g => data.appendTag(g.save()))
|
graphs.foreach(
|
||||||
|
g =>
|
||||||
|
{
|
||||||
|
val tag = new NBTTagCompound
|
||||||
|
g.save(tag)
|
||||||
|
data.appendTag(tag)
|
||||||
|
}
|
||||||
|
)
|
||||||
nbt.setTag("graphs", data)
|
nbt.setTag("graphs", data)
|
||||||
return nbt
|
return nbt
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ class PartMultimeter extends PartFace with IRedstonePart with IPacketReceiver wi
|
||||||
if (!world.isRemote)
|
if (!world.isRemote)
|
||||||
{
|
{
|
||||||
if (doDetect) updateDetections
|
if (doDetect) updateDetections
|
||||||
val detectedValue = getGrid.graphs(detectType).getDouble
|
val detectedValue = getGrid.graphs(detectType).getDouble()
|
||||||
var outputRedstone = false
|
var outputRedstone = false
|
||||||
|
|
||||||
detectMode match
|
detectMode match
|
||||||
|
@ -152,7 +152,6 @@ class PartMultimeter extends PartFace with IRedstonePart with IPacketReceiver wi
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
getGrid.energyGraph.queue(Compatibility.getEnergy(tileEntity, receivingSide))
|
getGrid.energyGraph.queue(Compatibility.getEnergy(tileEntity, receivingSide))
|
||||||
getGrid.energyCapacityGraph.queue(Compatibility.getMaxEnergy(tileEntity, receivingSide))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
def getDetectedTile: TileEntity =
|
def getDetectedTile: TileEntity =
|
||||||
|
@ -243,16 +242,16 @@ class PartMultimeter extends PartFace with IRedstonePart with IPacketReceiver wi
|
||||||
updateServer
|
updateServer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def updateServer
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
def toggleDetectionValue
|
def toggleDetectionValue
|
||||||
{
|
{
|
||||||
detectType = ((detectType + 1) % getGrid.graphs.size).asInstanceOf[Byte]
|
detectType = ((detectType + 1) % getGrid.graphs.size).asInstanceOf[Byte]
|
||||||
updateServer
|
updateServer
|
||||||
}
|
}
|
||||||
|
|
||||||
def updateServer
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
def getGrid: GridMultimeter =
|
def getGrid: GridMultimeter =
|
||||||
{
|
{
|
||||||
if (grid == null)
|
if (grid == null)
|
||||||
|
|
|
@ -103,7 +103,7 @@ object RenderMultimeter extends ISimpleItemRenderer
|
||||||
|
|
||||||
for (i <- 0 until part.getGrid.graphs.size)
|
for (i <- 0 until part.getGrid.graphs.size)
|
||||||
{
|
{
|
||||||
if (part.getGrid.graphs(i).head != null && !(part.getGrid.graphs(i).head == part.getGrid.graphs(i).getDefault))
|
if (part.getGrid.graphs(i).head != null /*&& !(part.getGrid.graphs(i).head == part.getGrid.graphs(i))*/ )
|
||||||
{
|
{
|
||||||
information :+= part.getGrid.getDisplay(i)
|
information :+= part.getGrid.getDisplay(i)
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,7 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
|
||||||
if (manualCrankTime > 0)
|
if (manualCrankTime > 0)
|
||||||
{
|
{
|
||||||
//A punch has around 5000 Newtons
|
//A punch has around 5000 Newtons
|
||||||
mechanicalNode.rotate((if (isClockwiseCrank) 2 else -2) * manualCrankTime, (if (isClockwiseCrank) 0.5 else -0.5) * manualCrankTime)
|
mechanicalNode.accelerate((if (isClockwiseCrank) 2 else -2) * manualCrankTime)
|
||||||
manualCrankTime -= 1
|
manualCrankTime -= 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ class TileWaterTurbine extends TileTurbine
|
||||||
{
|
{
|
||||||
if (powerTicks > 0)
|
if (powerTicks > 0)
|
||||||
{
|
{
|
||||||
getMultiBlock.get.mechanicalNode.rotate(getWaterPower, getWaterPower / 100)
|
getMultiBlock.get.mechanicalNode.accelerate(getWaterPower)
|
||||||
powerTicks -= 1
|
powerTicks -= 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ class TileWaterTurbine extends TileTurbine
|
||||||
powerTicks = 20
|
powerTicks = 20
|
||||||
worldObj.setBlockToAir(xCoord, yCoord + 1, zCoord)
|
worldObj.setBlockToAir(xCoord, yCoord + 1, zCoord)
|
||||||
worldObj.setBlock(xCoord, yCoord - 1, zCoord, Blocks.flowing_water)
|
worldObj.setBlock(xCoord, yCoord - 1, zCoord, Blocks.flowing_water)
|
||||||
getMultiBlock.get.mechanicalNode.rotate(10000, 10)
|
getMultiBlock.get.mechanicalNode.accelerate(10000)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,12 +98,12 @@ class TileWaterTurbine extends TileTurbine
|
||||||
|
|
||||||
if (getDirection.offsetX != 0)
|
if (getDirection.offsetX != 0)
|
||||||
{
|
{
|
||||||
getMultiBlock.get.mechanicalNode.rotate(if (invert) -1 else 1 * Math.abs(getWaterPower * vector.z * (7 - metadata) / 7f), 10)
|
getMultiBlock.get.mechanicalNode.accelerate(if (invert) -1 else 1 * Math.abs(getWaterPower * vector.z * (7 - metadata) / 7f))
|
||||||
powerTicks = 20
|
powerTicks = 20
|
||||||
}
|
}
|
||||||
if (getDirection.offsetZ != 0)
|
if (getDirection.offsetZ != 0)
|
||||||
{
|
{
|
||||||
getMultiBlock.get.mechanicalNode.rotate(if (invert) -1 else 1 * Math.abs(getWaterPower * vector.x * (7 - metadata) / 7f), 10)
|
getMultiBlock.get.mechanicalNode.accelerate(if (invert) -1 else 1 * Math.abs(getWaterPower * vector.x * (7 - metadata) / 7f))
|
||||||
powerTicks = 20
|
powerTicks = 20
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,12 +77,12 @@ class TileWindTurbine extends TileTurbine with IBoilHandler
|
||||||
computePower()
|
computePower()
|
||||||
|
|
||||||
windPower = MathUtility.lerp(windPower, nextWindPower, ticks % 20 / 20d)
|
windPower = MathUtility.lerp(windPower, nextWindPower, ticks % 20 / 20d)
|
||||||
getMultiBlock.get.mechanicalNode.rotate(windPower * multiBlockRadius / 20, windPower / multiBlockRadius / 20)
|
getMultiBlock.get.mechanicalNode.accelerate(windPower * multiBlockRadius / 20)
|
||||||
}
|
}
|
||||||
|
|
||||||
//Generate from steam
|
//Generate from steam
|
||||||
val steamPower = if (gasTank.getFluid != null) gasTank.drain(gasTank.getFluidAmount, true).amount else 0 * 1000 * Settings.steamMultiplier
|
val steamPower = if (gasTank.getFluid != null) gasTank.drain(gasTank.getFluidAmount, true).amount else 0 * 1000 * Settings.steamMultiplier
|
||||||
getMultiBlock.get.mechanicalNode.rotate(steamPower * multiBlockRadius / 20, steamPower / multiBlockRadius / 20)
|
getMultiBlock.get.mechanicalNode.accelerate(steamPower * multiBlockRadius / 20)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue