Made angularVelocity and torque protected fields
This commit is contained in:
parent
31a510d028
commit
0d1bbf3660
7 changed files with 57 additions and 79 deletions
|
@ -95,7 +95,6 @@ object MechanicalContent extends ContentHolder
|
|||
recipes += shaped(new ItemStack(blockWaterTurbine, 1, 1), "SWS", "WGW", "SWS", 'G', new ItemStack(blockWaterTurbine, 1, 0), 'W', Blocks.stone, 'S', Items.stick)
|
||||
recipes += shaped(new ItemStack(blockWaterTurbine, 1, 2), "SWS", "WGW", "SWS", 'G', new ItemStack(blockWaterTurbine, 1, 1), 'W', UniversalRecipe.PRIMARY_METAL.get, 'S', Items.stick)
|
||||
|
||||
recipes += shaped(blockElectricTurbine, " B ", "BMB", " B ", 'B', UniversalRecipe.SECONDARY_PLATE.get, 'M', UniversalRecipe.MOTOR.get)
|
||||
recipes += shaped(blockPump, "PPP", "GGG", "PPP", 'P', itemPipe, 'G', new ItemStack(itemGear, 1, 2))
|
||||
|
||||
recipes += shaped(new ItemStack(itemPipe, 3, PipeMaterials.ceramic.id), "BBB", " ", "BBB", 'B', Items.brick)
|
||||
|
|
|
@ -72,13 +72,6 @@ class PartGear extends PartMechanical with IMultiBlockStructure[PartGear]
|
|||
|
||||
if (itemStack != null && itemStack.getItem.isInstanceOf[ItemHandCrank])
|
||||
{
|
||||
if (!world.isRemote && ControlKeyModifer.isControlDown(player))
|
||||
{
|
||||
getMultiBlock.get.mechanicalNode.torque = -getMultiBlock.get.mechanicalNode.torque
|
||||
getMultiBlock.get.mechanicalNode.angularVelocity = -getMultiBlock.get.mechanicalNode.angularVelocity
|
||||
return true
|
||||
}
|
||||
|
||||
isClockwiseCrank = player.isSneaking
|
||||
getMultiBlock.get.manualCrankTime = 40
|
||||
|
||||
|
|
|
@ -66,9 +66,9 @@ 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 * inversion
|
||||
val angularAcceleration = deltaTorque / n.momentOfInertia
|
||||
n.angularVelocity = angularAcceleration * deltaTime * inversion
|
||||
n._angularVelocity = angularAcceleration * deltaTime * inversion
|
||||
|
||||
if (Math.abs(n.torque - prevTorque) >= 0.1)
|
||||
n.onTorqueChanged()
|
||||
|
|
|
@ -16,8 +16,24 @@ import scala.beans.BeanProperty
|
|||
*/
|
||||
class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](parent) with TMultipartNode[NodeMechanical] with TMechanicalNode with IVectorWorld
|
||||
{
|
||||
var torque = 0D
|
||||
var angularVelocity = 0D
|
||||
protected[grid] var _torque = 0D
|
||||
protected[grid] var _angularVelocity = 0D
|
||||
|
||||
/**
|
||||
* Gets the angular velocity of the mechanical device from a specific side
|
||||
*
|
||||
* @return Angular velocity in meters per second
|
||||
*/
|
||||
override def angularVelocity = _angularVelocity
|
||||
|
||||
def angularVelocity_=(newVel: Double) = _angularVelocity = newVel
|
||||
|
||||
/**
|
||||
* Gets the torque of the mechanical device from a specific side
|
||||
*
|
||||
* @return force
|
||||
*/
|
||||
override def torque = _torque
|
||||
|
||||
/**
|
||||
* Buffer values used by the grid to transfer mechanical energy.
|
||||
|
@ -55,7 +71,6 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par
|
|||
return prevAngle
|
||||
}
|
||||
|
||||
|
||||
override def rotate(torque: Double)
|
||||
{
|
||||
bufferTorque += torque
|
||||
|
|
|
@ -9,9 +9,15 @@ import resonantinduction.mechanical.mech.grid.NodeMechanical
|
|||
*
|
||||
* @author Calclavia, Darkguardsman
|
||||
*/
|
||||
class TurbineNode(parent: TileTurbine) extends NodeMechanical(parent)
|
||||
class NodeTurbine(parent: TileTurbine) extends NodeMechanical(parent)
|
||||
{
|
||||
|
||||
/**
|
||||
* The mechanical load
|
||||
* @return Torque in Newton meters per second
|
||||
*/
|
||||
override def getLoad = 100d
|
||||
|
||||
/**
|
||||
* Moment of inertia = m * r * r
|
||||
* Where "m" is the mass and "r" is the radius of the object.
|
||||
|
@ -25,7 +31,7 @@ class TurbineNode(parent: TileTurbine) extends NodeMechanical(parent)
|
|||
|
||||
override def canConnect[B](other: B, from: ForgeDirection): Boolean =
|
||||
{
|
||||
return turbine.getMultiBlock.isPrimary && other.isInstanceOf[NodeMechanical] && !(other.isInstanceOf[TurbineNode]) && from == turbine.getDirection
|
||||
return turbine.getMultiBlock.isPrimary && other.isInstanceOf[NodeMechanical] && !(other.isInstanceOf[NodeTurbine]) && from == turbine.getDirection
|
||||
}
|
||||
|
||||
/**
|
|
@ -30,7 +30,7 @@ class TileTurbine extends TileMechanical(Material.wood) with IMultiBlockStructur
|
|||
normalRender = false
|
||||
isOpaqueCube = false
|
||||
setTextureName("material_wood_surface")
|
||||
mechanicalNode = new TurbineNode(this)
|
||||
mechanicalNode = new NodeTurbine(this)
|
||||
rotationMask = 63
|
||||
|
||||
override def onRemove(block: Block, par1: Int)
|
||||
|
@ -129,20 +129,6 @@ class TileTurbine extends TileMechanical(Material.wood) with IMultiBlockStructur
|
|||
return worldObj
|
||||
}
|
||||
|
||||
override def use(player: EntityPlayer, side: Int, hit: Vector3): Boolean =
|
||||
{
|
||||
if (player.getCurrentEquippedItem != null && player.getCurrentEquippedItem.getItem.isInstanceOf[ItemHandCrank])
|
||||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
mechanicalNode.torque = -mechanicalNode.torque
|
||||
mechanicalNode.angularVelocity = -mechanicalNode.angularVelocity
|
||||
}
|
||||
return true
|
||||
}
|
||||
return super.use(player, side, hit)
|
||||
}
|
||||
|
||||
override def configure(player: EntityPlayer, side: Int, hit: Vector3): Boolean =
|
||||
{
|
||||
if (!player.isSneaking)
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package resonantinduction.mechanical.mech.turbine
|
||||
|
||||
import java.lang.reflect.Method
|
||||
import java.util.List
|
||||
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper
|
||||
|
@ -12,11 +11,11 @@ import net.minecraft.tileentity.TileEntity
|
|||
import net.minecraft.util.Vec3
|
||||
import net.minecraft.world.IBlockAccess
|
||||
import net.minecraftforge.common.util.ForgeDirection
|
||||
import resonant.api.grid.INodeProvider
|
||||
import resonant.content.prefab.itemblock.ItemBlockMetadata
|
||||
import resonant.lib.transform.vector.Vector3
|
||||
import resonant.lib.wrapper.WrapList._
|
||||
import resonantinduction.core.Settings
|
||||
import resonant.api.grid.INodeProvider
|
||||
import resonant.lib.transform.vector.Vector3
|
||||
import resonantinduction.mechanical.mech.grid.NodeMechanical
|
||||
|
||||
/**
|
||||
|
@ -28,63 +27,57 @@ import resonantinduction.mechanical.mech.grid.NodeMechanical
|
|||
*/
|
||||
class TileWaterTurbine extends TileTurbine
|
||||
{
|
||||
var powerTicks: Int = 0
|
||||
var powerTicks = 0
|
||||
|
||||
//Constructor
|
||||
this.itemBlock_$eq(classOf[ItemBlockMetadata])
|
||||
mechanicalNode.torque = defaultTorque
|
||||
mechanicalNode = new TurbineNode((this))
|
||||
itemBlock = classOf[ItemBlockMetadata]
|
||||
mechanicalNode = new NodeTurbine(this)
|
||||
{
|
||||
override def canConnect[B](other: B, from: ForgeDirection): Boolean =
|
||||
{
|
||||
if (other.isInstanceOf[NodeMechanical] && !(other.isInstanceOf[TileTurbine]))
|
||||
{
|
||||
val sourceTile: TileEntity = toVectorWorld.add(from).getTileEntity
|
||||
|
||||
if (sourceTile.isInstanceOf[INodeProvider])
|
||||
{
|
||||
val sourceInstance: NodeMechanical = sourceTile.asInstanceOf[INodeProvider].getNode(classOf[NodeMechanical], from.getOpposite).asInstanceOf[NodeMechanical]
|
||||
return sourceInstance == other && (from == getDirection.getOpposite || from == getDirection)
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
override def update
|
||||
override def update()
|
||||
{
|
||||
super.update
|
||||
if (getMultiBlock.isConstructed)
|
||||
{
|
||||
mechanicalNode.torque = (defaultTorque / (1d / multiBlockRadius)).asInstanceOf[Long]
|
||||
}
|
||||
else
|
||||
{
|
||||
mechanicalNode.torque = defaultTorque / 12
|
||||
}
|
||||
super.update()
|
||||
|
||||
if (getDirection.offsetY != 0)
|
||||
{
|
||||
maxPower = 10000
|
||||
if (powerTicks > 0)
|
||||
{
|
||||
getMultiBlock.get.power += getWaterPower
|
||||
getMultiBlock.get.mechanicalNode.rotate(getWaterPower)
|
||||
powerTicks -= 1
|
||||
}
|
||||
|
||||
if (ticks % 20 == 0)
|
||||
{
|
||||
val blockIDAbove: Block = worldObj.getBlock(xCoord, yCoord + 1, zCoord)
|
||||
val metadata: Int = worldObj.getBlockMetadata(xCoord, yCoord + 1, zCoord)
|
||||
val isWater: Boolean = (blockIDAbove == Blocks.water || blockIDAbove == Blocks.flowing_water)
|
||||
val isWater: Boolean = blockIDAbove == Blocks.water || blockIDAbove == Blocks.flowing_water
|
||||
if (isWater && worldObj.isAirBlock(xCoord, yCoord - 1, zCoord) && metadata == 0)
|
||||
{
|
||||
powerTicks = 20
|
||||
worldObj.setBlockToAir(xCoord, yCoord + 1, zCoord)
|
||||
worldObj.setBlock(xCoord, yCoord - 1, zCoord, Blocks.flowing_water)
|
||||
getMultiBlock.get.mechanicalNode.rotate(10000)
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
maxPower = 2500
|
||||
val currentDir: ForgeDirection = getDirection
|
||||
for (dir <- ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
|
@ -95,32 +88,21 @@ class TileWaterTurbine extends TileTurbine
|
|||
val metadata: Int = worldObj.getBlockMetadata(check.xi, check.yi, check.zi)
|
||||
if (blockID == Blocks.water || blockID == Blocks.flowing_water)
|
||||
{
|
||||
try
|
||||
|
||||
val m = ReflectionHelper.findMethod(classOf[BlockDynamicLiquid], null, Array[String]("getFlowVector", "func_72202_i"), classOf[IBlockAccess], Integer.TYPE, Integer.TYPE, Integer.TYPE)
|
||||
val vector = new Vector3(m.invoke(Blocks.water, Array(worldObj, check.xi, check.yi, check.zi)).asInstanceOf[Vec3])
|
||||
val invert = (currentDir.offsetZ > 0 && vector.x < 0) || (currentDir.offsetZ < 0 && vector.x > 0) || (currentDir.offsetX > 0 && vector.z > 0) || (currentDir.offsetX < 0 && vector.z < 0)
|
||||
|
||||
if (getDirection.offsetX != 0)
|
||||
{
|
||||
val m: Method = ReflectionHelper.findMethod(classOf[BlockDynamicLiquid], null, Array[String]("getFlowVector", "func_72202_i"), classOf[IBlockAccess], Integer.TYPE, Integer.TYPE, Integer.TYPE)
|
||||
val vector: Vector3 = new Vector3(m.invoke(Blocks.water, Array(worldObj, check.xi, check.yi, check.zi)).asInstanceOf[Vec3])
|
||||
if ((currentDir.offsetZ > 0 && vector.x < 0) || (currentDir.offsetZ < 0 && vector.x > 0) || (currentDir.offsetX > 0 && vector.z > 0) || (currentDir.offsetX < 0 && vector.z < 0))
|
||||
{
|
||||
mechanicalNode.torque = -mechanicalNode.torque
|
||||
}
|
||||
if (getDirection.offsetX != 0)
|
||||
{
|
||||
getMultiBlock.get.power += Math.abs(getWaterPower * vector.z * (7 - metadata) / 7f)
|
||||
powerTicks = 20
|
||||
}
|
||||
if (getDirection.offsetZ != 0)
|
||||
{
|
||||
getMultiBlock.get.power += Math.abs(getWaterPower * vector.x * (7 - metadata) / 7f)
|
||||
powerTicks = 20
|
||||
}
|
||||
getMultiBlock.get.mechanicalNode.rotate(if (invert) -1 else 1 * Math.abs(getWaterPower * vector.z * (7 - metadata) / 7f))
|
||||
powerTicks = 20
|
||||
}
|
||||
if (getDirection.offsetZ != 0)
|
||||
{
|
||||
getMultiBlock.get.mechanicalNode.rotate(if (invert) -1 else 1 * Math.abs(getWaterPower * vector.x * (7 - metadata) / 7f))
|
||||
powerTicks = 20
|
||||
}
|
||||
catch
|
||||
{
|
||||
case e: Exception =>
|
||||
{
|
||||
e.printStackTrace
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -131,10 +113,7 @@ class TileWaterTurbine extends TileTurbine
|
|||
* Gravitation Potential Energy:
|
||||
* PE = mgh
|
||||
*/
|
||||
private def getWaterPower: Long =
|
||||
{
|
||||
return (maxPower / (2 - tier + 1)) * Settings.WATER_POWER_RATIO
|
||||
}
|
||||
private def getWaterPower = (10000 / (2 - tier + 1)) * Settings.WATER_POWER_RATIO
|
||||
|
||||
override def getSubBlocks(par1: Item, par2CreativeTabs: CreativeTabs, par3List: List[_])
|
||||
{
|
||||
|
|
Loading…
Add table
Reference in a new issue