Testfor block with custom name

I'm making "magic blocks": if you are standing on a specific block you get a potion effect like speed, instant health, strength, etc. The only problem is while trying to make it survival friendly I want the player to have to rename a diamond block to the certain name to make the potion effects work. /execute @a ~ ~ ~ detect ~ ~-1 ~ minecraft:diamond_block 0 /effect @a minecraft:strength 5 30

So that's what I use currently but is there an NBT tag that makes it so the detect part can testfor a diamond block that's been named in an anvil?


When you place a named block, it loses its name tag, making it impossible to detect if it was ever named. What you can do, however, is set a custom data value:

/setblock ~ ~ ~ diamond_block 1

Then, replace detect ~ ~-1 ~ diamond_block 0 with diamond_block 1. You can use values 1 through 15, but values above 15 are not supported.

Note: In some versions of the game (and possibly the latest updates), blocks with custom data may have a missing texture, and the custom data may not be saved properly. You'll have to look into this yourself as I can't test it at the moment.


Blocks cannot have names. If you use an anvil, that only renames the item stack. Instead of trying to detect the block, try spawning an invisible marker armor stand with a custom name. e.g. /summon ArmorStand ~ ~-1 ~ {Invisible:1, Marker: 1, CustomName: "Magic Block"}. You could then use the execute command to do things based on that armor stand.