Fixed pipe packets

This commit is contained in:
Calclavia 2014-11-11 20:51:23 +08:00
parent 6b625208fc
commit b8b4b866c5
8 changed files with 95 additions and 110 deletions

View file

@ -1,29 +1,32 @@
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()
lazy val segment = getNewSegments(0.375f)
/** 0.4 box shaped wire designed to be used for insulation */
lazy val WIRE_INSULATION = getNewWireInsulationSegments()
lazy val thickSegment = getNewSegments(0.3f)
/** 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))
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()
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]] =
def getNewPanelSegments: Array[Array[Cuboid6]] =
{
val segments = Array.ofDim[Cuboid6](6, 2);
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)
@ -35,37 +38,21 @@ final object CuboidShapes
}
return segments
}
/**
* Generates then returns a new set of wire segments that are .3m in size
* @return 7 part array
*/
def getNewWireSegments() : Array[IndexedCuboid6] =
def getNewSegments(thickness: Float): Array[IndexedCuboid6] =
{
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
}
/**
* 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))
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
}
}

View file

@ -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)

View file

@ -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)

View file

@ -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

View file

@ -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)

View file

@ -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)

View file

@ -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)
}*/
}
}
/**

View file

@ -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)
}