From fc80d822dd05739f2d5f11cd4a0355dac9bf5382 Mon Sep 17 00:00:00 2001 From: RTTV Date: Fri, 1 Jul 2022 12:37:21 -0400 Subject: [PATCH] using x, y, and z replaces for player coordinates --- src/main/java/ca/rttv/chatcalc/MathEngine.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/java/ca/rttv/chatcalc/MathEngine.java b/src/main/java/ca/rttv/chatcalc/MathEngine.java index c838978..b1e14bc 100644 --- a/src/main/java/ca/rttv/chatcalc/MathEngine.java +++ b/src/main/java/ca/rttv/chatcalc/MathEngine.java @@ -5,7 +5,6 @@ import net.minecraft.client.MinecraftClient; import net.minecraft.text.LiteralTextContent; import net.minecraft.text.MutableText; -import net.minecraft.text.Style; import net.minecraft.text.Text; import org.slf4j.Logger; @@ -13,17 +12,24 @@ import java.util.List; import java.util.Optional; import java.util.stream.Collectors; -import java.util.stream.Stream; public class MathEngine { public static final Logger LOGGER = LogUtils.getLogger(); public static double eval(String input) { - input = input.toLowerCase().replaceAll("pi", "3.141592653589793").replaceAll("\\*\\*", "^").replaceAll("(?!c)e(?!il)", "2.718281828459045").replaceAll(",(?! )", ""); + MinecraftClient client = MinecraftClient.getInstance(); + input = input.toLowerCase() + .replaceAll("pi", "3.141592653589793") + .replaceAll("\\*\\*", "^").replaceAll("(?!c)e(?!il)", "2.718281828459045") + .replaceAll(",(?! )", ""); + if (client.player != null) { + input = input.replaceAll("x", String.valueOf(client.player.getX())) + .replaceAll("y", String.valueOf(client.player.getY())) + .replaceAll("z", String.valueOf(client.player.getZ())); + } List tokens = new ArrayList<>(input.length()); // array of custom objects which do different things each Optional> currentType = Optional.empty(); StringBuilder sb = new StringBuilder(); - MinecraftClient client = MinecraftClient.getInstance(); for (int i = 0; i < input.length(); i++) { char c = input.charAt(i);