diff --git a/src/main/java/io/wispforest/owo/serialization/Endec.java b/src/main/java/io/wispforest/owo/serialization/Endec.java index d01d0f7b..1d9fa4a9 100644 --- a/src/main/java/io/wispforest/owo/serialization/Endec.java +++ b/src/main/java/io/wispforest/owo/serialization/Endec.java @@ -6,10 +6,7 @@ import com.mojang.serialization.DataResult; import com.mojang.serialization.DynamicOps; import io.wispforest.owo.serialization.endec.*; -import io.wispforest.owo.serialization.format.edm.EdmDeserializer; -import io.wispforest.owo.serialization.format.edm.EdmEndec; -import io.wispforest.owo.serialization.format.edm.EdmOps; -import io.wispforest.owo.serialization.format.edm.EdmSerializer; +import io.wispforest.owo.serialization.format.edm.*; import net.minecraft.util.Util; import org.jetbrains.annotations.Nullable; @@ -411,7 +408,7 @@ default Codec codec(SerializationAttribute... assumedAttributes) { @Override public DataResult> decode(DynamicOps ops, D input) { try { - return DataResult.success(new Pair<>(Endec.this.decode(new EdmDeserializer(ops.convertTo(EdmOps.INSTANCE, input), assumedAttributes)), input)); + return DataResult.success(new Pair<>(Endec.this.decode(new LenientEdmDeserializer(ops.convertTo(EdmOps.INSTANCE, input), assumedAttributes)), input)); } catch (Exception e) { return DataResult.error(e::getMessage); } diff --git a/src/main/java/io/wispforest/owo/serialization/StructEndec.java b/src/main/java/io/wispforest/owo/serialization/StructEndec.java index 76b645c0..e44a2033 100644 --- a/src/main/java/io/wispforest/owo/serialization/StructEndec.java +++ b/src/main/java/io/wispforest/owo/serialization/StructEndec.java @@ -1,10 +1,7 @@ package io.wispforest.owo.serialization; import com.mojang.serialization.*; -import io.wispforest.owo.serialization.format.edm.EdmDeserializer; -import io.wispforest.owo.serialization.format.edm.EdmElement; -import io.wispforest.owo.serialization.format.edm.EdmOps; -import io.wispforest.owo.serialization.format.edm.EdmSerializer; +import io.wispforest.owo.serialization.format.edm.*; import net.minecraft.util.Util; import java.util.HashMap; @@ -57,7 +54,7 @@ public DataResult decode(DynamicOps ops, MapLike input) { ); }); - return DataResult.success(StructEndec.this.decode(new EdmDeserializer(EdmElement.wrapMap(map)))); + return DataResult.success(StructEndec.this.decode(new LenientEdmDeserializer(EdmElement.wrapMap(map)))); } catch (Exception e) { return DataResult.error(e::getMessage); } diff --git a/src/main/java/io/wispforest/owo/serialization/format/edm/EdmDeserializer.java b/src/main/java/io/wispforest/owo/serialization/format/edm/EdmDeserializer.java index 2f27bb2a..068132b1 100644 --- a/src/main/java/io/wispforest/owo/serialization/format/edm/EdmDeserializer.java +++ b/src/main/java/io/wispforest/owo/serialization/format/edm/EdmDeserializer.java @@ -55,6 +55,7 @@ public long readLong() { public float readFloat() { return this.getValue().cast(); } + @Override public double readDouble() { return this.getValue().cast(); @@ -64,12 +65,12 @@ public double readDouble() { @Override public int readVarInt() { - return this.getValue().cast(); + return this.readInt(); } @Override public long readVarLong() { - return this.getValue().cast(); + return this.readLong(); } // --- diff --git a/src/main/java/io/wispforest/owo/serialization/format/edm/LenientEdmDeserializer.java b/src/main/java/io/wispforest/owo/serialization/format/edm/LenientEdmDeserializer.java new file mode 100644 index 00000000..9c40f0a2 --- /dev/null +++ b/src/main/java/io/wispforest/owo/serialization/format/edm/LenientEdmDeserializer.java @@ -0,0 +1,55 @@ +package io.wispforest.owo.serialization.format.edm; + +import io.wispforest.owo.serialization.SerializationAttribute; + +public class LenientEdmDeserializer extends EdmDeserializer { + + public LenientEdmDeserializer(EdmElement serialized, SerializationAttribute... extraAttributes) { + super(serialized, extraAttributes); + } + + // --- + + @Override + public byte readByte() { + return this.getValue().cast().byteValue(); + } + + @Override + public short readShort() { + return this.getValue().cast().shortValue(); + } + + @Override + public int readInt() { + return this.getValue().cast().intValue(); + } + + @Override + public long readLong() { + return this.getValue().cast().longValue(); + } + + // --- + + @Override + public float readFloat() { + return this.getValue().cast().floatValue(); + } + + @Override + public double readDouble() { + return this.getValue().cast().doubleValue(); + } + + // --- + + @Override + public boolean readBoolean() { + if(this.getValue().value() instanceof Number number){ + return number.byteValue() == 1; + } + + return super.readBoolean(); + } +}