This data tag makes any block that holds items, a locked container that can only be opened by holding an item named exactly like the lock.
Making a "key" is as simple as naming an item in an anvil, the problem is applying the lock on the container, which can only be done with commands.
The first thing the mod does is allowing to "lock" a container by using the "key" item on the block while sneaking. The same action will "unlock" a container if done with the corresponding key.
Next, the mod protects all locked containers from being mined by players or broken by explosions. It also prevents hoppers from extracting items, unless both the container and the hopper have the same lock.
Last, it hides the data tag holding the name of an item when sending packets to the players, preventing the use of modified minecraft clients (cheaters) from finding out the string used to lock the containers. Also, on player death, only the original owner will be able to pickup dropped items that have been named (and, as a side effect, those items will not despawn), although they can still be destroyed if they fall on lava, fire, etc.
Right now the "mod" is composed by only one java file:
It uses the javassist library to alter the minecraft classes bytecode:
The compiled class has to be packed in a jar with a java agent manifest file:
java -javaagent:lockable-chests.jar -jar minecraft_server.jar
I'll try to provide later a compiled jar file for testing.