I want to give players random enchantment books with enchants

So in my friend's server, I created a datapack that allows me to give random enchantment books with random levels with a command using /loot give. (full command is
/loot give <username> loot enchant1book:enchanted_books
. There are two different folders for this:
-"enchant1book" gives the player a random book with a blue name with the random enchant, meaning the enchantment can't be combined with other enchants or tools/armor/etc.
-Whereas "enchant2book" gives the player an enchantment book with a yellow name, meaning it can be combined with other enchants or tools/etc., BUT it comes without any actual enchantments in it, it's just an item called "Enchantment Book"

The problem here is that I want to give players a random enchantment book WITH enchants and that CAN be combined in an anvil. Any idea on how I can do this? Plus, I want to do this using commands, so when I do the first mentioned command it will do what I said.

This is the code for enchant1book (blue name):
{
  "type": "minecraft:chest",
  "pools": [
    {
      "rolls": 1,
      "entries": [
        {
          "type": "minecraft:item",
          "name": "minecraft:enchanted_book",
          "functions": [
            {
              "function": "minecraft:enchant_randomly",
              "enchantments": [
                "minecraft:aqua_affinity",
                "minecraft:bane_of_arthropods",
                "minecraft:binding_curse",
                "minecraft:blast_protection",
                "minecraft:channeling",
                "minecraft:depth_strider",
                "minecraft:efficiency",
                "minecraft:feather_falling",
                "minecraft:fire_aspect",
                "minecraft:fire_protection",
                "minecraft:flame",
                "minecraft:fortune",
                "minecraft:frost_walker",
                "minecraft:impaling",
                "minecraft:infinity",
                "minecraft:knockback",
                "minecraft:looting",
                "minecraft:loyalty",
                "minecraft:luck_of_the_sea",
                "minecraft:lure",
                "minecraft:mending",
                "minecraft:multishot",
                "minecraft:piercing",
                "minecraft:power",
                "minecraft:projectile_protection",
                "minecraft:protection",
                "minecraft:punch",
                "minecraft:quick_charge",
                "minecraft:respiration",
                "minecraft:riptide",
                "minecraft:sharpness",
                "minecraft:silk_touch",
                "minecraft:smite",
                "minecraft:soul_speed",
                "minecraft:sweeping",
                "minecraft:thorns",
                "minecraft:unbreaking",
                "minecraft:vanishing_curse"
              ]
            }
          ]
        }
      ]
    }
  ]
}

And this is the code for enchant2book (yellow name):
{
  "type": "minecraft:chest",
  "pools": [
    {
      "rolls": 1,
      "entries": [
        {
          "type": "minecraft:item",
          "name": "minecraft:enchanted_book",
          "functions": [
            {
              "function": "minecraft:enchant_with_levels",
              "levels": 1,
              "treasure": true
            }
          ]
        }
      ]
    }
  ]
}


And below I will attach what enchant1book and enchant2book give you respectively.
image.png
image.png
Was this page helpful?