2015-01-14 12:06:03 +01:00
|
|
|
package edx.mechanical.mech.gearshaft
|
2014-09-27 19:52:43 +02:00
|
|
|
|
2015-01-14 12:06:03 +01:00
|
|
|
import edx.core.interfaces.TNodeMechanical
|
|
|
|
import edx.mechanical.mech.gear.{NodeGear, PartGear}
|
|
|
|
import edx.mechanical.mech.grid.NodeMechanical
|
2014-09-27 19:52:43 +02:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection
|
2014-12-09 23:46:07 +01:00
|
|
|
import resonant.api.tile.INodeProvider
|
2014-10-27 18:31:42 +01:00
|
|
|
import resonant.lib.transform.vector.Vector3
|
2014-11-10 12:28:36 +01:00
|
|
|
import resonant.lib.wrapper.ForgeDirectionWrapper._
|
2014-09-27 19:52:43 +02:00
|
|
|
|
2014-11-22 11:25:59 +01:00
|
|
|
class NodeGearShaft(parent: PartGearShaft) extends NodeMechanical(parent)
|
2014-09-27 19:52:43 +02:00
|
|
|
{
|
2015-01-22 16:10:36 +01:00
|
|
|
override def inertia: Double =
|
2014-10-26 15:41:40 +01:00
|
|
|
{
|
2014-11-09 07:07:39 +01:00
|
|
|
return shaft.tier match
|
2014-09-27 19:52:43 +02:00
|
|
|
{
|
2015-01-23 07:54:19 +01:00
|
|
|
case 0 => 3
|
|
|
|
case 1 => 5
|
|
|
|
case 2 => 4
|
2014-11-09 07:49:56 +01:00
|
|
|
}
|
|
|
|
}
|
2014-09-27 19:52:43 +02:00
|
|
|
|
2015-01-14 12:06:03 +01:00
|
|
|
def shaft: PartGearShaft = getParent.asInstanceOf[PartGearShaft]
|
|
|
|
|
2014-11-09 07:07:39 +01:00
|
|
|
override def rebuild()
|
2014-10-26 15:41:40 +01:00
|
|
|
{
|
2014-11-09 07:49:56 +01:00
|
|
|
//Check only two possible sides for connections
|
|
|
|
for (toDir <- Seq(shaft.placementSide, shaft.placementSide.getOpposite))
|
2014-10-26 15:41:40 +01:00
|
|
|
{
|
2014-11-09 07:49:56 +01:00
|
|
|
var found = false
|
|
|
|
|
|
|
|
///Check within this block for another gear plate that will move this shaft
|
2014-11-13 03:22:46 +01:00
|
|
|
val otherNode = shaft.tile.asInstanceOf[INodeProvider].getNode(classOf[NodeMechanical], toDir)
|
2014-11-09 07:49:56 +01:00
|
|
|
|
|
|
|
if (otherNode != null && otherNode != this && canConnect(otherNode, toDir) && otherNode.canConnect(this, toDir.getOpposite))
|
2014-10-26 15:41:40 +01:00
|
|
|
{
|
2014-11-09 07:49:56 +01:00
|
|
|
connect(otherNode, toDir)
|
|
|
|
found = true
|
|
|
|
}
|
2014-11-02 12:33:59 +01:00
|
|
|
|
2014-11-09 07:49:56 +01:00
|
|
|
if (!found)
|
|
|
|
{
|
|
|
|
///Check for other gear shafts outside this tile
|
|
|
|
val checkTile = new Vector3(shaft.tile).add(toDir).getTileEntity(world)
|
|
|
|
|
|
|
|
if (checkTile.isInstanceOf[INodeProvider])
|
2014-09-27 19:52:43 +02:00
|
|
|
{
|
2014-11-26 16:13:49 +01:00
|
|
|
val instance = checkTile.asInstanceOf[INodeProvider].getNode(classOf[NodeMechanical], toDir.getOpposite)
|
2014-11-09 07:49:56 +01:00
|
|
|
|
2014-11-26 16:13:49 +01:00
|
|
|
if (instance != null && instance != this && instance.getParent.isInstanceOf[PartGearShaft] && canConnect(instance, toDir) && instance.canConnect(this, toDir.getOpposite))
|
2014-10-26 15:41:40 +01:00
|
|
|
{
|
2014-11-09 07:49:56 +01:00
|
|
|
connect(instance, toDir)
|
2014-10-26 15:41:40 +01:00
|
|
|
}
|
2014-09-27 19:52:43 +02:00
|
|
|
}
|
2014-10-26 15:41:40 +01:00
|
|
|
}
|
2014-09-27 19:52:43 +02:00
|
|
|
}
|
2014-10-26 15:41:40 +01:00
|
|
|
}
|
2014-09-27 19:52:43 +02:00
|
|
|
|
2014-11-04 15:06:08 +01:00
|
|
|
override def canConnect[B](other: B, from: ForgeDirection): Boolean =
|
2014-10-26 15:41:40 +01:00
|
|
|
{
|
2014-11-13 03:22:46 +01:00
|
|
|
if (other.isInstanceOf[NodeMechanical])
|
2014-09-27 19:52:43 +02:00
|
|
|
{
|
2014-11-26 16:13:49 +01:00
|
|
|
if (other.asInstanceOf[NodeMechanical].getParent.isInstanceOf[PartGear])
|
2014-10-26 15:41:40 +01:00
|
|
|
{
|
2014-11-26 16:13:49 +01:00
|
|
|
val gear = other.asInstanceOf[NodeMechanical].getParent.asInstanceOf[PartGear]
|
2014-10-26 15:41:40 +01:00
|
|
|
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)))
|
2014-09-27 19:52:43 +02:00
|
|
|
{
|
2014-10-26 15:41:40 +01:00
|
|
|
return false
|
2014-09-27 19:52:43 +02:00
|
|
|
}
|
2014-10-26 15:41:40 +01:00
|
|
|
}
|
2014-09-27 19:52:43 +02:00
|
|
|
}
|
2014-11-26 16:13:49 +01:00
|
|
|
|
2014-10-26 15:41:40 +01:00
|
|
|
return from == shaft.placementSide || from == shaft.placementSide.getOpposite
|
|
|
|
}
|
2014-09-27 19:52:43 +02:00
|
|
|
|
2014-11-19 05:12:53 +01:00
|
|
|
override def inverseRotation(other: TNodeMechanical): Boolean = other.isInstanceOf[NodeGear] && other.asInstanceOf[NodeGear].parent.asInstanceOf[PartGear].placementSide.offset < Vector3.zero
|
2014-09-27 19:52:43 +02:00
|
|
|
}
|