Added TNodePartConnector

This commit is contained in:
Calclavia 2014-09-14 15:02:11 +08:00
parent fa255a469b
commit 1678afe96e
7 changed files with 118 additions and 101 deletions

View file

@ -0,0 +1,28 @@
package resonantinduction.core.prefab
import codechicken.multipart.PartMap
import codechicken.multipart.TMultiPart
import codechicken.multipart.TileMultipart
import net.minecraftforge.common.util.ForgeDirection
import universalelectricity.api.core.grid.INode
import universalelectricity.api.core.grid.INodeProvider
/**
* Created by robert on 8/13/2014.
*/
class TNodeProvider extends TileMultipart with INodeProvider
{
def getNode(nodeType: Class[_ <: INode], from: ForgeDirection): INode =
{
var nodePart: TMultiPart = partMap(from.ordinal)
if (nodePart == null)
{
nodePart = partMap(PartMap.CENTER.ordinal)
}
if (nodePart.isInstanceOf[INodeProvider])
{
return (nodePart.asInstanceOf[INodeProvider]).getNode(nodeType, from)
}
return null
}
}

View file

@ -1,30 +0,0 @@
package resonantinduction.core.prefab;
import codechicken.multipart.PartMap;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.TileMultipart;
import net.minecraftforge.common.util.ForgeDirection;
import universalelectricity.api.core.grid.INode;
import universalelectricity.api.core.grid.INodeProvider;
/**
* Created by robert on 8/13/2014.
*/
public class TraitNodeProvider extends TileMultipart implements INodeProvider
{
@Override
public INode getNode(Class<? extends INode> nodeType, ForgeDirection from)
{
TMultiPart nodePart = partMap(from.ordinal());
if (nodePart == null)
{
nodePart = partMap(PartMap.CENTER.ordinal());
}
if (nodePart instanceof INodeProvider)
{
return ((INodeProvider) nodePart).getNode(nodeType, from);
}
return null;
}
}

View file

@ -41,12 +41,10 @@ object PartFramedNode
}
}
abstract class PartFramedNode extends TMultiPart with INodeProvider with TSlottedPart with TNormalOcclusion with TIconHitEffects
abstract class PartFramedNode extends TMultiPart with TNodePartConnector with TSlottedPart with TNormalOcclusion with TIconHitEffects
{
/** Bitmask connections */
var connectionMask: Byte = 0x00
protected var connections: Array[AnyRef] = new Array[AnyRef](6)
protected var node: INode = null
@SideOnly(Side.CLIENT)
protected var breakIcon: IIcon = null
@ -146,21 +144,6 @@ abstract class PartFramedNode extends TMultiPart with INodeProvider with TSlotte
return PartFramedNode.connectionMapContainsSide(getAllCurrentConnections, side)
}
override def onWorldJoin()
{
node.reconstruct()
}
override def onNeighborChanged()
{
node.reconstruct()
}
override def onWorldSeparate()
{
node.deconstruct()
}
/** Packet Methods */
def sendConnectionUpdate()
{
@ -192,34 +175,4 @@ abstract class PartFramedNode extends TMultiPart with INodeProvider with TSlotte
tile.markRender
}
}
def getNode(nodeType: Class[_ <: INode], from: ForgeDirection): INode =
{
if (node != null && nodeType != null)
{
return node
}
return null
}
override def save(nbt: NBTTagCompound)
{
super.save(nbt)
if (node.isInstanceOf[ISave])
node.asInstanceOf[ISave].save(nbt)
}
override def load(nbt: NBTTagCompound)
{
super.load(nbt)
if (node.isInstanceOf[ISave])
node.asInstanceOf[ISave].load(nbt)
}
def getNode: INode = node
def setNode(n: INode)
{ node = n }
}

View file

@ -0,0 +1,53 @@
package resonantinduction.core.prefab.part.connector
import codechicken.multipart.TMultiPart
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.common.util.ForgeDirection
import universalelectricity.api.core.grid.{INode, INodeProvider, ISave}
/**
* A node trait that can be mixed into any multipart nodes.
* @author Calclavia
*/
trait TNodePartConnector extends TMultiPart with INodeProvider
{
protected lazy val node: INode = null
override def onWorldJoin()
{
node.reconstruct()
}
override def onNeighborChanged()
{
node.reconstruct()
}
override def onWorldSeparate()
{
node.deconstruct()
}
override def save(nbt: NBTTagCompound)
{
super.save(nbt)
if (node.isInstanceOf[ISave])
node.asInstanceOf[ISave].save(nbt)
}
override def load(nbt: NBTTagCompound)
{
super.load(nbt)
if (node.isInstanceOf[ISave])
node.asInstanceOf[ISave].load(nbt)
}
override def getNode(nodeType: Class[_ <: INode], from: ForgeDirection): INode =
{
if (nodeType == node.getClass)
return node
return null
}
}

