SPIGOT-4576: Fix attributes in itemstack internal data being lost

This commit is contained in:
md_5 2019-01-14 10:20:24 +11:00
parent 8059a937eb
commit 50fbc3f190
3 changed files with 9 additions and 1 deletions

View file

@ -111,6 +111,8 @@ public class CraftMetaBlockState extends CraftMetaItem implements BlockStateMeta
@Override @Override
void deserializeInternal(NBTTagCompound tag, Object context) { void deserializeInternal(NBTTagCompound tag, Object context) {
super.deserializeInternal(tag, context);
if (tag.hasKeyOfType(BLOCK_ENTITY_TAG.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND)) { if (tag.hasKeyOfType(BLOCK_ENTITY_TAG.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND)) {
blockEntityTag = tag.getCompound(BLOCK_ENTITY_TAG.NBT); blockEntityTag = tag.getCompound(BLOCK_ENTITY_TAG.NBT);
} }

View file

@ -385,7 +385,7 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
static Multimap<Attribute, AttributeModifier> buildModifiers(NBTTagCompound tag, ItemMetaKey key) { static Multimap<Attribute, AttributeModifier> buildModifiers(NBTTagCompound tag, ItemMetaKey key) {
Multimap<Attribute, AttributeModifier> modifiers = HashMultimap.create(); Multimap<Attribute, AttributeModifier> modifiers = HashMultimap.create();
if (!tag.hasKey(key.NBT)) { if (!tag.hasKeyOfType(key.NBT, CraftMagicNumbers.NBT.TAG_LIST)) {
return modifiers; return modifiers;
} }
NBTTagList mods = tag.getList(key.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND); NBTTagList mods = tag.getList(key.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND);
@ -504,6 +504,10 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable {
} }
void deserializeInternal(NBTTagCompound tag, Object context) { void deserializeInternal(NBTTagCompound tag, Object context) {
// SPIGOT-4576: Need to migrate from internal to proper data
if (tag.hasKeyOfType(ATTRIBUTES.NBT, CraftMagicNumbers.NBT.TAG_LIST)) {
this.attributeModifiers = buildModifiers(tag, ATTRIBUTES);
}
} }
static Map<Enchantment, Integer> buildEnchantments(Map<String, Object> map, ItemMetaKey key) { static Map<Enchantment, Integer> buildEnchantments(Map<String, Object> map, ItemMetaKey key) {

View file

@ -58,6 +58,8 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
@Override @Override
void deserializeInternal(NBTTagCompound tag, Object context) { void deserializeInternal(NBTTagCompound tag, Object context) {
super.deserializeInternal(tag, context);
if (tag.hasKeyOfType(SKULL_PROFILE.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND)) { if (tag.hasKeyOfType(SKULL_PROFILE.NBT, CraftMagicNumbers.NBT.TAG_COMPOUND)) {
profile = GameProfileSerializer.deserialize(tag.getCompound(SKULL_PROFILE.NBT)); profile = GameProfileSerializer.deserialize(tag.getCompound(SKULL_PROFILE.NBT));
} }