#nbt path for Selected item display name (1.21.1)

1 messages · Page 1 of 1 (latest)

ionic verge
#

/data get entity justaGremlin__ SelectedItem but i want the display name of the item held

sacred gorgeBOT
#

<@&1201956957406109788>

Someone will come and help soon!

💬 While you wait, take this time to provide more context and details.

🙇 If nobody has answered you by <t:1732221151:t>, feel free to use the Summon Helpers button to ping our helper team.

✅ Once your question has been resolved (or you no longer need it), please click Resolve Question or run /resolve

livid drift
#

SelectedItem.components."minecraft:item_name"

tribal tundra
#

The name that is displayed can come from multiple components or may not even be in its nbt (if it’s not changed)

ionic verge
#

it has been changed

livid drift
#

If it's been changed in an anvil then it's custom_name

tribal tundra
#

You can always look at the data using the command you used and follow it from there.
To get "c", you'd use a.b

{"a": {"b": "c"}, "d": "e"}
#

And that way you can navigate to the correct component

ionic verge
#

ohhh i got u

#

how would i make this look better

#

becuase i want it to just say SPELL NAME

tribal tundra
#

In a text component you can try and add "interpret": true

ionic verge
#

would that be possible through a function

#

im not familiar with "interpret "

tribal tundra
#

Is this in the actionbar?

ionic verge
#

ye

#

oh wait i see

#

mcstacker has an option for it

tribal tundra
#

Because there you are probably using a text component, like {text:"Something"} and just like "text" you can add "interpret"

tribal tundra
ionic verge
#

lol thanks i never even noticed it

#

ive turned interpret to true and now its not displaying anything

#

im so confused its just stopped working now

#

nvm i got it now i think

ionic verge
#

would this also work for other characters like "["

tribal tundra
#

You know how snbt (the thing you see when using a data get for example) is a bunch of key value pairs?
The path just "follows" these keys
So item.components.minecraft:custom_name
looks at the whole nbt, then goes into the "item" key. In there it looks for a "components" key and so on

ionic verge
#

ohhhhh i miss understood that

tribal tundra
#

For arrays [] it works slightly differently
[0] selected the first element (they start at 0)
[5] selected the 6th element and so on
[-1] selects the last element
[-3] the third from the end and so on

#

You can also do something like [{slot:0b}] which returns all elements that have a "slot" key that is set to 0b

#

A path like that looks like
something.array[12]

#

And you can follow up like you’d expect array[12].data.id

ionic verge
#

when u say "element" what is that refering to?, is it just the context of the datapath?

tribal tundra
#

Yes, it can be a string, number, other object or array

#

What ever is at that path

ionic verge
#

like if i was looking for selectedslot [2] it would be slot 2

#

im guessing thats prob fomatted wrong but u get the idea

tribal tundra
#

Maybe an example helps

Data:
{array:[a,b,c,d,e]}
Path:
array[0] => a
array[2] => c
array[-1] => e
array[-3] => c
#

And these letters could also be numbers, objects, arrays or anything else

#

I think they need to be the same data type though

#

So all floats, all strings or all objects and so on

#

You can also try these out if you have the game open, that may help you to get used to it

#

/data get entity @s Inventory[{Slot:0b}].id
this would for example get the id of the item in your first hotbar slot

ionic verge
#

that didnt work

#

im on 1.21.1 if thats important here

sharp roost
#

Do you have an item in your first hotbar slot?

ionic verge
#

i do

sharp roost
#

Ah I think slot is still capitalised: Slot

#

Unlike count, which was turned to lowercase

ionic verge
#

there we go, it worked now

sharp roost
#

Minecraft is so inconsistent lol

ionic verge
#

the capitalation (ignore spelling) throws me to often lol

tribal tundra
ionic verge
#

it threw me so long when they changed effect ids

sharp roost
#

I'm surprised they didn't change it to slot when they changed count

ionic verge
#

lmao

tribal tundra
#

🤷 we will never know, mojangs ways are beyond us :D

ionic verge
#

since ur both here lol, how would i go about separating this from the name to use in other commands

#

im trying to make a spell creation system, i wanted to originaly use a writeable book but i couldnt be arsed to make an id system and storage for all the players, im using ameythyst shards

#

i wanted it so the "[1-2-3-4]" is the fomula if that makes sense

#

i can make a separate post if u want lol

tribal tundra
#

You can use data … string, it’s not that straightforward though

ionic verge
#

would i have to throw it in to a storage system?

tribal tundra
#

Yeah, item -> storage and then you can execute if data storage or use a macro

ionic verge
#

howd i do it using a macro, i cant be bothered to make a id based storage system

tribal tundra
#

It’s pretty much a string replacement for commands

#

I think it’s probably best if you start a new post, it almost midnight for me and I gotta get up early ^^
And Gears is also European

tribal tundra
ionic verge
#

ah true, ok thanks alot tho

#

been a huge help

sacred gorgeBOT
# ionic verge ah true, ok thanks alot tho
🎗️ Is your question resolved?

If your question is resolved, that's great to hear! Make sure to run /resolve or click the Resolve Question button. Otherwise, feel free to continue asking for help! :D