mirror of
https://github.com/Minestom/Minestom.git
synced 2025-02-01 21:11:33 +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}.
|
* Basic serializers for {@link Tag tags}.
|
||||||
*/
|
*/
|
||||||
final class Serializers {
|
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<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<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);
|
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) {
|
static <T> Entry<T, NBTCompound> fromTagSerializer(TagSerializer<T> serializer) {
|
||||||
return new Serializers.Entry<>(NBTType.TAG_Compound,
|
return new Serializers.Entry<>(NBTType.TAG_Compound,
|
||||||
(NBTCompound compound) -> {
|
(NBTCompound compound) -> {
|
||||||
if (compound.isEmpty()) return null;
|
if ((!SERIALIZE_EMPTY_COMPOUND) && compound.isEmpty()) return null;
|
||||||
return serializer.read(TagHandler.fromCompound(compound));
|
return serializer.read(TagHandler.fromCompound(compound));
|
||||||
},
|
},
|
||||||
(value) -> {
|
(value) -> {
|
||||||
|
@ -281,7 +281,7 @@ final class TagHandlerImpl implements TagHandler {
|
|||||||
this.entries.forValues(entry -> {
|
this.entries.forValues(entry -> {
|
||||||
final Tag tag = entry.tag;
|
final Tag tag = entry.tag;
|
||||||
final NBT nbt = entry.updatedNbt();
|
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);
|
tmp.put(tag.getKey(), nbt);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -313,7 +313,7 @@ final class TagHandlerImpl implements TagHandler {
|
|||||||
tmp.put(tag.getKey(), nbt);
|
tmp.put(tag.getKey(), nbt);
|
||||||
entries.put(tag.index, valueToEntry(result, tag, value));
|
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
|
return null; // Empty child node
|
||||||
result.compound = tmp.toCompound();
|
result.compound = tmp.toCompound();
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
Reference in New Issue
Block a user