Skip to main content
added 504 characters in body
Source Link
ginkgo
  • 2.6k
  • 1
  • 15
  • 30

Yes, item tags exist. The item tag file would look like this:

swords.json

{
  "values": [
    "minecraft:wooden_sword",
    "minecraft:stone_sword",
    "minecraft:golden_sword",
    "minecraft:iron_sword",
    "minecraft:diamond_sword",
    "minecraft:netherite_sword"
  ]
}

Here it is, working:

Item tag

However, even though the wiki says that "Item tags can be called when testing for item arguments in commands with #(namespaced ID)", this does not seem to be true. This Reddit comment also confirms that this is not possible:

... [Testing for item tags] is not one of the functionalities of NBT item testing. You've got to remember that when testing for something's NBT, the entity has to have identical NBT to the one you're providing. No item will have the Item.id tag equal to "#bhtype:swords", unfortunately. Minecraft recognises it as a proper command because you have the Item.id value as an identifiable TAG_String, nothing more. ...

Here is a workaround:

execute unless entity @s[nbt=!{SelectedItem:{id:"minecraft:wooden_sword"}},nbt=!{SelectedItem:{id:"minecraft:stone_sword"}},nbt=!{SelectedItem:{id:"minecraft:golden_sword"}},nbt=!{SelectedItem:{id:"minecraft:iron_sword"}},nbt=!{SelectedItem:{id:"minecraft:diamond_sword"}},nbt=!{SelectedItem:{id:"minecraft:netherite_sword"}}] run say I'm holding a sword

Good luck on your PvP map :)


As ExpertCoder14 commented, "if you're using a data pack, you can use a predicate to test for an item tag."

This is what the predicate would look like:

holding_sword.json

{
  "condition": "minecraft:entity_properties",
  "entity": "this",
  "predicate": {
    "equipment": {
      "mainhand": {
        "tag": "test:swords"
      }
    }
  }
}

Then you could use this command:

/execute if predicate test:holding_sword run say I'm holding a sword

Yes, item tags exist. The item tag file would look like this:

swords.json

{
  "values": [
    "minecraft:wooden_sword",
    "minecraft:stone_sword",
    "minecraft:golden_sword",
    "minecraft:iron_sword",
    "minecraft:diamond_sword",
    "minecraft:netherite_sword"
  ]
}

Here it is, working:

Item tag

However, even though the wiki says that "Item tags can be called when testing for item arguments in commands with #(namespaced ID)", this does not seem to be true. This Reddit comment also confirms that this is not possible:

... [Testing for item tags] is not one of the functionalities of NBT item testing. You've got to remember that when testing for something's NBT, the entity has to have identical NBT to the one you're providing. No item will have the Item.id tag equal to "#bhtype:swords", unfortunately. Minecraft recognises it as a proper command because you have the Item.id value as an identifiable TAG_String, nothing more. ...

Here is a workaround:

execute unless entity @s[nbt=!{SelectedItem:{id:"minecraft:wooden_sword"}},nbt=!{SelectedItem:{id:"minecraft:stone_sword"}},nbt=!{SelectedItem:{id:"minecraft:golden_sword"}},nbt=!{SelectedItem:{id:"minecraft:iron_sword"}},nbt=!{SelectedItem:{id:"minecraft:diamond_sword"}},nbt=!{SelectedItem:{id:"minecraft:netherite_sword"}}] run say I'm holding a sword

Good luck on your PvP map :)

Yes, item tags exist. The item tag file would look like this:

swords.json

{
  "values": [
    "minecraft:wooden_sword",
    "minecraft:stone_sword",
    "minecraft:golden_sword",
    "minecraft:iron_sword",
    "minecraft:diamond_sword",
    "minecraft:netherite_sword"
  ]
}

Here it is, working:

Item tag

However, even though the wiki says that "Item tags can be called when testing for item arguments in commands with #(namespaced ID)", this does not seem to be true. This Reddit comment also confirms that this is not possible:

... [Testing for item tags] is not one of the functionalities of NBT item testing. You've got to remember that when testing for something's NBT, the entity has to have identical NBT to the one you're providing. No item will have the Item.id tag equal to "#bhtype:swords", unfortunately. Minecraft recognises it as a proper command because you have the Item.id value as an identifiable TAG_String, nothing more. ...

Here is a workaround:

execute unless entity @s[nbt=!{SelectedItem:{id:"minecraft:wooden_sword"}},nbt=!{SelectedItem:{id:"minecraft:stone_sword"}},nbt=!{SelectedItem:{id:"minecraft:golden_sword"}},nbt=!{SelectedItem:{id:"minecraft:iron_sword"}},nbt=!{SelectedItem:{id:"minecraft:diamond_sword"}},nbt=!{SelectedItem:{id:"minecraft:netherite_sword"}}] run say I'm holding a sword

Good luck on your PvP map :)


As ExpertCoder14 commented, "if you're using a data pack, you can use a predicate to test for an item tag."

This is what the predicate would look like:

holding_sword.json

{
  "condition": "minecraft:entity_properties",
  "entity": "this",
  "predicate": {
    "equipment": {
      "mainhand": {
        "tag": "test:swords"
      }
    }
  }
}

Then you could use this command:

/execute if predicate test:holding_sword run say I'm holding a sword
Source Link
ginkgo
  • 2.6k
  • 1
  • 15
  • 30

Yes, item tags exist. The item tag file would look like this:

swords.json

{
  "values": [
    "minecraft:wooden_sword",
    "minecraft:stone_sword",
    "minecraft:golden_sword",
    "minecraft:iron_sword",
    "minecraft:diamond_sword",
    "minecraft:netherite_sword"
  ]
}

Here it is, working:

Item tag

However, even though the wiki says that "Item tags can be called when testing for item arguments in commands with #(namespaced ID)", this does not seem to be true. This Reddit comment also confirms that this is not possible:

... [Testing for item tags] is not one of the functionalities of NBT item testing. You've got to remember that when testing for something's NBT, the entity has to have identical NBT to the one you're providing. No item will have the Item.id tag equal to "#bhtype:swords", unfortunately. Minecraft recognises it as a proper command because you have the Item.id value as an identifiable TAG_String, nothing more. ...

Here is a workaround:

execute unless entity @s[nbt=!{SelectedItem:{id:"minecraft:wooden_sword"}},nbt=!{SelectedItem:{id:"minecraft:stone_sword"}},nbt=!{SelectedItem:{id:"minecraft:golden_sword"}},nbt=!{SelectedItem:{id:"minecraft:iron_sword"}},nbt=!{SelectedItem:{id:"minecraft:diamond_sword"}},nbt=!{SelectedItem:{id:"minecraft:netherite_sword"}}] run say I'm holding a sword

Good luck on your PvP map :)