Skip to content

Commit 01d86aa

Browse files
committed
fix implementation of missing property endec
1 parent 8d18025 commit 01d86aa

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/main/java/com/glisco/deathlog/death_info/properties/MissingDeathInfoProperty.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
import com.glisco.deathlog.death_info.DeathInfoProperty;
44
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.*;
96
import io.wispforest.owo.serialization.format.nbt.NbtEndec;
107
import net.minecraft.nbt.NbtCompound;
118
import net.minecraft.text.Text;
@@ -41,14 +38,27 @@ public static class Type extends DeathInfoPropertyType<MissingDeathInfoProperty>
4138
private final StructEndec<MissingDeathInfoProperty> endec = new StructEndec<>() {
4239
@Override
4340
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);
4647
}
4748
}
4849

4950
@Override
5051
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+
}
5262
}
5363
};
5464

0 commit comments

Comments
 (0)