Updated to new canConnect method

This commit is contained in:
Calclavia 2014-11-04 22:06:08 +08:00
parent 60341da346
commit edea703bac
10 changed files with 43 additions and 41 deletions

View file

@ -1,11 +1,8 @@
package resonantinduction.electrical.transformer
import net.minecraft.tileentity.TileEntity
import net.minecraftforge.common.util.ForgeDirection
import resonant.lib.grid.Compatibility
import resonant.api.grid.INodeProvider
import resonant.lib.grid.node.DCNode
import resonant.lib.transform.vector.VectorWorld
/**
* Created by robert on 8/11/2014.
@ -13,7 +10,7 @@ import resonant.lib.transform.vector.VectorWorld
class ElectricTransformerNode(parent: INodeProvider) extends DCNode(parent: INodeProvider)
{
var connectionDirection: ForgeDirection = ForgeDirection.NORTH
var input: Boolean = true;
var input = true
var otherNode: ElectricTransformerNode = null
var step: Int = 2
@ -33,12 +30,12 @@ class ElectricTransformerNode(parent: INodeProvider) extends DCNode(parent: INod
return 120
}
override def canConnect(source: AnyRef, from: ForgeDirection): Boolean =
override def canConnect[B <: DCNode](obj: B, from: ForgeDirection): Boolean =
{
return source.isInstanceOf[INodeProvider] && from == connectionDirection
return obj.isInstanceOf[INodeProvider] && from == connectionDirection
}
/*
/*
override def addEnergy(dir: ForgeDirection, wattage: Double, doAdd: Boolean): Double =
{
if (input)

View file

@ -441,7 +441,7 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
return true
}
}
else if (canConnect(part, toDir))
else if (canConnect(dcNode, toDir))
{
connect(dcNode, toDir)
return true
@ -844,7 +844,7 @@ class PartFlatWire extends PartAbstract with TWire with TFacePart with TNormalOc
return null
}
override def canConnect(node: AnyRef, from: ForgeDirection): Boolean =
override def canConnect[B <: DCNode](obj: B, from: ForgeDirection): Boolean =
{
if (node.isInstanceOf[FlatWireNode])
{

View file

@ -2,10 +2,10 @@ 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
import resonant.api.grid.INodeProvider
/**
* Pressure node for the pipe
@ -35,13 +35,13 @@ class PipePressureNode(parent: PartPipe) extends NodePressure(parent) with TMult
{
val check = tile.asInstanceOf[INodeProvider].getNode(classOf[NodePressure], dir.getOpposite)
if (check.isInstanceOf[NodePressure] && canConnect(check,dir) && check.asInstanceOf[NodePressure].canConnect(this, dir.getOpposite))
if (check.isInstanceOf[NodePressure] && canConnect(check, dir) && check.asInstanceOf[NodePressure].canConnect(this, dir.getOpposite))
{
pipe.connectionMask = pipe.connectionMask.openMask(dir)
connect(check, dir)
}
}
else if (canConnect(tile,dir))
else if (tile.isInstanceOf[IFluidHandler] && canConnect(tile.asInstanceOf[IFluidHandler], dir))
{
pipe.connectionMask = pipe.connectionMask.openMask(dir)
connect(tile.asInstanceOf[IFluidHandler], dir)
@ -56,7 +56,7 @@ class PipePressureNode(parent: PartPipe) extends NodePressure(parent) with TMult
}
}
override def canConnect(source: AnyRef, from: ForgeDirection): Boolean =
override def canConnect[B <: IFluidHandler](source: B, from: ForgeDirection): Boolean =
{
if (!pipe.isBlockedOnSide(from))
{

View file

@ -1,11 +1,13 @@
package resonantinduction.mechanical.fluid.transport
import net.minecraftforge.common.util.ForgeDirection
import net.minecraftforge.fluids.IFluidHandler
import resonantinduction.core.prefab.node.NodePressure
import resonant.api.grid.INodeProvider
/**
* Created by robert on 9/27/2014.
* A node for the pump
* @author Calclavia
*/
class PumpNode(parent: INodeProvider) extends NodePressure(parent)
{
@ -27,7 +29,7 @@ class PumpNode(parent: INodeProvider) extends NodePressure(parent)
return 0
}
override def canConnect(source: AnyRef, from: ForgeDirection): Boolean =
override def canConnect[B <: IFluidHandler](source: B, from: ForgeDirection): Boolean =
{
return super.canConnect(source, from) && (from == pump.getDirection || from == pump.getDirection.getOpposite)
}

View file

