From 0c05b3a46f65c9a3eecab20ae4381c387b1cb341 Mon Sep 17 00:00:00 2001 From: Moulberry Date: Thu, 16 Nov 2023 23:54:49 +0800 Subject: [PATCH] WorldProperties: Add default serialization for null values --- .../axiom/world_properties/WorldPropertyDataType.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/moulberry/axiom/world_properties/WorldPropertyDataType.java b/src/main/java/com/moulberry/axiom/world_properties/WorldPropertyDataType.java index e3d163d..23790f6 100644 --- a/src/main/java/com/moulberry/axiom/world_properties/WorldPropertyDataType.java +++ b/src/main/java/com/moulberry/axiom/world_properties/WorldPropertyDataType.java @@ -4,7 +4,9 @@ import io.netty.buffer.Unpooled; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.world.item.Item; +import net.minecraft.world.item.Items; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; import java.nio.charset.StandardCharsets; @@ -22,7 +24,7 @@ public abstract class WorldPropertyDataType { @Override public byte[] serialize(Boolean value) { - return new byte[] { value ? (byte)1 : (byte)0 }; + return new byte[] { value != null && value ? (byte)1 : (byte)0 }; } @Override @@ -39,6 +41,8 @@ public abstract class WorldPropertyDataType { @Override public byte[] serialize(Integer value) { + if (value == null) value = 0; + FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer(8)); buf.writeVarInt(value); @@ -62,6 +66,7 @@ public abstract class WorldPropertyDataType { @Override public byte[] serialize(String value) { + if (value == null) value = ""; return value.getBytes(StandardCharsets.UTF_8); } @@ -79,6 +84,8 @@ public abstract class WorldPropertyDataType { @Override public byte[] serialize(Item value) { + if (value == null) value = Items.AIR; + FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer(8)); buf.writeId(BuiltInRegistries.ITEM, value); @@ -102,6 +109,8 @@ public abstract class WorldPropertyDataType { @Override public byte[] serialize(Block value) { + if (value == null) value = Blocks.AIR; + FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer(8)); buf.writeId(BuiltInRegistries.BLOCK, value);