diff --git a/src/main/java/minihud/config/Configs.java b/src/main/java/minihud/config/Configs.java index 50cc2b9f2..53988aea5 100644 --- a/src/main/java/minihud/config/Configs.java +++ b/src/main/java/minihud/config/Configs.java @@ -39,7 +39,7 @@ public static class Generic public static final IntegerConfig DROPPED_CHUNKS_HASH_SIZE = new IntegerConfig("droppedChunksHashSize", -1, -1, Integer.MAX_VALUE); public static final IntegerConfig CHUNK_UNLOAD_BUCKET_OVERLAY_RADIUS = new IntegerConfig("chunkUnloadBucketOverlayChunkRadius", -1, -1, 40); public static final BooleanConfig CHUNK_UNLOAD_BUCKET_HASH_SIZE = new BooleanConfig("chunkUnloadBucketHashSize", true); - public static final StringConfig COORDINATE_FORMAT_STRING = new StringConfig( "coordinateFormat", "x: %.1f y: %.1f z: %.1f"); + public static final StringConfig COORDINATE_FORMAT_STRING = new StringConfig( "coordinateFormat", "x: {x:%.1f} y: {y:%.1f} z: {z:%.1f}"); public static final BooleanConfig COORDINATE_FORMAT_CUSTOMIZED = new BooleanConfig("coordinateFormatCustomized", false); public static final BooleanConfig PATH_FINDING_DEBUG_POINT_WIDTH = new BooleanConfig("pathFindingDebugPointWidth", true); public static final BooleanConfig FIX_VANILLA_DEBUG_RENDERERS = new BooleanConfig("enableVanillaDebugRendererFix", true); diff --git a/src/main/java/minihud/event/RenderHandler.java b/src/main/java/minihud/event/RenderHandler.java index 0ca3b9d56..bda298254 100644 --- a/src/main/java/minihud/event/RenderHandler.java +++ b/src/main/java/minihud/event/RenderHandler.java @@ -518,8 +518,45 @@ else if (type == InfoLineToggle.COORDINATES || { try { - str.append(String.format(Configs.Generic.COORDINATE_FORMAT_STRING.getValue(), - x, bbY, z)); + // Follow a python like formatted string input, parse then make it java + StringBuilder javaFormat = new StringBuilder(128); + // aka stuff between {} + Matcher matcher = Pattern.compile("\\{([^\\}]+)\\}").matcher(line); + + int from = 0, to = 0; + float[] vals = {x, bbY, z}; + + for (int i = 0; i < 3; i++) + { + if (!matcher.find(from)) + { + break; + } + + to = matcher.start(); + // Add the content between the {x:%.2f} + javaFormat.append(line.substring(from, to)); + + String[] parts = matcher.group(1).split(":"); + String varname = parts[0], format = parts[1]; + + if (varname.equals("x")) + { + vals[i] = x; + } + else if (varname.equals("y")) + { + vals[i] = bbY; + } else if (varname.equals("z")) + { + vals[i] = z; + } + javaFormat.append(format); + + from = matcher.end(); + } + + str.append(String.format(javaFormat.toString(), vals[0], vals[1], vals[2])); } // Uh oh, someone done goofed their format string... :P catch (Exception e) diff --git a/src/main/resources/assets/minihud/lang/en_us.lang b/src/main/resources/assets/minihud/lang/en_us.lang index 843ac9f48..28ff5f532 100644 --- a/src/main/resources/assets/minihud/lang/en_us.lang +++ b/src/main/resources/assets/minihud/lang/en_us.lang @@ -19,7 +19,7 @@ minihud.config.comment.blockgridoverlayradius=The radius to render the Block Gri minihud.config.comment.chunkunloadbucketoverlayfontscale=The font scale for the Chunk Unload Order (HashSet bucket) overlay minihud.config.comment.chunkunloadbucketoverlaychunkradius=The radius of chunks to render the Chunk Unload Order overlay text in.\n\nUse §b-1§r for the normal render distance minihud.config.comment.chunkunloadbuckethashsize=Enables the more accurate chunk unload bucket calculation, taken from the Carpet mod -minihud.config.comment.coordinateformat=The format string for the coordinate line (Info Lines -> §eCoordinates§r). Needs to have three float format strings specifiers!\n\n§eNote:§r You must enable the §eCustomized Coordinate Format§r option for this custom format string to be used. +minihud.config.comment.coordinateformat=The format string for the coordinate line (Info Lines -> §eCoordinates§r). You may remove any of these.\n\n§eNote:§r You must enable the §eCustomized Coordinate Format§r option for this custom format string to be used. minihud.config.comment.coordinateformatcustomized=Use the customized coordinate format string from §eCoordinate Format§r for the §eCoordinates§r info line minihud.config.comment.debugmessages=Enables some debug messages to the game console, which can be helpful when diagnozing something not working as expected minihud.config.comment.droppedchunkshashsize=The HashSet size for the chunk unload order calculation, if §eChunk Unload Order Hash Size§r is enabled.\n\nUse §b-1§r for automatically fetching the current value in single player or on servers that have the Carpet mod.\n\nA value other than §b-1§r will override the automatic value, including the proper value received from a Carpet server.