Minecraft command block door using a key [duplicate]
So I'm making a dungeon based off Legend of Zelda, and I want to make a door that opens when you have a key in your inventory. Say the key is called "Small Key". How can I get it to open when you're 5 blocks away from the door?
Best Answer
First of all, summon an invisible ArmorStand at your door, replacing X, Y and Z with the coordinates of the bottom part of your door:
/summon ArmorStand X Y Z {CustomName:"keyDetector",Invisible:1,Invulnerable:1}
Next, run the following commands in Always Active mode in command blocks, running the first command in a repeating command block (repeating_command_block) and the others in chain command blocks (chain_command_block), following the repeating command block:
/scoreboard players tag @a add hasKey {Inventory:[{tag:{display:{Name:"Small Key"}}}]}
/execute @a[tag=hasKey] ~ ~ ~ /execute @e[name=keyDetector,type=ArmorStand] ~ ~ ~ /setblock ~ ~ ~ wooden_door 4
/execute @a[tag=hasKey] ~ ~ ~ /execute @e[name=keyDetector,type=ArmorStand] ~ ~ ~ /setblock ~ ~1 ~ wooden_door 9
So in the end it should look something like this:
The command blocks, containing the command blocks in order from left to right:
The door with the ArmorStand (for display purposes you can see the ArmorStand and it's name on this image, but you shouldn't be able to see it on your map):
Pictures about "Minecraft command block door using a key [duplicate]"
![Minecraft command block door using a key [duplicate] - Crop hacker silhouette typing on computer keyboard while hacking system Minecraft command block door using a key [duplicate] - Crop hacker silhouette typing on computer keyboard while hacking system](/assets/images/minecraft_command_block_door_using_a_key_duplicate_1.jpeg)
![Minecraft command block door using a key [duplicate] - Assorted-color House Facade in Park Minecraft command block door using a key [duplicate] - Assorted-color House Facade in Park](/assets/images/minecraft_command_block_door_using_a_key_duplicate_2.jpeg)
![Minecraft command block door using a key [duplicate] - Deadlock With Key on Hole Minecraft command block door using a key [duplicate] - Deadlock With Key on Hole](/assets/images/minecraft_command_block_door_using_a_key_duplicate_3.jpeg)
How do you make a command block door lock?
So here are the steps for it.How do you make an automatic door in Minecraft with command blocks?
With repeating command blocks, one can perform commands that other players can not perform. To get a repeating command block, players must use the /give command like so: /give @p minecraft:repeating_command_block <amount> .How I Made Adventure Map-Like Doors with Keys! | Minecraft Java 1.17+ | Command Toolbox #6
More answers regarding minecraft command block door using a key [duplicate]
Answer 2
Instead of using command blocks to detect the key and open the door, you can just use a hopper sorter to get the key from the person (which also doubles as removing the key from their inventory since they don't need it anymore) and then have it trigger command blocks which open the door.
Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.
Images: Keira Burton, Anete Lusina, Pixabay, Pixabay


