From b8b4b866c5a487d53a54bd073f549f67766e2ee4 Mon Sep 17 00:00:00 2001 From: Calclavia Date: Tue, 11 Nov 2014 20:51:23 +0800 Subject: [PATCH] Fixed pipe packets --- .../core/prefab/part/CuboidShapes.scala | 103 ++++++++---------- .../core/prefab/part/PartFace.scala | 2 +- .../prefab/part/connector/PartAbstract.scala | 2 +- .../part/connector/PartFramedNode.scala | 28 ++--- .../prefab/part/connector/TColorable.scala | 20 +--- .../prefab/part/connector/TMaterial.scala | 12 +- .../mechanical/fluid/pipe/PartPipe.scala | 36 ++++-- .../mechanical/mech/gear/PartGear.scala | 2 +- 8 files changed, 95 insertions(+), 110 deletions(-) diff --git a/src/main/scala/resonantinduction/core/prefab/part/CuboidShapes.scala b/src/main/scala/resonantinduction/core/prefab/part/CuboidShapes.scala index 856bc9cc5..c92a0a15e 100644 --- a/src/main/scala/resonantinduction/core/prefab/part/CuboidShapes.scala +++ b/src/main/scala/resonantinduction/core/prefab/part/CuboidShapes.scala @@ -1,71 +1,58 @@ package resonantinduction.core.prefab.part import codechicken.lib.raytracer.IndexedCuboid6 -import codechicken.lib.vec.{Vector3, Rotation, Cuboid6} +import codechicken.lib.vec.{Cuboid6, Rotation, Vector3} -/** Reference sheet for commonly created cuboid shape sets. +/** + * Reference sheet for commonly created cuboid shape sets. * Created by robert on 10/18/2014. */ -final object CuboidShapes +object CuboidShapes { - /** 0.3 box shaped centered wire */ - lazy val WIRE_SEGMENTS = getNewWireSegments() - /** 0.4 box shaped wire designed to be used for insulation */ - lazy val WIRE_INSULATION = getNewWireInsulationSegments() - /** Center segment of wire */ - lazy val WIRE_CENTER: IndexedCuboid6 = new IndexedCuboid6(7, new Cuboid6(0.375, 0.375, 0.375, 0.625, 0.625, 0.625)) - /** 1/8th thick panel box can be used for anything flat */ - lazy val PANEL = getNewPanelSegments() + /** 0.3 box shaped centered wire */ + lazy val segment = getNewSegments(0.375f) + /** 0.4 box shaped wire designed to be used for insulation */ + lazy val thickSegment = getNewSegments(0.3f) + /** Center segment of wire */ + lazy val center = new IndexedCuboid6(7, new Cuboid6(0.375, 0.375, 0.375, 0.625, 0.625, 0.625)) + /** Center segment of insulation */ + lazy val thickCenter = new IndexedCuboid6(7, new Cuboid6(0.3, 0.3, 0.3, 0.7, 0.7, 0.7)) + /** 1/8th thick panel box can be used for anything flat */ + lazy val panel = getNewPanelSegments - /** - * Generates then returns a new set of panel segments that are .125m in size - * @return 6 part matrix - */ - def getNewPanelSegments() : Array[Array[Cuboid6]] = - { - val segments = Array.ofDim[Cuboid6](6, 2); - segments(0)(0) = new Cuboid6(1 / 8D, 0, 0, 7 / 8D, 1 / 8D, 1) - segments(0)(1) = new Cuboid6(0, 0, 1 / 8D, 1, 1 / 8D, 7 / 8D) + /** + * Generates then returns a new set of panel segments that are .125m in size + * @return 6 part matrix + */ + def getNewPanelSegments: Array[Array[Cuboid6]] = + { + val segments = Array.ofDim[Cuboid6](6, 2) + segments(0)(0) = new Cuboid6(1 / 8D, 0, 0, 7 / 8D, 1 / 8D, 1) + segments(0)(1) = new Cuboid6(0, 0, 1 / 8D, 1, 1 / 8D, 7 / 8D) - for (s <- 1 until 6) - { - val t = Rotation.sideRotations(s).at(Vector3.center) - segments(s)(0) = segments(0)(0).copy().apply(t) - segments(s)(1) = segments(0)(1).copy().apply(t) - } - return segments - } - /** - * Generates then returns a new set of wire segments that are .3m in size - * @return 7 part array - */ - def getNewWireSegments() : Array[IndexedCuboid6] = + for (s <- 1 until 6) { - val segments = new Array[IndexedCuboid6](7) - segments(0) = new IndexedCuboid6(0, new Cuboid6(0.36, 0.000, 0.36, 0.64, 0.36, 0.64)) - segments(1) = new IndexedCuboid6(1, new Cuboid6(0.36, 0.64, 0.36, 0.64, 1.000, 0.64)) - segments(2) = new IndexedCuboid6(2, new Cuboid6(0.36, 0.36, 0.000, 0.64, 0.64, 0.36)) - segments(3) = new IndexedCuboid6(3, new Cuboid6(0.36, 0.36, 0.64, 0.64, 0.64, 1.000)) - segments(4) = new IndexedCuboid6(4, new Cuboid6(0.000, 0.36, 0.36, 0.36, 0.64, 0.64)) - segments(5) = new IndexedCuboid6(5, new Cuboid6(0.64, 0.36, 0.36, 1.000, 0.64, 0.64)) - segments(6) = new IndexedCuboid6(6, new Cuboid6(0.36, 0.36, 0.36, 0.64, 0.64, 0.64)) - return segments + val t = Rotation.sideRotations(s).at(Vector3.center) + segments(s)(0) = segments(0)(0).copy().apply(t) + segments(s)(1) = segments(0)(1).copy().apply(t) } + return segments + } - /** - * Generates then returns a new set of insulation segments that are .4m in size - * @return 7 part array - */ - def getNewWireInsulationSegments() : Array[IndexedCuboid6] = - { - val segments = new Array[IndexedCuboid6](7) - segments(0) = new IndexedCuboid6(0, new Cuboid6(0.3, 0.0, 0.3, 0.7, 0.3, 0.7)) - segments(1) = new IndexedCuboid6(1, new Cuboid6(0.3, 0.7, 0.3, 0.7, 1.0, 0.7)) - segments(2) = new IndexedCuboid6(2, new Cuboid6(0.3, 0.3, 0.0, 0.7, 0.7, 0.3)) - segments(3) = new IndexedCuboid6(3, new Cuboid6(0.3, 0.3, 0.7, 0.7, 0.7, 1.0)) - segments(4) = new IndexedCuboid6(4, new Cuboid6(0.0, 0.3, 0.3, 0.3, 0.7, 0.7)) - segments(5) = new IndexedCuboid6(5, new Cuboid6(0.7, 0.3, 0.3, 1.0, 0.7, 0.7)) - segments(6) = new IndexedCuboid6(6, new Cuboid6(0.3, 0.3, 0.3, 0.7, 0.7, 0.7)) - return segments - } + /** + * Generates then returns a new set of wire segments that are .3m in size + * @return 7 part array + */ + def getNewSegments(thickness: Float): Array[IndexedCuboid6] = + { + val segments = new Array[IndexedCuboid6](7) + segments(0) = new IndexedCuboid6(0, new Cuboid6(thickness, 0.0, thickness, 1 - thickness, thickness, 1 - thickness)) + segments(1) = new IndexedCuboid6(1, new Cuboid6(thickness, 1 - thickness, thickness, 1 - thickness, 1.0, 1 - thickness)) + segments(2) = new IndexedCuboid6(2, new Cuboid6(thickness, thickness, 0.0, 1 - thickness, 1 - thickness, thickness)) + segments(3) = new IndexedCuboid6(3, new Cuboid6(thickness, thickness, 1 - thickness, 1 - thickness, 1 - thickness, 1.0)) + segments(4) = new IndexedCuboid6(4, new Cuboid6(0.0, thickness, thickness, thickness, 1 - thickness, 1 - thickness)) + segments(5) = new IndexedCuboid6(5, new Cuboid6(1 - thickness, thickness, thickness, 1.0, 1 - thickness, 1 - thickness)) + segments(6) = new IndexedCuboid6(6, new Cuboid6(thickness, thickness, thickness, 1 - thickness, 1 - thickness, 1 - thickness)) + return segments + } } diff --git a/src/main/scala/resonantinduction/core/prefab/part/PartFace.scala b/src/main/scala/resonantinduction/core/prefab/part/PartFace.scala index eb4bfa561..2668ece66 100644 --- a/src/main/scala/resonantinduction/core/prefab/part/PartFace.scala +++ b/src/main/scala/resonantinduction/core/prefab/part/PartFace.scala @@ -56,7 +56,7 @@ abstract class PartFace extends PartAbstract with TCuboidPart with JNormalOcclus override def solid(arg0: Int): Boolean = true - override def getOcclusionBoxes: JIterable[Cuboid6] = CuboidShapes.PANEL(placementSide.ordinal).toList + override def getOcclusionBoxes: JIterable[Cuboid6] = CuboidShapes.panel(placementSide.ordinal).toList override def occlusionTest(npart: TMultiPart): Boolean = NormalOcclusionTest.apply(this, npart) 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 78f093c29..c04634a0d 100644 --- a/src/main/scala/resonantinduction/core/prefab/part/connector/PartAbstract.scala +++ b/src/main/scala/resonantinduction/core/prefab/part/connector/PartAbstract.scala @@ -77,7 +77,7 @@ abstract class PartAbstract extends TMultiPart with TraitTicker override final def readDesc(packet: MCDataInput) { - read(packet) + read(packet, packet.readUByte) } override final def read(packet: MCDataInput) diff --git a/src/main/scala/resonantinduction/core/prefab/part/connector/PartFramedNode.scala b/src/main/scala/resonantinduction/core/prefab/part/connector/PartFramedNode.scala index 21291a950..38a16611e 100644 --- a/src/main/scala/resonantinduction/core/prefab/part/connector/PartFramedNode.scala +++ b/src/main/scala/resonantinduction/core/prefab/part/connector/PartFramedNode.scala @@ -12,6 +12,7 @@ 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.wrapper.BitmaskWrapper._ import resonantinduction.core.prefab.part.CuboidShapes import scala.collection.convert.wrapAll._ @@ -26,7 +27,7 @@ abstract class PartFramedNode extends PartAbstract with TPartNodeProvider with T protected var breakIcon: IIcon = null /** Client Side */ - private var testingSide: ForgeDirection = null + protected var testingSide: ForgeDirection = null protected val node: NodeConnector[_] @@ -35,27 +36,21 @@ abstract class PartFramedNode extends PartAbstract with TPartNodeProvider with T override def getStrength(hit: MovingObjectPosition, player: EntityPlayer): Float = 10f - override def getBounds: Cuboid6 = CuboidShapes.WIRE_CENTER + override def getBounds: Cuboid6 = CuboidShapes.center override def getBrokenIcon(side: Int): IIcon = breakIcon def getOcclusionBoxes: Set[Cuboid6] = getCollisionBoxes /** Rendering and block bounds. */ - override def getCollisionBoxes: Set[Cuboid6] = - { - val collisionBoxes = mutable.Set.empty[Cuboid6] - collisionBoxes ++= getSubParts - return collisionBoxes - } + override def getCollisionBoxes: Set[Cuboid6] = mutable.Set.empty[Cuboid6] ++ getSubParts override def getSubParts: JIterable[IndexedCuboid6] = { - val currentSides = if (this.isInstanceOf[TInsulatable] && this.asInstanceOf[TInsulatable].insulated) CuboidShapes.WIRE_INSULATION else CuboidShapes.WIRE_SEGMENTS - + val sideCuboids = if (this.isInstanceOf[TInsulatable] && this.asInstanceOf[TInsulatable].insulated) CuboidShapes.thickSegment else CuboidShapes.segment val list = mutable.Set.empty[IndexedCuboid6] - list += CuboidShapes.WIRE_CENTER - list ++= ForgeDirection.VALID_DIRECTIONS.filter(s => connectionMapContainsSide(clientRenderMask, s) || s == testingSide).map(s => currentSides(s.ordinal())) + list += CuboidShapes.center + list ++= ForgeDirection.VALID_DIRECTIONS.filter(s => clientRenderMask.mask(s) || s == testingSide).map(s => sideCuboids(s.ordinal())) return list } @@ -70,7 +65,7 @@ abstract class PartFramedNode extends PartAbstract with TPartNodeProvider with T return !expandable } - def isCurrentlyConnected(side: ForgeDirection): Boolean = connectionMapContainsSide(clientRenderMask, side) + def isCurrentlyConnected(side: ForgeDirection): Boolean = clientRenderMask.mask(side) override def write(packet: MCDataOutput, id: Int) { @@ -78,8 +73,7 @@ abstract class PartFramedNode extends PartAbstract with TPartNodeProvider with T if (id == 0) { - // packet.writeByte(0) - // packet.writeByte(node.connectedMask.toByte) + packet.writeByte(node.connectedMask.toByte) } } @@ -89,11 +83,11 @@ abstract class PartFramedNode extends PartAbstract with TPartNodeProvider with T if (id == 0) { - // clientRenderMask = packet.readByte() - tile.markRender() + clientRenderMask = packet.readByte() } } + @deprecated def connectionMapContainsSide(connections: Int, side: ForgeDirection): Boolean = { val tester = 1 << side.ordinal diff --git a/src/main/scala/resonantinduction/core/prefab/part/connector/TColorable.scala b/src/main/scala/resonantinduction/core/prefab/part/connector/TColorable.scala index 2d1bac501..6c8c86d97 100644 --- a/src/main/scala/resonantinduction/core/prefab/part/connector/TColorable.scala +++ b/src/main/scala/resonantinduction/core/prefab/part/connector/TColorable.scala @@ -34,15 +34,10 @@ trait TColorable extends PartAbstract { tile.notifyPartChange(this) onPartChanged(this) - sendColorUpdate() + sendPacket(2) } } - def sendColorUpdate() - { - //tile.getWriteStream(this).writeByte(2).writeInt(this.colorID) - } - /** * Changes the wire's color. */ @@ -69,21 +64,14 @@ trait TColorable extends PartAbstract override def write(packet: MCDataOutput, id: Int) { - super.write(packet, id) - if (id == 0 || id == 2) packet.writeByte(colorID.toByte) } - override def read(packet: MCDataInput, packetID: Int) + override def read(packet: MCDataInput, id: Int) { - packetID match - { - case 0 => colorID = packet.readByte - case 2 => - colorID = packet.readInt() - tile.markRender() - } + if (id == 0 || id == 2) + colorID = packet.readByte() } override def save(nbt: NBTTagCompound) diff --git a/src/main/scala/resonantinduction/core/prefab/part/connector/TMaterial.scala b/src/main/scala/resonantinduction/core/prefab/part/connector/TMaterial.scala index c87a38b87..2f0524973 100644 --- a/src/main/scala/resonantinduction/core/prefab/part/connector/TMaterial.scala +++ b/src/main/scala/resonantinduction/core/prefab/part/connector/TMaterial.scala @@ -15,18 +15,18 @@ trait TMaterial[M] extends PartAbstract def getMaterialID: Int - override def read(packet: MCDataInput, id: Int) - { - if (id == 0) - setMaterial(packet.readByte) - } - override def write(packet: MCDataOutput, id: Int) { if (id == 0) packet.writeByte(getMaterialID.toByte) } + override def read(packet: MCDataInput, id: Int) + { + if (id == 0) + setMaterial(packet.readUByte()) + } + override def save(nbt: NBTTagCompound) { super.save(nbt) diff --git a/src/main/scala/resonantinduction/mechanical/fluid/pipe/PartPipe.scala b/src/main/scala/resonantinduction/mechanical/fluid/pipe/PartPipe.scala index a7bf51102..88e6a3863 100644 --- a/src/main/scala/resonantinduction/mechanical/fluid/pipe/PartPipe.scala +++ b/src/main/scala/resonantinduction/mechanical/fluid/pipe/PartPipe.scala @@ -1,8 +1,11 @@ package resonantinduction.mechanical.fluid.pipe +import java.lang.{Iterable => JIterable} + import codechicken.lib.data.{MCDataInput, MCDataOutput} +import codechicken.lib.raytracer.IndexedCuboid6 import codechicken.lib.render.CCRenderState -import codechicken.lib.vec.Vector3 +import codechicken.lib.vec.{Cuboid6, Vector3} import cpw.mods.fml.relauncher.{Side, SideOnly} import net.minecraft.client.renderer.RenderBlocks import net.minecraft.item.ItemStack @@ -10,9 +13,14 @@ import net.minecraft.nbt.NBTTagCompound import net.minecraftforge.common.util.ForgeDirection import net.minecraftforge.fluids._ import resonant.lib.`type`.EvictingList +import resonantinduction.core.prefab.part.CuboidShapes import resonantinduction.core.prefab.part.connector.{PartFramedNode, TColorable, TMaterial} import resonantinduction.mechanical.MechanicalContent import resonantinduction.mechanical.fluid.pipe.PipeMaterials.PipeMaterial +import resonant.lib.wrapper.BitmaskWrapper._ + +import scala.collection.convert.wrapAll._ +import scala.collection.mutable /** * Fluid transport pipe @@ -34,6 +42,17 @@ class PartPipe extends PartFramedNode with TMaterial[PipeMaterial] with TColorab material = PipeMaterials.ceramic node.onConnectionChanged = () => sendPacket(0) + override def getBounds: Cuboid6 = CuboidShapes.thickCenter + + override def getSubParts: JIterable[IndexedCuboid6] = + { + val sideCuboids = CuboidShapes.thickSegment + val list = mutable.Set.empty[IndexedCuboid6] + list += CuboidShapes.thickCenter + list ++= ForgeDirection.VALID_DIRECTIONS.filter(s => clientRenderMask.mask(s) || s == testingSide).map(s => sideCuboids(s.ordinal())) + return list + } + def preparePlacement(meta: Int) { setMaterial(meta) @@ -65,11 +84,9 @@ class PartPipe extends PartFramedNode with TMaterial[PipeMaterial] with TColorab override def write(packet: MCDataOutput, id: Int) { super[PartFramedNode].write(packet, id) + super[TMaterial].write(packet, id) + super[TColorable].write(packet, id) -// super[TMaterial].write(packet, id) -// super[TColorable].write(packet, id) - - /* if (id == 3) { //Tank Packet @@ -78,21 +95,20 @@ class PartPipe extends PartFramedNode with TMaterial[PipeMaterial] with TColorab val tempTank = if (tank.getFluid != null) new FluidTank(tank.getFluid.getFluid, averageAmount, tank.getCapacity) else new FluidTank(tank.getCapacity) tempTank.writeToNBT(nbt) packet.writeInt(tank.getCapacity).writeNBTTagCompound(nbt) - }*/ + } } override def read(packet: MCDataInput, packetID: Int) { super[PartFramedNode].read(packet, packetID) + super[TMaterial].read(packet, packetID) + super[TColorable].read(packet, packetID) -// super[TMaterial].read(packet, packetID) -// super[TColorable].read(packet, packetID) -/* if (packetID == 3) { tank.setCapacity(packet.readInt) tank.readFromNBT(packet.readNBTTagCompound) - }*/ + } } /** diff --git a/src/main/scala/resonantinduction/mechanical/mech/gear/PartGear.scala b/src/main/scala/resonantinduction/mechanical/mech/gear/PartGear.scala index 38b1a71af..2edb4b9ca 100644 --- a/src/main/scala/resonantinduction/mechanical/mech/gear/PartGear.scala +++ b/src/main/scala/resonantinduction/mechanical/mech/gear/PartGear.scala @@ -184,7 +184,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 <- CuboidShapes.PANEL(this.placementSide.ordinal)) + for (v <- CuboidShapes.panel(this.placementSide.ordinal)) { list.add(v) }