How to check the value of a Tag and execute another command when equal to a desired value?



  • I'm trying to have a lectern teleport me when I place the correctly named book on its top. So far, I've tried using this command:

    /execute if data block 50005 10 50009 Book.tag[{title:"Bookname"}] run tp 100 10 100
    

    If I remove the last part of the path specifying the string, the last "run" command does execute, so I'm getting the feeling that "execute if data" only checks if the target has a Tag, rather than checking if the said tag has the requested value. Am I using the wrong command or the wrong selector?

    I'm running version: 1.14.4



  • The "Book" block does not exist in Minecraft. You should write this command for lentern block and check its nbt data instead. The correct command is:

    /execute if data block 50005 10 50009 minecraft:lectern{Book: {tag: {title: "Bookname"}}} run tp 100 10 100

    Also you can use the official Minecraft wiki to view nbt path of block. For example, https://minecraft.fandom.com/wiki/Lectern#Block_data .




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2