3
Command Help: Putting Scores into NBT Data
Hello!
I have been trying to work out a way to put the number of a scoreboard inside a NBT tag (e.g., Test:The Scoreboard Valueb). I have not been able to figure it out for the life of me.
Any help would be appreciated!
I have been trying to work out a way to put the number of a scoreboard inside a NBT tag (e.g., Test:The Scoreboard Valueb). I have not been able to figure it out for the life of me.
Any help would be appreciated!
Create an account or sign in to comment.
5
1
You can use this:
Have a look at my tutorial blog for more information about combining scoreboard and NBT powers, or view the full /execute spec here. =)
EDIT: Ah, I missed the context you explained in a comment... Maybe you should copy that to the description haha
/execute store result <entity|block|storage> (...) <type> <scale> run scoreboard players get <player> <objective>
Have a look at my tutorial blog for more information about combining scoreboard and NBT powers, or view the full /execute spec here. =)
EDIT: Ah, I missed the context you explained in a comment... Maybe you should copy that to the description haha
1
I think you have to make many command blocks and define scores. Something like this (Commands for 1.16):
scoreboard players set @a Item 0
scoreboard players set @a[nbt={SelectedItem:{id:"minecraft:iron_sword",tag:{Damage:1}}}] Item 1
scoreboard players set @a[nbt={SelectedItem:{id:"minecraft:iron_sword",tag:{Damage:2}}}] Item 2
scoreboard players set @a[nbt={SelectedItem:{id:"minecraft:iron_sword",tag:{Damage:3}}}] Item 3
You can use for example Inventory instead of SelectedItem. Then youre able to define a slot where this Item should be in too.
With the scores you can use replaceitem:
replaceitem @a[scores={Item=1}] weapon.offhand ITEM1
replaceitem @a[scores={Item=2}] weapon.offhand ITEM2
replaceitem @a[scores={Item=3}] weapon.offhand ITEM3
So just define how you get the scores 1, 2, 3, ... and then its easy. Hope I could help you.
Kodisa
scoreboard players set @a Item 0
scoreboard players set @a[nbt={SelectedItem:{id:"minecraft:iron_sword",tag:{Damage:1}}}] Item 1
scoreboard players set @a[nbt={SelectedItem:{id:"minecraft:iron_sword",tag:{Damage:2}}}] Item 2
scoreboard players set @a[nbt={SelectedItem:{id:"minecraft:iron_sword",tag:{Damage:3}}}] Item 3
You can use for example Inventory instead of SelectedItem. Then youre able to define a slot where this Item should be in too.
With the scores you can use replaceitem:
replaceitem @a[scores={Item=1}] weapon.offhand ITEM1
replaceitem @a[scores={Item=2}] weapon.offhand ITEM2
replaceitem @a[scores={Item=3}] weapon.offhand ITEM3
So just define how you get the scores 1, 2, 3, ... and then its easy. Hope I could help you.
Kodisa
1
Thank you!
I sort of already figured out I'm going to have to bite some bullet to get it to work. I was just hoping there was something I was missing. Thanks again!
I sort of already figured out I'm going to have to bite some bullet to get it to work. I was just hoping there was something I was missing. Thanks again!
1
I am trying to figure out a way to replace an item in the offhand with the same item but with a different NBT tag number because I know you can not modify player data.
1
Note that modifying an item in offhand is still considered modifying the player and that's impossible. You can use /replaceitem to clear the offhand and then use my comment above to insert your scoreboard value into an item on the ground (that you made with /summon) the player will then automatically pick it up and have to manually move it back to their offhand.
If you want to replace the value straight away, you have to make separate commands like Kodisa said.
If you want to replace the value straight away, you have to make separate commands like Kodisa said.