Key Data Pack Logo
Locked Chest as hologram
Locked Chest as hologram
Chest has been unlocked
Locked Door

Key

1.20.2 +

Lock your containers and doors to protect your items and buildings from other players and Creepers. Press shift and right-click on the block to lock or unlock it.

Crafting
Key Recipe

[1.20.2 - 1.20.4] The Crafting Table will show a Knowledge Book as the result. This will be replaced by the Key after crafting.

The Key is damaged every time a block is locked. This functionality can be changed in the settings of the Data Pack. The damage can also occur when unlocking, every time the Key is used or be completely deactivated. To increase its durability, it can also be enchanted with Unbreaking or Mending.

[1.21.2 +] The Key has a default durability of 400 and can be repaired with a Gold Ingot in the Anvil. The durability can be changed on the download page of the Data Pack.
[1.20.2 - 1.21.1] The Key has a durability of 100 and can be repaired by dropping it with a Gold Ingot onto an Anvil.

Locking and settings

If a player locks a container or door, only that player can unlock it again. The Key itself doesn't matter in this process, as the lock only remembers the player.

In addition, you can allow the name of the Key to be used as password in the settings. This allows all players who use the right password to unlock the lock. To prevent forgotten passwords, the last player to lock the container or door owns it and can therefore also unlock it with any Key as described above.

If desired, the maximum number of locked blocks per player and the total in the world can be defined in the settings.

You can open the settings with the following command:

/function keylock:settings/menu

Use the follwing command to set the maximum numbers to unlimited:

/scoreboard players reset #max_player keylock /scoreboard players reset #max_world keylock

Locked containers

Once a container has been locked, the items inside can no longer be accessed, even by breaking it or placing a hopper underneath it.
This also means that locked furnaces and similar blocks cannot process the items inside and the fuel currently in use is not preserved. If items are placed in a locked container via a hopper, they will be dropped when the container is unlocked.

Settings Menu:

  • The automatic unlocking of containers can be activated. This causes all containers within a defined radius around the player to be unlocked, as long as the player is the owner of the container or has the correct Key with password selected in their hotbar. After the player has moved away, the container is automatically locked again.
  • The behaviour of locked containers can be changed. Locked containers can either be made unbreakable or replaced by holograms. Furthermore, the container can also remain as a block and only be replaced by a hologram once it has been destroyed.
    A hologram is a visualisation of the locked container. A player can walk through it without resistance and place and break blocks in it.

Locked doors and fence gates

All locked doors, trapdoors and fence gates are unbreakable and cannot be opened. However, the lock can be released by a piston if it moves the door, trapdoor or fence gate. Removing the support block from a normal door also causes the door to break.

If a double door is locked, both door leaves are locked.

Settings Menu:

  • The automatic opening of double doors can be activated. This setting applies to all doors, regardless of whether they are locked.
  • The automatic opening of doors can be activated. If this is activated, all doors that are three blocks in front of the player are opened. After the player has moved away, the door is automatically closed again.
  • The automatic unlocking of doors can be activated. This will unlock and open all doors that are three blocks in front of the player, provided the player is the owner of the door or has selected the correct key and password in their hotbar. After the player has moved away, the door is automatically closed and locked again.


Important technical stuff

Be aware that other Data Packs and mods that change the functionality of containers and doors can interrupt the operation of this pack. In the case of containers, this could result in the loss of items.

Never kill all entities in the world, as the lock status of the block is stored in special entities.

A server admin can use an Admin Key to unlock the locked blocks of another player:

/function keylock:admin_key

If a container or door can no longer be unlocked, an attempt should first be made to break it. If the locked block replaces itself, an Admin Key can be used to unlock it. If a locked container no longer replaces itself, the original container must be placed again first. The following command can then be used to restore the items in the container:

/function keylock:container/repair with block <container position>

This command cannot be used if a container has been locked again at the same position with new items in it. This will overwrite the data at this position.
The items themselves are not saved in the special entity, but in the command storage. The file is located in the data folder of your world and is called command_storage_keylock.dat.

Adjust lockable Blocks

The easiest way to select the lockable blocks is on the download page of the Data Pack. If these need to be changed after the first download, the Data Pack must first be unzipped. All lockable blocks are defined under the folder data/tags/blocks.

All lockable containers are stored in the containers.json file. The following blocks from Vanilla can be locked when defined in this file:
barrel, blast_furnace, brewing_stand, chest, dispenser, dropper, furnace, hopper, smoker, trapped_chest and all colour variants of the shulker_box

All lockable doors are stored in the doors.json file. All doors from Vanilla can be locked when defined in this file.

All lockable trapdoors and fence gates are stored in the trapgate.json file. All trapdoors and fence gates from Vanilla can be locked when defined in this file.

It is also possible to add blocks from mods. To do this, the block ID is stored in the most fitting block tag json file. In addition, it is always necessary to check whether the locking works correctly before using it.

Older versions for 1.15 - 1.20.4

If you want to use the older version of this Data Pack, you can get it here.

In this version you can only lock normal chests, but this version can be used from Minecraft 1.15 onwards.

Get older versions