|
2 | 2 |
|
3 | 3 | import com.glisco.deathlog.death_info.DeathInfoProperty; |
4 | 4 | import com.glisco.deathlog.death_info.DeathInfoPropertyType; |
5 | | -import io.wispforest.endec.Deserializer; |
6 | | -import io.wispforest.endec.SerializationContext; |
7 | | -import io.wispforest.endec.Serializer; |
8 | | -import io.wispforest.endec.StructEndec; |
| 5 | +import io.wispforest.endec.*; |
9 | 6 | import io.wispforest.owo.serialization.format.nbt.NbtEndec; |
10 | 7 | import net.minecraft.nbt.NbtCompound; |
11 | 8 | import net.minecraft.text.Text; |
@@ -41,14 +38,27 @@ public static class Type extends DeathInfoPropertyType<MissingDeathInfoProperty> |
41 | 38 | private final StructEndec<MissingDeathInfoProperty> endec = new StructEndec<>() { |
42 | 39 | @Override |
43 | 40 | public void encodeStruct(SerializationContext ctx, Serializer<?> serializer, Serializer.Struct struct, MissingDeathInfoProperty value) { |
44 | | - for (String key : value.data.getKeys()) { |
45 | | - struct.field(key, ctx, NbtEndec.ELEMENT, value.data.get(key)); |
| 41 | + if (serializer instanceof SelfDescribedSerializer<?>) { |
| 42 | + for (String key : value.data.getKeys()) { |
| 43 | + struct.field(key, ctx, NbtEndec.ELEMENT, value.data.get(key)); |
| 44 | + } |
| 45 | + } else { |
| 46 | + NbtEndec.COMPOUND.encode(ctx, serializer, value.data); |
46 | 47 | } |
47 | 48 | } |
48 | 49 |
|
49 | 50 | @Override |
50 | 51 | public MissingDeathInfoProperty decodeStruct(SerializationContext ctx, Deserializer<?> deserializer, Deserializer.Struct struct) { |
51 | | - return new MissingDeathInfoProperty(Type.this, NbtEndec.COMPOUND.decode(ctx, deserializer)); |
| 52 | + if (deserializer instanceof SelfDescribedDeserializer<?>) { |
| 53 | + var map = NbtEndec.ELEMENT.mapOf().decode(ctx, deserializer); |
| 54 | + |
| 55 | + var compound = new NbtCompound(); |
| 56 | + map.forEach(compound::put); |
| 57 | + |
| 58 | + return new MissingDeathInfoProperty(Type.this, compound); |
| 59 | + } else { |
| 60 | + return new MissingDeathInfoProperty(Type.this, NbtEndec.COMPOUND.decode(ctx, deserializer)); |
| 61 | + } |
52 | 62 | } |
53 | 63 | }; |
54 | 64 |
|
|
0 commit comments