Fixed negative mechanical energy

This commit is contained in:
Calclavia 2014-11-23 10:05:04 +08:00
parent cf06b90dc0
commit 074f8fd57d
5 changed files with 23 additions and 16 deletions

View file

@ -30,8 +30,8 @@ class MechanicalGrid extends GridNode[NodeMechanical](classOf[NodeMechanical]) w
getNodes.foreach(
n =>
{
n._torque = 0
n._angularVelocity = 0
n.torque = 0
n.angularVelocity = 0
}
)
@ -77,20 +77,20 @@ class MechanicalGrid extends GridNode[NodeMechanical](classOf[NodeMechanical]) w
val invert = if (curr.inverseRotation(prev)) -1 else 1
val addTorque = torque * ratio * invert
val addVel = angularVelocity / ratio * invert
curr._torque += addTorque
curr._angularVelocity += addVel * deltaTime
curr.torque += addTorque
curr.angularVelocity += addVel * deltaTime
curr.connections.filter(!passed.contains(_)).foreach(c => recurse(deltaTime, addTorque, addVel, passed :+ c))
}
else
{
//Calculate energy loss
val power = torque * angularVelocity
val netEnergy = power - load * deltaTime
val netEnergy = Math.max(power - load * deltaTime, 0)
val netTorque = netEnergy * (torque / power)
val netVelocity = netEnergy * (angularVelocity / power)
curr._torque += netTorque
curr._angularVelocity += netVelocity * deltaTime
curr.torque += netTorque
curr.angularVelocity += netVelocity * deltaTime
curr.connections.filter(!passed.contains(_)).foreach(c => recurse(deltaTime, netTorque, netVelocity, passed :+ c))
}
}

View file

@ -17,8 +17,8 @@ import scala.collection.convert.wrapAll._
*/
class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](parent) with TTileConnector[NodeMechanical] with TMultipartNode[NodeMechanical] with TNodeMechanical with IVectorWorld
{
protected[grid] var _torque = 0D
protected[grid] var _angularVelocity = 0D
private var _torque = 0D
private var _angularVelocity = 0D
protected[grid] var prevTorque = 0D
protected[grid] var prevAngularVelocity = 0D
@ -39,6 +39,8 @@ class NodeMechanical(parent: INodeProvider) extends NodeGrid[NodeMechanical](par
*/
override def torque = _torque
def torque_=(newTorque: Double) = _torque = newTorque
/**
* Buffer values used by the grid to transfer mechanical energy.
*/

View file

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

View file

@ -43,7 +43,7 @@ class TileGrindingWheel extends TileMechanical(Material.rock)
{
super.update()
counter = Math.max(counter + Math.abs(mechanicalNode.torque), 0)
doWork
doWork()
}
override def collide(entity: Entity)

View file

@ -2,7 +2,7 @@ package resonantinduction.mechanical.mech.turbine
import java.util.List
import cpw.mods.fml.relauncher.{SideOnly, Side}
import cpw.mods.fml.relauncher.{Side, SideOnly}
import net.minecraft.creativetab.CreativeTabs
import net.minecraft.init.{Blocks, Items}
import net.minecraft.item.{Item, ItemStack}
@ -33,6 +33,7 @@ object TileWindTurbine
@SideOnly(Side.CLIENT)
val model = AdvancedModelLoader.loadModel(new ResourceLocation(Reference.domain, Reference.modelPath + "windTurbines.obj"))
}
class TileWindTurbine extends TileTurbine with IBoilHandler
{
/**
@ -75,12 +76,12 @@ class TileWindTurbine extends TileTurbine with IBoilHandler
computePower()
windPower = MathUtility.lerp(windPower, nextWindPower, ticks % 20 / 20d)
getMultiBlock.get.mechanicalNode.rotate(windPower * multiBlockRadius / 20, windPower / multiBlockRadius / 20)
}
//Generate from steam
getMultiBlock.get.mechanicalNode.rotate(if (gasTank.getFluid != null) gasTank.drain(gasTank.getFluidAmount, true).amount else 0 * 1000 * Settings.steamMultiplier, 10)
val steamPower = if (gasTank.getFluid != null) gasTank.drain(gasTank.getFluidAmount, true).amount else 0 * 1000 * Settings.steamMultiplier
getMultiBlock.get.mechanicalNode.rotate(steamPower * multiBlockRadius / 20, steamPower / multiBlockRadius / 20)
}
}
}
@ -134,7 +135,7 @@ class TileWindTurbine extends TileTurbine with IBoilHandler
val hasBonus = biome.isInstanceOf[BiomeGenOcean] || biome.isInstanceOf[BiomeGenPlains] || biome == BiomeGenBase.river
val windSpeed = (worldObj.rand.nextFloat / 5) + (yCoord / 256f) * (if (hasBonus) 1.2f else 1) + worldObj.getRainStrength(0.5f)
nextWindPower = materialMultiplier * multiblockMultiplier * windSpeed * efficiency * Settings.WIND_POWER_RATIO / 20
nextWindPower = 10 * materialMultiplier * multiblockMultiplier * windSpeed * efficiency * Settings.WIND_POWER_RATIO / 20
}
override def getSubBlocks(par1: Item, par2CreativeTabs: CreativeTabs, par3List: List[_])
@ -190,10 +191,12 @@ class TileWindTurbine extends TileTurbine with IBoilHandler
if (tier == 0)
{
RenderUtility.bind(Reference.blockTextureDirectory + "planks_oak.png")
} else if (tier == 1)
}
else if (tier == 1)
{
RenderUtility.bind(Reference.blockTextureDirectory + "cobblestone.png")
} else if (tier == 2)
}
else if (tier == 2)
{
RenderUtility.bind(Reference.blockTextureDirectory + "iron_block.png")