Big gears can now be constructed

This commit is contained in:
Calclavia 2014-11-13 14:17:05 +08:00
parent 08977ccbfb
commit 03e04b3ae3
4 changed files with 33 additions and 38 deletions

View file

@ -1,21 +1,21 @@
package resonantinduction.mechanical.mech.gear
import codechicken.multipart.{TMultiPart, TileMultipart}
import net.minecraft.tileentity.TileEntity
import net.minecraftforge.common.util.ForgeDirection
import resonant.lib.multiblock.reference.MultiBlockHandler
import resonant.lib.transform.vector.Vector3
import codechicken.multipart.TMultiPart
import codechicken.multipart.TileMultipart
class GearMultiBlockHandler(wrapper: PartGear) extends MultiBlockHandler[PartGear](wrapper: PartGear)
{
override def getWrapperAt(position: Vector3): PartGear =
{
val tile: TileEntity = position.getTileEntity(this.tile.getWorld)
val tile = position.getTileEntity(this.tile.getWorld)
if (tile.isInstanceOf[TileMultipart])
{
val part: TMultiPart = (tile.asInstanceOf[TileMultipart]).partMap(getPlacementSide.ordinal)
val part = tile.asInstanceOf[TileMultipart].partMap(getPlacementSide.ordinal)
if (part.isInstanceOf[PartGear])
{
if ((part.asInstanceOf[PartGear]).tier == this.tile.tier)
@ -27,8 +27,5 @@ class GearMultiBlockHandler(wrapper: PartGear) extends MultiBlockHandler[PartGea
return null
}
def getPlacementSide: ForgeDirection =
{
return tile.placementSide
}
def getPlacementSide: ForgeDirection = tile.placementSide
}

View file

@ -199,8 +199,11 @@ class NodeGear(parent: PartGear) extends NodeMechanical(parent: PartGear)
override def inverseRotation(other: TMechanicalNode): Boolean = !other.isInstanceOf[GearShaftNode] || (other.isInstanceOf[GearShaftNode] && parent.placementSide.offset < Vector3.zero)
override def ratio = if (gear.getMultiBlock.isConstructed) 1.5f else super.ratio
override def getRadius(dir: ForgeDirection, other: TMechanicalNode): Double =
{
//The ratio is the same if it is a gear placed back to back with each other OR a shaft
val deltaPos: Vector3 = new VectorWorld(other.asInstanceOf[IVectorWorld]).subtract(toVectorWorld)
val caseX = gear.placementSide.offsetX != 0 && deltaPos.y == 0 && deltaPos.z == 0
val caseY = gear.placementSide.offsetY != 0 && deltaPos.x == 0 && deltaPos.z == 0

View file

@ -32,7 +32,7 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
var manualCrankTime = 0D
var multiBlockRadius: Int = 1
/** Multiblock */
var multiBlock: GearMultiBlockHandler = null
val multiBlock = new GearMultiBlockHandler(this)
//Constructor
mechanicalNode = new NodeGear(this)
@ -63,6 +63,8 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
override def activate(player: EntityPlayer, hit: MovingObjectPosition, itemStack: ItemStack): Boolean =
{
if (!world.isRemote)
println(mechanicalNode.connections)
if (itemStack != null && itemStack.getItem.isInstanceOf[ItemHandCrank])
{
if (!world.isRemote && ControlKeyModifer.isControlDown(player))
@ -79,11 +81,13 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
player.addExhaustion(0.01f)
return true
}
if (WrenchUtility.isWrench(itemStack))
{
getMultiBlock.toggleConstruct
getMultiBlock.toggleConstruct()
return true
}
return super.activate(player, hit, itemStack)
}
@ -96,7 +100,7 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
/** Is this gear block the one in the center-edge of the multiblock that can interact with other
* gears?
*
* @return*/
* @return */
def isCenterMultiBlock: Boolean =
{
if (!getMultiBlock.isConstructed)
@ -143,12 +147,7 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
getMultiBlock.save(nbt)
}
override def getMultiBlockVectors: java.util.List[resonant.lib.transform.vector.Vector3] =
{
val vec = new resonant.lib.transform.vector.Vector3(this.x, this.y, this.z)
var array: java.util.List[resonant.lib.transform.vector.Vector3] = vec.getAround(this.world, placementSide, 1)
return array
}
override def getMultiBlockVectors: java.util.List[resonant.lib.transform.vector.Vector3] = new resonant.lib.transform.vector.Vector3().getAround(this.world, placementSide, 1)
def getWorld: World =
{
@ -167,11 +166,7 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
}
}
def getMultiBlock: GearMultiBlockHandler =
{
if (multiBlock == null) multiBlock = new GearMultiBlockHandler(this)
return multiBlock
}
override def getMultiBlock: GearMultiBlockHandler = multiBlock
override def getNode[N <: INode](nodeType: Class[_ <: N], from: ForgeDirection): N =
{

View file

@ -67,19 +67,19 @@ class MechanicalGrid extends GridNode[NodeMechanical](classOf[NodeMechanical]) w
val prevAngularVelocity = n.angularVelocity
val inversion = if (spinMap(n)) 1 else -1
n.torque = deltaTorque * inversion
n.torque = deltaTorque * n.ratio * inversion
val angularAcceleration = deltaTorque / n.momentOfInertia
n.angularVelocity = angularAcceleration * deltaTime * inversion
n.angularVelocity = angularAcceleration / n.ratio * deltaTime * inversion
if (Math.abs(prevTorque - n.torque) >= 0.1)
n.onTorqueChanged()
if (Math.abs(prevAngularVelocity - n.angularVelocity) >= 0.1)
n.onVelocityChanged()
})
//Clear buffers
inputs.foreach(_.bufferTorque = 0)
n.bufferTorque = 0
})
}
}