mojira.dev
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

Linked issues

Attachments

Comments 17

removed the following:

  • trackingPosition: net.minecraft.world.storage.MapData.readFromNBT(NBTTagCompound):69

  • DifficultyLocked: net.minecraft.world.storage.WorldInfo.WorldInfo(NBTTagCompound):217

These 2 can't be touched by commands.

@FVbico I think it would be better to change all affected nbt, even those that can not be touched by commands. That has the advantage of beeing consistent and it is better for mods. I actually reported this bug because I am writing a mod.

The thing is, your ticket is about requiring the correct suffix for some tags (none for some int tags) but editing those 2 requires third party software and the use of that is not supported.

Still it would be more consistent in the code and therefor easier for mojang to maintain.

@FBbico. So it's a bug since it's not consistent in the vanilla code, additionally he's showing it in the case for modding that it causes issues. It still causes issues in vanilla with commands as you require the "1b" part unlike most nbt tags with only needs an integer (like "NoGravity:1").

7 more comments

Can confirm in 1.17.1.

Armor Color no longer seems to use key 1, it uses 99

Updated Names: (yarn 1.17.1)
ShowParticles + ShowIcon: net.minecraft.entity.effect.StatusEffectInstance.fromNbt()
rewardExp + xp + priceMultiplier: net.minecraft.village.TradeOffer

repairCost did not change at all

Can confirm in 1.18.1.

Can confirm in 1.18.2 and 22w19a.

Can confirm in 1.19.2.

Adrodoc55

Tommy Wallberg

Confirmed

Platform

Low

Commands, Data Packs

NBT

Minecraft 1.11.2, Minecraft 17w15a, Minecraft 17w16a, Minecraft 1.12.2, Minecraft 1.13-pre5, ..., 1.18.2, 22w19a, 1.19.2, 1.20.1, 1.21

24w33a

Retrieved