Fixed pipe connections

This commit is contained in:
Calclavia 2014-09-21 14:47:53 +08:00
parent 928356ed27
commit 87b100b6a5
9 changed files with 125 additions and 178 deletions

View file

@ -24,7 +24,8 @@ object ResonantPartFactory extends IPartFactory
{
MultiPartRegistry.registerParts(this, partMap.keys.toArray)
MultipartGenerator.registerTrait("universalelectricity.api.core.grid.INodeProvider", "resonantinduction.core.prefab.TNodeProvider")
MultipartGenerator.registerTrait("universalelectricity.api.core.grid.INodeProvider", "resonantinduction.core.prefab.pass.TNodeProvider")
MultipartGenerator.registerPassThroughInterface("net.minecraftforge.fluids.IFluidHandler")
}
def createPart(name: String, client: Boolean): TMultiPart =

View file

@ -4,7 +4,8 @@ import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids._
/**
* Created by robert on 8/14/2014.
* Multipart Trait
* @author Calclavia
*/
trait TFluidHandler extends IFluidHandler
{

View file

@ -1,29 +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.
*/
class TNodeProvider extends TileMultipart with INodeProvider
{
def getNode(nodeType: Class[_ <: INode], from: ForgeDirection): INode =
{
var nodePart = 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

@ -81,9 +81,7 @@ abstract class PartFramedNode extends PartAbstract with TNodePartConnector with
return list
}
def getSlotMask = PartMap.CENTER.mask
def getHollowSize: Int = if (this.isInstanceOf[TInsulatable] && this.asInstanceOf[TInsulatable].insulated) 8 else 6
override def getSlotMask = PartMap.CENTER.mask
def isBlockedOnSide(side: ForgeDirection): Boolean =
{

View file

@ -46,7 +46,7 @@ trait TNodePartConnector extends TMultiPart with INodeProvider
override def getNode(nodeType: Class[_ <: INode], from: ForgeDirection): INode =
{
if (nodeType == node.getClass)
if (nodeType.isAssignableFrom(node.getClass) || node.getClass == nodeType)
return node
return null
}

View file

@ -0,0 +1,25 @@
package resonantinduction.core.prefab.pass
import codechicken.multipart.{PartMap, TileMultipart}
import net.minecraftforge.common.util.ForgeDirection
import universalelectricity.api.core.grid.{INode, INodeProvider}
/**
* Multipart Trait
* @author Calclavia
*/
class TNodeProvider extends TileMultipart with INodeProvider
{
def getNode(nodeType: Class[_ <: INode], from: ForgeDirection): INode =
{
var nodePart = 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,9 +1,8 @@
package resonantinduction.mechanical.fluid.pipe
import codechicken.lib.data.{MCDataOutput, MCDataInput}
import codechicken.lib.data.{MCDataInput, MCDataOutput}
import codechicken.lib.render.CCRenderState
import codechicken.lib.vec.Vector3
import codechicken.multipart.{TNormalOcclusion, TSlottedPart}
import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.minecraft.client.renderer.RenderBlocks
import net.minecraft.item.ItemStack
@ -138,65 +137,45 @@ class PartPipe extends PartFramedNode with TMaterial[PipeMaterial] with TColorab
RenderPipe.render(this, pos.x, pos.y, pos.z, frame)
}
def getItem: ItemStack =
{
return new ItemStack(Mechanical.itemPipe, 1, getMaterialID)
}
def getItem: ItemStack = new ItemStack(Mechanical.itemPipe, 1, getMaterialID)
def fill(from: ForgeDirection, resource: FluidStack, doFill: Boolean): Int =
override def fill(from: ForgeDirection, resource: FluidStack, doFill: Boolean): Int =
{
if (!world.isRemote)
{
if (doFill)
{
markPacket = true
}
return tank.fill(resource, doFill)
}
return 0
}
def drain(from: ForgeDirection, resource: FluidStack, doDrain: Boolean): FluidStack =
override def drain(from: ForgeDirection, resource: FluidStack, doDrain: Boolean): FluidStack =
{
return drain(from, resource.amount, doDrain)
}
def drain(from: ForgeDirection, maxDrain: Int, doDrain: Boolean): FluidStack =
override def drain(from: ForgeDirection, maxDrain: Int, doDrain: Boolean): FluidStack =
{
if (!world.isRemote)
{
if (doDrain)
{
markPacket = true
}
return tank.drain(maxDrain, doDrain)
}
return null
}
def canFill(from: ForgeDirection, fluid: Fluid): Boolean =
{
return true
}
override def canFill(from: ForgeDirection, fluid: Fluid): Boolean = true
def canDrain(from: ForgeDirection, fluid: Fluid): Boolean =
{
return true
}
override def canDrain(from: ForgeDirection, fluid: Fluid): Boolean = true
def getTankInfo(from: ForgeDirection): Array[FluidTankInfo] =
{
return Array[FluidTankInfo](tank.getInfo)
}
override def getTankInfo(from: ForgeDirection): Array[FluidTankInfo] = Array[FluidTankInfo](tank.getInfo)
override def drawBreaking(renderBlocks: RenderBlocks)
{
CCRenderState.reset()
}
override def getSlotMask: Int =
{
return 0
}
}

View file

@ -1,112 +0,0 @@
package resonantinduction.mechanical.fluid.pipe;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.IFluidHandler;
import resonant.lib.utility.WorldUtility;
import resonantinduction.core.prefab.node.NodePressure;
import resonantinduction.core.prefab.part.connector.TColorable$;
import universalelectricity.api.core.grid.INode;
import universalelectricity.api.core.grid.INodeProvider;
/**
* Pressure node for the pipe
*
* @author Calclavia, Darkguardsman
*/
public class PipePressureNode extends NodePressure
{
public PipePressureNode(PartPipe parent)
{
super(parent);
}
public PartPipe pipe()
{
return (PartPipe) this.getParent();
}
public void doRecache()
{
connections.clear();
if (world() != null)
{
int previousConnections = pipe().connectionMask();
pipe().connectionMask_$eq((byte) 0);
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS)
{
TileEntity tile = position().add(dir).getTileEntity(world());
if (tile instanceof IFluidHandler)
{
if (tile instanceof INodeProvider)
{
// If anything happens while trying to access the node then forget about it.
INode check = null;
try
{
check = ((INodeProvider) tile).getNode(NodePressure.class, dir.getOpposite());
}
catch (Exception err)
{
check = null;
}
if (check != null && check instanceof NodePressure && canConnect(dir, check) && ((NodePressure) check).canConnect(dir.getOpposite(), this))
{
pipe().connectionMask_$eq(WorldUtility.setEnableSide(pipe().connectionMask(), dir, true));
connections.put(check, dir);
}
}
else if (canConnect(dir, tile))
{
pipe().connectionMask_$eq(WorldUtility.setEnableSide(pipe().connectionMask(), dir, true));
connections.put(tile, dir);
}
}
}
/** Only send packet updates if visuallyConnected changed. */
if (!world().isRemote && previousConnections != pipe().connectionMask())
{
pipe().sendConnectionUpdate();
}
}
}
@Override
public boolean canConnect(ForgeDirection from, Object source)
{
if (!pipe().isBlockedOnSide(from))
{
if (source instanceof NodePressure)
{
NodePressure otherNode = (NodePressure) source;
if (otherNode.getParent() instanceof PartPipe)
{
PartPipe otherPipe = (PartPipe) otherNode.getParent();
if (!otherPipe.isBlockedOnSide(from.getOpposite()) && pipe().material() == otherPipe.material())
{
return pipe().getColor() == otherPipe.getColor() || (pipe().getColor() == TColorable$.MODULE$.defaultColor() || otherPipe.getColor() == TColorable$.MODULE$.defaultColor());
}
return false;
}
}
return super.canConnect(from, source) || source instanceof IFluidHandler;
}
return false;
}
@Override
public String toString()
{
return this.getClass().getSimpleName() + this.hashCode();
}
}

View file

@ -0,0 +1,84 @@
package resonantinduction.mechanical.fluid.pipe
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids.IFluidHandler
import resonant.lib.wrapper.BitmaskWrapper._
import resonantinduction.core.prefab.node.{TMultipartNode, NodePressure}
import resonantinduction.core.prefab.part.connector.TColorable
import universalelectricity.api.core.grid.INodeProvider
/**
* Pressure node for the pipe
*
* @author Calclavia, Darkguardsman
*/
class PipePressureNode(parent: PartPipe) extends NodePressure(parent) with TMultipartNode
{
def pipe: PartPipe = getParent.asInstanceOf[PartPipe]
override def buildConnections()
{
connections.clear()
if (world != null)
{
val previousConnections = pipe.connectionMask
pipe.connectionMask = 0
for (dir <- ForgeDirection.VALID_DIRECTIONS)
{
val tile = position.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(dir, check) && check.asInstanceOf[NodePressure].canConnect(dir.getOpposite, this))
{
pipe.connectionMask = pipe.connectionMask.openMask(dir)
connections.put(check, dir)
}
}
else if (canConnect(dir, tile))
{
pipe.connectionMask = pipe.connectionMask.openMask(dir)
connections.put(tile, dir)
}
}
}
if (!world.isRemote && previousConnections != pipe.connectionMask)
{
pipe.sendConnectionUpdate
}
}
}
override def canConnect(from: ForgeDirection, source: AnyRef): Boolean =
{
if (!pipe.isBlockedOnSide(from))
{
if (source.isInstanceOf[PipePressureNode])
{
val otherNode = source.asInstanceOf[PipePressureNode]
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(from, source) || source.isInstanceOf[IFluidHandler]
}
return false
}
override def toString: String = getClass.getSimpleName + hashCode
}