Changed a few api methods for gears

This commit is contained in:
Robert S 2014-06-04 03:23:16 -04:00
parent 96499a7c0d
commit 109d716cd2
8 changed files with 29 additions and 26 deletions

View file

@ -82,7 +82,7 @@ public class TileMotor extends TileElectrical implements IRotatable, INodeProvid
if (receive > 0)
{
double percentageUsed = receive / power;
node.apply(this, -node.getTorque() * percentageUsed, -node.getAngularVelocity() * percentageUsed);
node.apply(this, -node.getTorque() * percentageUsed, -node.getAngularSpeed() * percentageUsed);
}
}
@ -108,11 +108,11 @@ public class TileMotor extends TileElectrical implements IRotatable, INodeProvid
if (currentTorque != 0)
setTorque = Math.min(setTorque, maxTorque) * (node.getTorque() / currentTorque);
double currentVelo = Math.abs(node.getAngularVelocity());
double currentVelo = Math.abs(node.getAngularSpeed());
if (currentVelo != 0)
setAngularVelocity = Math.min(+setAngularVelocity, maxAngularVelocity) * (node.getAngularVelocity() / currentVelo);
setAngularVelocity = Math.min(+setAngularVelocity, maxAngularVelocity) * (node.getAngularSpeed() / currentVelo);
node.apply(this, setTorque - node.getTorque(), setAngularVelocity - node.getAngularVelocity());
node.apply(this, setTorque - node.getTorque(), setAngularVelocity - node.getAngularSpeed());
energy.extractEnergy((long) Math.abs(setTorque * setAngularVelocity), true);
}
}

View file

@ -280,7 +280,7 @@ public class PartMultimeter extends PartFace implements IConnector<MultimeterNet
if (instance != null)
{
getNetwork().torqueGraph.queue(instance.getTorque());
getNetwork().angularVelocityGraph.queue(instance.getAngularVelocity());
getNetwork().angularVelocityGraph.queue(instance.getAngularSpeed());
getNetwork().powerGraph.queue((long) instance.getPower());
}
}

View file

@ -16,14 +16,6 @@ import universalelectricity.api.vector.Vector3;
import codechicken.multipart.TMultiPart;
/** A mechanical node for mechanical energy.
* <p/>
* Useful Formula:
* <p/>
* Power is the work per unit time. Power (W) = Torque (Strength of the rotation, Newton Meters) x
* Speed (Angular Velocity, RADIAN PER SECOND). *OR* Power = Torque / Time
* <p/>
* Torque = r (Radius) * F (Force) * sin0 (Direction/Angle of the force applied. 90 degrees if
* optimal.)
*
* @author Calclavia */
@SuppressWarnings("rawtypes")
@ -61,6 +53,12 @@ public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalN
this.connectionMap = connectionMap;
return this;
}
@Override
public double getRadius()
{
return 0.5;
}
@Override
public void update(float deltaTime)
@ -100,7 +98,7 @@ public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalN
torque += torqueLoss;
}
double velocityLoss = Math.min(Math.abs(getAngularVelocity()), (Math.abs(getAngularVelocity() * getAngularVelocityLoad()) + getAngularVelocityLoad() / 10) * deltaTime);
double velocityLoss = Math.min(Math.abs(getAngularSpeed()), (Math.abs(getAngularSpeed() * getAngularVelocityLoad()) + getAngularVelocityLoad() / 10) * deltaTime);
if (angularVelocity > 0)
{
@ -147,7 +145,7 @@ public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalN
torque -= applyTorque;
}
double targetVelocity = inversion * adjacentMech.getAngularVelocity() * ratio;
double targetVelocity = inversion * adjacentMech.getAngularSpeed() * ratio;
double applyVelocity = targetVelocity * acceleration;
if (Math.abs(angularVelocity + applyVelocity) < Math.abs(targetVelocity))
@ -194,7 +192,7 @@ public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalN
}
@Override
public double getAngularVelocity()
public double getAngularSpeed()
{
return torque != 0 ? angularVelocity : 0;
}
@ -263,7 +261,7 @@ public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalN
@Override
public double getEnergy()
{
return getTorque() * getAngularVelocity();
return getTorque() * getAngularSpeed();
}
@Override
@ -292,6 +290,6 @@ public class MechanicalNode extends Node<INodeProvider, TickingGrid, MechanicalN
super.save(nbt);
nbt.setDouble("torque", torque);
nbt.setDouble("angularVelocity", angularVelocity);
}
}
}

