mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-21 15:41:38 +01:00
Allow serialisation of empty nbt components
This commit is contained in:
parent
99941e511c
commit
56a6cfc2fb
@ -12,6 +12,8 @@ import java.util.function.Function;
|
||||
* Basic serializers for {@link Tag tags}.
|
||||
*/
|
||||
final class Serializers {
|
||||
static final boolean SERIALIZE_EMPTY_COMPOUND = System.getProperty("minestom.serialization.serialize-nbt-compound", "false").equalsIgnoreCase("true");
|
||||
|
||||
static final Entry<Byte, NBTByte> BYTE = new Entry<>(NBTType.TAG_Byte, NBTByte::getValue, NBT::Byte);
|
||||
static final Entry<Boolean, NBTByte> BOOLEAN = new Entry<>(NBTType.TAG_Byte, NBTByte::asBoolean, NBT::Boolean);
|
||||
static final Entry<Short, NBTShort> SHORT = new Entry<>(NBTType.TAG_Short, NBTShort::getValue, NBT::Short);
|
||||
@ -31,7 +33,7 @@ final class Serializers {
|
||||
static <T> Entry<T, NBTCompound> fromTagSerializer(TagSerializer<T> serializer) {
|
||||
return new Serializers.Entry<>(NBTType.TAG_Compound,
|
||||
(NBTCompound compound) -> {
|
||||
if (compound.isEmpty()) return null;
|
||||
if ((!SERIALIZE_EMPTY_COMPOUND) && compound.isEmpty()) return null;
|
||||
return serializer.read(TagHandler.fromCompound(compound));
|
||||
},
|
||||
(value) -> {
|
||||
|
@ -281,7 +281,7 @@ final class TagHandlerImpl implements TagHandler {
|
||||
this.entries.forValues(entry -> {
|
||||
final Tag tag = entry.tag;
|
||||
final NBT nbt = entry.updatedNbt();
|
||||
if (!tag.entry.isPath() || !((NBTCompound) nbt).isEmpty()) {
|
||||
if (!tag.entry.isPath() || (!Serializers.SERIALIZE_EMPTY_COMPOUND) && !((NBTCompound) nbt).isEmpty()) {
|
||||
tmp.put(tag.getKey(), nbt);
|
||||
}
|
||||
});
|
||||
@ -313,7 +313,7 @@ final class TagHandlerImpl implements TagHandler {
|
||||
tmp.put(tag.getKey(), nbt);
|
||||
entries.put(tag.index, valueToEntry(result, tag, value));
|
||||
});
|
||||
if (tmp.isEmpty() && parent != null)
|
||||
if ((!Serializers.SERIALIZE_EMPTY_COMPOUND) && tmp.isEmpty() && parent != null)
|
||||
return null; // Empty child node
|
||||
result.compound = tmp.toCompound();
|
||||
return result;
|
||||
|
Loading…
Reference in New Issue
Block a user