Testfor block with custom name

Testfor block with custom name - White shabby concrete wall with cracked stucco

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?



Best Answer

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.




Pictures about "Testfor block with custom name"

Testfor block with custom name - Assorted-color House Facade in Park
Testfor block with custom name - Crop unrecognizable person with toy aircraft near multicolored decorative world map with continents attached on white background in light studio
Testfor block with custom name - White visiting card with empty space for data placed on light pink background



How do you summon animals with custom names?

How to Enter the Command
  • Open the Chat Window. The easiest way to run a command in Minecraft is within the chat window.
  • Type the Command. In this example, we are going to summon a cow named Daisy in Minecraft Java Edition (PC/Mac) 1.18 with the following command: /summon cow ~ ~ ~ {CustomName:"\\"Daisy\\""}




  • Learn Command Blocks (Ep 2): Testfor \u0026 Testforblock




    More answers regarding testfor block with custom name

    Answer 2

    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.

    Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

    Images: Tatiana Syrikova, Pixabay, Monstera, Angela Roma