View file

@ -116,7 +116,7 @@ public class TileMechanicalTurbine extends TileTurbineBase implements INodeProvi
if (mechanicalNode.angularVelocity < 0)
angularVelocity = -Math.abs(angularVelocity);
mechanicalNode.apply(this, (torque - mechanicalNode.getTorque()) / 10, (angularVelocity - mechanicalNode.getAngularVelocity()) / 10);
mechanicalNode.apply(this, (torque - mechanicalNode.getTorque()) / 10, (angularVelocity - mechanicalNode.getAngularSpeed()) / 10);
}
}

View file

@ -46,7 +46,7 @@ public class TilePump extends TileMechanical implements IPressureNodeProvider, I
@Override
public int getMaxFlowRate()
{
return (int) Math.abs(mechanicalNode.getAngularVelocity() * 1000);
return (int) Math.abs(mechanicalNode.getAngularSpeed() * 1000);
}
@Override

View file

@ -9,7 +9,11 @@ import universalelectricity.api.vector.Vector3;
* @author Darkguardsman */
public interface IMechanicalNode extends INode
{
/** Gets the radius of the gear in meters. Used to calculate torque and gear ratio */
public double getRadius();
/** The Rotational force */
@Deprecated
public double getTorque();
/** TODO remove */
@ -20,12 +24,13 @@ public interface IMechanicalNode extends INode
@Deprecated
public double getPower();
/** The Rotational velocity */
public double getAngularVelocity();
/** The Rotational speed of the object */
public double getAngularSpeed();
/** Applies rotational force and velocity to the mechanical object */
public void apply(Object source, double torque, double angularVelocity);
@Deprecated
public float getRatio(ForgeDirection dir, IMechanicalNode with);
@Deprecated

View file

@ -102,12 +102,12 @@ public class TileGrindingWheel extends TileMechanical implements IRotatable
}
if (mechanicalNode.getAngularVelocity() != 0)
if (mechanicalNode.getAngularSpeed() != 0)
{
// Move entity based on the direction of the block.
ForgeDirection dir = getDirection();
dir = ForgeDirection.getOrientation(!(dir.ordinal() % 2 == 0) ? dir.ordinal() - 1 : dir.ordinal()).getOpposite();
double speed = mechanicalNode.getAngularVelocity() / 20;
double speed = mechanicalNode.getAngularSpeed() / 20;
entity.addVelocity(dir.offsetX * speed, Math.random() * speed, dir.offsetZ * speed);
}
}

View file

@ -97,7 +97,7 @@ public class TileMixer extends TileMechanical implements IInventory
*/
public boolean canWork()
{
return mechanicalNode.getAngularVelocity() != 0 && !areaBlockedFromMoving;
return mechanicalNode.getAngularSpeed() != 0 && !areaBlockedFromMoving;
}
public void doWork()
@ -116,7 +116,7 @@ public class TileMixer extends TileMechanical implements IInventory
*/
Vector3 originalPosition = new Vector3(entity);
Vector3 relativePosition = originalPosition.clone().subtract(new Vector3(this).add(0.5));
relativePosition.rotate(-mechanicalNode.getAngularVelocity(), 0, 0);
relativePosition.rotate(-mechanicalNode.getAngularSpeed(), 0, 0);
Vector3 newPosition = new Vector3(this).add(0.5).add(relativePosition);
Vector3 difference = newPosition.difference(originalPosition).scale(0.5);