I have searched this forum and the internet, but all the proposed solutions don’t work for one reason or another. Since someone removed the “Minecraft PE” part of my title (Why?), I'm just going to add that iPadOS is the platform I am on.

Background:
I built a (somewhat large) hotel/resort in my world, and I was interested in adding a keycard system for the doors. Because of the way the structure is built (and there is no way I am going to remodel something this size), there is only room for three blocks under the door.
Horrible example below:

|xxxxxxxxxx|DoorIsHere|xxxxxxx|
|OpenBlock|OpenBlock|OpenBlock|

Is there a way I can create a system to unlock the door when tapped by the player (and only the player) with the key using these four open blocks? There are over 100 doors, and each would need its own key, plus, I would like a master key if that is possible. I would like to avoid the use of mods, but if that is the only way...

If the use of a button is needed, it can be placed on the bottom wall block, but I would rather no button be used. If possible, I would just like the player to tap the door, and the door would open if the player holds the correct key.

Another user posted a solution that incorporates the use of tags, so is there any way I can put a command block under (Or preferable under and to the left of) the door and have the door open if a player with the correct tag/key taps it? If “Tags” are not the best way to do this, that's fine!

Edit: I removed the fact that there is an open block directly to the right of the door because I would rather there not be a non-matching block on the wall next to every door. If a block is needed there (And there is no other way to do this), I guess I would be willing to do it. Thanks again for any suggestions.

Edit 2: Someone suggested having the command blocks elsewhere, and after some thought, I would be willing to do this. My thought on this is to have a room full of command blocks that would somehow ‘talk’ to the door and open it if the player with the key tapped it (or a button next to it). Would anyone know how to do this? Thanks!

Edit 3: Does anyone have anything that could work? At this point I'm willing to accept anything with the command block, even of it requires multiple blocks away from the door. I have unlimited (almost) space away from the door, so let me know what would work! (No, I don't want to create a 20 block system for each door :)


Note: This answer does NOT meet the requirements of the question, given that a door cannot be placed on a redstone comparator. However, I'm leaving it due to the amount of effort I put into it. The underlying concept may still be useful to future readers. I should really avoid answering in the evenings from now on. 😂


This can be accomplished with two commands:

  • The tag command can be used to serve as the "key".
  • The testfor command can be used to determine if a nearby player has the expected "key".

📝 Required Items

  • 1 Command Block
  • 1 Redstone Comparator
  • 1 Redstone Dust
  • 1 Block (any kind that allows placement of redstone dust)
  • 2 Buttons

🧰 Configuration

Since you have three spots under the door and one to the side, place 1 command block, 1 redstone comparator, 1 block that allows placement of redstone dust, and 1 sprinkle of redstone dust in the following configuration:

Screenshot of the aforementioned configuration.

The command block should be given the following command and configuration:

# Command (replace number in the tag with the number of the door)
testfor @p[tag=door_number,r=3]

# Configuration
Repeat
Unconditional
Needs Redstone
50 Ticks

Giving a delay in ticks with a repeating configuration allows the door to automatically close once the player leaves the immediate area. You'll also need to use a button to trigger the command block from both sides of the door (allowing players to open the door):

Screenshot of the button placement.

🔑 Keys

You still need to give players the keys to their rooms, which you can do with the tag command:

tag player_name_here add door_number