From 344085f4efc5708e0be4b26dcd24eeb0c975b82f Mon Sep 17 00:00:00 2001 From: Imeguras Date: Mon, 8 Aug 2022 12:00:48 +0100 Subject: [PATCH] Added the ability to use KmM as abreviatures for example 1m is equals to 1 million while 1K is 1000 --- .../api/command/datatypes/RelativeCoordinate.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/api/java/baritone/api/command/datatypes/RelativeCoordinate.java b/src/api/java/baritone/api/command/datatypes/RelativeCoordinate.java index 7d77a96c..b8f30a77 100644 --- a/src/api/java/baritone/api/command/datatypes/RelativeCoordinate.java +++ b/src/api/java/baritone/api/command/datatypes/RelativeCoordinate.java @@ -26,7 +26,8 @@ import java.util.stream.Stream; public enum RelativeCoordinate implements IDatatypePost { INSTANCE; - private static Pattern PATTERN = Pattern.compile("^(~?)([+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)([k-k]?)|)$"); + private static String ScalesAliasRegex = "[kKmM]"; + private static Pattern PATTERN = Pattern.compile("^(~?)([+-]?(?:\\d+(?:\\.\\d*)?|\\.\\d+)("+ScalesAliasRegex+"?)|)$"); @Override public Double apply(IDatatypeContext ctx, Double origin) throws CommandException { @@ -41,11 +42,15 @@ public enum RelativeCoordinate implements IDatatypePost { boolean isRelative = !matcher.group(1).isEmpty(); - double offset = matcher.group(2).isEmpty() ? 0 : Double.parseDouble(matcher.group(2).replaceAll("k", "")); - - if (matcher.group(2).contains("k")) { + double offset = matcher.group(2).isEmpty() ? 0 : Double.parseDouble(matcher.group(2).replaceAll(ScalesAliasRegex, "")); + + if (matcher.group(2).toLowerCase().contains("k")) { offset *= 1000; } + if (matcher.group(2).toLowerCase().contains("m")) { + offset *= 1000000; + } + if (isRelative) { return origin + offset;