22
33import dev .dfonline .codeclient .CodeClient ;
44import dev .dfonline .codeclient .OverlayManager ;
5+ import dev .dfonline .codeclient .Utility ;
56import dev .dfonline .codeclient .config .Config ;
67import dev .dfonline .codeclient .location .Plot ;
78import net .minecraft .client .render .VertexConsumerProvider ;
1011import net .minecraft .network .listener .PacketListener ;
1112import net .minecraft .network .packet .Packet ;
1213import net .minecraft .network .packet .s2c .play .OverlayMessageS2CPacket ;
13- import net .minecraft .text .MutableText ;
14- import net .minecraft .text .Style ;
14+ import net .minecraft .text .PlainTextContent ;
1515import net .minecraft .text .Text ;
16+ import net .minecraft .text .TextColor ;
1617import net .minecraft .util .Formatting ;
17- import net .minecraft .util .math .Vec3d ;
1818
19+ import java .util .ArrayList ;
1920import java .util .List ;
21+ import java .util .Objects ;
2022
2123public class Debug {
22- public static boolean active = false ;
24+ private static Double CPU = null ;
25+ private static List <Text > text = null ;
26+ private static boolean active = false ;
2327
24- public static Variables variables = new Variables ();
25- public static Double CPU = null ;
26- private static Variable variable ;
28+ public static void clean () {
29+ CPU = null ;
30+ text = null ;
31+ active = false ;
32+ }
2733
2834 public static <T extends PacketListener > boolean handlePacket (Packet <T > packet ) {
2935 if (!Config .getConfig ().CCDBUG ) return false ;
3036 if (packet instanceof OverlayMessageS2CPacket overlay ) {
31- String message = overlay .getMessage ().getString ();
32- String [] args = message .split (" " );
33- if (args .length > 0 && args [0 ].equals ("ccdbug" )) {
34- if (args .length > 1 ) {
35- if (args [1 ].equals ("hello" )) {
36- active = true ;
37- if (args .length > 3 && CodeClient .location instanceof Plot plot ) {
38- plot .setOrigin (Integer .parseInt (args [2 ]), Integer .parseInt (args [3 ]));
39- }
40- }
41- if (args .length > 2 && args [1 ].equals ("var" )) {
42- if (args [2 ].equals ("set" )) {
43- variable = new Variable (message .replaceFirst ("^ccdbug var set " ,"" ));
44- }
45- if (args [2 ].equals ("type" )) {
46- Variable .ValueType type = Variable .ValueType .valueTypeMap .get (message .replaceFirst ("^ccdbug var type " ,"" ));
47- variable .type = type ;
48- if (type == Variable .ValueType .Dead ) {
49- variables .addOrUpdate (variable );
50- variable = null ;
51- }
52- }
53- if (args [2 ].equals ("value" ) && variable != null ) {
54- variable .value = message .replaceFirst ("^ccdbug var value " , "" );
55- variables .addOrUpdate (variable );
56- variable = null ;
57- }
37+ var txt = overlay .getMessage ();
38+ if (Text .empty ().equals (txt )) {
39+ Utility .debug ("empty" );
40+ return false ;
41+ }
42+ var siblings = txt .getSiblings ();
43+ if (siblings .isEmpty ()) {
44+ Utility .debug ("no siblings" );
45+ return false ;
46+ }
47+ var command = siblings .get (0 );
48+ if (!Objects .equals (command .getStyle ().getColor (), TextColor .fromRgb (0x00ccdb ))) return false ;
49+ if (command .getContent ().equals (new PlainTextContent .Literal ("ccdbug text" ))) {
50+ boolean first = true ;
51+ text = new ArrayList <>();
52+ for (var part : siblings ) {
53+ if (first ) {
54+ first = false ;
55+ continue ;
5856 }
57+ text .add (part );
5958 }
60- // updateDisplay();
61- return true ;
62- }
63- if (active && message .matches ("^CPU Usage: \\ [▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮] \\ ([\\ d.]+%\\ )$" )) {
64- CPU = Double .parseDouble (message .replaceAll ("(^CPU Usage: \\ [▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮] \\ (|%\\ )$)" ,"" ));
65- return true ;
6659 }
60+ active = true ;
61+ return true ;
62+ // if(command) {
63+ // if(siblings.size() > 1) {
64+ // text = siblings.get(1);
65+ // }
66+ // else {
67+ // text = Text.empty();
68+ // }
69+ // updateDisplay();
70+ // }
6771 }
6872 return false ;
6973 }
7074
7175 public static void updateDisplay () {
76+ if (!active ) return ;
77+ if (text == null ) return ;
7278 OverlayManager .setOverlayText ();
73- OverlayManager .addOverlayText (Text .literal ("CCDBUG" ).formatted (Formatting .YELLOW ,Formatting .BOLD ));
79+ OverlayManager .addOverlayText (Text .empty (). append ( Text . literal ("CCDBUG" ).formatted (Formatting .YELLOW ,Formatting .BOLD )). append ( " (/abort to hide)" ));
7480 if (CPU != null ) {
7581 OverlayManager .addOverlayText (Text .literal ("CPU Usage: " ).formatted (Formatting .GOLD ).append (Text .literal (String .valueOf (CPU )).formatted (Formatting .AQUA )));
82+ OverlayManager .addOverlayText (Text .empty ());
7683 }
77- OverlayManager .addOverlayText (Text .empty ());
78- List <Variable > variableList = List .copyOf (variables .variables );
79- for (Variable variable : variableList ) {
80- MutableText text = Text .literal (variable .type .name ).fillStyle (Style .EMPTY .withColor (variable .type .color )).append (" " ).append (Text .literal (variable .name ).formatted (Formatting .YELLOW ));
81- if (variable .value != null ) {
82- text .append (" " ).append (Text .literal (variable .value ).formatted (Formatting .AQUA ));
83- }
84- OverlayManager .addOverlayText (text );
84+ for (var line : text ) {
85+ OverlayManager .addOverlayText (line );
8586 }
8687 }
8788
@@ -90,25 +91,11 @@ public static void tick() {
9091 updateDisplay ();
9192 }
9293 else {
93- active = false ;
94- variables .clear ();
9594 CPU = null ;
9695 }
9796 }
9897
9998 public static void render (MatrixStack matrices , VertexConsumerProvider .Immediate vertexConsumers ) {
100- for (Variable variable : variables .variables ) {
101- if (variable .type == Variable .ValueType .Loc && CodeClient .location instanceof Plot plot ) {
102- try {
103- String [] posmaker = variable .value .replaceAll ("^\\ [|,|]$" ,"" ).split (" " );
104- Vec3d pos = new Vec3d (
105- Double .parseDouble (posmaker [0 ]),
106- Double .parseDouble (posmaker [1 ]),
107- Double .parseDouble (posmaker [2 ]))
108- .add (plot .getX (),0 , plot .getZ ());
109- DebugRenderer .drawString (matrices ,vertexConsumers , variable .name , pos .x ,pos .y ,pos .z , 0xFFFFFF , 0.02F , true , 0 , true );
110- } catch (Exception ignored ) {}
111- }
112- }
99+ 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 );
113100 }
114101}
0 commit comments