Dying costs you hearts, not your inventory. Set how many hearts a death takes, how many deaths it takes to lose one, and a floor you can never fall below - so only the hearts you earned are ever at risk.
Turn the enchanted books you find into permanent villager trades. Hand a villager a book and it learns that enchantment. Works with modded enchantments.