Fixed some gear connection logic

This commit is contained in:
Calclavia 2014-11-23 11:59:44 +08:00
parent b70ddf1e04
commit 6328ced137
4 changed files with 44 additions and 25 deletions

View file

@ -68,7 +68,7 @@ class NodeGear(parent: PartGear) extends NodeMechanical(parent: PartGear)
}
if (tile.isInstanceOf[INodeProvider])
{
val instance: NodeMechanical = (tile.asInstanceOf[INodeProvider]).getNode(classOf[NodeMechanical], if (checkDir == gear.placementSide.getOpposite) ForgeDirection.UNKNOWN else checkDir).asInstanceOf[NodeMechanical]
val instance: NodeMechanical = tile.asInstanceOf[INodeProvider].getNode(classOf[NodeMechanical], if (checkDir == gear.placementSide.getOpposite) ForgeDirection.UNKNOWN else checkDir).asInstanceOf[NodeMechanical]
if (!directionMap.containsValue(checkDir) && instance != this && checkDir != gear.placementSide && instance != null && instance.canConnect(this, checkDir.getOpposite))
{
connect(instance, checkDir)
@ -87,11 +87,11 @@ class NodeGear(parent: PartGear) extends NodeMechanical(parent: PartGear)
if (!directionMap.containsValue(toDir) && checkTile.isInstanceOf[INodeProvider])
{
val instance = checkTile.asInstanceOf[INodeProvider].getNode(classOf[NodeMechanical], gear.placementSide)
val other = checkTile.asInstanceOf[INodeProvider].getNode(classOf[NodeMechanical], gear.placementSide)
if (instance != null && instance != this && instance.canConnect(this, toDir.getOpposite) && !instance.isInstanceOf[NodeGearShaft])
if (other != null && other != this && canConnect(other, toDir.getOpposite) && other.canConnect(this, toDir) && !other.isInstanceOf[NodeGearShaft])
{
connect(instance, toDir)
connect(other, toDir)
}
}
}
@ -178,27 +178,33 @@ class NodeGear(parent: PartGear) extends NodeMechanical(parent: PartGear)
}
else
{
//This object is from the sides of the gear
val otherTile = other.asInstanceOf[NodeMechanical].toVectorWorld.add(from.getOpposite).getTileEntity
if (otherTile.isInstanceOf[INodeProvider] && otherTile.isInstanceOf[TileMultipart])
//This object is from the sides of the gear. It can either be a gear within this block or outside
if (other.isInstanceOf[NodeGear])
{
val otherPart = otherTile.asInstanceOf[TileMultipart].partMap(gear.placementSide.ordinal)
if (otherPart.isInstanceOf[PartGear])
val otherParent = other.parent.asInstanceOf[PartGear]
//Check inside this block
if (otherParent.tile == parent.tile)
{
if (gear != otherPart)
{
return otherPart.asInstanceOf[PartGear].isCenterMultiBlock
}
else
{
return true
}
return otherParent.placementSide != parent.placementSide && otherParent != parent.placementSide.getOpposite
}
else
//Check for gear outside this block placed on the same plane
val otherTile = other.toVectorWorld.getTileEntity
if (otherTile.isInstanceOf[TileMultipart])
{
return true
if (otherTile.asInstanceOf[TileMultipart].partMap(gear.placementSide.ordinal()) == other.parent)
{
//We found another gear, but check if we are connecting to the center spaces of the gear
//If this is a multiblock, "otherTile" would be the center of that gear, not the adjacent
val adjacentTile = toVectorWorld.add(from.getOpposite).getTileEntity
if (adjacentTile.isInstanceOf[TileMultipart])
{
val adjacentPart = adjacentTile.asInstanceOf[TileMultipart].partMap(gear.placementSide.ordinal)
return adjacentPart.asInstanceOf[PartGear].isCenterMultiBlock
}
}
}
}
}

View file

@ -43,14 +43,21 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
if (world != null) sendPacket(2)
}
mechanicalNode.onGridReconstruct = () => if (world != null && !world.isRemote) sendPacket(2)
mechanicalNode.onGridReconstruct = () =>
{
if (world != null)
{
sendPacket(1)
sendPacket(2)
}
}
//TODO: Can we not have update ticks here?
override def update()
{
super.update()
if (!this.world.isRemote)
if (!world.isRemote)
{
if (manualCrankTime > 0)
{
@ -66,7 +73,7 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
override def activate(player: EntityPlayer, hit: MovingObjectPosition, itemStack: ItemStack): Boolean =
{
if (!world.isRemote)
println(mechanicalNode)
println(mechanicalNode + " in " + mechanicalNode.grid)
if (itemStack != null && itemStack.getItem.isInstanceOf[ItemHandCrank])
{

View file

@ -9,7 +9,7 @@ import resonantinduction.mechanical.mech.grid.NodeMechanical
*/
class NodeGrinder(parent: TileGrindingWheel) extends NodeMechanical(parent: TileGrindingWheel)
{
override def getLoad = 1000d
override def getLoad = 1000d * angularVelocity
override def canConnect[B <: NodeMechanical](other: B, from: ForgeDirection): Boolean =
{

View file

@ -44,6 +44,12 @@ class TileGrindingWheel extends TileMechanical(Material.rock)
super.update()
counter = Math.max(counter + Math.abs(mechanicalNode.torque), 0)
doWork()
if(!world.isRemote)
{
println(mechanicalNode)
sendPacket(1)
}
}
override def collide(entity: Entity)