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); } } }