Mojira Archive
MC-112257

Some NBT tags require the correct suffix

NBT CanPickUpLoot requires byte suffix, but most other NBTs don't.

Steps to reproduce

  1. /summon zombie ~ ~ ~ {CanPickUpLoot:1}
  2. Throw an item at the zombie
  3. The zombie will not pickup the item

If you use

/summon zombie ~ ~ ~ {CanPickUpLoot:1b}

it will work.

Possible fix
Based on the decompiled code of 1.10.2 using forge the issue comes from here:

net.minecraft.entity.EntityLiving.readEntityFromNBT(NBTTagCompound):511
    /**
     * (abstract) Protected helper method to read subclass entity data from NBT.
     */
    public void readEntityFromNBT(NBTTagCompound compound)
    {
        super.readEntityFromNBT(compound);

        if (compound.hasKey("CanPickUpLoot", 1))
        {
            this.setCanPickUpLoot(compound.getBoolean("CanPickUpLoot"));
        }

Instead of compound.hasKey("CanPickUpLoot", 1), it should be compound.hasKey("CanPickUpLoot", 99) to work with all primitive types.

net.minecraft.nbt.NBTTagCompound.hasKey(String, int):215
    /**
     * Returns whether the given string has been previously stored as a key in this tag compound as a particular type,
     * denoted by a parameter in the form of an ordinal. If the provided ordinal is 99, this method will match tag types
     * representing numbers.
     */
    public boolean hasKey(String key, int type)
    {
        int i = this.getTagId(key);
        return i == type ? true : (type != 99 ? false : i == 1 || i == 2 || i == 3 || i == 4 || i == 5 || i == 6);
    }

Here are some other affected nbts:

  • color: net.minecraft.item.ItemArmor.getColor(ItemStack):161
  • RepairCost: net.minecraft.item.ItemStack.getRepairCost():1001
  • ShowParticles: net.minecraft.potion.PotionEffect.readCustomPotionEffectFromNBT(NBTTagCompound):241
  • rewardExp: net.minecraft.village.MerchantRecipe.readFromTags(NBTTagCompound):152

Fixed

Adrodoc55

[Mojang] TommyWallberg

2017-01-05, 03:18 AM

2024-07-23, 11:18 AM

2024-07-23, 11:18 AM

16

9

Confirmed

Low

Platform

Commands, Data Packs

NBT

Minecraft 1.11.2 - 1.21Minecraft 1.11.2, Minecraft 17w15a, Minecraft 17w16a, Minecraft 1.12.2, Minecraft 1.13-pre5, 1.15.1, 1.15.2, 20w10a, 1.16.3, 20w51a, 21w03a, 1.16.5, 21w05b, 21w06a, 21w08b, 1.17 Pre-release 3, 1.17.1, 1.18.1, 1.18.2, 22w19a, 1.19.2, 1.20.1, 1.21

24w33a