From 5373b7c12acb0aabea0221d2edebe7dd9672ce5d Mon Sep 17 00:00:00 2001 From: Calclavia Date: Sat, 17 Jan 2015 12:30:25 +0800 Subject: [PATCH] Refactored grid classes --- .../scala/edx/basic/fluid/tank/TileTank.scala | 3 +- .../core/prefab/node/NodeFluidPressure.scala | 2 +- .../edx/core/prefab/node/TMultipartNode.scala | 2 +- .../core/prefab/node/TileFluidProvider.scala | 10 ++--- .../part/connector/PartFramedNode.scala | 2 +- .../part/connector/TPartNodeProvider.scala | 2 +- .../edx/electrical/battery/GridBattery.scala | 2 +- .../edx/electrical/generator/TileMotor.scala | 2 +- .../multimeter/MultimeterGrid.scala | 2 +- .../edx/mechanical/mech/TileMechanical.scala | 26 ++++++------- .../mechanical/mech/grid/MechanicalGrid.scala | 2 +- .../mechanical/mech/grid/NodeMechanical.scala | 39 +++++++++---------- 12 files changed, 46 insertions(+), 48 deletions(-) diff --git a/src/main/scala/edx/basic/fluid/tank/TileTank.scala b/src/main/scala/edx/basic/fluid/tank/TileTank.scala index 5801e5bb4..230481ca4 100644 --- a/src/main/scala/edx/basic/fluid/tank/TileTank.scala +++ b/src/main/scala/edx/basic/fluid/tank/TileTank.scala @@ -17,10 +17,9 @@ import net.minecraft.world.IBlockAccess import net.minecraftforge.common.util.ForgeDirection import net.minecraftforge.fluids._ import org.lwjgl.opengl.GL11 -import resonant.api.tile.IRemovable import resonant.api.tile.IRemovable.ISneakPickup import resonant.api.tile.node.INode -import resonant.lib.grid.node.Node +import resonant.lib.grid.core.Node import resonant.lib.render.block.RenderConnectedTexture import resonant.lib.render.{FluidRenderUtility, RenderBlockUtility, RenderUtility} import resonant.lib.transform.vector.Vector3 diff --git a/src/main/scala/edx/core/prefab/node/NodeFluidPressure.scala b/src/main/scala/edx/core/prefab/node/NodeFluidPressure.scala index 8a6ff7a83..e4f95851c 100644 --- a/src/main/scala/edx/core/prefab/node/NodeFluidPressure.scala +++ b/src/main/scala/edx/core/prefab/node/NodeFluidPressure.scala @@ -4,7 +4,7 @@ import net.minecraftforge.common.util.ForgeDirection import net.minecraftforge.fluids.{FluidContainerRegistry, IFluidHandler} import resonant.api.IUpdate import resonant.api.tile.INodeProvider -import resonant.lib.grid.UpdateTicker +import resonant.lib.grid.core.UpdateTicker import resonant.lib.prefab.fluid.NodeFluid import scala.collection.convert.wrapAll._ diff --git a/src/main/scala/edx/core/prefab/node/TMultipartNode.scala b/src/main/scala/edx/core/prefab/node/TMultipartNode.scala index 8592510a3..d99f263c2 100644 --- a/src/main/scala/edx/core/prefab/node/TMultipartNode.scala +++ b/src/main/scala/edx/core/prefab/node/TMultipartNode.scala @@ -3,7 +3,7 @@ package edx.core.prefab.node import codechicken.multipart.TMultiPart import net.minecraft.tileentity.TileEntity import net.minecraft.world.World -import resonant.lib.grid.node.NodeConnector +import resonant.lib.grid.core.NodeConnector /** * A trait that allows nodes to works with Forge Multipart. This trait MUST be mixed in. diff --git a/src/main/scala/edx/core/prefab/node/TileFluidProvider.scala b/src/main/scala/edx/core/prefab/node/TileFluidProvider.scala index 863f75961..88f2be613 100644 --- a/src/main/scala/edx/core/prefab/node/TileFluidProvider.scala +++ b/src/main/scala/edx/core/prefab/node/TileFluidProvider.scala @@ -5,7 +5,7 @@ import net.minecraft.block.material.Material import net.minecraft.nbt.NBTTagCompound import net.minecraftforge.common.util.ForgeDirection import net.minecraftforge.fluids._ -import resonant.lib.grid.node.TSpatialNodeProvider +import resonant.lib.grid.core.TSpatialNodeProvider import resonant.lib.network.discriminator.PacketType import resonant.lib.network.handle.{TPacketReceiver, TPacketSender} import resonant.lib.prefab.fluid.NodeFluid @@ -94,10 +94,6 @@ abstract class TileFluidProvider(material: Material) extends SpatialTile(materia override def drain(from: ForgeDirection, maxDrain: Int, doDrain: Boolean): FluidStack = fluidNode.drain(from, maxDrain, doDrain) - override def canFill(from: ForgeDirection, fluid: Fluid): Boolean = fluidNode.canFill(from, fluid) - - override def canDrain(from: ForgeDirection, fluid: Fluid): Boolean = fluidNode.canDrain(from, fluid) - def fluidNode = _fluidNode def fluidNode_=(newNode: NodeFluid) @@ -112,6 +108,10 @@ abstract class TileFluidProvider(material: Material) extends SpatialTile(materia nodes.add(fluidNode) } + override def canFill(from: ForgeDirection, fluid: Fluid): Boolean = fluidNode.canFill(from, fluid) + + override def canDrain(from: ForgeDirection, fluid: Fluid): Boolean = fluidNode.canDrain(from, fluid) + override def fill(from: ForgeDirection, resource: FluidStack, doFill: Boolean): Int = fluidNode.fill(from, resource, doFill) override def getTankInfo(from: ForgeDirection): Array[FluidTankInfo] = fluidNode.getTankInfo(from) diff --git a/src/main/scala/edx/core/prefab/part/connector/PartFramedNode.scala b/src/main/scala/edx/core/prefab/part/connector/PartFramedNode.scala index fb9c88ff1..4e85fb3c1 100644 --- a/src/main/scala/edx/core/prefab/part/connector/PartFramedNode.scala +++ b/src/main/scala/edx/core/prefab/part/connector/PartFramedNode.scala @@ -12,7 +12,7 @@ import edx.core.prefab.part.CuboidShapes import net.minecraft.entity.player.EntityPlayer import net.minecraft.util.{IIcon, MovingObjectPosition} import net.minecraftforge.common.util.ForgeDirection -import resonant.lib.grid.node.NodeConnector +import resonant.lib.grid.core.NodeConnector import resonant.lib.wrapper.BitmaskWrapper._ import scala.collection.convert.wrapAll._ diff --git a/src/main/scala/edx/core/prefab/part/connector/TPartNodeProvider.scala b/src/main/scala/edx/core/prefab/part/connector/TPartNodeProvider.scala index ba3082f7c..a47c7816d 100644 --- a/src/main/scala/edx/core/prefab/part/connector/TPartNodeProvider.scala +++ b/src/main/scala/edx/core/prefab/part/connector/TPartNodeProvider.scala @@ -9,7 +9,7 @@ import resonant.api.ISave import resonant.api.tile.INodeProvider import resonant.api.tile.node.INode import resonant.lib.debug.DebugInfo -import resonant.lib.grid.node.Node +import resonant.lib.grid.core.Node import scala.collection.convert.wrapAll._ diff --git a/src/main/scala/edx/electrical/battery/GridBattery.scala b/src/main/scala/edx/electrical/battery/GridBattery.scala index 6075cea62..8c8f1811b 100644 --- a/src/main/scala/edx/electrical/battery/GridBattery.scala +++ b/src/main/scala/edx/electrical/battery/GridBattery.scala @@ -2,7 +2,7 @@ package edx.electrical.battery import java.util.{Arrays, LinkedHashSet, Set} -import resonant.lib.grid.Grid +import resonant.lib.grid.core.Grid import scala.collection.JavaConversions._ diff --git a/src/main/scala/edx/electrical/generator/TileMotor.scala b/src/main/scala/edx/electrical/generator/TileMotor.scala index cc1f35028..7cd12f788 100644 --- a/src/main/scala/edx/electrical/generator/TileMotor.scala +++ b/src/main/scala/edx/electrical/generator/TileMotor.scala @@ -13,7 +13,7 @@ import net.minecraftforge.client.model.AdvancedModelLoader import net.minecraftforge.common.util.ForgeDirection import org.lwjgl.opengl.GL11 import resonant.lib.content.prefab.TElectric -import resonant.lib.grid.node.TSpatialNodeProvider +import resonant.lib.grid.core.TSpatialNodeProvider import resonant.lib.prefab.tile.spatial.SpatialTile import resonant.lib.prefab.tile.traits.TRotatable import resonant.lib.render.RenderUtility diff --git a/src/main/scala/edx/electrical/multimeter/MultimeterGrid.scala b/src/main/scala/edx/electrical/multimeter/MultimeterGrid.scala index 205d02215..7aee31f3d 100644 --- a/src/main/scala/edx/electrical/multimeter/MultimeterGrid.scala +++ b/src/main/scala/edx/electrical/multimeter/MultimeterGrid.scala @@ -3,7 +3,7 @@ package edx.electrical.multimeter import edx.electrical.multimeter.graph._ import net.minecraft.nbt.{NBTTagCompound, NBTTagList} import resonant.api.IUpdate -import resonant.lib.grid.{Grid, UpdateTicker} +import resonant.lib.grid.core.{Grid, UpdateTicker} import resonant.lib.transform.vector.Vector3 import resonant.lib.utility.LanguageUtility import resonant.lib.utility.science.UnitDisplay diff --git a/src/main/scala/edx/mechanical/mech/TileMechanical.scala b/src/main/scala/edx/mechanical/mech/TileMechanical.scala index 3d6600394..fde4efe07 100644 --- a/src/main/scala/edx/mechanical/mech/TileMechanical.scala +++ b/src/main/scala/edx/mechanical/mech/TileMechanical.scala @@ -5,7 +5,7 @@ import io.netty.buffer.ByteBuf import net.minecraft.block.material.Material import net.minecraft.entity.player.EntityPlayer import net.minecraftforge.common.util.ForgeDirection -import resonant.lib.grid.node.TSpatialNodeProvider +import resonant.lib.grid.core.TSpatialNodeProvider import resonant.lib.network.discriminator.PacketType import resonant.lib.network.handle.{TPacketReceiver, TPacketSender} import resonant.lib.prefab.tile.spatial.SpatialTile @@ -42,6 +42,18 @@ abstract class TileMechanical(material: Material) extends SpatialTile(material: return false } + def mechanicalNode = _mechanicalNode + + def mechanicalNode_=(newNode: NodeMechanical) + { + _mechanicalNode = newNode + mechanicalNode.onVelocityChanged = () => sendPacket(1) + nodes.removeAll(nodes.filter(_.isInstanceOf[NodeMechanical])) + nodes.add(mechanicalNode) + } + + mechanicalNode = new NodeMechanical(this) + override def write(buf: ByteBuf, id: Int) { super.write(buf, id) @@ -64,16 +76,4 @@ abstract class TileMechanical(material: Material) extends SpatialTile(material: } } - mechanicalNode = new NodeMechanical(this) - - def mechanicalNode = _mechanicalNode - - def mechanicalNode_=(newNode: NodeMechanical) - { - _mechanicalNode = newNode - mechanicalNode.onVelocityChanged = () => sendPacket(1) - nodes.removeAll(nodes.filter(_.isInstanceOf[NodeMechanical])) - nodes.add(mechanicalNode) - } - } \ No newline at end of file diff --git a/src/main/scala/edx/mechanical/mech/grid/MechanicalGrid.scala b/src/main/scala/edx/mechanical/mech/grid/MechanicalGrid.scala index 17ef87525..24fb9d772 100644 --- a/src/main/scala/edx/mechanical/mech/grid/MechanicalGrid.scala +++ b/src/main/scala/edx/mechanical/mech/grid/MechanicalGrid.scala @@ -1,7 +1,7 @@ package edx.mechanical.mech.grid import resonant.api.IUpdate -import resonant.lib.grid.{GridNode, UpdateTicker} +import resonant.lib.grid.core.{GridNode, UpdateTicker} import scala.collection.convert.wrapAll._ diff --git a/src/main/scala/edx/mechanical/mech/grid/NodeMechanical.scala b/src/main/scala/edx/mechanical/mech/grid/NodeMechanical.scala index 81cada03e..8d3c34a91 100644 --- a/src/main/scala/edx/mechanical/mech/grid/NodeMechanical.scala +++ b/src/main/scala/edx/mechanical/mech/grid/NodeMechanical.scala @@ -4,8 +4,7 @@ import edx.core.interfaces.TNodeMechanical import edx.core.prefab.node.TMultipartNode import resonant.api.tile.INodeProvider import resonant.lib.debug.DebugInfo -import resonant.lib.grid.GridNode -import resonant.lib.grid.node.{NodeGrid, TTileConnector} +import resonant.lib.grid.core.{GridNode, NodeGrid, TTileConnector} import resonant.lib.transform.vector.IVectorWorld import scala.beans.BeanProperty @@ -52,6 +51,15 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par return prevAngle } + /** + * Gets the angular velocity of the mechanical device from a specific side + * + * @return Angular velocity in meters per second + */ + override def angularVelocity = _angularVelocity + + def angularVelocity_=(newVel: Double) = _angularVelocity = newVel + /** * Sets the mechanical node's angle based on its connections */ @@ -80,24 +88,6 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par def power: Double = torque * angularVelocity - /** - * Gets the angular velocity of the mechanical device from a specific side - * - * @return Angular velocity in meters per second - */ - override def angularVelocity = _angularVelocity - - def angularVelocity_=(newVel: Double) = _angularVelocity = newVel - - /** - * Gets the torque of the mechanical device from a specific side - * - * @return force - */ - override def torque = _torque - - def torque_=(newTorque: Double) = _torque = newTorque - def getMechanicalGrid: MechanicalGrid = super.grid.asInstanceOf[MechanicalGrid] override def newGrid: GridNode[NodeMechanical] = new MechanicalGrid @@ -108,6 +98,15 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par override def toString = "NodeMechanical [" + connections.size() + " Torque: " + BigDecimal(torque).setScale(2, BigDecimal.RoundingMode.HALF_UP) + " Velocity: " + BigDecimal(angularVelocity).setScale(2, BigDecimal.RoundingMode.HALF_UP) + "]" + /** + * Gets the torque of the mechanical device from a specific side + * + * @return force + */ + override def torque = _torque + + def torque_=(newTorque: Double) = _torque = newTorque + /** * The class used to compare when making connections */