View file

@ -5,16 +5,16 @@ import codechicken.multipart.TMultiPart
import net.minecraft.item.{Item, ItemStack}
import net.minecraft.nbt.NBTTagCompound
import net.minecraftforge.common.util.ForgeDirection
import resonantinduction.core.prefab.part.connector.{TColorable, TInsulatable, TMaterial, TPart}
import resonantinduction.core.prefab.part.connector._
import resonantinduction.electrical.ElectricalContent
import universalelectricity.api.core.grid.INodeProvider
import universalelectricity.api.core.grid.{INode, INodeProvider}
import universalelectricity.simulator.dc.DCNode
/**
* Class extended by wires
* @author Calclavia
*/
abstract class TWire extends TMultiPart with TPart with TMaterial[WireMaterial] with TInsulatable with TColorable
abstract class TWire extends TMultiPart with TNodePartConnector with TPart with TMaterial[WireMaterial] with TInsulatable with TColorable
{
override protected val insulationItem: Item = ElectricalContent.itemInsulation

View file

@ -19,6 +19,8 @@ import net.minecraftforge.common.util.ForgeDirection
import org.lwjgl.opengl.GL11
import resonantinduction.core.util.MultipartUtil
import resonantinduction.electrical.wire.base.TWire
import universalelectricity.api.core.grid.{INodeProvider, INode}
import universalelectricity.simulator.dc.DCNode
import scala.collection.convert.wrapAll._
@ -50,7 +52,11 @@ object PartFlatWire
class PartFlatWire extends TWire with TFacePart with TNormalOcclusion
{
/**
* The current side the wire is placed on
*/
var side: Byte = 0
/**
* A map of the corners.
* <p/>
@ -65,6 +71,17 @@ class PartFlatWire extends TWire with TFacePart with TNormalOcclusion
*/
var connMap: Int = 0x00
override lazy val node = new FlatWireNode(this)
/**
* Flat wire node handles all the connection logic
* @param provider
*/
class FlatWireNode (provider:INodeProvider) extends DCNode(provider)
{
}
def connections: Array[AnyRef] =
{
return null
@ -72,7 +89,7 @@ class PartFlatWire extends TWire with TFacePart with TNormalOcclusion
def preparePlacement(side: Int, meta: Int)
{
this.side = (side ^ 1).asInstanceOf[Byte]
this.side = (side ^ 1).toByte
setMaterial(meta)
}
@ -135,24 +152,18 @@ class PartFlatWire extends TWire with TFacePart with TNormalOcclusion
super.onRemoved
if (!world.isRemote)
{
for (r <- 0 until 4)
{
var r: Int = 0
while (r < 4)
if (maskConnects(r))
{
if ((connMap & 1 << r) != 0)
{
if (maskConnects(r))
{
if ((connMap & 1 << r) != 0)
{
notifyCornerChange(r)
}
else if ((connMap & 0x10 << r) != 0)
{
notifyStraightChange(r)
}
}
notifyCornerChange(r)
}
else if ((connMap & 0x10 << r) != 0)
{
notifyStraightChange(r)
}
({r += 1; r - 1 })
}
}
}
@ -174,13 +185,15 @@ class PartFlatWire extends TWire with TFacePart with TNormalOcclusion
}
tile.markDirty
}
this.recalculateConnections
super.onChunkLoad
recalculateConnections()
super.onChunkLoad()
}
override def onAdded
{
super.onAdded
super.onAdded()
if (!world.isRemote)
{
updateOpenConnections

View file

@ -22,7 +22,7 @@ import resonantinduction.mechanical.fluid.pipe.PipeMaterials.PipeMaterial
*/
class PartPipe extends PartFramedNode with TMaterial[PipeMaterial] with TColorable with TSlottedPart with TNormalOcclusion with IFluidHandler
{
protected final val tank: FluidTank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME)
protected final val tank = new FluidTank(FluidContainerRegistry.BUCKET_VOLUME)
/**
* Computes the average fluid for client to render.
@ -30,7 +30,7 @@ class PartPipe extends PartFramedNode with TMaterial[PipeMaterial] with TColorab
private val averageTankData = new EvictingList[Integer](20)
private var markPacket: Boolean = true
setNode(new PipePressureNode(this))
override lazy val node = new PipePressureNode(this)
def preparePlacement(meta: Int)
{