Converted grid class to scala
This commit is contained in:
parent
c52bca4a12
commit
0c58b76ccb
6 changed files with 86 additions and 75 deletions
|
@ -9,10 +9,12 @@ import scala.collection.JavaConversions._
|
|||
/** Basic grid designed to be used for creating a level look for batteries connected together
|
||||
* @author robert(Darkguardsman)
|
||||
*/
|
||||
class GridBattery extends Grid[TileBattery](classOf[TileBattery])
|
||||
class GridBattery extends Grid[TileBattery]
|
||||
{
|
||||
var totalEnergy: Double = 0
|
||||
var totalCapacity: Double = 0
|
||||
var totalEnergy = 0d
|
||||
var totalCapacity = 0d
|
||||
|
||||
nodeClass = classOf[TileBattery]
|
||||
|
||||
/**
|
||||
* Causes the energy shared by all batteries to be distributed out to all linked batteries
|
||||
|
@ -66,13 +68,13 @@ class GridBattery extends Grid[TileBattery](classOf[TileBattery])
|
|||
if (totalEnergy > 0 && amountOfNodes > 0)
|
||||
{
|
||||
var remainingEnergy: Double = totalEnergy
|
||||
val firstNode: TileBattery = this.getFirstNode
|
||||
val firstNode: TileBattery = nodes.head
|
||||
|
||||
for (node <- this.getNodes)
|
||||
{
|
||||
if (node != firstNode && !Arrays.asList(exclusion).contains(node))
|
||||
{
|
||||
val percentage: Double = (node.energy.getEnergyCapacity / totalCapacity)
|
||||
val percentage: Double = node.energy.getEnergyCapacity / totalCapacity
|
||||
val energyForBattery: Double = Math.max(totalEnergy * percentage, 0)
|
||||
node.energy.setEnergy(energyForBattery)
|
||||
remainingEnergy -= energyForBattery
|
||||
|
|
|
@ -73,12 +73,12 @@ class GuiMultimeter(inventoryPlayer: InventoryPlayer, multimeter: PartMultimeter
|
|||
|
||||
protected override def drawGuiContainerForegroundLayer(mouseX: Int, mouseY: Int)
|
||||
{
|
||||
val graphName: String = multimeter.getNetwork.getLocalized(multimeter.getNetwork.graphs(multimeter.graphType))
|
||||
val graphName: String = multimeter.getGrid.getLocalized(multimeter.getGrid.graphs(multimeter.graphType))
|
||||
super.drawGuiContainerForegroundLayer(mouseX, mouseY)
|
||||
val s: String = LanguageUtility.getLocal("item.resonantinduction:multimeter.name")
|
||||
this.fontRendererObj.drawString(s, this.xSize / 2 - this.fontRendererObj.getStringWidth(s) / 2, 6, 4210752)
|
||||
this.fontRendererObj.drawString(EnumColor.INDIGO + "Detection Type", 9, 20, 4210752)
|
||||
this.fontRendererObj.drawString(multimeter.getNetwork.getDisplay(multimeter.detectType), 9, 60, 4210752)
|
||||
this.fontRendererObj.drawString(multimeter.getGrid.getDisplay(multimeter.detectType), 9, 60, 4210752)
|
||||
this.fontRendererObj.drawString(LanguageUtility.getLocal("gui.resonantinduction.multimeter.logic") + " " + EnumColor.RED + LanguageUtility.getLocal("gui.resonantinduction.multimeter." + this.multimeter.getMode.display), 9, 75, 4210752)
|
||||
this.fontRendererObj.drawString(graphName, 95, 115, 4210752)
|
||||
this.textFieldLimit.drawTextBox()
|
||||
|
|
|
@ -11,7 +11,7 @@ import resonant.lib.utility.science.UnitDisplay
|
|||
import scala.collection.convert.wrapAll._
|
||||
import scala.collection.mutable.ArrayBuffer
|
||||
|
||||
class MultimeterGrid extends Grid[PartMultimeter](classOf[PartMultimeter]) with IUpdate
|
||||
class MultimeterGrid extends Grid[PartMultimeter] with IUpdate
|
||||
{
|
||||
final val displayInformation = new ArrayBuffer[String]
|
||||
/**
|
||||
|
@ -51,6 +51,8 @@ class MultimeterGrid extends Grid[PartMultimeter](classOf[PartMultimeter]) with
|
|||
var primaryMultimeter: PartMultimeter = null
|
||||
private var doUpdate: Boolean = false
|
||||
|
||||
nodeClass = classOf[PartMultimeter]
|
||||
|
||||
graphs += energyGraph
|
||||
graphs += powerGraph
|
||||
graphs += energyCapacityGraph
|
||||
|
@ -108,14 +110,30 @@ class MultimeterGrid extends Grid[PartMultimeter](classOf[PartMultimeter]) with
|
|||
return node.isInstanceOf[PartMultimeter] && node.asInstanceOf[PartMultimeter].world != null && node.asInstanceOf[PartMultimeter].tile != null
|
||||
}
|
||||
|
||||
override def reconstruct
|
||||
override def reconstruct()
|
||||
{
|
||||
if (getNodes.size > 0)
|
||||
{
|
||||
primaryMultimeter = null
|
||||
upperBound = null
|
||||
lowerBound = null
|
||||
super.reconstruct
|
||||
|
||||
nodes.foreach(node =>
|
||||
{
|
||||
node.setGrid(this)
|
||||
if (primaryMultimeter == null) primaryMultimeter = node
|
||||
if (upperBound == null)
|
||||
{
|
||||
upperBound = node.getPosition.add(1)
|
||||
}
|
||||
if (lowerBound == null)
|
||||
{
|
||||
lowerBound = node.getPosition
|
||||
}
|
||||
upperBound = upperBound.max(node.getPosition.add(1))
|
||||
lowerBound = lowerBound.min(node.getPosition)
|
||||
})
|
||||
|
||||
center = upperBound.midPoint(lowerBound)
|
||||
upperBound -= center
|
||||
lowerBound -= center
|
||||
|
@ -126,8 +144,8 @@ class MultimeterGrid extends Grid[PartMultimeter](classOf[PartMultimeter]) with
|
|||
|
||||
getNodes foreach (c =>
|
||||
{
|
||||
c.updateDesc
|
||||
c.updateGraph
|
||||
c.updateDesc()
|
||||
c.updateGraph()
|
||||
})
|
||||
|
||||
doUpdate = true
|
||||
|
@ -153,21 +171,4 @@ class MultimeterGrid extends Grid[PartMultimeter](classOf[PartMultimeter]) with
|
|||
nbt.setTag("graphs", data)
|
||||
return nbt
|
||||
}
|
||||
|
||||
protected override def reconstructNode(node: PartMultimeter)
|
||||
{
|
||||
node.setNetwork(this)
|
||||
if (primaryMultimeter == null) primaryMultimeter = node
|
||||
if (upperBound == null)
|
||||
{
|
||||
upperBound = node.getPosition.add(1)
|
||||
}
|
||||
if (lowerBound == null)
|
||||
{
|
||||
lowerBound = node.getPosition
|
||||
}
|
||||
upperBound = upperBound.max(node.getPosition.add(1))
|
||||
lowerBound = lowerBound.min(node.getPosition)
|
||||
}
|
||||
|
||||
}
|
|
@ -45,15 +45,15 @@ class PartMultimeter extends PartFace with IRedstonePart with IPacketReceiver wi
|
|||
var isPrimary: Boolean = false
|
||||
private var detectMode = DetectModes.NONE
|
||||
private var doDetect: Boolean = true
|
||||
private var network: MultimeterGrid = null
|
||||
private var grid: MultimeterGrid = null
|
||||
|
||||
override def preRemove
|
||||
override def preRemove()
|
||||
{
|
||||
if (!world.isRemote)
|
||||
getNetwork.remove(this)
|
||||
getGrid.remove(this)
|
||||
}
|
||||
|
||||
def updateDesc
|
||||
def updateDesc()
|
||||
{
|
||||
writeDesc(getWriteStream)
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ class PartMultimeter extends PartFace with IRedstonePart with IPacketReceiver wi
|
|||
if (!world.isRemote)
|
||||
{
|
||||
if (doDetect) updateDetections
|
||||
val detectedValue = getNetwork.graphs(detectType).getDouble
|
||||
val detectedValue = getGrid.graphs(detectType).getDouble
|
||||
var outputRedstone = false
|
||||
|
||||
detectMode match
|
||||
|
@ -99,7 +99,7 @@ class PartMultimeter extends PartFace with IRedstonePart with IPacketReceiver wi
|
|||
case _ =>
|
||||
}
|
||||
|
||||
getNetwork.markUpdate
|
||||
getGrid.markUpdate
|
||||
if (ticks % 20 == 0)
|
||||
{
|
||||
if (outputRedstone != redstoneOn)
|
||||
|
@ -137,9 +137,9 @@ class PartMultimeter extends PartFace with IRedstonePart with IPacketReceiver wi
|
|||
|
||||
if (instance != null)
|
||||
{
|
||||
getNetwork.torqueGraph.queue(instance.torque)
|
||||
getNetwork.angularVelocityGraph.queue(instance.angularVelocity)
|
||||
getNetwork.powerGraph.queue(instance.torque * instance.angularVelocity)
|
||||
getGrid.torqueGraph.queue(instance.torque)
|
||||
getGrid.angularVelocityGraph.queue(instance.angularVelocity)
|
||||
getGrid.powerGraph.queue(instance.torque * instance.angularVelocity)
|
||||
}
|
||||
}
|
||||
if (tileEntity.isInstanceOf[IFluidHandler])
|
||||
|
@ -148,11 +148,11 @@ class PartMultimeter extends PartFace with IRedstonePart with IPacketReceiver wi
|
|||
|
||||
if (fluidInfo != null)
|
||||
{
|
||||
fluidInfo.filter(info => info != null && info.fluid != null).foreach(info => getNetwork.fluidGraph.queue(info.fluid.amount))
|
||||
fluidInfo.filter(info => info != null && info.fluid != null).foreach(info => getGrid.fluidGraph.queue(info.fluid.amount))
|
||||
}
|
||||
}
|
||||
getNetwork.energyGraph.queue(Compatibility.getEnergy(tileEntity, receivingSide))
|
||||
getNetwork.energyCapacityGraph.queue(Compatibility.getMaxEnergy(tileEntity, receivingSide))
|
||||
getGrid.energyGraph.queue(Compatibility.getEnergy(tileEntity, receivingSide))
|
||||
getGrid.energyCapacityGraph.queue(Compatibility.getMaxEnergy(tileEntity, receivingSide))
|
||||
}
|
||||
|
||||
def getDetectedTile: TileEntity =
|
||||
|
@ -179,17 +179,17 @@ class PartMultimeter extends PartFace with IRedstonePart with IPacketReceiver wi
|
|||
packet.writeByte(detectMode.id)
|
||||
packet.writeByte(detectType)
|
||||
packet.writeByte(graphType)
|
||||
packet.writeNBTTagCompound(getNetwork.center.writeNBT(new NBTTagCompound))
|
||||
packet.writeNBTTagCompound(getNetwork.size.writeNBT(new NBTTagCompound))
|
||||
packet.writeBoolean(getNetwork.isEnabled)
|
||||
packet.writeNBTTagCompound(getGrid.center.writeNBT(new NBTTagCompound))
|
||||
packet.writeNBTTagCompound(getGrid.size.writeNBT(new NBTTagCompound))
|
||||
packet.writeBoolean(getGrid.isEnabled)
|
||||
}
|
||||
case 2 =>
|
||||
{
|
||||
//Graph
|
||||
packet.writeByte(2)
|
||||
isPrimary = getNetwork.isPrimary(this)
|
||||
isPrimary = getGrid.isPrimary(this)
|
||||
packet.writeBoolean(isPrimary)
|
||||
if (isPrimary) packet.writeNBTTagCompound(getNetwork.save)
|
||||
if (isPrimary) packet.writeNBTTagCompound(getGrid.save)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -205,9 +205,9 @@ class PartMultimeter extends PartFace with IRedstonePart with IPacketReceiver wi
|
|||
detectMode = DetectModes(packet.readByte).asInstanceOf[DetectModes.DetectMode]
|
||||
detectType = packet.readByte
|
||||
graphType = packet.readByte
|
||||
getNetwork.center = new Vector3(packet.readNBTTagCompound)
|
||||
getNetwork.size = new Vector3(packet.readNBTTagCompound)
|
||||
getNetwork.isEnabled = packet.readBoolean
|
||||
getGrid.center = new Vector3(packet.readNBTTagCompound)
|
||||
getGrid.size = new Vector3(packet.readNBTTagCompound)
|
||||
getGrid.isEnabled = packet.readBoolean
|
||||
}
|
||||
case 1 =>
|
||||
{
|
||||
|
@ -216,7 +216,7 @@ class PartMultimeter extends PartFace with IRedstonePart with IPacketReceiver wi
|
|||
case 2 =>
|
||||
{
|
||||
isPrimary = packet.readBoolean
|
||||
if (isPrimary) getNetwork.load(packet.readNBTTagCompound)
|
||||
if (isPrimary) getGrid.load(packet.readNBTTagCompound)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -238,14 +238,10 @@ class PartMultimeter extends PartFace with IRedstonePart with IPacketReceiver wi
|
|||
|
||||
def toggleGraphType
|
||||
{
|
||||
graphType = ((graphType + 1) % getNetwork.graphs.size).asInstanceOf[Byte]
|
||||
graphType = ((graphType + 1) % getGrid.graphs.size).asInstanceOf[Byte]
|
||||
updateServer
|
||||
}
|
||||
|
||||
def updateServer
|
||||
{
|
||||
}
|
||||
|
||||
def toggleMode
|
||||
{
|
||||
detectMode = DetectModes((detectMode.id + 1) % DetectModes.values.size).asInstanceOf[DetectModes.DetectMode]
|
||||
|
@ -254,10 +250,14 @@ class PartMultimeter extends PartFace with IRedstonePart with IPacketReceiver wi
|
|||
|
||||
def toggleDetectionValue
|
||||
{
|
||||
detectType = ((detectType + 1) % getNetwork.graphs.size).asInstanceOf[Byte]
|
||||
detectType = ((detectType + 1) % getGrid.graphs.size).asInstanceOf[Byte]
|
||||
updateServer
|
||||
}
|
||||
|
||||
def updateServer
|
||||
{
|
||||
}
|
||||
|
||||
override def load(nbt: NBTTagCompound)
|
||||
{
|
||||
super.load(nbt)
|
||||
|
@ -368,23 +368,23 @@ class PartMultimeter extends PartFace with IRedstonePart with IPacketReceiver wi
|
|||
@SideOnly(Side.CLIENT)
|
||||
override def getRenderBounds: Cuboid6 =
|
||||
{
|
||||
if (isPrimary) return Cuboid6.full.copy.expand(new Vector3(getNetwork.size.x, getNetwork.size.y, getNetwork.size.z))
|
||||
if (isPrimary) return Cuboid6.full.copy.expand(new Vector3(getGrid.size.x, getGrid.size.y, getGrid.size.z))
|
||||
return Cuboid6.full
|
||||
}
|
||||
|
||||
def getNetwork: MultimeterGrid =
|
||||
def getGrid: MultimeterGrid =
|
||||
{
|
||||
if (network == null)
|
||||
if (grid == null)
|
||||
{
|
||||
network = new MultimeterGrid
|
||||
network.add(this)
|
||||
grid = new MultimeterGrid
|
||||
grid.add(this)
|
||||
}
|
||||
return network
|
||||
return grid
|
||||
}
|
||||
|
||||
def setNetwork(network: MultimeterGrid)
|
||||
def setGrid(network: MultimeterGrid)
|
||||
{
|
||||
this.network = network
|
||||
grid = network
|
||||
}
|
||||
|
||||
override def toString: String = "[PartMultimeter]" + x + "x " + y + "y " + z + "z " + getSlotMask + "s "
|
||||
|
|
|
@ -85,11 +85,11 @@ object RenderMultimeter extends ISimpleItemRenderer
|
|||
}
|
||||
|
||||
GL11.glPopMatrix()
|
||||
if (part.getNetwork.isEnabled && part.isPrimary)
|
||||
if (part.getGrid.isEnabled && part.isPrimary)
|
||||
{
|
||||
GL11.glPushMatrix()
|
||||
GL11.glTranslated(x + 0.5, y + 0.5, z + 0.5)
|
||||
val centerTranslation: Vector3 = part.getNetwork.center - new Vector3(part.x, part.y, part.z) - 0.5
|
||||
val centerTranslation: Vector3 = part.getGrid.center - new Vector3(part.x, part.y, part.z) - 0.5
|
||||
GL11.glTranslated(centerTranslation.x, centerTranslation.y, centerTranslation.z)
|
||||
RenderUtility.rotateFaceBlockToSideOutwards(part.getDirection.getOpposite)
|
||||
if (part.getDirection.offsetY != 0)
|
||||
|
@ -101,18 +101,18 @@ object RenderMultimeter extends ISimpleItemRenderer
|
|||
|
||||
var information = Seq.empty[String]
|
||||
|
||||
for (i <- 0 until part.getNetwork.graphs.size)
|
||||
for (i <- 0 until part.getGrid.graphs.size)
|
||||
{
|
||||
if (part.getNetwork.graphs(i).get != null && !(part.getNetwork.graphs(i).get == part.getNetwork.graphs(i).getDefault))
|
||||
if (part.getGrid.graphs(i).get != null && !(part.getGrid.graphs(i).get == part.getGrid.graphs(i).getDefault))
|
||||
{
|
||||
information :+= part.getNetwork.getDisplay(i)
|
||||
information :+= part.getGrid.getDisplay(i)
|
||||
}
|
||||
}
|
||||
|
||||
if (information.size <= 0) information :+= LanguageUtility.getLocal("tooltip.noInformation")
|
||||
|
||||
val displacement = 0.72f / information.size
|
||||
val maxScale = (part.getNetwork.size.x + part.getNetwork.size.z).asInstanceOf[Float] * 0.004f
|
||||
val maxScale = (part.getGrid.size.x + part.getGrid.size.z).asInstanceOf[Float] * 0.004f
|
||||
|
||||
GL11.glTranslatef(0, 0, -displacement * (information.size / 2f))
|
||||
|
||||
|
@ -121,9 +121,9 @@ object RenderMultimeter extends ISimpleItemRenderer
|
|||
val info = information(i)
|
||||
GL11.glPushMatrix()
|
||||
GL11.glTranslatef(0, 0, displacement * i)
|
||||
if (dir.offsetX != 0) RenderUtility.renderText(info, (part.getNetwork.size.z * 0.9f).asInstanceOf[Float], maxScale)
|
||||
else if (dir.offsetY != 0) RenderUtility.renderText(info, (Math.min(part.getNetwork.size.x, part.getNetwork.size.z) * 0.9f).asInstanceOf[Float], maxScale)
|
||||
else if (dir.offsetZ != 0) RenderUtility.renderText(info, (part.getNetwork.size.x * 0.9f).asInstanceOf[Float], maxScale)
|
||||
if (dir.offsetX != 0) RenderUtility.renderText(info, (part.getGrid.size.z * 0.9f).asInstanceOf[Float], maxScale)
|
||||
else if (dir.offsetY != 0) RenderUtility.renderText(info, (Math.min(part.getGrid.size.x, part.getGrid.size.z) * 0.9f).asInstanceOf[Float], maxScale)
|
||||
else if (dir.offsetZ != 0) RenderUtility.renderText(info, (part.getGrid.size.x * 0.9f).asInstanceOf[Float], maxScale)
|
||||
GL11.glPopMatrix()
|
||||
}
|
||||
GL11.glPopMatrix()
|
||||
|
|
|
@ -9,7 +9,7 @@ import scala.collection.convert.wrapAll._
|
|||
* A grid that manages the mechanical objects
|
||||
* @author Calclavia
|
||||
*/
|
||||
class MechanicalGrid extends GridNode[NodeMechanical](classOf[NodeMechanical]) with IUpdate
|
||||
class MechanicalGrid extends GridNode[NodeMechanical] with IUpdate
|
||||
{
|
||||
/**
|
||||
* The energy loss of this grid
|
||||
|
@ -26,6 +26,8 @@ class MechanicalGrid extends GridNode[NodeMechanical](classOf[NodeMechanical]) w
|
|||
*/
|
||||
private var allPassed = Seq.empty[NodeMechanical]
|
||||
|
||||
nodeClass = classOf[NodeMechanical]
|
||||
|
||||
/**
|
||||
* Rebuild the node list starting from the first node and recursively iterating through its connections.
|
||||
*/
|
||||
|
@ -36,6 +38,12 @@ class MechanicalGrid extends GridNode[NodeMechanical](classOf[NodeMechanical]) w
|
|||
isLocked = false
|
||||
}
|
||||
|
||||
override def deconstruct(first: NodeMechanical)
|
||||
{
|
||||
super.deconstruct(first)
|
||||
UpdateTicker.threaded.removeUpdater(this)
|
||||
}
|
||||
|
||||
override def update(deltaTime: Double)
|
||||
{
|
||||
getNodes synchronized
|
||||
|
@ -148,5 +156,5 @@ class MechanicalGrid extends GridNode[NodeMechanical](classOf[NodeMechanical]) w
|
|||
}
|
||||
}
|
||||
|
||||
override def updateRate: Int = if (getNodes.size > 0 && !dead) 20 else 0
|
||||
override def updateRate: Int = if (getNodes.size > 0) 20 else 0
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue