0

I've been trying to detect the use of a custom Carrot on a stick using scoreboards.

The way I'm doing this is by spawning one with a custom model, name and tag:

give @p carrot_on_a_stick{display:{Name:'"Rubick"'},CustomModelData:963,Rubick:1b}

Then I add a new scoreboard objective:

scoreboard objectives add rubiclick minecraft.used:minecraft.carrot_on_a_stick

Where I then use to detect if the player used the item but I use the detection to also make sure it has either the custom name, OR tag:

execute as @a[scores={rubiclick=1..},nbt={SelectedItem:{id:"minecraft:carrot_on_a_stick"},tag:{display:{Name:'"Rubick"'}}}] at @s run effect give @a weakness 1 1 false

or

execute as @a[scores={rubiclick=1..},nbt={SelectedItem:{id:"minecraft:carrot_on_a_stick"},tag:"Rubick:1b"}] at @s run effect give @a weakness 1 1 false

but neither method seems to work, yet I can detect a regular Carrot on a stick use with:

execute as @a[scores={rubiclick=1..},nbt={SelectedItem:{id:"minecraft:carrot_on_a_stick"}}] at @s run effect give @a weakness 1 1 false

Does anyone know what I'm doing wrong here?

1
  • Why are you attempting to test for the name or the tag? I can't think of any scenarios where this type of testing is needed, just pick either the name or the tag, and test for that property only.
    – One 2 Many
    Nov 5, 2021 at 23:28

1 Answer 1

0

Your first trial was the closest, but it was wrong:


You entered:

{
  SelectedItem: {
    id: "minecraft:carrot_on_a_stick"
  },
  tag: {
    display: {
      Name: '"Rubick"'
    }
  }
}

The correct NBT that you should enter is:

{
  SelectedItem: {
    id: "minecraft:carrot_on_a_stick",
    tag: {
      display: {
        Name: '"Rubick"'
      }
    }
  }
}

Notice how tag is inside SelectedItem, not inside of it.

But while you're at it, you should avoid testing for custom item names. Instead, you should add a custom tag to your item. Your second failed trial above was an (incorrect) attempt to test for a custom item tag. This test failed because, you had the issue above, and your custom tag was in ""s, signifying a string, when it isn't.

The correct format to test for a custom item tag is:

SelectedItem: {
  id: "_____",
  Count: 1b,
  tag: {
    Rubick: 1b
  }
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .