how to make a named trident execute a command

So i'm making this world with lots of commands and when a trident hits the ground, it makes a cow named bob spawn. and when an arrow hits the ground, it gives a diamond. two is not enough for my next idea so i was wondering if it's possible to make it so that it only works if the trident that's named touches the ground. So like, let's say there is a trident. when it hits the ground it spawns a cow named bob. well im wanting a trident that is called trident2 to give you a netherite ingot. I want it to be this command:

/execute at @e[type=trident,nbt={inGround:1b}] run give @p netherite_ingot

but instead the trident is called trident2. is this possible?

1 Answer

If you want to target and entity with a specific nbt, have that entity somewhere and run

/data get entity <your entity>

And look where the info is hidden. With the trident, we can see the name is stored in

Trident.tag.display.Name

And so, the nbt structure we want is

nbt={Trident:{tag:{display:{Name:'{"text":"trident2"}'}}}}

Thus, our final command will look like this:

/execute at @e[type=trident,nbt={inGround:1b,Trident:{tag:{display:{Name:'{"text":"trident2"}'}}}}] run give @p netherite_ingot
/execute as @e[type=trident,nbt={inGround:1b,Trident:{tag:{display:{Name:'{"text":"trident2"}'}}}}] run kill @s
2

You Might Also Like