Multimeters now display torque and angular velocity
This commit is contained in:
parent
84b13c027c
commit
2a858059b4
7 changed files with 126 additions and 43 deletions
|
@ -83,28 +83,22 @@ public class TileGenerator extends TileElectrical implements IRotatable
|
||||||
if (tile instanceof IMechanical)
|
if (tile instanceof IMechanical)
|
||||||
{
|
{
|
||||||
IMechanical mech = ((IMechanical) tile).getInstance(outputDir.getOpposite());
|
IMechanical mech = ((IMechanical) tile).getInstance(outputDir.getOpposite());
|
||||||
long extract = energy.extractEnergy(energy.getEnergy() / 2, false);
|
long extract = energy.extractEnergy(energy.getEnergy() / 2, false);
|
||||||
|
|
||||||
if (mech != null)
|
if (mech != null)
|
||||||
{
|
{
|
||||||
if (extract > 0)
|
if (extract > 0)
|
||||||
{
|
{
|
||||||
final float maxAngularVelocity = energy.getEnergyCapacity() / (float) torqueRatio;
|
final float maxAngularVelocity = extract / (float) torqueRatio;
|
||||||
final long maxTorque = (long) ((double) energy.getEnergyCapacity() / maxAngularVelocity);
|
final long maxTorque = (long) (((double) extract) / maxAngularVelocity);
|
||||||
float setAngularVelocity = extract / (float) torqueRatio;
|
|
||||||
long setTorque = (long) (((double) extract) / setAngularVelocity);
|
float setAngularVelocity = maxAngularVelocity;
|
||||||
|
long setTorque = maxTorque;
|
||||||
|
|
||||||
long currentTorque = Math.abs(mech.getTorque());
|
long currentTorque = Math.abs(mech.getTorque());
|
||||||
|
|
||||||
if (currentTorque != 0)
|
if (currentTorque != 0)
|
||||||
{
|
setTorque = Math.min(setTorque, maxTorque) * (mech.getTorque() / currentTorque);
|
||||||
setTorque = Math.min(+setTorque, maxTorque) * (mech.getTorque() / currentTorque);
|
|
||||||
|
|
||||||
if (setTorque < currentTorque)
|
|
||||||
{
|
|
||||||
setTorque = (long) Math.max(setTorque, currentTorque * (currentTorque / maxTorque));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float currentVelo = Math.abs(mech.getAngularVelocity());
|
float currentVelo = Math.abs(mech.getAngularVelocity());
|
||||||
if (currentVelo != 0)
|
if (currentVelo != 0)
|
||||||
|
|
|
@ -21,12 +21,12 @@ public abstract class Graph<V extends Comparable<V>>
|
||||||
* Each point represents a tick.
|
* Each point represents a tick.
|
||||||
*/
|
*/
|
||||||
protected List<V> points = new ArrayList<V>();
|
protected List<V> points = new ArrayList<V>();
|
||||||
private V peak;
|
private V peak = getDefault();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Queue for the next update to insert into the graph.
|
* Queue for the next update to insert into the graph.
|
||||||
*/
|
*/
|
||||||
protected V queue;
|
protected V queue = getDefault();
|
||||||
|
|
||||||
public Graph(int maxPoints)
|
public Graph(int maxPoints)
|
||||||
{
|
{
|
||||||
|
@ -63,6 +63,11 @@ public abstract class Graph<V extends Comparable<V>>
|
||||||
return points.size() > x ? points.get(x) : getDefault();
|
return points.size() > x ? points.get(x) : getDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public V get()
|
||||||
|
{
|
||||||
|
return get(0);
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void queue(V value);
|
public abstract void queue(V value);
|
||||||
|
|
||||||
public void doneQueue()
|
public void doneQueue()
|
||||||
|
@ -70,9 +75,12 @@ public abstract class Graph<V extends Comparable<V>>
|
||||||
add(queue);
|
add(queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract V getDefault();
|
protected abstract V getDefault();
|
||||||
|
|
||||||
public abstract void load(NBTTagCompound nbt);
|
public void load(NBTTagCompound nbt)
|
||||||
|
{
|
||||||
|
points.clear();
|
||||||
|
}
|
||||||
|
|
||||||
public abstract NBTTagCompound save();
|
public abstract NBTTagCompound save();
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
package resonantinduction.electrical.multimeter;
|
||||||
|
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.nbt.NBTTagList;
|
||||||
|
|
||||||
|
public class GraphF extends Graph<Float>
|
||||||
|
{
|
||||||
|
public GraphF(int maxPoints)
|
||||||
|
{
|
||||||
|
super(maxPoints);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void queue(Float value)
|
||||||
|
{
|
||||||
|
queue += value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void doneQueue()
|
||||||
|
{
|
||||||
|
super.doneQueue();
|
||||||
|
queue = 0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Float getDefault()
|
||||||
|
{
|
||||||
|
return 0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load(NBTTagCompound nbt)
|
||||||
|
{
|
||||||
|
super.load(nbt);
|
||||||
|
|
||||||
|
NBTTagList nbtList = nbt.getTagList("DataPoints");
|
||||||
|
|
||||||
|
for (int i = 0; i < nbtList.tagCount(); ++i)
|
||||||
|
{
|
||||||
|
NBTTagCompound nbtPoint = (NBTTagCompound) nbtList.tagAt(i);
|
||||||
|
points.add(nbtPoint.getFloat("data"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public NBTTagCompound save()
|
||||||
|
{
|
||||||
|
NBTTagCompound nbt = new NBTTagCompound();
|
||||||
|
NBTTagList data = new NBTTagList();
|
||||||
|
|
||||||
|
for (Float value : points)
|
||||||
|
{
|
||||||
|
NBTTagCompound nbtPoint = new NBTTagCompound();
|
||||||
|
nbtPoint.setFloat("data", value);
|
||||||
|
data.appendTag(nbtPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
nbt.setTag("DataPoints", data);
|
||||||
|
return nbt;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -30,6 +30,7 @@ public class GraphL extends Graph<Long>
|
||||||
|
|
||||||
public void load(NBTTagCompound nbt)
|
public void load(NBTTagCompound nbt)
|
||||||
{
|
{
|
||||||
|
super.load(nbt);
|
||||||
NBTTagList nbtList = nbt.getTagList("DataPoints");
|
NBTTagList nbtList = nbt.getTagList("DataPoints");
|
||||||
|
|
||||||
for (int i = 0; i < nbtList.tagCount(); ++i)
|
for (int i = 0; i < nbtList.tagCount(); ++i)
|
||||||
|
@ -48,7 +49,6 @@ public class GraphL extends Graph<Long>
|
||||||
{
|
{
|
||||||
NBTTagCompound nbtPoint = new NBTTagCompound();
|
NBTTagCompound nbtPoint = new NBTTagCompound();
|
||||||
nbtPoint.setLong("data", value);
|
nbtPoint.setLong("data", value);
|
||||||
|
|
||||||
data.appendTag(nbtPoint);
|
data.appendTag(nbtPoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,9 +18,12 @@ public class MultimeterNetwork extends Network<MultimeterNetwork, PartMultimeter
|
||||||
/**
|
/**
|
||||||
* The available graphs to be handled.
|
* The available graphs to be handled.
|
||||||
*/
|
*/
|
||||||
|
private int maxData = 20 * 10;
|
||||||
private final List<Graph> graphs = new ArrayList<Graph>();
|
private final List<Graph> graphs = new ArrayList<Graph>();
|
||||||
public final GraphL energyGraph = new GraphL(20 * 10);
|
public final GraphL energyGraph = new GraphL(maxData);
|
||||||
public final GraphL energyCapacityGraph = new GraphL(20 * 10);
|
public final GraphL energyCapacityGraph = new GraphL(1);
|
||||||
|
public final GraphL torqueGraph = new GraphL(maxData);
|
||||||
|
public final GraphF angularVelocityGraph = new GraphF(maxData);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The absolute center of the multimeter screens.
|
* The absolute center of the multimeter screens.
|
||||||
|
@ -51,6 +54,8 @@ public class MultimeterNetwork extends Network<MultimeterNetwork, PartMultimeter
|
||||||
{
|
{
|
||||||
graphs.add(energyGraph);
|
graphs.add(energyGraph);
|
||||||
graphs.add(energyCapacityGraph);
|
graphs.add(energyCapacityGraph);
|
||||||
|
graphs.add(torqueGraph);
|
||||||
|
graphs.add(angularVelocityGraph);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -63,8 +68,11 @@ public class MultimeterNetwork extends Network<MultimeterNetwork, PartMultimeter
|
||||||
@Override
|
@Override
|
||||||
public void update()
|
public void update()
|
||||||
{
|
{
|
||||||
energyGraph.doneQueue();
|
for (Graph graph : graphs)
|
||||||
energyCapacityGraph.doneQueue();
|
{
|
||||||
|
graph.doneQueue();
|
||||||
|
}
|
||||||
|
|
||||||
doUpdate = false;
|
doUpdate = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -154,8 +162,8 @@ public class MultimeterNetwork extends Network<MultimeterNetwork, PartMultimeter
|
||||||
|
|
||||||
for (int i = 0; i < nbtList.tagCount(); ++i)
|
for (int i = 0; i < nbtList.tagCount(); ++i)
|
||||||
{
|
{
|
||||||
NBTTagCompound nbtPoint = (NBTTagCompound) nbtList.tagAt(i);
|
NBTTagCompound nbtCompound = (NBTTagCompound) nbtList.tagAt(i);
|
||||||
graphs.get(i).load(nbtPoint);
|
graphs.get(i).load(nbtCompound);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -182,7 +182,8 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
||||||
|
|
||||||
if (!world().isRemote)
|
if (!world().isRemote)
|
||||||
{
|
{
|
||||||
long detectedEnergy = getDetectedEnergy();
|
updateDetections();
|
||||||
|
long detectedEnergy = getNetwork().energyGraph.get(0);
|
||||||
|
|
||||||
boolean outputRedstone = false;
|
boolean outputRedstone = false;
|
||||||
|
|
||||||
|
@ -217,7 +218,7 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
||||||
tile().notifyPartChange(this);
|
tile().notifyPartChange(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (getNetwork().energyGraph.get(1) != detectedEnergy)
|
// if (getNetwork().energyGraph.get(1) != detectedEnergy)
|
||||||
{
|
{
|
||||||
updateGraph();
|
updateGraph();
|
||||||
}
|
}
|
||||||
|
@ -238,6 +239,9 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
||||||
ForgeDirection receivingSide = getDirection().getOpposite();
|
ForgeDirection receivingSide = getDirection().getOpposite();
|
||||||
TileEntity tileEntity = getDetectedTile();
|
TileEntity tileEntity = getDetectedTile();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update Energy Graph
|
||||||
|
*/
|
||||||
if (tileEntity instanceof IConductor)
|
if (tileEntity instanceof IConductor)
|
||||||
{
|
{
|
||||||
IConnector<IEnergyNetwork> conductor = ((IConductor) tileEntity).getInstance(receivingSide.getOpposite());
|
IConnector<IEnergyNetwork> conductor = ((IConductor) tileEntity).getInstance(receivingSide.getOpposite());
|
||||||
|
@ -259,13 +263,25 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
||||||
{
|
{
|
||||||
IMechanical instance = ((IMechanical) tileEntity).getInstance(receivingSide);
|
IMechanical instance = ((IMechanical) tileEntity).getInstance(receivingSide);
|
||||||
|
|
||||||
|
if (instance == null)
|
||||||
|
{
|
||||||
|
instance = ((IMechanical) tileEntity).getInstance(ForgeDirection.UNKNOWN);
|
||||||
|
}
|
||||||
|
|
||||||
if (instance != null)
|
if (instance != null)
|
||||||
{
|
{
|
||||||
|
getNetwork().torqueGraph.queue(instance.getTorque());
|
||||||
|
getNetwork().angularVelocityGraph.queue(instance.getAngularVelocity());
|
||||||
getNetwork().energyGraph.queue((long) (instance.getTorque() * instance.getAngularVelocity()));
|
getNetwork().energyGraph.queue((long) (instance.getTorque() * instance.getAngularVelocity()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CompatibilityModule.getEnergy(tileEntity, receivingSide);
|
getNetwork().energyGraph.queue(CompatibilityModule.getEnergy(tileEntity, receivingSide));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update Energy Capacity Graph
|
||||||
|
*/
|
||||||
|
getNetwork().energyCapacityGraph.queue(CompatibilityModule.getMaxEnergy(tileEntity, receivingSide));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -329,11 +345,6 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
||||||
toggleMode();
|
toggleMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getDetectedEnergy()
|
|
||||||
{
|
|
||||||
return getDetectedEnergy(getDirection().getOpposite(), getDetectedTile());
|
|
||||||
}
|
|
||||||
|
|
||||||
public TileEntity getDetectedTile()
|
public TileEntity getDetectedTile()
|
||||||
{
|
{
|
||||||
ForgeDirection direction = getDirection();
|
ForgeDirection direction = getDirection();
|
||||||
|
@ -345,6 +356,7 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
||||||
return ForgeDirection.getOrientation(this.side);
|
return ForgeDirection.getOrientation(this.side);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
public static long getDetectedEnergy(ForgeDirection side, TileEntity tileEntity)
|
public static long getDetectedEnergy(ForgeDirection side, TileEntity tileEntity)
|
||||||
{
|
{
|
||||||
if (tileEntity instanceof IConductor)
|
if (tileEntity instanceof IConductor)
|
||||||
|
@ -377,16 +389,6 @@ public class PartMultimeter extends JCuboidPart implements IConnector<Multimeter
|
||||||
return CompatibilityModule.getEnergy(tileEntity, side);
|
return CompatibilityModule.getEnergy(tileEntity, side);
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getDetectedCapacity()
|
|
||||||
{
|
|
||||||
return getDetectedCapacity(getDirection().getOpposite(), getDetectedTile());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static long getDetectedCapacity(ForgeDirection side, TileEntity tileEntity)
|
|
||||||
{
|
|
||||||
return CompatibilityModule.getMaxEnergy(tileEntity, side);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void toggleMode()
|
public void toggleMode()
|
||||||
{
|
{
|
||||||
if (!this.world().isRemote)
|
if (!this.world().isRemote)
|
||||||
|
|
|
@ -158,12 +158,23 @@ public class RenderMultimeter
|
||||||
information.set(0, str);
|
information.set(0, str);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (part.getNetwork().torqueGraph.get(0) != 0)
|
||||||
|
{
|
||||||
|
information.add("Torque: " + UnitDisplay.getDisplayShort(part.getNetwork().torqueGraph.get(0), Unit.NEWTON_METER));
|
||||||
|
}
|
||||||
|
if (part.getNetwork().angularVelocityGraph.get(0) != 0)
|
||||||
|
{
|
||||||
|
information.add("Speed: " + UnitDisplay.roundDecimals(part.getNetwork().angularVelocityGraph.get(0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
GL11.glTranslatef(0, 0, -0.2f * (information.size() / 2));
|
||||||
|
|
||||||
for (int i = 0; i < information.size(); i++)
|
for (int i = 0; i < information.size(); i++)
|
||||||
{
|
{
|
||||||
String info = information.get(i);
|
String info = information.get(i);
|
||||||
|
|
||||||
GL11.glPushMatrix();
|
GL11.glPushMatrix();
|
||||||
GL11.glTranslatef(0, 0, 0.3f * i);
|
GL11.glTranslatef(0, 0, 0.2f * i);
|
||||||
if (dir.offsetX == 0)
|
if (dir.offsetX == 0)
|
||||||
RenderUtility.renderText(info, (float) (part.getNetwork().size.x * 0.9f), 0.5f);
|
RenderUtility.renderText(info, (float) (part.getNetwork().size.x * 0.9f), 0.5f);
|
||||||
if (dir.offsetZ == 0)
|
if (dir.offsetZ == 0)
|
||||||
|
|
Loading…
Add table
Reference in a new issue