Fixed pipe connections

This commit is contained in:
Calclavia 2014-11-08 22:35:48 +08:00
parent e480b76b64
commit bb8c0fd47d
5 changed files with 89 additions and 81 deletions

View file

@ -26,6 +26,7 @@ class NodePressure(parent: INodeProvider, volume: Int = FluidContainerRegistry.B
def update(deltaTime: Double)
{
println(world)
if (!world.isRemote)
{
updatePressure()

View file

@ -11,95 +11,100 @@ import cpw.mods.fml.relauncher.{Side, SideOnly}
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 resonantinduction.core.prefab.part.CuboidShapes
import scala.collection.convert.wrapAll._
import scala.collection.mutable
abstract class PartFramedNode extends PartAbstract with TPartNodeProvider with TSlottedPart with TNormalOcclusion with TIconHitEffects
{
/** Bitmask connections */
protected var clientRenderMask = 0x00
/** Bitmask connections */
protected var clientRenderMask = 0x00
@SideOnly(Side.CLIENT)
protected var breakIcon: IIcon = null
@SideOnly(Side.CLIENT)
protected var breakIcon: IIcon = null
/** Client Side */
private var testingSide: ForgeDirection = null
/** Client Side */
private var testingSide: ForgeDirection = null
override def getStrength(hit: MovingObjectPosition, player: EntityPlayer): Float = 10f
protected val node: NodeConnector[_]
override def getBounds: Cuboid6 = CuboidShapes.WIRE_CENTER
//Check if lazy val will be null?
nodes.add(node)
override def getBrokenIcon(side: Int): IIcon = breakIcon
override def getStrength(hit: MovingObjectPosition, player: EntityPlayer): Float = 10f
def getOcclusionBoxes: Set[Cuboid6] = getCollisionBoxes
override def getBounds: Cuboid6 = CuboidShapes.WIRE_CENTER
/** Rendering and block bounds. */
override def getCollisionBoxes: Set[Cuboid6] =
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 getSubParts: JIterable[IndexedCuboid6] =
{
val currentSides = if (this.isInstanceOf[TInsulatable] && this.asInstanceOf[TInsulatable].insulated) CuboidShapes.WIRE_INSULATION else CuboidShapes.WIRE_SEGMENTS
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()))
return list
}
override def getSlotMask = PartMap.CENTER.mask
def isBlockedOnSide(side: ForgeDirection): Boolean =
{
val blocker: TMultiPart = tile.partMap(side.ordinal)
testingSide = side
val expandable = NormalOcclusionTest.apply(this, blocker)
testingSide = null
return !expandable
}
def isCurrentlyConnected(side: ForgeDirection): Boolean = connectionMapContainsSide(clientRenderMask, side)
/** Packet Methods */
def sendConnectionUpdate()
{
if (!world.isRemote)
tile.getWriteStream(this).writeByte(0).writeByte(node.connectedMask)
}
override def readDesc(packet: MCDataInput)
{
super.readDesc(packet)
clientRenderMask = packet.readByte
}
override def writeDesc(packet: MCDataOutput)
{
super.writeDesc(packet)
packet.writeByte(clientRenderMask)
}
override def read(packet: MCDataInput, packetID: Int)
{
super.read(packet, packetID)
if (packetID == 0)
{
val collisionBoxes = mutable.Set.empty[Cuboid6]
collisionBoxes ++= getSubParts
return collisionBoxes
clientRenderMask = packet.readByte
tile.markRender()
}
}
override def getSubParts: JIterable[IndexedCuboid6] =
{
val currentSides = if (this.isInstanceOf[TInsulatable] && this.asInstanceOf[TInsulatable].insulated) CuboidShapes.WIRE_INSULATION else CuboidShapes.WIRE_SEGMENTS
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()))
return list
}
override def getSlotMask = PartMap.CENTER.mask
def isBlockedOnSide(side: ForgeDirection): Boolean =
{
val blocker: TMultiPart = tile.partMap(side.ordinal)
testingSide = side
val expandable = NormalOcclusionTest.apply(this, blocker)
testingSide = null
return !expandable
}
def isCurrentlyConnected(side: ForgeDirection): Boolean = connectionMapContainsSide(clientRenderMask, side)
/** Packet Methods */
def sendConnectionUpdate()
{
if (!world.isRemote)
tile.getWriteStream(this).writeByte(0).writeByte(node)
}
override def readDesc(packet: MCDataInput)
{
super.readDesc(packet)
clientRenderMask = packet.readByte
}
override def writeDesc(packet: MCDataOutput)
{
super.writeDesc(packet)
packet.writeByte(clientRenderMask)
}
override def read(packet: MCDataInput, packetID: Int)
{
super.read(packet, packetID)
if (packetID == 0)
{
clientRenderMask = packet.readByte
tile.markRender()
}
}
def connectionMapContainsSide(connections: Int, side: ForgeDirection): Boolean =
{
val tester = 1 << side.ordinal
return (connections & tester) > 0
}
def connectionMapContainsSide(connections: Int, side: ForgeDirection): Boolean =
{
val tester = 1 << side.ordinal
return (connections & tester) > 0
}
}

View file

@ -76,7 +76,9 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
*/
var connectionMask = 0x00
override lazy val node = new FlatWireNode(this)
private val node = new FlatWireNode(this)
nodes.add(node)
def preparePlacement(side: Int, meta: Int)
{
@ -392,7 +394,7 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
val to = ForgeDirection.getOrientation(absDir)
val from = to.getOpposite
if(part != null)
if (part != null)
{
val node = part.asInstanceOf[INodeProvider].getNode(classOf[DCNode], from)
@ -466,7 +468,7 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
if (canConnect(dcNode, toDir))
{
if(dcNode.canConnect(this, ForgeDirection.UNKNOWN))
if (dcNode.canConnect(this, ForgeDirection.UNKNOWN))
{
connect(dcNode, toDir)
return true

View file

@ -12,7 +12,7 @@ import resonantinduction.core.prefab.part.connector.TColorable
*
* @author Calclavia, Darkguardsman
*/
class PipeNode(parent: PartPipe) extends NodePressure(parent) with TMultipartNode[IFluidHandler]
class NodePipe(parent: PartPipe) extends NodePressure(parent) with TMultipartNode[IFluidHandler]
{
def pipe: PartPipe = getParent.asInstanceOf[PartPipe]
@ -47,9 +47,9 @@ class PipeNode(parent: PartPipe) extends NodePressure(parent) with TMultipartNod
{
if (!pipe.isBlockedOnSide(from))
{
if (source.isInstanceOf[PipeNode])
if (source.isInstanceOf[NodePipe])
{
val otherNode = source.asInstanceOf[PipeNode]
val otherNode = source.asInstanceOf[NodePipe]
val otherPipe = otherNode.pipe

View file

@ -23,7 +23,7 @@ class PartPipe extends PartFramedNode with TMaterial[PipeMaterial] with TColorab
{
val tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME)
override lazy val node = new PipeNode(this)
override lazy val node = new NodePipe(this)
/**
* Computes the average fluid for client to render.