Fixed shoulder entity not getting removed
This commit is contained in:
parent
73efb10181
commit
dfe2d22da3
2 changed files with 21 additions and 9 deletions
|
@ -372,13 +372,14 @@ public class EntityPropertyRegistryImpl implements EntityPropertyRegistry {
|
||||||
// Player
|
// Player
|
||||||
NBTProperty.NBTDecoder<ParrotVariant> parrotVariantDecoder = (variant) -> {
|
NBTProperty.NBTDecoder<ParrotVariant> parrotVariantDecoder = (variant) -> {
|
||||||
NBTCompound compound = new NBTCompound();
|
NBTCompound compound = new NBTCompound();
|
||||||
|
if (variant == null) return compound;
|
||||||
compound.setTag("id", new NBTString("minecraft:parrot"));
|
compound.setTag("id", new NBTString("minecraft:parrot"));
|
||||||
compound.setTag("Variant", new NBTInt(variant.ordinal()));
|
compound.setTag("Variant", new NBTInt(variant.ordinal()));
|
||||||
return compound;
|
return compound;
|
||||||
};
|
};
|
||||||
int shoulderIndex = skinLayersIndex+2;
|
int shoulderIndex = skinLayersIndex+2;
|
||||||
register(new NBTProperty<>("shoulder_entity_left", 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));
|
register(new NBTProperty<>("shoulder_entity_right", ParrotVariant.class, shoulderIndex, parrotVariantDecoder, true));
|
||||||
|
|
||||||
if (!ver.isNewerThanOrEquals(ServerVersion.V_1_13)) return;
|
if (!ver.isNewerThanOrEquals(ServerVersion.V_1_13)) return;
|
||||||
// Pufferfish
|
// Pufferfish
|
||||||
|
|
|
@ -14,32 +14,43 @@ public class NBTProperty<T> extends EntityPropertyImpl<T> {
|
||||||
private final EntityDataType<NBTCompound> type;
|
private final EntityDataType<NBTCompound> type;
|
||||||
private final NBTDecoder<T> decoder;
|
private final NBTDecoder<T> decoder;
|
||||||
private final int index;
|
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<T> clazz, int index, NBTDecoder<T> decoder, EntityDataType<NBTCompound> type) {
|
public NBTProperty(String name, T defaultValue, Class<T> clazz, int index, NBTDecoder<T> decoder, boolean allowNull, EntityDataType<NBTCompound> type) {
|
||||||
super(name, defaultValue, clazz);
|
super(name, defaultValue, clazz);
|
||||||
this.decoder = decoder;
|
this.decoder = decoder;
|
||||||
this.index = index;
|
this.index = index;
|
||||||
|
this.allowNull = allowNull;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public NBTProperty(String name, T defaultValue, int index, NBTDecoder<T> decoder) {
|
public NBTProperty(String name, T defaultValue, int index, NBTDecoder<T> decoder, boolean allowNull) {
|
||||||
this(name, defaultValue, (Class<T>) defaultValue.getClass(), index, decoder, EntityDataTypes.NBT);
|
this(name, defaultValue, (Class<T>) defaultValue.getClass(), index, decoder, allowNull, EntityDataTypes.NBT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public NBTProperty(String name, T defaultValue, int index, NBTDecoder<T> decoder, EntityDataType<NBTCompound> type) {
|
public NBTProperty(String name, T defaultValue, int index, NBTDecoder<T> decoder) {
|
||||||
this(name, defaultValue, (Class<T>) defaultValue.getClass(), index, decoder, type);
|
this(name, defaultValue, (Class<T>) defaultValue.getClass(), index, decoder, false, EntityDataTypes.NBT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public NBTProperty(String name, T defaultValue, int index, NBTDecoder<T> decoder, boolean allowNull, EntityDataType<NBTCompound> type) {
|
||||||
|
this(name, defaultValue, (Class<T>) defaultValue.getClass(), index, decoder, allowNull, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public NBTProperty(String name, Class<T> clazz, int index, NBTDecoder<T> decoder, boolean allowNull) {
|
||||||
|
this(name, null, clazz, index, decoder, allowNull, EntityDataTypes.NBT);
|
||||||
}
|
}
|
||||||
|
|
||||||
public NBTProperty(String name, Class<T> clazz, int index, NBTDecoder<T> decoder) {
|
public NBTProperty(String name, Class<T> clazz, int index, NBTDecoder<T> decoder) {
|
||||||
this(name, null, clazz, index, decoder, EntityDataTypes.NBT);
|
this(name, null, clazz, index, decoder, false, EntityDataTypes.NBT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(Player player, PacketEntity entity, boolean isSpawned, Map<Integer, EntityData> properties) {
|
public void apply(Player player, PacketEntity entity, boolean isSpawned, Map<Integer, EntityData> properties) {
|
||||||
T value = entity.getProperty(this);
|
T value = entity.getProperty(this);
|
||||||
if (value == null) return;
|
if (value == null && !allowNull) return;
|
||||||
properties.put(index, newEntityData(index, type, decoder.decode(value)));
|
properties.put(index, newEntityData(index, type, decoder.decode(value)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue