Why does /execute store refuse to update an NBT number when provided with a scoreboard value?

Why does /execute store refuse to update an NBT number when provided with a scoreboard value? - Trendy young Asian women choosing cotton bags in fashion boutique

Here are some commands for you to try in MCJE 1.16. Run the following commands in the chat:

  1. Set up a scoreboard objective. (or use an existing test objective if you hate piling them up, like me)

    /scoreboard objectives add test dummy
    
  2. Set your own score. Set it to a number you'll remember. Make it low, like 5.

    /scoreboard players set @s test 5
    
  3. Give yourself a diamond sword with enchantments. Give it a level of a different number than you picked in step 2. I pick 9.

    /give @s diamond_sword{Enchantments:[{id:"minecraft:sharpness",lvl:9s}]}
    
  4. Try to set the diamond sword's enchantment level to the number in the scoreboard. This is the command I used:

    /data modify entity @s Inventory[{id:"minecraft:diamond_sword"}].tag.Enchantments[{id:"minecraft:sharpness"}].lvl short 1 run scoreboard players get @s test
    

What this command should do is get your test score and store it in the Sharpness level of the diamond sword. But it doesn't. The level remains 9.

Here is another example with shorter commands. Do steps 1 and 2 like normal, but here's where we'll change things up:

  1. Give yourself a piece of dirt. (any item will do)

    /give @s dirt
    
  2. Modify the count of that dirt stack by setting it to the scoreboard value.

    /execute store result entity @s Inventory[{id:"minecraft:dirt"}].Count byte 1 run scoreboard players get @s test
    

Does the count of items modify? For me, it doesn't.

I tested this out using a command chain. Peeking into the command block for command #4, I can see the correct scoreboard value returned: ExpertCoder14 has 5 test, but the scoreboard value still isn't updated.

I checked all the fields, and they were all correct:

  • NBT path: I used /data get with the same NBT path and got back the old value. This means I am using the correct path to target the value to update.
  • Scale: I checked the Minecraft Wiki page on /execute store. The scale is a number that the command result will be multiplied by before storing. I set it to 1.0. This should be correct.

I also ran some additional trials:

  • I used the if subcommand to test for a number of entities instead of /scoreboard players get. Here was a command:

    /execute store result entity @s Inventory[{id:"minecraft:dirt"}].Count byte 1 if entity @e
    

    Sample output:

    Test passed, count: 14
    

But the NBT value doesn't change!

Am I doing something wrong? Is this behaviour normal? Is there a bug report that I missed? What is going on?



Best Answer

You can't modify player nbt. You have to move the item to a container modify the conatiner's item. Then loot the item back into the player's inventory. The following link shows you how to edit items in a player's hand. Here. I hope this helped.




Pictures about "Why does /execute store refuse to update an NBT number when provided with a scoreboard value?"

Why does /execute store refuse to update an NBT number when provided with a scoreboard value? - Customer with eco friendly bag in supermarket
Why does /execute store refuse to update an NBT number when provided with a scoreboard value? - Stack of Folded Denim Pants on the Shelves
Why does /execute store refuse to update an NBT number when provided with a scoreboard value? - Black female shopper reading label on food in supermarket



How do I change my NBT data entity?

You can use the /data command to get, merge and remove NBT tags (formerly called data tags) for entities and block entities. The /data command is most useful for changing attributes of a mob after the mob has spawned or modifying attributes of a block entity after you have placed it.

What does NBT mean in Minecraft commands?

The Named Binary Tag (NBT) format is a tree data structure used by Minecraft in many save files to store arbitrary data. The format is comprised of a handful of tags. Tags have a numeric ID, a name, and a payload. A user-accessible version in the form of strings is the stringified Named Binary Tag (SNBT) format.

How do I use NBT data?

NBT tags are used in game commands such as: /summon, /data, /give, /fill, /setblock. The NBT tag is always surrounded in {} such as {NoAI:1}. If there is more than one NBT tag used in a command, the NBT tags are separated by a comma such as {NoAI:1, IsBaby:1}. Each entity (or mob) has its own unique set of NBT tags.

How does execute command work in Minecraft?

/execute executes another command but allows changing the executor, changing the position and angle it is executed at, adding preconditions, and storing its result.



/execute store // Minecraft 1.19 Command Tutorial




Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: Sam Lion, Michael Burrows, cottonbro, Laura James