Minecraft: how to trigger an item command?

Hu
- in Mods
20

I have a server that is about only vanilla (so without mods and plugins etc). I now need an item that teleports me to the spawn. But how can I make such an item using commands?

Be

What do you want as a trigger and what kind of item should it be?

For example, an item that is dropped or an item that is simply held in the main hand could be tested. In my opinion the best method is with right click detection. However, this method only works with the carrot rod or the tangled mushroom rod.

And what are the coordinates of the spawn.

Hu

Compass. Spawn coordinates 0 55 0

Be

And when should you be teleported to the spawn? When you drop a compass?

Hu

Is it also possible with a left or right click

Be

This only works with carrot rods or tangled mushroom rods. However, you could also use a texture pack to texture them

Hu

Um, I once saw a map where someone in vanilla had a compass and went into the inv and left-clicked the Kommpass and it went

Be

Could it be that the world had its own texture pack, because I don't know how to do it.

Hu

Do you know how to test via execute whether an item is not in the inventory at a certain slot and how to give an item in a certain slot via command.

Be

Yes

Hu

How because then I have a solution

Be

/ execute as @a [nbt =! {Inventory: [{Slot: 10b, id: "minecraft: stone", Count: 1b}]}] run

and

/ replaceitem entity @p hotbar.5 stone

Be

How?

Hu

I take a first command block that tests whether you don't have a certain unnamed compass in the slot (not hotbar) and then gives the player a tag called lobby. The 4 command block gives the player the item in the slot. The third teleports and the second clears the item and the fifth removes the tag. So you can then open the inv and then left-click the item there

Hu

How do you know the order?

Be

Oh, I thought you meant a right click in the game (like striking with a sword).

And the command is actually pretty easy to figure out. With the command "/ data get entity @s" you get the whole NBT data of the player displayed. There you will also find the inventory, which contains all the points.

In order not to have to search so long, you can also use this command "/ data get entity @s Inventory", which then shows you the NBT data from the inventory directly.

Hu

Ah, thanks

Hu

Help me. I gave myself an unnamed compass by command and then entered the data with / data get @s. I said to the test it should say hi if the compass is not there in the inventory. But it says hi when it's there and when it's not.

Be

Then you probably entered the wrong slot number or forgot the b after it.

In the picture you can see the slot number

Minecraft: how to trigger an item command
Be

https://blockbench.net/tools/clg/index.php?c=l_tp-to-spawn%C2%A7%C2%A7rua/%C2%A7x;+as+@a%C2%A7(nbt=!%C2%A7c(Inventory:%C2%A7(%C2%A7c(Slot:9b,tag:%C2%A7c(spawn_tp:1b%C2%A7c)%C2%A7c)%C2%A7)%C2%A7c)%C2%A7)+run+%C2%A7tp;+@s+0+20+0%C2%A7%C2%A7cca/%C2%A7x;+as+@a%C2%A7(nbt=!%C2%A7c(Inventory:%C2%A7(%C2%A7c(Slot:9b,tag:%C2%A7c(spawn_tp:1b%C2%A7c)%C2%A7c)%C2%A7)%C2%A7c)%C2%A7)+run+clear+@s+compass%C2%A7c(spawn_tp:1b%C2%A7c)%C2%A7%C2%A7cua/%C2%A7ri;+entity+@a+inventory.0+compass%C2%A7c(display:%C2%A7c(Name:'%C2%A7c('%C2%A7t;':'Gehe+zum+Spawn','italic':false%C2%A7c)',Lore:%C2%A7('%C2%A7c('%C2%A7t;':'Klicke+auf+das+Item+um+zum+Spawn+%C2%A7tp;iert+werden.','%C2%A7c;':'gray','italic':false%C2%A7c)'%C2%A7)%C2%A7&c1=c),spawn_tp:1b%C2%A7c)+1

Be

The last command is not correctly adopted by the website. This is how it is correct:

/ replaceitem entity @a inventory.0 compass {display: {Name: '{"text": "Go to spawn", "italic": false}', Lore: ['{"text": "Click on the item teleported to the spawn. "," color ":" gray "," italic ": false} ']}, spawn_tp: 1b} 1