2

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?

3
  • The wiki says that the data command fails if you try to edit a player's data – Authom Sep 11 '20 at 13:11
  • @Macks What counts as player data? – ExpertCoder14 Sep 11 '20 at 14:02
  • @ExpertCoder14 Any data that would show up with /data get entity @s – ginkgo Sep 12 '20 at 16:35
0

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.

3
  • Could you expand this answer to include all the information that I’ll need without directing me to external sites? It’s a rule here, because if you direct me to an external page, you are basically deferring the answering to someone else. – ExpertCoder14 Oct 26 '20 at 0:46
  • ok ill edit the answer – randomuser922 Oct 27 '20 at 14:09
  • @ExpertCoder14 I updated the answer go check it out. Its on the duplicate. – randomuser922 Oct 27 '20 at 15:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.