diff options
author | Bass <tudurap.com@gmail.com> | 2019-02-07 12:53:38 +0000 |
---|---|---|
committer | Bass <tudurap.com@gmail.com> | 2019-02-07 13:25:07 +0000 |
commit | 3218e5bdbfbf2c4769ae57f61c312af26ae315d6 (patch) | |
tree | 44e10ba15512640c7bbeea794de2083ed14bbad4 | |
parent | 0954868ae218f3a77c408eb2eea6d20691c894ac (diff) | |
download | GT5-Unofficial-3218e5bdbfbf2c4769ae57f61c312af26ae315d6.tar.gz GT5-Unofficial-3218e5bdbfbf2c4769ae57f61c312af26ae315d6.tar.bz2 GT5-Unofficial-3218e5bdbfbf2c4769ae57f61c312af26ae315d6.zip |
Added rounding to fix hist value range
I really dislike ever having to deal with any floats ever.
-rw-r--r-- | src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java index bc0a402822..83d1e4e7df 100644 --- a/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java +++ b/src/main/java/com/github/technus/tectech/thing/metaTileEntity/single/GT_MetaTileEntity_TeslaCoil.java @@ -14,6 +14,8 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack;
import java.util.ArrayList;
+import static java.lang.Math.round;
+
public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryBuffer {
public boolean powerPassToggle = false; //Power Pass for public viewing
@@ -36,6 +38,14 @@ public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryB private long outputCurrent = 1; //Tesla Current Output
private long outputEuT = outputVoltage * outputCurrent; //Tesla Power Output
+ //All credit to ivan-stin who gave a solution at https://stackoverflow.com/questions/8911356/whats-the-best-practice-to-round-a-float-to-2-decimals
+ public static float round2(float number, int scale) {
+ int pow = 10;
+ for (int i = 1; i < scale; i++)
+ pow *= 10;
+ float tmp = number * pow;
+ return ( (float) ( (int) ((tmp - (int) tmp) >= 0.5f ? tmp + 1 : tmp) ) ) / pow;
+ }
public GT_MetaTileEntity_TeslaCoil(int aID, String aName, String aNameRegional, int aTier, int aSlotCount) {
super(aID, aName, aNameRegional, aTier, "Tesla Coil Transceiver", aSlotCount);
@@ -46,22 +56,23 @@ public class GT_MetaTileEntity_TeslaCoil extends GT_MetaTileEntity_BasicBatteryB super(aName, aTier, aDescription, aTextures, aSlotCount);
}
- //TODO Redo the string formatting to be actually sane-ish
public void onScrewdriverRightClick(byte aSide, EntityPlayer aPlayer, float aX, float aY, float aZ) {
if (aPlayer.isSneaking()) {
- if (histHigh < histHighLimit && histHigh - histStep != histLow) {
+ if (histHigh < histHighLimit) {
histHigh += histStep;
} else {
histHigh = histLow + histStep;
}
- PlayerChatHelper.SendInfo(aPlayer, "Hysteresis High Changed to " + (histHigh * 100F)+ "%");
+ histHigh = round2(histHigh,2);
+ PlayerChatHelper.SendInfo(aPlayer, "Hysteresis High Changed to " + round(histHigh * 100F) + "%");
} else {
- if (histLow > histLowLimit && histLow - histStep != histLow) {
+ if (histLow > histLowLimit) {
histLow -= histStep;
} else {
histLow = histHigh - histStep;
}
- PlayerChatHelper.SendInfo(aPlayer, "Hysteresis Low Changed to " + (histLow * 100F)+ "%");
+ histLow = round2(histLow,2);
+ PlayerChatHelper.SendInfo(aPlayer, "Hysteresis Low Changed to " + round(histLow * 100F) + "%");
}
}
|