I've made these commands to lock a door and make it only able to open if a user is holding an item called "Hotel Master Key".

This summons an armor stand, and I have placed it in front of the door to stop rightclicking to open it. I've done this 2 more times for the corners of the door.

/summon minecraft:armor_stand ~ ~ ~ {CustomNameVisible:0b,NoGravity:1b,Invulnerable:1b,Invisible:1b,NoBasePlate:1b,PersistenceRequired:1b,DisabledSlots:4144959,CustomName:"{\"text\":\"Main Door\"}"}

I've made a execute command to check if the player trying to enter is holding the correct item.

/execute if entity @a[nbt={SelectedItem:{id:"minecraft:tripwire_hook",Count:1b,tag:{display:{Name:"{\"text\":\"Hotel Master Key\",\"color\":\"white\",\"bold\":true,\"italic\":false}"},HideFlags:63}}}]

I've also made a command that kills the armor stands if the first command was true using a chain and conditional commandblock.

/kill @e[distance=..3,type=armor_stand,name=Main Door]

How would I make it so that the door would become re-locked (armor stands would come back) after 3 seconds?

Please don't suggest that I should use a iron door.

  • 1
    You will want to set up a scoreboard objective to count ticks, and increase that objective once every tick starting when the door has been opened up until it equals 60 (3 seconds). Then, run the commands to replace the armor stands, reset the counter, and stop it from ticking in a chain when the timer has reached 60.
    – Nik3141
    Commented Jun 23, 2019 at 20:34
  • Your second command does nothing: "if there is an entity with those conditions, then… nothing." Commented Jun 23, 2019 at 22:29

2 Answers 2


You could remove the armour stand's hitbox temporarily instead of killing it:

/data merge entity @e[type=armor_stand,name="Main Door",distance=..3] {Marker:1}

Then just undo that three seconds later:

/data merge entity @e[type=armor_stand,name="Main Door",distance=..3] {Marker:0}

I suggest you use iron golems instead of armor stands, because they have a bigger hitbox that covers the door completely. I tried it with armor stands, but I was able to still open the door if I clicked at the very top of it. You could summon an iron golem with this command:

/summon minecraft:iron_golem ~ ~ ~ {NoAI:1b,Invulnerable:1b,Invisible:1b,PersistenceRequired:1b,ActiveEffects:[{Id:14,Amplifier:0,Duration:2000000000,ShowParticles:0b}],Tags:["door"]}

It will stay invisible for more than 3 years and it will have a door-tag that will be useful in these commands:

/execute as @e[type=minecraft:iron_golem,tag=door] at @s positioned ~ 64 ~ if entity @a[distance=..3] run tp @s ~ 60 ~
/execute as @e[type=minecraft:iron_golem,tag=door] at @s positioned ~ 64 ~ unless entity @a[distance=..3] run tp @s ~ 64 ~

These commands will teleport the golems down and up, away from the door and back to it. They assume that all the golems stand at y=64 and that y=60 is not important for anything else (like a cellar).

You can change the target selector @a[distance=..3] to also check for the key, so the commands in your case may look like this:

/execute as @e[type=minecraft:iron_golem,tag=door] at @s positioned ~ 64 ~ if entity @a[nbt={SelectedItem:{id:"minecraft:tripwire_hook",Count:1b,tag:{display:{Name:"{\"text\":\"Hotel Master Key\",\"color\":\"white\",\"bold\":true,\"italic\":false}"},HideFlags:63}}},distance=..3] run tp @s ~ 60 ~
/execute as @e[type=minecraft:iron_golem,tag=door] at @s positioned ~ 64 ~ unless entity @a[nbt={SelectedItem:{id:"minecraft:tripwire_hook",Count:1b,tag:{display:{Name:"{\"text\":\"Hotel Master Key\",\"color\":\"white\",\"bold\":true,\"italic\":false}"},HideFlags:63}}},distance=..3] run tp @s ~ 64 ~

Note: This is not a time based solution, the door gets relocked when no player with a key is near it

Note 2: This does NOT close the door, you still need to close it somehow

Note 3: 3 years should be long enough, but if you feel paranoid, then you can reset the ActiveEffects-tag on a slow clock (maybe a daylight detector on top of an impulse command block), to make the effect last forever. The command for that may look like this:

/execute as @e[type=minecraft:iron_golem,tag=door] run data modify entity @s ActiveEffects set value [{Id:14,Amplifier:0,Duration:200000000,ShowParticles:0b}]

Note 4: You can still use armor stands if you like them more, there is nothing special about iron golems except for their huge hitbox

  • The iron golems have particles. Commented Jun 27, 2019 at 23:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .