To testfor the Item's damage, use the "Damage" tag.
/testfor @e[type=Item,r=4] {Item:{id:"minecraft:anvil",Damage:0s}}
To test for a custom name, you can use the "tag" tag. With this tag you can define NBT tags for non-entity items. (Items in a player's inventory)
In this case, you need the "display" tag
/testfor @e[type=Item,r=4] {Item:{id:"minecraft:anvil",Damage:0s,tag:{display:{Name:"Custom Name Here"}}}}
Disclaimer
The section symbol is deprecated. You should avoid using it as much as possible and be aware that it will not work in the future. It is being replaced by the JSON text component, which is already supported by chat (accessible with /tellraw
), book pages, sign text, and the /title
command.
In-game with signs
Because sign text supports the text component, it also supports unicode characters (declared as \u####
). The character for the section symbol is \u00A7
.
You would use the sign to run a clickEvent that provides you with a command block that uses the section symbol at the appropriate location in its syntax. You'd then place the command block where needed.
Note that this will only work for signs because it's the sign running the command, rather than the player being forced the run the command in the chat like with /tellraw
or book pages. The player would otherwise be kicked for trying to type the section symbol.
Example command:
/setblock ~ ~1 ~ minecraft:standing_sign 0 replace {Text1:"[\"\"]",Text2:"[\"\"]",Text3:"[\"\"]",Text4:"{\"text\":\"Click\",\"clickEvent\":{\"action\":\"run_command\",\"value\":\"/give @p minecraft:command_block 1 0 {BlockEntityTag:{Command:/summon Item ~ ~1 ~ {Item:{id:\\\"minecraft:stone\\\",Count:1b,tag:{display:{Name:\\\"\u00A71Custom Name\\\"}}}}}}\"}}"}
Using loot tables
A custom loot table can be created to provide you with a command block containing the section symbol, which can be pasted into the JSON file directly.
For example, the following would provide the necessary command block that you'd place where desired:
{
"pools": [
{
"rolls": 1,
"entries": [
{
"type": "item",
"name": "minecraft:command_block",
"weight": 1,
"functions": [
{
"function": "minecraft:set_nbt",
"tag": "{BlockEntityTag:{Command:/summon Item ~ ~1 ~ {Item:{id:\"minecraft:stone\",Count:1b,tag:{display:{Name:\"ยง1Custom Name\"}}}}}}"
}
]
}
]
}
]
}
The command to place the chest containing the command block (assuming filepath world_name/data/loot_tables/custom/cmd.json
):
/setblock ~ ~1 ~ minecraft:chest 0 replace {LootTable:"custom:cmd"}
You can modify the command block that contains the /summon
command using either of these programs to contain the section symbol at the desired spot in its syntax.
Using MCEdit, you'd locate the command block, double-click it, and paste the section symbol and color code within the command itself.
With NBTExplorer, you would need to locate the command block first by copy/pasting into the program's Search tool. You would then double-click the Command
value and paste the section symbol at the appropriate location.
Best Answer
Saplings use the
Damage
tag to store their type. Dark Oak's value is 5 andDamage
is ashort
type, hence thes
.This command should test for a dark oak sapling in the chest.