This is a datapack for versions 1.21 and above. It adds a simple enchantment which protects enchanted items from being dropped on death.
This datapack is inspired by similar mods and datapacks for previous versions. I couldn't find one using the new data-driven enchantment functionality in 1.21 so I decided to make it for myself with the aim of keeping it as simple and understandable as possible.
This enchantment cannot be obtained in survival by default, and is intended more as a utility for servers, maps, packs and other projects. I may create an alt version which is obtainable through enchanting in the future, but for now you're free to download this version and add it to the obtainable enchantment tags yourself, it's not too difficult to do.
Items with durability will lose 20% of their durability upon death, so dying doesn't come without drawbacks. However, this damage will never fully break the item. You will hear a small noise on respawn to signify that items have been returned to you.
This datapack requires the chunk at 0,0 to be force-loaded to function correctly. This will be done automatically on load. On a server, spawn chunks are always loaded by default so this should make no difference, however this may have a very minor impact in singleplayer.
Compatible with keepinventory (enchantment will have no effect). Will likely break with doimmediaterespawn. Items are attributed to and returned to players based on their UUID, so will likely break on offline-mode servers.
Due to how the void deletes items after a single tick, this enchantment will NOT protect items from death to the void. This may be fixed in the future, but its tricky.
Want to ask questions directly? I don't have a discord server, but you can send me a message request @livelaughlord