-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
206 additions
and
0 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
src/main/java/dev/dfonline/codeclient/dev/Debug/Debug.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package dev.dfonline.codeclient.dev.Debug; | ||
|
||
import dev.dfonline.codeclient.CodeClient; | ||
import dev.dfonline.codeclient.OverlayManager; | ||
import dev.dfonline.codeclient.location.Plot; | ||
import net.minecraft.client.render.VertexConsumerProvider; | ||
import net.minecraft.client.render.debug.DebugRenderer; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
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.Text; | ||
import net.minecraft.util.Formatting; | ||
import net.minecraft.util.math.Vec3d; | ||
|
||
import java.util.List; | ||
|
||
public class Debug { | ||
public static boolean active = false; | ||
|
||
public static Variables variables = new Variables(); | ||
public static Double CPU = null; | ||
private static Variable variable; | ||
|
||
public static <T extends PacketListener> boolean handlePacket(Packet<T> packet) { | ||
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.value = message.replaceFirst("^ccdbug var value ", ""); | ||
variables.addOrUpdate(variable); | ||
variable = null; | ||
} | ||
} | ||
} | ||
// updateDisplay(); | ||
return true; | ||
} | ||
if(message.matches("^CPU Usage: \\[▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮] \\([\\d\\.]+%\\)$")) { | ||
CPU = Double.parseDouble(message.replaceAll("(^CPU Usage: \\[▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮▮] \\(|%\\)$)","")); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public static void updateDisplay() { | ||
OverlayManager.setOverlayText(); | ||
OverlayManager.addOverlayText(Text.literal("CCDBUG").formatted(Formatting.YELLOW,Formatting.BOLD)); | ||
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()); | ||
List<Variable> 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); | ||
} | ||
} | ||
|
||
public static void tick() { | ||
if(active && CodeClient.location instanceof Plot) { | ||
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) {} | ||
} | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/main/java/dev/dfonline/codeclient/dev/Debug/Variable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package dev.dfonline.codeclient.dev.Debug; | ||
|
||
import net.minecraft.text.TextColor; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import dev.dfonline.codeclient.actiondump.Argument.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<String, ValueType> valueTypeMap; | ||
static { | ||
HashMap<String, ValueType> map = new HashMap<>(); | ||
for (ValueType type: values()) { | ||
map.put(type.name, type); | ||
} | ||
valueTypeMap = Map.copyOf(map); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/dev/dfonline/codeclient/dev/Debug/Variables.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package dev.dfonline.codeclient.dev.Debug; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Objects; | ||
|
||
public class Variables { | ||
public ArrayList<Variable> 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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/dev/dfonline/codeclient/mixin/MDebugRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package dev.dfonline.codeclient.mixin; | ||
|
||
import dev.dfonline.codeclient.dev.Debug.Debug; | ||
import net.minecraft.client.render.VertexConsumerProvider; | ||
import net.minecraft.client.render.debug.DebugRenderer; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(DebugRenderer.class) | ||
public class MDebugRenderer { | ||
@Inject(method = "render", at = @At("HEAD")) | ||
private void onRender(MatrixStack matrices, VertexConsumerProvider.Immediate vertexConsumers, double cameraX, double cameraY, double cameraZ, CallbackInfo ci) { | ||
Debug.render(matrices, vertexConsumers); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters