diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java index c5b08dc..61e04c3 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/EntityPropertyRegistryImpl.java @@ -372,13 +372,14 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry { // Player NBTProperty.NBTDecoder parrotVariantDecoder = (variant) -> { NBTCompound compound = new NBTCompound(); + if (variant == null) return compound; compound.setTag("id", new NBTString("minecraft:parrot")); compound.setTag("Variant", new NBTInt(variant.ordinal())); return compound; }; int shoulderIndex = skinLayersIndex+2; - register(new NBTProperty<>("shoulder_entity_left", ParrotVariant.class, shoulderIndex++, parrotVariantDecoder)); - register(new NBTProperty<>("shoulder_entity_right", ParrotVariant.class, shoulderIndex, parrotVariantDecoder)); + register(new NBTProperty<>("shoulder_entity_left", ParrotVariant.class, shoulderIndex++, parrotVariantDecoder, true)); + register(new NBTProperty<>("shoulder_entity_right", ParrotVariant.class, shoulderIndex, parrotVariantDecoder, true)); if (!ver.isNewerThanOrEquals(ServerVersion.V_1_13)) return; // Pufferfish diff --git a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/NBTProperty.java b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/NBTProperty.java index 9829790..9faa28d 100644 --- a/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/NBTProperty.java +++ b/plugin/src/main/java/lol/pyr/znpcsplus/entity/properties/NBTProperty.java @@ -14,32 +14,43 @@ public class NBTProperty extends EntityPropertyImpl { private final EntityDataType type; private final NBTDecoder decoder; private final int index; + private final boolean allowNull; // This means that the decoder can have null input, not that the property can be null - public NBTProperty(String name, T defaultValue, Class clazz, int index, NBTDecoder decoder, EntityDataType type) { + public NBTProperty(String name, T defaultValue, Class clazz, int index, NBTDecoder decoder, boolean allowNull, EntityDataType type) { super(name, defaultValue, clazz); this.decoder = decoder; this.index = index; + this.allowNull = allowNull; this.type = type; } @SuppressWarnings("unchecked") - public NBTProperty(String name, T defaultValue, int index, NBTDecoder decoder) { - this(name, defaultValue, (Class) defaultValue.getClass(), index, decoder, EntityDataTypes.NBT); + public NBTProperty(String name, T defaultValue, int index, NBTDecoder decoder, boolean allowNull) { + this(name, defaultValue, (Class) defaultValue.getClass(), index, decoder, allowNull, EntityDataTypes.NBT); } @SuppressWarnings("unchecked") - public NBTProperty(String name, T defaultValue, int index, NBTDecoder decoder, EntityDataType type) { - this(name, defaultValue, (Class) defaultValue.getClass(), index, decoder, type); + public NBTProperty(String name, T defaultValue, int index, NBTDecoder decoder) { + this(name, defaultValue, (Class) defaultValue.getClass(), index, decoder, false, EntityDataTypes.NBT); + } + + @SuppressWarnings("unchecked") + public NBTProperty(String name, T defaultValue, int index, NBTDecoder decoder, boolean allowNull, EntityDataType type) { + this(name, defaultValue, (Class) defaultValue.getClass(), index, decoder, allowNull, type); + } + + public NBTProperty(String name, Class clazz, int index, NBTDecoder decoder, boolean allowNull) { + this(name, null, clazz, index, decoder, allowNull, EntityDataTypes.NBT); } public NBTProperty(String name, Class clazz, int index, NBTDecoder decoder) { - this(name, null, clazz, index, decoder, EntityDataTypes.NBT); + this(name, null, clazz, index, decoder, false, EntityDataTypes.NBT); } @Override public void apply(Player player, PacketEntity entity, boolean isSpawned, Map properties) { T value = entity.getProperty(this); - if (value == null) return; + if (value == null && !allowNull) return; properties.put(index, newEntityData(index, type, decoder.decode(value))); }