diff --git a/src/main/java/dev/dfonline/codeclient/CodeClient.java b/src/main/java/dev/dfonline/codeclient/CodeClient.java index 23da2116..b6e2f6b0 100644 --- a/src/main/java/dev/dfonline/codeclient/CodeClient.java +++ b/src/main/java/dev/dfonline/codeclient/CodeClient.java @@ -175,10 +175,11 @@ public static void clean() { CodeClient.location = null; BuildPhaser.disableClipping(); Commands.confirm = null; + Debug.clean(); } /** - * As much as possible, set CodeClient to it's startup state. + * As much as possible, set CodeClient to its startup state. */ public static void reset() { clean(); diff --git a/src/main/java/dev/dfonline/codeclient/dev/Debug/Debug.java b/src/main/java/dev/dfonline/codeclient/dev/Debug/Debug.java index 6f235983..837291b5 100644 --- a/src/main/java/dev/dfonline/codeclient/dev/Debug/Debug.java +++ b/src/main/java/dev/dfonline/codeclient/dev/Debug/Debug.java @@ -2,6 +2,7 @@ import dev.dfonline.codeclient.CodeClient; import dev.dfonline.codeclient.OverlayManager; +import dev.dfonline.codeclient.Utility; import dev.dfonline.codeclient.config.Config; import dev.dfonline.codeclient.location.Plot; import net.minecraft.client.render.VertexConsumerProvider; @@ -10,78 +11,78 @@ import net.minecraft.network.listener.PacketListener; import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.s2c.play.OverlayMessageS2CPacket; -import net.minecraft.text.MutableText; -import net.minecraft.text.Style; +import net.minecraft.text.PlainTextContent; import net.minecraft.text.Text; +import net.minecraft.text.TextColor; import net.minecraft.util.Formatting; -import net.minecraft.util.math.Vec3d; +import java.util.ArrayList; import java.util.List; +import java.util.Objects; public class Debug { - public static boolean active = false; + private static Double CPU = null; + private static List text = null; + private static boolean active = false; - public static Variables variables = new Variables(); - public static Double CPU = null; - private static Variable variable; + public static void clean() { + CPU = null; + text = null; + active = false; + } public static boolean handlePacket(Packet packet) { if(!Config.getConfig().CCDBUG) return false; if(packet instanceof OverlayMessageS2CPacket overlay) { - String message = overlay.getMessage().getString(); - String[] args = message.split(" "); - if(args.length > 0 && args[0].equals("ccdbug")) { - if(args.length > 1) { - if(args[1].equals("hello")) { - active = true; - if(args.length > 3 && CodeClient.location instanceof Plot plot) { - plot.setOrigin(Integer.parseInt(args[2]), Integer.parseInt(args[3])); - } - } - if(args.length > 2 && args[1].equals("var")) { - if(args[2].equals("set")) { - variable = new Variable(message.replaceFirst("^ccdbug var set ","")); - } - if(args[2].equals("type")) { - Variable.ValueType type = Variable.ValueType.valueTypeMap.get(message.replaceFirst("^ccdbug var type ","")); - variable.type = type; - if(type == Variable.ValueType.Dead) { - variables.addOrUpdate(variable); - variable = null; - } - } - if(args[2].equals("value") && variable != null) { - variable.value = message.replaceFirst("^ccdbug var value ", ""); - variables.addOrUpdate(variable); - variable = null; - } + var txt = overlay.getMessage(); + if(Text.empty().equals(txt)) { + Utility.debug("empty"); + return false; + } + var siblings = txt.getSiblings(); + if(siblings.isEmpty()) { + Utility.debug("no siblings"); + return false; + } + var command = siblings.get(0); + if(!Objects.equals(command.getStyle().getColor(), TextColor.fromRgb(0x00ccdb))) return false; + if(command.getContent().equals(new PlainTextContent.Literal("ccdbug text"))) { + boolean first = true; + text = new ArrayList<>(); + for (var part: siblings) { + if(first) { + first = false; + continue; } + text.add(part); } -// updateDisplay(); - return true; - } - if(active && message.matches("^CPU Usage: \\[▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮] \\([\\d.]+%\\)$")) { - CPU = Double.parseDouble(message.replaceAll("(^CPU Usage: \\[▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮] \\(|%\\)$)","")); - return true; } + active = true; + return true; +// if(command) { +// if(siblings.size() > 1) { +// text = siblings.get(1); +// } +// else { +// text = Text.empty(); +// } +// updateDisplay(); +// } } return false; } public static void updateDisplay() { + if(!active) return; + if(text == null) return; OverlayManager.setOverlayText(); - OverlayManager.addOverlayText(Text.literal("CCDBUG").formatted(Formatting.YELLOW,Formatting.BOLD)); + OverlayManager.addOverlayText(Text.empty().append(Text.literal("CCDBUG").formatted(Formatting.YELLOW,Formatting.BOLD)).append(" (/abort to hide)")); if(CPU != null) { OverlayManager.addOverlayText(Text.literal("CPU Usage: ").formatted(Formatting.GOLD).append(Text.literal(String.valueOf(CPU)).formatted(Formatting.AQUA))); + OverlayManager.addOverlayText(Text.empty()); } - OverlayManager.addOverlayText(Text.empty()); - List variableList = List.copyOf(variables.variables); - for (Variable variable: variableList) { - MutableText text = Text.literal(variable.type.name).fillStyle(Style.EMPTY.withColor(variable.type.color)).append(" ").append(Text.literal(variable.name).formatted(Formatting.YELLOW)); - if(variable.value != null) { - text.append(" ").append(Text.literal(variable.value).formatted(Formatting.AQUA)); - } - OverlayManager.addOverlayText(text); + for(var line: text) { + OverlayManager.addOverlayText(line); } } @@ -90,25 +91,11 @@ public static void tick() { updateDisplay(); } else { - active = false; - variables.clear(); CPU = null; } } public static void render(MatrixStack matrices, VertexConsumerProvider.Immediate vertexConsumers) { - for (Variable variable: variables.variables) { - if(variable.type == Variable.ValueType.Loc && CodeClient.location instanceof Plot plot) { - try { - String[] posmaker = variable.value.replaceAll("^\\[|,|]$","").split(" "); - Vec3d pos = new Vec3d( - Double.parseDouble(posmaker[0]), - Double.parseDouble(posmaker[1]), - Double.parseDouble(posmaker[2])) - .add(plot.getX(),0, plot.getZ()); - DebugRenderer.drawString(matrices,vertexConsumers, variable.name, pos.x,pos.y,pos.z, 0xFFFFFF, 0.02F, true, 0, true); - } catch (Exception ignored) {} - } - } + if(active) DebugRenderer.drawString(matrices,vertexConsumers, "womp womp", CodeClient.MC.player.getX(),CodeClient.MC.player.getY(),CodeClient.MC.player.getZ(), 0, 0.02F, true, 0, true); } } diff --git a/src/main/java/dev/dfonline/codeclient/dev/Debug/Variable.java b/src/main/java/dev/dfonline/codeclient/dev/Debug/Variable.java deleted file mode 100644 index 0ab68a1b..00000000 --- a/src/main/java/dev/dfonline/codeclient/dev/Debug/Variable.java +++ /dev/null @@ -1,48 +0,0 @@ -package dev.dfonline.codeclient.dev.Debug; - -import net.minecraft.text.TextColor; - -import java.util.HashMap; -import java.util.Map; - -import dev.dfonline.codeclient.hypercube.actiondump.Icon.Type; - -public class Variable { - public ValueType type; - public String name; - public String value = null; - - Variable(String name) { - this.name = name; - } - - public static enum ValueType { - Dead("Dead", Type.NONE.color), - Num("Number", Type.NUMBER.color), - Txt("Text", Type.TEXT.color), - Loc("Location", Type.LOCATION.color), - Item("Item", Type.ITEM.color), - List("List", Type.LIST.color), - Pot("Potion Effect", Type.POTION.color), - Snd("Sound", Type.SOUND.color), - Pfx("Particle", Type.PARTICLE.color), - Vec("Vector", Type.VECTOR.color), - Dict("Dictionary", Type.DICT.color); - - public String name; - public TextColor color; - ValueType(String name, TextColor color) { - this.name = name; - this.color = color; - } - - public static Map valueTypeMap; - static { - HashMap map = new HashMap<>(); - for (ValueType type: values()) { - map.put(type.name, type); - } - valueTypeMap = Map.copyOf(map); - } - } -} diff --git a/src/main/java/dev/dfonline/codeclient/dev/Debug/Variables.java b/src/main/java/dev/dfonline/codeclient/dev/Debug/Variables.java deleted file mode 100644 index 8d2e3982..00000000 --- a/src/main/java/dev/dfonline/codeclient/dev/Debug/Variables.java +++ /dev/null @@ -1,23 +0,0 @@ -package dev.dfonline.codeclient.dev.Debug; - -import java.util.ArrayList; -import java.util.Objects; - -public class Variables { - public ArrayList variables = new ArrayList<>(); - public Variables() {} - - public void addOrUpdate(Variable variable) { - for (int i = 0; i < variables.size(); i++) { - if(Objects.equals(variables.get(i).name, variable.name)) { - variables.set(i, variable); - return; - } - } - variables.add(variable); - } - - public void clear() { - variables.clear(); - } -}