The Bug
The game has two kinds of enchantments, StoredEnchantments for books and Enchantments for everything else. The loot table function enchant_randomly will give the wrong kind of enchantment to books if another function has already enchanted it.
{
"type": "minecraft:chest",
"pools": [
{
"rolls": {
"min": 4.0,
"max": 8.0,
"type": "minecraft:uniform"
},
"entries": [
{
"type": "minecraft:item",
"functions": [
{
"function": "minecraft:enchant_with_levels",
"levels": 30,
"treasure": true
},
{
"function": "enchant_randomly",
"enchantments": [
"protection",
"fire_protection",
"feather_falling",
"blast_protection",
"projectile_protection",
"thorns",
"depth_strider",
"frost_walker",
"sharpness",
"knockback",
"fire_aspect",
"looting",
"efficiency",
"silk_touch",
"unbreaking",
"fortune",
"power",
"punch",
"flame",
"infinity",
"mending"
]
}
],
"name": "minecraft:book"
}
]
}
]
}
The same thing happens if the function enchant_randomly is used twice, with the second enchantment being bugged.
If the function enchant_randomly is used on its own, then it gives a StoredEnchantment as intended.
If the function enchant_randomly is used, then enchant_with_levels, then enchant_with_levels won't give any enchantments at all.
Seems to still be in 22w14a.