I'm working with my datapack but got stuck with this problem. We're basically connecting nbt numbers into a players scoreboard number.

I'm trying to link an item's nbt to a scoreboard. For example, let's say I have a scoreboard called 'Change'. The item I am holding will have the tag 'CustomItem:1b' and 'Change:1b'.

First, we make the scoreboard 'change'.

scoreboard objectives add Change dummy

Next, the command detects if the player is holding an item with the nbt 'CustomItem:1b'.

execute as @a if entity @s[nbt={SelectedItem:{tag:{CustomItem:1b}}}] run ...

Now it checks the item you hold, to see if the number in the nbt 'Change:10b' meaning '10' is different from your current score. I want this to only happen when you first hold the item. If it is different then:

  1. give the player the tag Change
.... run tag @s[tag=!ChangeDone] add Change
  1. The player with the tag 'Change' will link the nbt of the item in their hand to the scoreboard. Since the current nbt of the item is 'Change:10b', your score will be changed to 10 in the 'Change' scoreboard

  2. Check again if the 'Change:10b' is the same, if it is the same then 'Change' tag is removed and 'ChangeDone' tag is added

... run tag @s[tag=Change] add ChangeDone
.... run tag @s remove Change

Now I want to detect all players with the tag 'ChangeDone' to see if their item's nbt 'Change:10b' number and score is different again

/execute as @a[tag=ChangeDone] ...

Now if I change my score with commands to 9 in 'change', the nbt and scoreboard will link again. But this time the number in the scoreboard will change the nbt of the item, from 'Change:10b' to 'Change:9b' .

From here if my score turns to 8 'Change:10b' will change to 'Change:8b'

Change score 7: 'Change:7b'
change score 6: 'Change:6b'

You get the point

My first thought was to collect the nbt data into a storage similar to

execute store result score @s Change run data get entity @s SelectedItem.tag.Damage

I feel as if I'm close to figuring this out, but I haven't found out how to do this.

Using this type of command can help us make Custom Durability, gun ammunition, ammunition clips, limited uses, and so much more. Anyone got ideas?


You must log in to answer this question.