@ -315,15 +315,15 @@ public class MechanicalNode extends NodeConnector<MechanicalNode> implements TMu
}
@Override
public boolean canConnect(Object object, ForgeDirection direction)
public <B extends MechanicalNode> boolean canConnect(B other, ForgeDirection from)
{
if (canConnect(direction))
if (canConnect(from))
{
if (object instanceof INodeProvider)
if (other instanceof INodeProvider)
{
return ((INodeProvider) object).getNode(MechanicalNode.class, direction.getOpposite()) instanceof MechanicalNode;
return ((INodeProvider) other).getNode(MechanicalNode.class, from.getOpposite()) instanceof MechanicalNode;
}
return object instanceof MechanicalNode;
return other instanceof MechanicalNode;
}
return false;
}

View file

@ -4,6 +4,7 @@ import codechicken.lib.vec.Rotation
import codechicken.multipart.{TMultiPart, TileMultipart}
import net.minecraft.tileentity.TileEntity
import net.minecraftforge.common.util.ForgeDirection
import resonant.lib.grid.node.DCNode
import resonantinduction.core.interfaces.IMechanicalNode
import resonantinduction.mechanical.mech.MechanicalNode
import resonantinduction.mechanical.mech.gearshaft.PartGearShaft
@ -80,7 +81,7 @@ class GearNode(parent: PartGear) extends MechanicalNode(parent: PartGear)
}
if (tile.isInstanceOf[INodeProvider])
{
val instance: MechanicalNode = (tile.asInstanceOf[INodeProvider]).getNode(classOf[MechanicalNode], if (checkDir eq gear.placementSide.getOpposite) ForgeDirection.UNKNOWN else checkDir).asInstanceOf[MechanicalNode]
val instance: MechanicalNode = (tile.asInstanceOf[INodeProvider]).getNode(classOf[MechanicalNode], if (checkDir == gear.placementSide.getOpposite) ForgeDirection.UNKNOWN else checkDir).asInstanceOf[MechanicalNode]
if (!directionMap.containsValue(checkDir) && instance != this && checkDir != gear.placementSide && instance != null && instance.canConnect(this,checkDir.getOpposite))
{
connect(instance, checkDir)
@ -111,19 +112,19 @@ class GearNode(parent: PartGear) extends MechanicalNode(parent: PartGear)
* Can this gear be connected BY the source?
*
* @param from - Direction source is coming from.
* @param with - The source of the connection.
* @param other - The source of the connection.
* @return True is so.
*/
override def canConnect(`with`: AnyRef,from: ForgeDirection): Boolean =
override def canConnect[B](other: B, from: ForgeDirection): Boolean =
{
if (!gear.getMultiBlock.isPrimary)
{
return false
}
if (`with`.isInstanceOf[MechanicalNode])
if (other.isInstanceOf[MechanicalNode])
{
val parent: INodeProvider = (`with`.asInstanceOf[MechanicalNode]).getParent
if (from eq gear.placementSide.getOpposite)
val parent: INodeProvider = (other.asInstanceOf[MechanicalNode]).getParent
if (from == gear.placementSide.getOpposite)
{
if (parent.isInstanceOf[PartGear] || parent.isInstanceOf[PartGearShaft])
{
@ -168,21 +169,21 @@ class GearNode(parent: PartGear) extends MechanicalNode(parent: PartGear)
if (sourceTile.isInstanceOf[INodeProvider])
{
val sourceInstance: MechanicalNode = (sourceTile.asInstanceOf[INodeProvider]).getNode(classOf[MechanicalNode], from).asInstanceOf[MechanicalNode]
return sourceInstance eq `with`
return sourceInstance == other
}
}
else if (from eq gear.placementSide)
else if (from == gear.placementSide)
{
val sourceTile: TileEntity = position.add(from).getTileEntity(world)
if (sourceTile.isInstanceOf[INodeProvider])
{
val sourceInstance: MechanicalNode = (sourceTile.asInstanceOf[INodeProvider]).getNode(classOf[MechanicalNode], from.getOpposite).asInstanceOf[MechanicalNode]
return sourceInstance eq `with`
return sourceInstance == other
}
}
else
{
val destinationTile: TileEntity = (`with`.asInstanceOf[MechanicalNode]).position.add(from.getOpposite).getTileEntity(world)
val destinationTile: TileEntity = (other.asInstanceOf[MechanicalNode]).position.add(from.getOpposite).getTileEntity(world)
if (destinationTile.isInstanceOf[INodeProvider] && destinationTile.isInstanceOf[TileMultipart])
{
val destinationPart: TMultiPart = (destinationTile.asInstanceOf[TileMultipart]).partMap(gear.placementSide.ordinal)
@ -207,7 +208,7 @@ class GearNode(parent: PartGear) extends MechanicalNode(parent: PartGear)
return false
}
override def getRadius(dir: ForgeDirection, `with`: IMechanicalNode): Double =
override def getRadius(dir: ForgeDirection, `with`: IMechanicalNode): Double =
{
val deltaPos: Vector3 = new VectorWorld(`with`.asInstanceOf[IVectorWorld]).subtract(position)
val caseX: Boolean = gear.placementSide.offsetX != 0 && deltaPos.y == 0 && deltaPos.z == 0

View file

@ -61,13 +61,13 @@ class GearShaftNode(parent: INodeProvider) extends MechanicalNode(parent)
}
}
override def canConnect(source: AnyRef, from: ForgeDirection): Boolean =
override def canConnect[B](other: B, from: ForgeDirection): Boolean =
{
if (source.isInstanceOf[MechanicalNode])
if (other.isInstanceOf[MechanicalNode])
{
if ((source.asInstanceOf[MechanicalNode]).getParent.isInstanceOf[PartGear])
if ((other.asInstanceOf[MechanicalNode]).getParent.isInstanceOf[PartGear])
{
val gear: PartGear = (source.asInstanceOf[MechanicalNode]).getParent.asInstanceOf[PartGear]
val gear: PartGear = (other.asInstanceOf[MechanicalNode]).getParent.asInstanceOf[PartGear]
if (!(Math.abs(gear.placementSide.offsetX) == Math.abs(shaft.placementSide.offsetX) && Math.abs(gear.placementSide.offsetY) == Math.abs(shaft.placementSide.offsetY) && Math.abs(gear.placementSide.offsetZ) == Math.abs(shaft.placementSide.offsetZ)))
{
return false

View file

@ -16,7 +16,7 @@ class GrinderNode(parent: TileGrindingWheel) extends MechanicalNode(parent: Tile
return getParent.asInstanceOf[TileGrindingWheel]
}
override def canConnect(source: AnyRef, from: ForgeDirection): Boolean =
override def canConnect[B](other: B, from: ForgeDirection): Boolean =
{
if (grider.getDirection == ForgeDirection.UP || grider.getDirection == ForgeDirection.DOWN)
{
@ -25,6 +25,7 @@ class GrinderNode(parent: TileGrindingWheel) extends MechanicalNode(parent: Tile
return grider.getDirection != from && grider.getDirection.getOpposite != from
}
override def inverseRotation(dir: ForgeDirection): Boolean =
{
return !(dir.offsetX > 0 || dir.offsetZ < 0 || dir.offsetY < 0)

View file

@ -35,15 +35,16 @@ class TileWaterTurbine extends TileTurbine
mechanicalNode.torque = defaultTorque
mechanicalNode = new TurbineNode((this))
{
override def canConnect(source: AnyRef, from: ForgeDirection): Boolean =
override def canConnect[B](other: B, from: ForgeDirection): Boolean =
{
if (source.isInstanceOf[MechanicalNode] && !(source.isInstanceOf[TileTurbine]))
if (other.isInstanceOf[MechanicalNode] && !(other.isInstanceOf[TileTurbine]))
{
val sourceTile: TileEntity = position.add(from).getTileEntity(getWorld)
if (sourceTile.isInstanceOf[INodeProvider])
{
val sourceInstance: MechanicalNode = sourceTile.asInstanceOf[INodeProvider].getNode(classOf[MechanicalNode], from.getOpposite).asInstanceOf[MechanicalNode]
return sourceInstance == source && (from == getDirection.getOpposite || from == getDirection)
return sourceInstance == other && (from == getDirection.getOpposite || from == getDirection)
}
}
return false

View file

@ -17,9 +17,9 @@ class TurbineNode(tileTurbineBase: TileTurbine) extends MechanicalNode(tileTurbi
return getParent.asInstanceOf[TileTurbine]
}
override def canConnect(source: AnyRef, from: ForgeDirection): Boolean =
override def canConnect[B](other: B, from: ForgeDirection): Boolean =
{
return turbine.getMultiBlock.isPrimary && source.isInstanceOf[MechanicalNode] && !(source.isInstanceOf[TurbineNode]) && from == turbine.getDirection
return turbine.getMultiBlock.isPrimary && other.isInstanceOf[MechanicalNode] && !(other.isInstanceOf[TurbineNode]) && from == turbine.getDirection
}
override def inverseRotation(dir: ForgeDirection): Boolean =