diff --git a/common/src/main/java/me/zacharias/speedometer/Client.java b/common/src/main/java/me/zacharias/speedometer/Client.java index 7d54380..45f1c73 100644 --- a/common/src/main/java/me/zacharias/speedometer/Client.java +++ b/common/src/main/java/me/zacharias/speedometer/Client.java @@ -115,7 +115,7 @@ public class Client { } speed = speed / speeds.size(); - double speedTypeSpeed = 0D; + double speedTypeSpeed; SpeedTypes speedType = Config.getSpeedType(); if (speedType == SpeedTypes.KNOT || (entity instanceof Boat && Config.getUseKnot())) { @@ -170,8 +170,8 @@ public class Client { g2d.drawLine(x3,y3,img.getWidth()/2,img.getHeight()/2); - int xPos = getPos(graphics, Config.getXPositionVisual(), 0, false, img.getWidth()); - int yPos = getPos(graphics, Config.getYPositionVisual(), 1, true, img.getHeight()); + int xPos = getPos(graphics, Config.getXPosition(), 0, false); + int yPos = getPos(graphics, Config.getYPosition(), 1, true); for(int x1 = 0; x1 < img.getWidth(); x1++){ for(int y1 = 0; y1 < img.getHeight(); y1++){ @@ -202,11 +202,13 @@ public class Client { // j -> y // k -> color RGB int String speedString = format + " " + SpeedTypes.getName(speedType).getString(); + int width = Minecraft.getInstance().font.width(speedString); + int lineHeight = Minecraft.getInstance().font.lineHeight; graphics.drawString( Minecraft.getInstance().font, speedString, - getPos(graphics, Config.getXPositionText(), 0, false, Minecraft.getInstance().font.width(speedString)), - getPos(graphics, Config.getYPositionText(), 1, true, Minecraft.getInstance().font.lineHeight), + getPos(graphics, Config.getXPosition(), 0, false) - width, + getPos(graphics, Config.getYPosition(), 1, true) - lineHeight, Config.getColor().getColor() ); } @@ -253,7 +255,7 @@ public class Client { static boolean flag = true; - private static int getPos(GuiGraphics event, String input, int type, boolean changeFlag, int Size) { + private static int getPos(GuiGraphics event, String input, int type, boolean changeFlag) { ArrayList passerPose = new ArrayList<>(); final char[] s = input.toCharArray(); try{ @@ -279,8 +281,6 @@ public class Client { }catch (NumberFormatException e){ passerPose.add(Character.toString(s[i])); } - }else if(s[i] == 'S' || s[i] == 's'){ - passerPose.add(String.valueOf(Size)); }else{ throw new Exception(); } diff --git a/common/src/main/java/me/zacharias/speedometer/Config.java b/common/src/main/java/me/zacharias/speedometer/Config.java index a86e687..cb06806 100644 --- a/common/src/main/java/me/zacharias/speedometer/Config.java +++ b/common/src/main/java/me/zacharias/speedometer/Config.java @@ -11,7 +11,7 @@ import static me.zacharias.speedometer.Speedometer.MOD_ID; public class Config { private static JSONObject Config; - public static final float configVersion = 2.1f; + public static final float configVersion = 3f; public static void initialize(){ if(Config != null) throw new RuntimeException("Already Initialized"); @@ -76,17 +76,25 @@ public class Config { if(!Config.has("visualSpeedometer")) { Config.put("visualSpeedometer", false); } - if(!Config.has("xPositionVisual")) { + + /*if(!Config.has("xPositionVisual")) { Config.put("xPositionVisual", "W-3"); } if(!Config.has("yPositionVisual")) { Config.put("yPositionVisual", "H-3"); } if(!Config.has("xPositionText")) { - Config.put("xPositionText", "W-70"); + Config.put("xPositionText", "W-3"); } if(!Config.has("yPositionText")) { - Config.put("yPositionText", "H-15"); + Config.put("yPositionText", "H-3"); + }*/ + + if(!Config.has("xPosition")) { + Config.put("xPosition", "W-3"); + } + if(!Config.has("yPosition")) { + Config.put("yPosition", "H-3"); } if(!Config.has("debug")) { @@ -167,7 +175,7 @@ public class Config { } } - public static String getXPositionVisual(){ + /*public static String getXPositionVisual(){ if(Config.has("xPositionVisual")) { return Config.getString("xPositionVisual"); }else{ @@ -196,6 +204,22 @@ public class Config { }else{ return "H-15"; } + }*/ + + public static String getYPosition(){ + if(Config.has("yPosition")) { + return Config.getString("yPosition"); + }else{ + return "H-15"; + } + } + + public static String getXPosition(){ + if(Config.has("xPosition")) { + return Config.getString("xPosition"); + }else{ + return "W-70"; + } } public static int getImageSize(){ @@ -226,6 +250,7 @@ public class Config { Config.put("visualSpeedometer", visualSpeedometer); } + /* public static void setXPositionVisual(String xPositionVisual){ Config.put("xPositionVisual", xPositionVisual); } @@ -240,6 +265,14 @@ public class Config { public static void setYPositionText(String yPositionText){ Config.put("yPositionText", yPositionText); + }*/ + + public static void setXPosition(String xPosition){ + Config.put("xPosition", xPosition); + } + + public static void setYPosition(String yPosition){ + Config.put("yPosition", yPosition); } public static void setDebug(boolean debug){ diff --git a/common/src/main/java/me/zacharias/speedometer/ConfigMenu.java b/common/src/main/java/me/zacharias/speedometer/ConfigMenu.java index ddec930..b256923 100644 --- a/common/src/main/java/me/zacharias/speedometer/ConfigMenu.java +++ b/common/src/main/java/me/zacharias/speedometer/ConfigMenu.java @@ -47,7 +47,7 @@ public class ConfigMenu { String yRegex = "H*h*S*s*\\+*-*\\**/*[0-9]*"; // Text Placement - + /* category.addEntry(entryBuilder.startStringDropdownMenu(Component.translatable("speedometer.config.xPosition.text"), Config.getXPositionText()) .setSaveConsumer(Config::setXPositionText) .setErrorSupplier(xPosition -> { @@ -101,6 +101,7 @@ public class ConfigMenu { .build() ); + category.addEntry(entryBuilder.startStringDropdownMenu(Component.translatable("speedometer.config.yPosition.visual"), Config.getYPositionVisual()) .setSaveConsumer(Config::setYPositionVisual) .setErrorSupplier(yPosition -> { @@ -116,6 +117,39 @@ public class ConfigMenu { Component.translatable("speedometer.config.tooltip.yPosition.line3") ) .build() + );*/ + + category.addEntry(entryBuilder.startStringDropdownMenu(Component.translatable("speedometer.config.xPosition"), Config.getXPosition()) + .setSaveConsumer(Config::setXPosition) + .setErrorSupplier(xPosition -> { + if(xPosition.matches(xRegex)){ + return Optional.empty(); + }else{ + return Optional.of(Component.translatable("speedometer.invalid")); + } + }) + .setTooltip( + Component.translatable("speedometer.config.tooltip.xPosition.line1"), + Component.translatable("speedometer.config.tooltip.xPosition.line2") + ) + .build() + ); + + + category.addEntry(entryBuilder.startStringDropdownMenu(Component.translatable("speedometer.config.yPosition"), Config.getYPosition()) + .setSaveConsumer(Config::setYPosition) + .setErrorSupplier(yPosition -> { + if(yPosition.matches(yRegex)){ + return Optional.empty(); + }else{ + return Optional.of(Component.translatable("speedometer.invalid")); + } + }) + .setTooltip( + Component.translatable("speedometer.config.tooltip.yPosition.line1"), + Component.translatable("speedometer.config.tooltip.yPosition.line2") + ) + .build() ); // Size of visual image diff --git a/common/src/main/resources/assets/speedometer/lang/en_us.json b/common/src/main/resources/assets/speedometer/lang/en_us.json index 5f2db36..494390e 100644 --- a/common/src/main/resources/assets/speedometer/lang/en_us.json +++ b/common/src/main/resources/assets/speedometer/lang/en_us.json @@ -9,6 +9,8 @@ "speedometer.config.yPosition.visual": "Y Position for Visual Meter", "speedometer.config.xPosition.text": "X Position for Text Meter", "speedometer.config.yPosition.text": "Y Position for Text Meter", + "speedometer.config.xPosition": "X Position for Meters", + "speedometer.config.yPosition": "Y Position for Meters", "speedometer.config.debug": "Debug", "speedometer.config.imageSize": "Image Size", diff --git a/forge/src/main/resources/updateChecker.json b/forge/src/main/resources/updateChecker.json index 2b0bb12..b8d0670 100644 --- a/forge/src/main/resources/updateChecker.json +++ b/forge/src/main/resources/updateChecker.json @@ -5,20 +5,22 @@ "2.0": "Made the speedometer text movable, added debug data display, added visual speedometer", "3.0": "Added size setting for visual speedometer, changed how the visual speedometer location is set", "3.1": "Fixed error in language file", - "3.2": "Correct checker for Client or Server environment, updated dependencies, added dependency check in mod data file, added a renamer to rename the mod file if it's on a server" + "3.2": "Correct checker for Client or Server environment, updated dependencies, added dependency check in mod data file, added a renamer to rename the mod file if it's on a server", + "4.0": "Removed the Size part of the position string, combined the visual and text location strings, updated config version to 3, fixed bug where the text would start to drift of screen if you where too fast" }, "1.20": { "1.0": "First version", "2.0": "Made the speedometer text movable, added debug data display, added visual speedometer", "3.0": "Added size setting for visual speedometer, changed how the visual speedometer location is set", "3.1": "Fixed error in language file", - "3.2": "Correct checker for Client or Server environment, updated dependencies, added dependency check in mod data file, added a renamer to rename the mod file if it's on a server" + "3.2": "Correct checker for Client or Server environment, updated dependencies, added dependency check in mod data file, added a renamer to rename the mod file if it's on a server", + "4.0": "Removed the Size part of the position string, combined the visual and text location strings, updated config version to 3, fixed bug where the text would start to drift of screen if you where too fast" }, "promos": { - "1.20.1-latest": "3.2", - "1.20.1-recommended": "3.2", + "1.20.1-latest": "4.0", + "1.20.1-recommended": "4.0", - "1.20-latest": "3.2", - "1.20-recommended": "3.2" + "1.20-latest": "4.0", + "1.20-recommended": "4.0" } } \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index db98434..28e4ff2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ org.gradle.jvmargs=-Xmx8G minecraft_version=1.20.1 archives_base_name=speedometer -mod_version=3.2 +mod_version=4 maven_group=me.zacharias architectury_version=9.1.10