From 7c01098fec2e9f7e1d6e44fb4422f53315df9e1e Mon Sep 17 00:00:00 2001 From: graycat27 <64903817+graycat27@users.noreply.github.com> Date: Sat, 13 Mar 2021 11:27:42 +0900 Subject: [PATCH 1/4] work for #38 Speed,Height old:123.457 -> new:123.5 --- .../flightHUDmod/consts/GuiTextFormat.java | 3 +++ .../github/graycat27/flightHUDmod/unit/Height.java | 6 +++--- .../github/graycat27/flightHUDmod/unit/Speed.java | 8 ++++---- .../flightHUDmod/consts/GuiTextFormatTest.java | 13 +++++++++++++ 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/project/src/main/java/com/github/graycat27/flightHUDmod/consts/GuiTextFormat.java b/project/src/main/java/com/github/graycat27/flightHUDmod/consts/GuiTextFormat.java index ce56e6d..874013c 100644 --- a/project/src/main/java/com/github/graycat27/flightHUDmod/consts/GuiTextFormat.java +++ b/project/src/main/java/com/github/graycat27/flightHUDmod/consts/GuiTextFormat.java @@ -7,6 +7,9 @@ */ public class GuiTextFormat { + /** 1,234.5 from Float */ + public static final String floatStr1f = "%,.1f"; + /** 1,234.568 from Float */ public static final String floatStr3f = "%,.3f"; diff --git a/project/src/main/java/com/github/graycat27/flightHUDmod/unit/Height.java b/project/src/main/java/com/github/graycat27/flightHUDmod/unit/Height.java index f8a2399..e824ef5 100644 --- a/project/src/main/java/com/github/graycat27/flightHUDmod/unit/Height.java +++ b/project/src/main/java/com/github/graycat27/flightHUDmod/unit/Height.java @@ -2,7 +2,7 @@ import net.minecraft.client.entity.player.ClientPlayerEntity; -import static com.github.graycat27.flightHUDmod.consts.GuiTextFormat.floatStr3f; +import static com.github.graycat27.flightHUDmod.consts.GuiTextFormat.floatStr1f; public class Height implements IUnit { @@ -36,9 +36,9 @@ public double getHeight(){ return (double)heightVal/DIGIT; } - /** 精度は小数第2位まで保証(3桁取得) */ + /** 精度は整数桁のみ保証(小数第2位で四捨五入した値を取得) */ public String valToString(){ - return String.format(floatStr3f, getHeight()); + return String.format(floatStr1f, getHeight()); } @Override diff --git a/project/src/main/java/com/github/graycat27/flightHUDmod/unit/Speed.java b/project/src/main/java/com/github/graycat27/flightHUDmod/unit/Speed.java index 1dc877a..3961ba3 100644 --- a/project/src/main/java/com/github/graycat27/flightHUDmod/unit/Speed.java +++ b/project/src/main/java/com/github/graycat27/flightHUDmod/unit/Speed.java @@ -2,7 +2,7 @@ import net.minecraft.client.entity.player.ClientPlayerEntity; -import static com.github.graycat27.flightHUDmod.consts.GuiTextFormat.floatStr3f; +import static com.github.graycat27.flightHUDmod.consts.GuiTextFormat.floatStr1f; public class Speed implements IUnit { @@ -84,7 +84,7 @@ public double getActualSpeed(){ return actualSpeed; } public String getActualSpeedValStr(){ - return String.format(floatStr3f, actualSpeed); + return String.format(floatStr1f, actualSpeed); } /** 水平速度を返す */ @@ -92,7 +92,7 @@ public double getHorizonSpeed(){ return horizonSpeed; } public String getHorizonSpeedValStr(){ - return String.format(floatStr3f, horizonSpeed); + return String.format(floatStr1f, horizonSpeed); } /** 鉛直速度を返す */ @@ -100,7 +100,7 @@ public double getVerticalSpeed(){ return verticalSpeed; } public String getVerticalSpeedValStr(){ - return String.format(floatStr3f, verticalSpeed); + return String.format(floatStr1f, verticalSpeed); } @Override diff --git a/project/src/test/java/com/github/graycat27/flightHUDmod/consts/GuiTextFormatTest.java b/project/src/test/java/com/github/graycat27/flightHUDmod/consts/GuiTextFormatTest.java index ed68829..70182b4 100644 --- a/project/src/test/java/com/github/graycat27/flightHUDmod/consts/GuiTextFormatTest.java +++ b/project/src/test/java/com/github/graycat27/flightHUDmod/consts/GuiTextFormatTest.java @@ -5,6 +5,19 @@ public class GuiTextFormatTest { + @Test + public void testFloatStr1f(){ + float f = 1234.56f; + String s = String.format(GuiTextFormat.floatStr1f, f); + assertEquals("1,234.6", s); //rounded number + } + @Test + public void testFloatStr1fRoundDown(){ + float f = 1234.32f; + String s = String.format(GuiTextFormat.floatStr1f, f); + assertEquals("1,234.3", s); //rounded number + } + @Test public void testFloatStr3f() { float f = 1234.5678f; From fa094e56e3885d7fbbb5824a0e5ca234df10f97d Mon Sep 17 00:00:00 2001 From: graycat27 <64903817+graycat27@users.noreply.github.com> Date: Sat, 13 Mar 2021 11:51:54 +0900 Subject: [PATCH 2/4] =?UTF-8?q?=E5=A7=BF=E5=8B=A2=E8=A8=88=E3=81=AE?= =?UTF-8?q?=E5=B0=8F=E6=95=B0=E5=AF=BE=E5=BF=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../flightHUDmod/consts/GuiTextFormat.java | 4 +- .../flightHUDmod/guiComponent/PitchMeter.java | 17 +++++-- .../graycat27/flightHUDmod/unit/Pitch.java | 17 ++++--- .../guiComponent/PitchMeterTest.java | 47 +++++++++++++++++++ 4 files changed, 70 insertions(+), 15 deletions(-) create mode 100644 project/src/test/java/com/github/graycat27/flightHUDmod/guiComponent/PitchMeterTest.java diff --git a/project/src/main/java/com/github/graycat27/flightHUDmod/consts/GuiTextFormat.java b/project/src/main/java/com/github/graycat27/flightHUDmod/consts/GuiTextFormat.java index 874013c..c0a290d 100644 --- a/project/src/main/java/com/github/graycat27/flightHUDmod/consts/GuiTextFormat.java +++ b/project/src/main/java/com/github/graycat27/flightHUDmod/consts/GuiTextFormat.java @@ -9,9 +9,11 @@ public class GuiTextFormat { /** 1,234.5 from Float */ public static final String floatStr1f = "%,.1f"; - /** 1,234.568 from Float */ public static final String floatStr3f = "%,.3f"; + /** 12° from int */ public static final String pitchStr = "%+d"+ DEGREES; + /** 12.3° from float */ + public static final String pitchStrDecimal = "%+.1f" + DEGREES; } diff --git a/project/src/main/java/com/github/graycat27/flightHUDmod/guiComponent/PitchMeter.java b/project/src/main/java/com/github/graycat27/flightHUDmod/guiComponent/PitchMeter.java index c5c3649..7fbabaa 100644 --- a/project/src/main/java/com/github/graycat27/flightHUDmod/guiComponent/PitchMeter.java +++ b/project/src/main/java/com/github/graycat27/flightHUDmod/guiComponent/PitchMeter.java @@ -13,6 +13,7 @@ import java.util.List; import static com.github.graycat27.flightHUDmod.consts.GuiTextFormat.pitchStr; +import static com.github.graycat27.flightHUDmod.consts.GuiTextFormat.pitchStrDecimal; import static com.github.graycat27.flightHUDmod.FlightHUDMod.modSettings; /** @@ -49,7 +50,7 @@ private void initDisplayComponent(){ int centerY = windowHeight / 2; //center display - int pitchWidth = mc.fontRenderer.getStringWidth(String.format(Line.angleText, getDgrString(Pitch.UP))); + int pitchWidth = mc.fontRenderer.getStringWidth(String.format(Line.angleText, getDgrStringDecimal1(Pitch.UP))); int markWidth = mc.fontRenderer.getStringWidth(Line.mark); int height = mc.fontRenderer.FONT_HEIGHT; boolean isVisible = this.isDisplayed(); @@ -102,16 +103,16 @@ private void initDisplayComponent(){ //movement marker Speed speed = FlightHUDMod.getGuiController().getSpeed(); if(speed != null){ - int flightDegrees; + float flightDegrees; double levelY; if(speed.getHorizonSpeed() != 0) { double actualSpeedAngleRad = Math.atan(speed.getVerticalSpeed() / speed.getHorizonSpeed()); - flightDegrees = (int) Math.toDegrees(actualSpeedAngleRad); + flightDegrees = (float) Math.toDegrees(actualSpeedAngleRad); }else { flightDegrees = speed.getVerticalSpeed() == 0 ? Pitch.LEVEL : (speed.getVerticalSpeed() > 0) ? Pitch.UP : Pitch.DOWN; } - int deltaDgr = flightDegrees - pitch.value(); + float deltaDgr = flightDegrees - pitch.value(); if(deltaDgr > Pitch.UP){ deltaDgr = Pitch.UP; } @@ -128,7 +129,7 @@ private void initDisplayComponent(){ levelY = windowHeight / 2.0 - height; } - String flightPitch = getDgrString(flightDegrees); + String flightPitch = getDgrStringDecimal1(flightDegrees); String flightPitchText = String.format("> %s <", flightPitch); int width = mc.fontRenderer.getStringWidth(flightPitchText); speedPitchTextDisplay = new TextDisplay(posX, (int)(centerY - levelY), @@ -144,6 +145,12 @@ public static String getDgrString(int pitchValue){ } return " "+ pitchValue + Pitch.DEGREES; } + public static String getDgrStringDecimal1(float pitchValue){ + if(pitchValue != Pitch.LEVEL) { + return String.format(pitchStrDecimal, pitchValue); + } + return " "+ pitchValue + Pitch.DEGREES; + } @Override diff --git a/project/src/main/java/com/github/graycat27/flightHUDmod/unit/Pitch.java b/project/src/main/java/com/github/graycat27/flightHUDmod/unit/Pitch.java index 15b06dd..d5ff3b5 100644 --- a/project/src/main/java/com/github/graycat27/flightHUDmod/unit/Pitch.java +++ b/project/src/main/java/com/github/graycat27/flightHUDmod/unit/Pitch.java @@ -2,7 +2,7 @@ import net.minecraft.client.entity.player.ClientPlayerEntity; -import static com.github.graycat27.flightHUDmod.guiComponent.PitchMeter.getDgrString; +import static com.github.graycat27.flightHUDmod.guiComponent.PitchMeter.getDgrStringDecimal1; public class Pitch implements IUnit { @@ -15,7 +15,7 @@ public class Pitch implements IUnit { public static final int UP = 90; /** 内部管理変数。仰俯角。下向きが正 */ - private int pitch; + private float pitch; /** コンストラクタ
* @throws IllegalArgumentException player must not be null. pitch must in -90 to 90 */ @@ -26,26 +26,25 @@ public Pitch(final ClientPlayerEntity player){ //プレイヤーの向いている仰俯角を算出 /* playerPitch = LEVELを0として、下を正とした回転角度 */ - float playerPitch = player.rotationPitch; - int intFlightPitch = Math.round((-1)*playerPitch); - if( intFlightPitch < DOWN || UP < intFlightPitch){ + float playerPitch = (-1)*player.rotationPitch; + if( playerPitch < DOWN || UP < playerPitch){ //must between -90to90 throw new IllegalArgumentException("direction must in -90to90 but was "+ pitch); } - this.pitch = intFlightPitch; + this.pitch = playerPitch; } - private Pitch(int pitch){ + private Pitch(float pitch){ this.pitch = pitch; } - public int value(){ + public float value(){ return pitch; } @Override public String valToString(){ - return getDgrString(pitch); + return getDgrStringDecimal1(pitch); } @Override diff --git a/project/src/test/java/com/github/graycat27/flightHUDmod/guiComponent/PitchMeterTest.java b/project/src/test/java/com/github/graycat27/flightHUDmod/guiComponent/PitchMeterTest.java new file mode 100644 index 0000000..6474297 --- /dev/null +++ b/project/src/test/java/com/github/graycat27/flightHUDmod/guiComponent/PitchMeterTest.java @@ -0,0 +1,47 @@ +package com.github.graycat27.flightHUDmod.guiComponent; + +import org.junit.Test; + +import static org.junit.jupiter.api.Assertions.*; + +public class PitchMeterTest { + + private final float f1 = 45.678f; + private final float f0 = 0.0f; + private final float fn1 = -45.678f; + + /* getDgrString */ + @Test + public void testGetDgrString(){ + String s = PitchMeter.getDgrString((int)f0); + assertEquals(" 0°", s); + } + @Test + public void testGetDgrString1(){ + String s = PitchMeter.getDgrString((int)f1); + assertEquals("+45°", s); //intキャストで切り捨て + } + @Test + public void testGetDgrString2(){ + String s = PitchMeter.getDgrString((int)fn1); + assertEquals("-45°", s); + } + + /* getDgrStringDecimal1 */ + @Test + public void testGetDgrStringDecimal1(){ + String s = PitchMeter.getDgrStringDecimal1(f0); + assertEquals(" 0.0°", s); + } + @Test + public void testGetDgrStringDecimal11(){ + String s = PitchMeter.getDgrStringDecimal1(f1); + assertEquals("+45.7°", s); //formatで四捨五入 + } + @Test + public void testGetDgrStringDecimal12(){ + String s = PitchMeter.getDgrStringDecimal1(fn1); + assertEquals("-45.7°", s); + } + +} \ No newline at end of file From 3c3fa0d9026b62af3e5663597f83fe0cd79acf52 Mon Sep 17 00:00:00 2001 From: graycat27 <64903817+graycat27@users.noreply.github.com> Date: Sat, 13 Mar 2021 12:04:48 +0900 Subject: [PATCH 3/4] =?UTF-8?q?=E6=8F=8F=E7=94=BB=E4=BD=8D=E7=BD=AE?= =?UTF-8?q?=E3=82=92=E4=B8=AD=E5=BF=83=E3=81=AB=E5=AF=84=E3=81=9B=E3=81=9F?= =?UTF-8?q?=20=EF=BC=8Aconfig=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=81=AE?= =?UTF-8?q?=E5=86=8D=E4=BD=9C=E6=88=90=E3=81=8C=E5=BF=85=E8=A6=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../github/graycat27/flightHUDmod/setting/ModSettings.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/project/src/main/java/com/github/graycat27/flightHUDmod/setting/ModSettings.java b/project/src/main/java/com/github/graycat27/flightHUDmod/setting/ModSettings.java index f1b9967..b39249a 100644 --- a/project/src/main/java/com/github/graycat27/flightHUDmod/setting/ModSettings.java +++ b/project/src/main/java/com/github/graycat27/flightHUDmod/setting/ModSettings.java @@ -19,9 +19,9 @@ private static class DefaultValue{ static boolean showHUD = true; static int interval = 15; static int positionCompass = 25; - static int positionHeight = 73; + static int positionHeight = 67; static int positionPitch = 50; - static int positionSpeed = 27; + static int positionSpeed = 33; } /** FlightHUDの表示ON/OFF */ From 7703627979a3dde236b376461a3852aca6632c8b Mon Sep 17 00:00:00 2001 From: graycat27 <64903817+graycat27@users.noreply.github.com> Date: Sat, 13 Mar 2021 12:15:47 +0900 Subject: [PATCH 4/4] =?UTF-8?q?0.0=C2=B0=E3=81=A80=C2=B0=E3=81=AE=E3=82=A4?= =?UTF-8?q?=E3=83=B3=E3=82=B8=E3=82=B2=E3=83=BC=E3=82=BF=E3=83=BC=E3=81=8C?= =?UTF-8?q?=E9=87=8D=E3=81=AA=E3=81=A3=E3=81=9F=E6=99=82=E3=81=AE=E8=A6=8B?= =?UTF-8?q?=E3=81=9F=E7=9B=AE=E3=82=92=E6=94=B9=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../github/graycat27/flightHUDmod/guiComponent/PitchMeter.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/project/src/main/java/com/github/graycat27/flightHUDmod/guiComponent/PitchMeter.java b/project/src/main/java/com/github/graycat27/flightHUDmod/guiComponent/PitchMeter.java index 7fbabaa..a86151e 100644 --- a/project/src/main/java/com/github/graycat27/flightHUDmod/guiComponent/PitchMeter.java +++ b/project/src/main/java/com/github/graycat27/flightHUDmod/guiComponent/PitchMeter.java @@ -129,7 +129,8 @@ private void initDisplayComponent(){ levelY = windowHeight / 2.0 - height; } - String flightPitch = getDgrStringDecimal1(flightDegrees); + String flightPitch = (-0.1f < flightDegrees && flightDegrees < 0.1f) ? + getDgrString((int)flightDegrees) : getDgrStringDecimal1(flightDegrees); String flightPitchText = String.format("> %s <", flightPitch); int width = mc.fontRenderer.getStringWidth(flightPitchText); speedPitchTextDisplay = new TextDisplay(posX, (int)(centerY - levelY),