mirror of
https://github.com/darksaid98/Flashback.git
synced 2026-12-01 14:38:50 +00:00
Stuff
This commit is contained in:
1 parent
9c4a30d224
commit
666398e480
174 files changed
+8694
-2942
No files matched your search
@@ -0,0 +1,33 @@
|
||||
package com.moulberry.flashback.serialization;
|
||||
|
||||
import com.google.gson.*;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.joml.Quaternionf;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class QuaternionTypeAdapater implements JsonSerializer<Quaternionf>, JsonDeserializer<Quaternionf> {
|
||||
@Override
|
||||
public Quaternionf deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
JsonArray jsonArray = json.getAsJsonArray();
|
||||
if (jsonArray.size() != 4) {
|
||||
throw new IllegalStateException("Error deserializing Quaternionf, expected array to have length 4, was length " + jsonArray.size() + " instead");
|
||||
}
|
||||
double x = jsonArray.get(0).getAsDouble();
|
||||
double y = jsonArray.get(1).getAsDouble();
|
||||
double z = jsonArray.get(2).getAsDouble();
|
||||
double w = jsonArray.get(3).getAsDouble();
|
||||
return new Quaternionf(x, y, z, w);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(Quaternionf src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonArray jsonArray = new JsonArray();
|
||||
jsonArray.add(src.x);
|
||||
jsonArray.add(src.y);
|
||||
jsonArray.add(src.z);
|
||||
jsonArray.add(src.w);
|
||||
return jsonArray;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.moulberry.flashback.serialization;
|
||||
|
||||
import com.google.gson.*;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class Vector3fTypeAdapater implements JsonSerializer<Vector3f>, JsonDeserializer<Vector3f> {
|
||||
@Override
|
||||
public Vector3f deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
JsonArray jsonArray = json.getAsJsonArray();
|
||||
if (jsonArray.size() != 3) {
|
||||
throw new IllegalStateException("Error deserializing Vector3f, expected array to have length 3, was length " + jsonArray.size() + " instead");
|
||||
}
|
||||
float x = jsonArray.get(0).getAsFloat();
|
||||
float y = jsonArray.get(1).getAsFloat();
|
||||
float z = jsonArray.get(2).getAsFloat();
|
||||
|
||||
return new Vector3f(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(Vector3f src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonArray jsonArray = new JsonArray();
|
||||
jsonArray.add(src.x);
|
||||
jsonArray.add(src.y);
|
||||
jsonArray.add(src.z);
|
||||
return jsonArray;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user