From b4229683064b8fe3e695290a5a6cdb56c0a5c25b Mon Sep 17 00:00:00 2001 From: Moulberry Date: Sat, 10 Feb 2024 16:41:06 +0800 Subject: [PATCH] Add support for line_argb, line_thickness and face_argb --- .../moulberry/axiom/marker/MarkerData.java | 84 ++++++++++++++++--- 1 file changed, 74 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/moulberry/axiom/marker/MarkerData.java b/src/main/java/com/moulberry/axiom/marker/MarkerData.java index e86411f..7f3c353 100644 --- a/src/main/java/com/moulberry/axiom/marker/MarkerData.java +++ b/src/main/java/com/moulberry/axiom/marker/MarkerData.java @@ -15,20 +15,39 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.UUID; -public record MarkerData(UUID uuid, Vec3 position, @Nullable String name, @Nullable Vec3 minRegion, @Nullable Vec3 maxRegion) { +public record MarkerData(UUID uuid, Vec3 position, @Nullable String name, @Nullable Vec3 minRegion, @Nullable Vec3 maxRegion, + int lineArgb, float lineThickness, int faceArgb) { public static MarkerData read(FriendlyByteBuf friendlyByteBuf) { UUID uuid = friendlyByteBuf.readUUID(); - Vec3 position = new Vec3(friendlyByteBuf.readDouble(), friendlyByteBuf.readDouble(), friendlyByteBuf.readDouble()); + Vec3 position = friendlyByteBuf.readVec3(); String name = friendlyByteBuf.readNullable(FriendlyByteBuf::readUtf); Vec3 minRegion = null; Vec3 maxRegion = null; - if (friendlyByteBuf.readBoolean()) { - minRegion = new Vec3(friendlyByteBuf.readDouble(), friendlyByteBuf.readDouble(), friendlyByteBuf.readDouble()); - maxRegion = new Vec3(friendlyByteBuf.readDouble(), friendlyByteBuf.readDouble(), friendlyByteBuf.readDouble()); + int lineArgb = 0; + float lineThickness = 0; + int faceArgb = 0; + + byte flags = friendlyByteBuf.readByte(); + + if ((flags & 1) != 0) { + minRegion = friendlyByteBuf.readVec3(); + maxRegion = friendlyByteBuf.readVec3(); } - return new MarkerData(uuid, position, name, minRegion, maxRegion); + if ((flags & 2) != 0) { + lineArgb = friendlyByteBuf.readInt(); + } + + if ((flags & 4) != 0) { + lineThickness = friendlyByteBuf.readFloat(); + } + + if ((flags & 8) != 0) { + faceArgb = friendlyByteBuf.readInt(); + } + + return new MarkerData(uuid, position, name, minRegion, maxRegion, lineArgb, lineThickness, faceArgb); } public static void write(FriendlyByteBuf friendlyByteBuf, MarkerData markerData) { @@ -38,16 +57,45 @@ public record MarkerData(UUID uuid, Vec3 position, @Nullable String name, @Nulla friendlyByteBuf.writeDouble(markerData.position.z); friendlyByteBuf.writeNullable(markerData.name, FriendlyByteBuf::writeUtf); + byte flags = 0; + + if (markerData.minRegion != null && markerData.maxRegion != null) { + flags |= 1; + } + + if (markerData.lineArgb != 0) { + flags |= 2; + } + + if (markerData.lineThickness != 0) { + flags |= 4; + } + + if (markerData.faceArgb != 0) { + flags |= 8; + } + + friendlyByteBuf.writeByte(flags); + if (markerData.minRegion != null && markerData.maxRegion != null) { - friendlyByteBuf.writeBoolean(true); friendlyByteBuf.writeDouble(markerData.minRegion.x); friendlyByteBuf.writeDouble(markerData.minRegion.y); friendlyByteBuf.writeDouble(markerData.minRegion.z); friendlyByteBuf.writeDouble(markerData.maxRegion.x); friendlyByteBuf.writeDouble(markerData.maxRegion.y); friendlyByteBuf.writeDouble(markerData.maxRegion.z); - } else { - friendlyByteBuf.writeBoolean(false); + } + + if (markerData.lineArgb != 0) { + friendlyByteBuf.writeInt(markerData.lineArgb); + } + + if (markerData.lineArgb != 0) { + friendlyByteBuf.writeFloat(markerData.lineThickness); + } + + if (markerData.faceArgb != 0) { + friendlyByteBuf.writeInt(markerData.faceArgb); } } @@ -83,6 +131,10 @@ public record MarkerData(UUID uuid, Vec3 position, @Nullable String name, @Nulla Vec3 minRegion = null; Vec3 maxRegion = null; + int lineArgb = 0; + float lineThickness = 0; + int faceArgb = 0; + if (data.contains("min", Tag.TAG_LIST) && data.contains("max", Tag.TAG_LIST)) { ListTag min = data.getList("min", Tag.TAG_DOUBLE); ListTag max = data.getList("max", Tag.TAG_DOUBLE); @@ -100,6 +152,18 @@ public record MarkerData(UUID uuid, Vec3 position, @Nullable String name, @Nulla } - return new MarkerData(marker.getUUID(), position, name, minRegion, maxRegion); + if (data.contains("line_argb", Tag.TAG_ANY_NUMERIC)) { + lineArgb = data.getInt("line_argb"); + } + + if (data.contains("line_thickness", Tag.TAG_ANY_NUMERIC)) { + lineThickness = data.getInt("line_thickness"); + } + + if (data.contains("face_argb", Tag.TAG_ANY_NUMERIC)) { + faceArgb = data.getInt("face_argb"); + } + + return new MarkerData(marker.getUUID(), position, name, minRegion, maxRegion, lineArgb, lineThickness, faceArgb); } }