so I have this command:
/execute as @e[type=minecraft:item,distance=1,limit=1] run data modify block -154 136 285 Lock set from entity @s Item.tag.display.Name
which is meant to lock a chest with the lock being the name of the item. However, the chest is not locked, and even from a command block I get no feedback. Any tips?
/execute as @e[type=minecraft:item,distance=1,limit=1] run data modify block -154 136 285 Lock set from entity @s Item.tag.display.Name
which is meant to lock a chest with the lock being the name of the item. However, the chest is not locked, and even from a command block I get no feedback. Any tips?
2
Unfortunately, the tag.display.Name is a JSON text component, while the Lock tag is plain string.
So when you rename an item in an anvil to "Key", the actual tag value will be '{"text":"Key"}'
When you lock a chest with "Key", you can open it with any item named Key, regardless of the JSON structure.
The problem with your command is that the chest Lock value will be '{"text":"Key"}' which only works if you actually type that code into an avil. Which obviously isn't what you want. Unless I'm wrong on what I just said (do comment if I am), there is no way of letting survival players pick their own key name. Maybe if you straight up put "Key" into the display.Name tag with a command (/give @s stick{tag:{....}}) it could work, but not sure.
So when you rename an item in an anvil to "Key", the actual tag value will be '{"text":"Key"}'
When you lock a chest with "Key", you can open it with any item named Key, regardless of the JSON structure.
The problem with your command is that the chest Lock value will be '{"text":"Key"}' which only works if you actually type that code into an avil. Which obviously isn't what you want. Unless I'm wrong on what I just said (do comment if I am), there is no way of letting survival players pick their own key name. Maybe if you straight up put "Key" into the display.Name tag with a command (/give @s stick{tag:{....}}) it could work, but not sure.
[distance=1] would mean that the entity has to be exactly 1 block away. I assume you wanted to use [distance=..1] , the two dots making it a maximum 1 block distance. Changing it should most likely fix it.
