From 0b84e739a027ea7e5cc5bd728625839928f95283 Mon Sep 17 00:00:00 2001 From: Trumeet Date: Thu, 14 Jul 2022 10:26:28 -0700 Subject: Refactor: Move WorldKey, Vec2f and Vec3d to the common package Signed-off-by: Trumeet --- src/main/java/moe/ymc/acron/common/Vec3d.java | 34 +++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/main/java/moe/ymc/acron/common/Vec3d.java (limited to 'src/main/java/moe/ymc/acron/common/Vec3d.java') diff --git a/src/main/java/moe/ymc/acron/common/Vec3d.java b/src/main/java/moe/ymc/acron/common/Vec3d.java new file mode 100644 index 0000000..593019f --- /dev/null +++ b/src/main/java/moe/ymc/acron/common/Vec3d.java @@ -0,0 +1,34 @@ +package moe.ymc.acron.common; + +import com.google.gson.*; +import com.google.gson.annotations.SerializedName; +import org.jetbrains.annotations.NotNull; + +import java.lang.reflect.Type; + +public record Vec3d(@SerializedName("x") double x, + @SerializedName("y") double y, + @SerializedName("z") double z) { + public Vec3d(@NotNull net.minecraft.util.math.Vec3d vec3d) { + this(vec3d.x, vec3d.y, vec3d.z); + } + + public static class Vec3dDeserializer implements JsonDeserializer { + @Override + public Vec3d deserialize(JsonElement json, + Type typeOfT, + JsonDeserializationContext context) throws JsonParseException { + final JsonObject object = json.getAsJsonObject(); + final double x = object.has("x") ? + object.get("x").getAsDouble() : + 0.0; + final double y = object.has("y") ? + object.get("y").getAsDouble() : + 0.0; + final double z = object.has("z") ? + object.get("z").getAsDouble() : + 0.0; + return new Vec3d(x, y, z); + } + } +} \ No newline at end of file -- cgit v1.2.3