TPartNodeProvider now supports multiple nodes
This commit is contained in:
parent
5a7af55b39
commit
e480b76b64
|
@ -1,9 +1,14 @@
|
|||
package resonantinduction.core.prefab.part.connector
|
||||
|
||||
import java.util
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import resonant.api.ISave
|
||||
import resonant.api.grid.{INode, INodeProvider}
|
||||
import resonant.lib.grid.node.Node
|
||||
|
||||
import scala.collection.convert.wrapAll._
|
||||
|
||||
/**
|
||||
* A node trait that can be mixed into any multipart nodes. Mixing this trait will cause nodes to reconstruct/deconstruct when needed.
|
||||
|
@ -11,50 +16,47 @@ import resonant.api.grid.{INode, INodeProvider}
|
|||
*/
|
||||
trait TPartNodeProvider extends PartAbstract with INodeProvider
|
||||
{
|
||||
protected lazy val node: INode = null
|
||||
protected val nodes = new util.HashSet[Node]
|
||||
|
||||
override def start()
|
||||
{
|
||||
super.start()
|
||||
node.reconstruct()
|
||||
|
||||
if (!world.isRemote)
|
||||
nodes.foreach(_.reconstruct())
|
||||
}
|
||||
|
||||
override def onWorldJoin()
|
||||
{
|
||||
node.reconstruct()
|
||||
if (!world.isRemote)
|
||||
nodes.foreach(_.reconstruct())
|
||||
}
|
||||
|
||||
override def onNeighborChanged()
|
||||
{
|
||||
node.reconstruct()
|
||||
if (!world.isRemote)
|
||||
nodes.foreach(_.reconstruct())
|
||||
}
|
||||
|
||||
override def onWorldSeparate()
|
||||
{
|
||||
node.deconstruct()
|
||||
nodes.foreach(_.deconstruct())
|
||||
}
|
||||
|
||||
override def save(nbt: NBTTagCompound)
|
||||
{
|
||||
super.save(nbt)
|
||||
|
||||
if (node.isInstanceOf[ISave])
|
||||
node.asInstanceOf[ISave].save(nbt)
|
||||
nodes.filter(_.isInstanceOf[ISave]).foreach(_.asInstanceOf[ISave].save(nbt))
|
||||
}
|
||||
|
||||
override def load(nbt: NBTTagCompound)
|
||||
{
|
||||
super.load(nbt)
|
||||
|
||||
if (node.isInstanceOf[ISave])
|
||||
node.asInstanceOf[ISave].load(nbt)
|
||||
nodes.filter(_.isInstanceOf[ISave]).foreach(_.asInstanceOf[ISave].load(nbt))
|
||||
}
|
||||
|
||||
override def getNode[N <: INode](nodeType: Class[_ <: N], from: ForgeDirection): N =
|
||||
{
|
||||
if (nodeType.isAssignableFrom(node.getClass))
|
||||
return node.asInstanceOf[N]
|
||||
|
||||
return null.asInstanceOf[N]
|
||||
return nodes.filter(node => nodeType.isAssignableFrom(node.getClass)).headOption.getOrElse(null).asInstanceOf[N]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 PipePressureNode(this)
|
||||
override lazy val node = new PipeNode(this)
|
||||
|
||||
/**
|
||||
* Computes the average fluid for client to render.
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
package resonantinduction.mechanical.fluid.pipe
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import net.minecraftforge.fluids.IFluidHandler
|
||||
import resonant.api.grid.INodeProvider
|
||||
import resonant.lib.wrapper.BitmaskWrapper._
|
||||
import resonantinduction.core.prefab.node.{NodePressure, TMultipartNode}
|
||||
import resonantinduction.core.prefab.part.connector.TColorable
|
||||
|
||||
/**
|
||||
* Pressure node for the pipe
|
||||
*
|
||||
* @author Calclavia, Darkguardsman
|
||||
*/
|
||||
class PipeNode(parent: PartPipe) extends NodePressure(parent) with TMultipartNode[IFluidHandler]
|
||||
{
|
||||
def pipe: PartPipe = getParent.asInstanceOf[PartPipe]
|
||||
|
||||
onConnectionChanged = () => if (!world.isRemote) pipe.sendConnectionUpdate()
|
||||
|
||||
override def rebuild()
|
||||
{
|
||||
for (dir <- ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
val tile = toVectorWorld.add(dir).getTileEntity(world)
|
||||
|
||||
if (tile.isInstanceOf[IFluidHandler])
|
||||
{
|
||||
if (tile.isInstanceOf[INodeProvider])
|
||||
{
|
||||
val check = tile.asInstanceOf[INodeProvider].getNode(classOf[NodePressure], dir.getOpposite)
|
||||
|
||||
if (check.isInstanceOf[NodePressure] && canConnect(check, dir) && check.asInstanceOf[NodePressure].canConnect(this, dir.getOpposite))
|
||||
{
|
||||
connect(check, dir)
|
||||
}
|
||||
}
|
||||
else if (tile.isInstanceOf[IFluidHandler] && canConnect(tile.asInstanceOf[IFluidHandler], dir))
|
||||
{
|
||||
connect(tile.asInstanceOf[IFluidHandler], dir)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override def canConnect[B <: IFluidHandler](source: B, from: ForgeDirection): Boolean =
|
||||
{
|
||||
if (!pipe.isBlockedOnSide(from))
|
||||
{
|
||||
if (source.isInstanceOf[PipeNode])
|
||||
{
|
||||
val otherNode = source.asInstanceOf[PipeNode]
|
||||
|
||||
val otherPipe = otherNode.pipe
|
||||
|
||||
if (!otherPipe.isBlockedOnSide(from.getOpposite) && pipe.material == otherPipe.material)
|
||||
{
|
||||
return pipe.getColor == otherPipe.getColor || (pipe.getColor == TColorable.defaultColor || otherPipe.getColor == TColorable.defaultColor)
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
return super.canConnect(source, from) || source.isInstanceOf[IFluidHandler]
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue