mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-21 12:32:13 +00:00
Add a proper temperature display utility
This commit is contained in:
1 parent
743d80b516
commit
fa9588d557
6 files changed
+162
-8
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package mekanism.api;
|
||||
|
||||
import mekanism.api.util.EnergyUtils.EnergyType;
|
||||
import mekanism.api.util.EnergyUtils.TempType;
|
||||
|
||||
public class MekanismConfig
|
||||
{
|
||||
@@ -27,6 +28,7 @@ public class MekanismConfig
|
||||
public static int userWorldGenVersion = 0;
|
||||
public static double ENERGY_PER_REDSTONE = 10000;
|
||||
public static EnergyType activeType = EnergyType.J;
|
||||
public static TempType tempUnit = TempType.K;
|
||||
public static double TO_IC2;
|
||||
public static double TO_BC;
|
||||
public static double TO_TE;
|
||||
|
||||
@@ -27,6 +27,38 @@ public class EnergyUtils
|
||||
}
|
||||
}
|
||||
|
||||
public static enum TemperatureUnit
|
||||
{
|
||||
KELVIN("Kelvin", "K", 0, 1),
|
||||
CELSIUS("Celsius", "C", 273.15, 1),
|
||||
RANKINE("Rankine", "R", 0, 5/9),
|
||||
FAHRENHEIT("Fahrenheit", "F", 459.67, 5/9),
|
||||
AMBIENT("Ambient", "+STP", 300, 1);
|
||||
|
||||
public String name;
|
||||
public String symbol;
|
||||
double zeroOffset;
|
||||
double intervalSize;
|
||||
|
||||
private TemperatureUnit(String s, String s1, double offset, double size)
|
||||
{
|
||||
name = s;
|
||||
symbol = s1;
|
||||
zeroOffset = offset;
|
||||
intervalSize = size;
|
||||
}
|
||||
|
||||
public double convertFromK(double T)
|
||||
{
|
||||
return (T * intervalSize) - zeroOffset;
|
||||
}
|
||||
|
||||
public double convertToK(double T)
|
||||
{
|
||||
return (T + zeroOffset) / intervalSize;
|
||||
}
|
||||
}
|
||||
|
||||
/** Metric system of measurement. */
|
||||
public static enum MeasurementUnit
|
||||
{
|
||||
@@ -174,6 +206,65 @@ public class EnergyUtils
|
||||
return roundDecimals(value, decimalPlaces) + " " + unit.name;
|
||||
}
|
||||
|
||||
public static String getDisplay(double T, TemperatureUnit unit, int decimalPlaces, boolean isShort)
|
||||
{
|
||||
String unitName = unit.name;
|
||||
String prefix = "";
|
||||
|
||||
double value = unit.convertFromK(T);
|
||||
|
||||
if(value < 0)
|
||||
{
|
||||
value = Math.abs(value);
|
||||
prefix = "-";
|
||||
}
|
||||
|
||||
if(isShort)
|
||||
{
|
||||
unitName = unit.symbol;
|
||||
}
|
||||
|
||||
if(value == 0)
|
||||
{
|
||||
return value + " " + unitName;
|
||||
}
|
||||
else {
|
||||
for(int i = 0; i < MeasurementUnit.values().length; i++)
|
||||
{
|
||||
MeasurementUnit lowerMeasure = MeasurementUnit.values()[i];
|
||||
|
||||
if(lowerMeasure.below(value) && lowerMeasure.ordinal() == 0)
|
||||
{
|
||||
return prefix + roundDecimals(lowerMeasure.process(value), decimalPlaces) + " " + lowerMeasure.getName(isShort) + unitName;
|
||||
}
|
||||
|
||||
if(lowerMeasure.ordinal() + 1 >= MeasurementUnit.values().length)
|
||||
{
|
||||
return prefix + roundDecimals(lowerMeasure.process(value), decimalPlaces) + " " + lowerMeasure.getName(isShort) + unitName;
|
||||
}
|
||||
|
||||
MeasurementUnit upperMeasure = MeasurementUnit.values()[i + 1];
|
||||
|
||||
if((lowerMeasure.above(value) && upperMeasure.below(value)) || lowerMeasure.value == value)
|
||||
{
|
||||
return prefix + roundDecimals(lowerMeasure.process(value), decimalPlaces) + " " + lowerMeasure.getName(isShort) + unitName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return prefix + roundDecimals(value, decimalPlaces) + " " + unitName;
|
||||
}
|
||||
|
||||
public static String getDisplayShort(double value, TemperatureUnit unit)
|
||||
{
|
||||
return getDisplay(value, unit, 2, true);
|
||||
}
|
||||
|
||||
public static String getDisplayShort(double value, TemperatureUnit unit, int decimalPlaces)
|
||||
{
|
||||
return getDisplay(value, unit, decimalPlaces, true);
|
||||
}
|
||||
|
||||
public static double roundDecimals(double d, int decimalPlaces)
|
||||
{
|
||||
int j = (int)(d*Math.pow(10, decimalPlaces));
|
||||
@@ -192,4 +283,13 @@ public class EnergyUtils
|
||||
EU,
|
||||
MJ
|
||||
}
|
||||
|
||||
public static enum TempType
|
||||
{
|
||||
K,
|
||||
C,
|
||||
R,
|
||||
F,
|
||||
STP
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import mekanism.api.MekanismConfig.general;
|
||||
import mekanism.api.MekanismConfig.usage;
|
||||
import mekanism.api.Pos3D;
|
||||
import mekanism.api.util.EnergyUtils.EnergyType;
|
||||
import mekanism.api.util.EnergyUtils.TempType;
|
||||
import mekanism.common.base.IUpgradeTile;
|
||||
import mekanism.common.block.BlockMachine.MachineType;
|
||||
import mekanism.common.entity.EntityRobit;
|
||||
@@ -244,6 +245,32 @@ public class CommonProxy
|
||||
}
|
||||
}
|
||||
|
||||
s = Mekanism.configuration.get(Configuration.CATEGORY_GENERAL, "Temperature Units", "K", null, new String[]{"K", "C", "R", "F"}).getString();
|
||||
|
||||
if(s != null)
|
||||
{
|
||||
if(s.trim().equalsIgnoreCase("k") || s.trim().equalsIgnoreCase("kelvin"))
|
||||
{
|
||||
general.tempUnit = TempType.K;
|
||||
}
|
||||
else if(s.trim().equalsIgnoreCase("c") || s.trim().equalsIgnoreCase("celsius") || s.trim().equalsIgnoreCase("centigrade"))
|
||||
{
|
||||
general.tempUnit = TempType.C;
|
||||
}
|
||||
else if(s.trim().equalsIgnoreCase("r") || s.trim().equalsIgnoreCase("rankine"))
|
||||
{
|
||||
general.tempUnit = TempType.R;
|
||||
}
|
||||
else if(s.trim().equalsIgnoreCase("f") || s.trim().equalsIgnoreCase("fahrenheit"))
|
||||
{
|
||||
general.tempUnit = TempType.F;
|
||||
}
|
||||
else if(s.trim().equalsIgnoreCase("a") || s.trim().equalsIgnoreCase("ambient") || s.trim().equalsIgnoreCase("stp"))
|
||||
{
|
||||
general.tempUnit = TempType.STP;
|
||||
}
|
||||
}
|
||||
|
||||
general.laserRange = Mekanism.configuration.get("general", "LaserRange", 64).getInt(64);
|
||||
general.laserEnergyNeededPerHardness = Mekanism.configuration.get("general", "LaserDiggingEnergy", 100000).getInt(100000);
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@ import mekanism.api.gas.Gas;
|
||||
import mekanism.api.gas.GasStack;
|
||||
import mekanism.api.util.EnergyUtils;
|
||||
import mekanism.api.util.EnergyUtils.ElectricUnit;
|
||||
import mekanism.api.util.EnergyUtils.TemperatureUnit;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.MekanismBlocks;
|
||||
import mekanism.common.OreDictCache;
|
||||
@@ -1154,6 +1155,30 @@ public final class MekanismUtils
|
||||
return "error";
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a rounded energy display of a defined amount of energy.
|
||||
* @param T - temperature to display
|
||||
* @return rounded energy display
|
||||
*/
|
||||
public static String getTemperatureDisplay(double T)
|
||||
{
|
||||
switch(general.tempUnit)
|
||||
{
|
||||
case K:
|
||||
return EnergyUtils.getDisplayShort(T, TemperatureUnit.KELVIN);
|
||||
case C:
|
||||
return EnergyUtils.getDisplayShort(T, TemperatureUnit.CELSIUS);
|
||||
case R:
|
||||
return EnergyUtils.getDisplayShort(T, TemperatureUnit.RANKINE);
|
||||
case F:
|
||||
return EnergyUtils.getDisplayShort(T, TemperatureUnit.FAHRENHEIT);
|
||||
case STP:
|
||||
return EnergyUtils.getDisplayShort(T, TemperatureUnit.AMBIENT);
|
||||
}
|
||||
|
||||
return "error";
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not BuildCraft power should be used, taking into account whether it is installed or another mod is
|
||||
* providing its API.
|
||||
|
||||
@@ -78,7 +78,7 @@ public class GuiReactorHeat extends GuiMekanism
|
||||
@Override
|
||||
public String getText(double level)
|
||||
{
|
||||
return "Plasma: " + (int)level + "C";
|
||||
return "Plasma: " + MekanismUtils.getTemperatureDisplay(level);
|
||||
}
|
||||
}, Type.STANDARD, this, MekanismUtils.getResource(ResourceType.GUI, "GuiTall.png"), 7, 50));
|
||||
guiElements.add(new GuiProgress(new IProgressInfoHandler()
|
||||
@@ -112,7 +112,7 @@ public class GuiReactorHeat extends GuiMekanism
|
||||
@Override
|
||||
public String getText(double level)
|
||||
{
|
||||
return "Case: " + (int)level + "C";
|
||||
return "Case: " + MekanismUtils.getTemperatureDisplay(level);
|
||||
}
|
||||
}, Type.STANDARD, this, MekanismUtils.getResource(ResourceType.GUI, "GuiTall.png"), 61, 50));
|
||||
guiElements.add(new GuiProgress(new IProgressInfoHandler()
|
||||
|
||||
@@ -58,16 +58,16 @@ public class GuiReactorStats extends GuiMekanism
|
||||
{
|
||||
fontRendererObj.drawString(EnumColor.DARK_GREEN + MekanismUtils.localize("gui.passive"), 6, 26, 0x404040);
|
||||
fontRendererObj.drawString(MekanismUtils.localize("gui.minInject") + ": " + (tileEntity.getReactor().getMinInjectionRate(false)), 16, 36, 0x404040);
|
||||
fontRendererObj.drawString(MekanismUtils.localize("gui.ignition") + ": " + (nf.format(tileEntity.getReactor().getIgnitionTemperature(false))), 16, 46, 0x404040);
|
||||
fontRendererObj.drawString(MekanismUtils.localize("gui.maxPlasma") + ": " + (nf.format(tileEntity.getReactor().getMaxPlasmaTemperature(false))), 16, 56, 0x404040);
|
||||
fontRendererObj.drawString(MekanismUtils.localize("gui.maxCasing") + ": " + (nf.format(tileEntity.getReactor().getMaxCasingTemperature(false))), 16, 66, 0x404040);
|
||||
fontRendererObj.drawString(MekanismUtils.localize("gui.ignition") + ": " + (MekanismUtils.getTemperatureDisplay(tileEntity.getReactor().getIgnitionTemperature(false))), 16, 46, 0x404040);
|
||||
fontRendererObj.drawString(MekanismUtils.localize("gui.maxPlasma") + ": " + (MekanismUtils.getTemperatureDisplay(tileEntity.getReactor().getMaxPlasmaTemperature(false))), 16, 56, 0x404040);
|
||||
fontRendererObj.drawString(MekanismUtils.localize("gui.maxCasing") + ": " + (MekanismUtils.getTemperatureDisplay(tileEntity.getReactor().getMaxCasingTemperature(false))), 16, 66, 0x404040);
|
||||
fontRendererObj.drawString(MekanismUtils.localize("gui.passiveGeneration") + ": " + MekanismUtils.getEnergyDisplay(tileEntity.getReactor().getPassiveGeneration(false, false))+"/t", 16, 76, 0x404040);
|
||||
|
||||
fontRendererObj.drawString(EnumColor.DARK_BLUE + MekanismUtils.localize("gui.active"), 6, 92, 0x404040);
|
||||
fontRendererObj.drawString(MekanismUtils.localize("gui.minInject") + ": " + (tileEntity.getReactor().getMinInjectionRate(true)), 16, 102, 0x404040);
|
||||
fontRendererObj.drawString(MekanismUtils.localize("gui.ignition") + ": " + (nf.format(tileEntity.getReactor().getIgnitionTemperature(true))), 16, 112, 0x404040);
|
||||
fontRendererObj.drawString(MekanismUtils.localize("gui.maxPlasma") + ": " + (nf.format(tileEntity.getReactor().getMaxPlasmaTemperature(true))), 16, 122, 0x404040);
|
||||
fontRendererObj.drawString(MekanismUtils.localize("gui.maxCasing") + ": " + (nf.format(tileEntity.getReactor().getMaxCasingTemperature(true))), 16, 132, 0x404040);
|
||||
fontRendererObj.drawString(MekanismUtils.localize("gui.ignition") + ": " + (MekanismUtils.getTemperatureDisplay(tileEntity.getReactor().getIgnitionTemperature(true))), 16, 112, 0x404040);
|
||||
fontRendererObj.drawString(MekanismUtils.localize("gui.maxPlasma") + ": " + (MekanismUtils.getTemperatureDisplay(tileEntity.getReactor().getMaxPlasmaTemperature(true))), 16, 122, 0x404040);
|
||||
fontRendererObj.drawString(MekanismUtils.localize("gui.maxCasing") + ": " + (MekanismUtils.getTemperatureDisplay(tileEntity.getReactor().getMaxCasingTemperature(true))), 16, 132, 0x404040);
|
||||
fontRendererObj.drawString(MekanismUtils.localize("gui.passiveGeneration") + ": " + MekanismUtils.getEnergyDisplay(tileEntity.getReactor().getPassiveGeneration(true, false))+"/t", 16, 142, 0x404040);
|
||||
fontRendererObj.drawString(MekanismUtils.localize("gui.steamProduction") + ": " + nf.format(tileEntity.getReactor().getSteamPerTick(false)) + "mB/t", 16, 152, 0x404040);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user