Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More flexible coordinate format #302

Open
wants to merge 1 commit into
base: liteloader_1.12.2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/minihud/config/Configs.java
Original file line number Diff line number Diff line change
@@ -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);
41 changes: 39 additions & 2 deletions src/main/java/minihud/event/RenderHandler.java
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion src/main/resources/assets/minihud/lang/en_us.lang
Original file line number Diff line number Diff line change
@@ -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.