From 453903bbee6c015f2f65b829cde616ca454288cf Mon Sep 17 00:00:00 2001 From: Robert S Date: Thu, 16 Oct 2014 08:13:57 -0400 Subject: [PATCH] Fixed a few parts implementing getType on their own, and make getType final to prevent this in the future --- .../prefab/part/connector/PartAbstract.scala | 2 +- .../mechanical/mech/PartMechanical.scala | 11 +--- .../mechanical/mech/gear/GearNode.scala | 59 +++++++------------ .../mechanical/mech/gear/PartGear.scala | 29 +++------ .../mech/gearshaft/PartGearShaft.scala | 5 -- 5 files changed, 33 insertions(+), 73 deletions(-) diff --git a/src/main/scala/resonantinduction/core/prefab/part/connector/PartAbstract.scala b/src/main/scala/resonantinduction/core/prefab/part/connector/PartAbstract.scala index 4d1e6a2de..9dcc7594c 100644 --- a/src/main/scala/resonantinduction/core/prefab/part/connector/PartAbstract.scala +++ b/src/main/scala/resonantinduction/core/prefab/part/connector/PartAbstract.scala @@ -71,5 +71,5 @@ abstract class PartAbstract extends TMultiPart with TraitTicker override def toString: String = "[" + getClass.getSimpleName + "]" + x + "x " + y + "y " + z + "z" - override def getType: String = ResonantPartFactory.prefix + getClass.getSimpleName + final override def getType: String = ResonantPartFactory.prefix + getClass.getSimpleName } \ No newline at end of file diff --git a/src/main/scala/resonantinduction/mechanical/mech/PartMechanical.scala b/src/main/scala/resonantinduction/mechanical/mech/PartMechanical.scala index e733f26df..39688bd33 100644 --- a/src/main/scala/resonantinduction/mechanical/mech/PartMechanical.scala +++ b/src/main/scala/resonantinduction/mechanical/mech/PartMechanical.scala @@ -11,18 +11,18 @@ import net.minecraft.nbt.NBTTagCompound import net.minecraft.util.MovingObjectPosition import net.minecraftforge.common.util.ForgeDirection import resonant.engine.ResonantEngine +import resonantinduction.core.prefab.part.connector.PartAbstract import universalelectricity.api.core.grid.{INode, INodeProvider} import universalelectricity.core.transform.vector.VectorWorld /** We assume all the force acting on the gear is 90 degrees. * * @author Calclavia */ -abstract class PartMechanical extends JCuboidPart with JNormalOcclusion with TFacePart with INodeProvider +abstract class PartMechanical extends PartAbstract with JNormalOcclusion with TFacePart with INodeProvider { /** Node that handles resonantinduction.mechanical action of the machine */ var node: MechanicalNode = null protected var prevAngularVelocity: Double = .0 - private[mech] var ticks: Int = 0 /** Packets */ private[mech] var markPacketUpdate: Boolean = false /** Simple debug external GUI */ @@ -54,11 +54,6 @@ abstract class PartMechanical extends JCuboidPart with JNormalOcclusion with TFa override def update { - ticks += 1 - if (ticks >= java.lang.Long.MAX_VALUE) - { - ticks = 0 - } this.node.update if (!world.isRemote) { @@ -145,7 +140,7 @@ abstract class PartMechanical extends JCuboidPart with JNormalOcclusion with TFa read(packet, packet.readUByte) } - def read(packet: MCDataInput, packetID: Int) + override def read(packet: MCDataInput, packetID: Int) { if (packetID == 0) { diff --git a/src/main/scala/resonantinduction/mechanical/mech/gear/GearNode.scala b/src/main/scala/resonantinduction/mechanical/mech/gear/GearNode.scala index 13feacf44..dd8f121b6 100644 --- a/src/main/scala/resonantinduction/mechanical/mech/gear/GearNode.scala +++ b/src/main/scala/resonantinduction/mechanical/mech/gear/GearNode.scala @@ -1,17 +1,14 @@ package resonantinduction.mechanical.mech.gear import codechicken.lib.vec.Rotation -import codechicken.multipart.TMultiPart -import codechicken.multipart.TileMultipart +import codechicken.multipart.{TMultiPart, TileMultipart} import net.minecraft.tileentity.TileEntity import net.minecraftforge.common.util.ForgeDirection import resonantinduction.core.interfaces.IMechanicalNode import resonantinduction.mechanical.mech.MechanicalNode import resonantinduction.mechanical.mech.gearshaft.PartGearShaft import universalelectricity.api.core.grid.INodeProvider -import universalelectricity.core.transform.vector.IVectorWorld -import universalelectricity.core.transform.vector.VectorWorld -import universalelectricity.core.transform.vector.Vector3 +import universalelectricity.core.transform.vector.{IVectorWorld, Vector3, VectorWorld} /** * Node for the gear @@ -73,29 +70,21 @@ class GearNode(parent: PartGear) extends MechanicalNode(parent: PartGear) addConnection(instance, gear.placementSide) } } + for (i <- 0 until 6) { - var i: Int = 0 - while (i < 6) + val checkDir: ForgeDirection = ForgeDirection.getOrientation(i) + var tile: TileEntity = gear.tile + if (gear.getMultiBlock.isConstructed && checkDir != gear.placementSide && checkDir != gear.placementSide.getOpposite) { + tile = new Vector3(gear.tile).add(checkDir).getTileEntity(world) + } + if (tile.isInstanceOf[INodeProvider]) + { + val instance: MechanicalNode = (tile.asInstanceOf[INodeProvider]).getNode(classOf[MechanicalNode], if (checkDir eq gear.placementSide.getOpposite) ForgeDirection.UNKNOWN else checkDir).asInstanceOf[MechanicalNode] + if (!connections.containsValue(checkDir) && instance != this && checkDir != gear.placementSide && instance != null && instance.canConnect(checkDir.getOpposite, this)) { - val checkDir: ForgeDirection = ForgeDirection.getOrientation(i) - var tile: TileEntity = gear.tile - if (gear.getMultiBlock.isConstructed && checkDir != gear.placementSide && checkDir != gear.placementSide.getOpposite) - { - tile = new Vector3(gear.tile).add(checkDir).getTileEntity(world) - } - if (tile.isInstanceOf[INodeProvider]) - { - val instance: MechanicalNode = (tile.asInstanceOf[INodeProvider]).getNode(classOf[MechanicalNode], if (checkDir eq gear.placementSide.getOpposite) ForgeDirection.UNKNOWN else checkDir).asInstanceOf[MechanicalNode] - if (!connections.containsValue(checkDir) && instance != this && checkDir != gear.placementSide && instance != null && instance.canConnect(checkDir.getOpposite, this)) - { - addConnection(instance, checkDir) - } - } + addConnection(instance, checkDir) } - ({ - i += 1; i - 1 - }) } } var displaceCheck: Int = 1 @@ -103,25 +92,17 @@ class GearNode(parent: PartGear) extends MechanicalNode(parent: PartGear) { displaceCheck = 2 } + for (i <- 0 until 4) { - var i: Int = 0 - while (i < 4) + val checkDir: ForgeDirection = ForgeDirection.getOrientation(Rotation.rotateSide(gear.placementSide.ordinal, i)) + val checkTile: TileEntity = new Vector3(gear.tile).add(checkDir).getTileEntity(world) + if (!connections.containsValue(checkDir) && checkTile.isInstanceOf[INodeProvider]) { + val instance: MechanicalNode = (checkTile.asInstanceOf[INodeProvider]).getNode(classOf[MechanicalNode], gear.placementSide).asInstanceOf[MechanicalNode] + if (instance != null && instance != this && instance.canConnect(checkDir.getOpposite, this) && !(instance.getParent.isInstanceOf[PartGearShaft])) { - val checkDir: ForgeDirection = ForgeDirection.getOrientation(Rotation.rotateSide(gear.placementSide.ordinal, i)) - val checkTile: TileEntity = new Vector3(gear.tile).add(checkDir).getTileEntity(world) - if (!connections.containsValue(checkDir) && checkTile.isInstanceOf[INodeProvider]) - { - val instance: MechanicalNode = (checkTile.asInstanceOf[INodeProvider]).getNode(classOf[MechanicalNode], gear.placementSide).asInstanceOf[MechanicalNode] - if (instance != null && instance != this && instance.canConnect(checkDir.getOpposite, this) && !(instance.getParent.isInstanceOf[PartGearShaft])) - { - addConnection(instance, checkDir) - } - } + addConnection(instance, checkDir) } - ({ - i += 1; i - 1 - }) } } } diff --git a/src/main/scala/resonantinduction/mechanical/mech/gear/PartGear.scala b/src/main/scala/resonantinduction/mechanical/mech/gear/PartGear.scala index 6938073d2..c3ac0b511 100644 --- a/src/main/scala/resonantinduction/mechanical/mech/gear/PartGear.scala +++ b/src/main/scala/resonantinduction/mechanical/mech/gear/PartGear.scala @@ -29,19 +29,13 @@ object PartGear oBoxes(0)(0) = new Cuboid6(1 / 8D, 0, 0, 7 / 8D, 1 / 8D, 1) oBoxes(0)(1) = new Cuboid6(0, 0, 1 / 8D, 1, 1 / 8D, 7 / 8D) + + for(s <- 1 until 6) { - var s: Int = 1 - while (s < 6) - { - { - val t: Transformation = Rotation.sideRotations(s).at(Vector3.center) - oBoxes(s)(0) = oBoxes(0)(0).copy.apply(t) - oBoxes(s)(1) = oBoxes(0)(1).copy.apply(t) - } - ({ - s += 1; s - 1 - }) - } + val t: Transformation = Rotation.sideRotations(s).at(Vector3.center) + oBoxes(s)(0) = oBoxes(0)(0).copy.apply(t) + oBoxes(s)(1) = oBoxes(0)(1).copy.apply(t) + } } @@ -109,7 +103,7 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear] /** Is this gear block the one in the center-edge of the multiblock that can interact with other * gears? * - * @return*/ + * @return */ def isCenterMultiBlock: Boolean = { if (!getMultiBlock.isConstructed) @@ -145,11 +139,6 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear] } } - def getType: String = - { - return "resonant_induction_gear" - } - override def load(nbt: NBTTagCompound) { super.load(nbt) @@ -165,7 +154,7 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear] override def getMultiBlockVectors: java.util.List[universalelectricity.core.transform.vector.Vector3] = { val vec = new universalelectricity.core.transform.vector.Vector3(this.x, this.y, this.z) - var array : java.util.List[universalelectricity.core.transform.vector.Vector3] = vec.getAround(this.world, placementSide, 1) + var array: java.util.List[universalelectricity.core.transform.vector.Vector3] = vec.getAround(this.world, placementSide, 1) return array } @@ -202,7 +191,7 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear] def getOcclusionBoxes: java.lang.Iterable[Cuboid6] = { val list: java.util.List[Cuboid6] = new util.ArrayList[Cuboid6]; - for(v <- PartGear.oBoxes(this.placementSide.ordinal)) + for (v <- PartGear.oBoxes(this.placementSide.ordinal)) { list.add(v) } diff --git a/src/main/scala/resonantinduction/mechanical/mech/gearshaft/PartGearShaft.scala b/src/main/scala/resonantinduction/mechanical/mech/gearshaft/PartGearShaft.scala index 2de7288bd..8ce39492d 100644 --- a/src/main/scala/resonantinduction/mechanical/mech/gearshaft/PartGearShaft.scala +++ b/src/main/scala/resonantinduction/mechanical/mech/gearshaft/PartGearShaft.scala @@ -58,11 +58,6 @@ class PartGearShaft extends PartMechanical } } - def getType: String = - { - return "resonant_induction_gear_shaft" - } - /** * Multipart Bounds */