RecipeViewerEvents.addInformation('item', (event) => {
    // https://kubejs.com/wiki/events/RecipeViewerEvents/addInformation

    /* Format Codes
    Obfuscated      §k
    Bold            §l
    Strikethrough   §m
    Underline       §n
    Italic          §o
    Reset Format    §r

    Colors:
    Dark Red        §4
    Red             §c
    Gold            §6
    Yellow          §e
    Dark Green      §2
    Green           §a
    Aqua            §b
    Dark Aqua       §3
    Dark Blue       §1
    Blue            §9
    Light Purple    §d
    Dark Purple 	§5
    White           §f
    Gray            §7
    Dark Gray       §8
    Black           §0

    */
    const descriptions = [
        {
            filter: ['ae2:sky_dust'],
            text: ['Sky Dust can be generated by pointing an Annihilation Plane at the sky at build limit (§2Y=319§r).']
        },
        {
            filter: beheading_tools,
            text: ['Easily cleaves the heads from your foes!']
        },
        {
            filter: [
                'minecraft:zombie_head',
                'minecraft:creeper_head',
                'minecraft:piglin_head',
                'minecraft:dragon_head',
                'minecraft:skeleton_skull',
                'minecraft:wither_skeleton_skull',
                'enderio:enderman_head'
            ],
            text: [
                'Heads may be obtained from mobs by killing them with particularly powerful axes and paxels.',
                ' ',
                'Search for §5#beheading§r in EMI for a list!'
            ]
        },

        {
            filter: ['enderio:industrial_insulation_block'],
            text: ['Absorbs and voids any fluids placed nearby.']
        },
        {
            filter: ['naturesaura:vacuum_bottle'],
            text: [
                'Use a Bottle and Cork in an area devoid of Aura.',
                ' ',
                `Can be automated using a JustDireThings Clicker.`
            ]
        },
        {
            filter: [
                Item.of('naturesaura:aura_bottle[naturesaura:aura_bottle_data={aura_type:"naturesaura:overworld"}]')
            ],
            text: [
                'Use a Bottle and Cork in an area of high Aura in the Overworld.',
                ' ',
                `Can be automated using a JustDireThings Clicker.`
            ]
        },

        {
            filter: ['naturesaura:gold_leaf'],
            text: [`Obtained by breaking Golden Leaves.`]
        },
        {
            filter: ['naturesaura:golden_leaves'],
            text: [`Obtained by using Brilliant Fiber on leaves. Allow to spread for best effect.`]
        },
        {
            filter: ['naturesaura:break_prevention'],
            text: [
                `When applied to a tool in an anvil, the tool will stop working when durability runs out instead of being destroyed.`
            ]
        },
        {
            filter: ['naturesaura:birth_spirit'],
            text: [`Obtained by manually breeding animals in high Aura areas.`]
        },
        {
            filter: ['naturesaura:projectile_generator'],
            text: [
                `May be automated with a Supplementaries Cannon.`,
                ` `,
                `Valid projectiles:`,
                ` `,
                `● Snowball:                7K`,
                `● Egg:                      10K`,
                `● Pollen Puff:            10K`,
                `● Slimeball:                10K`,
                `● Arrow:                30K`,
                `● Fire Charge:          35K`,
                `● Cannonball:             35K`,
                `● Bomb:                    35K`,
                `● Spectral Arrow:        40K`,
                `● Ender Pearl:            50K`,
                `● Wind Charge:          100K`,
                // `● Llama Spit:             100K`,
                `● Bottle o' Enchanting: 200K`,
                // `● Shulker Bullet:       300K`,
                `● Trident:                 3M`
            ]
        },
        {
            filter: ['industrialforegoing:ether_gas_bucket'],
            text: [
                `Enables auto-harvesting in the Hydroponic Bed.`,
                ` `,
                `Enables 5x Ore Multiplier in the Fermentation Station.`,
                ` `,
                `Enables gentle-harvesting in the Plant Gatherer.`
            ]
        },
        {
            filter: ['#malum:strange_materials'],
            text: [`May appear when using Bone Meal on Blighted land.`]
        },
        {
            filter: ['#industrialforegoing:sludge'],
            text: [`May be produced in a Sludge Refiner. Sludge is a by-product of the Plant Gatherer.`]
        },
        {
            filter: [
                'handcrafted:pillager_trophy',
                'handcrafted:vindicator_trophy',
                'handcrafted:evoker_trophy',
                'handcrafted:witch_trophy'
            ],
            text: [`Right-Click with an Antikythera Mechanism to bring it to life!`]
        },
        {
            filter: ['enigmatica:antikythera_mechanism'],
            text: [`Right-Click an Illager Trophy to bring it to life!`]
        },
        {
            filter: ['naturesaura:token_grief'],
            text: [
                `Drops from a Clockwork Witch.`,
                ` `,
                `Right-Click a Witch Trophy with an Antikythera Mechanism to bring it to life!`
            ]
        },
        {
            filter: ['naturesaura:token_euphoria'],
            text: [
                `Drops from a Clockwork Evoker.`,
                ` `,
                `Right-Click an Evoker Trophy with an Antikythera Mechanism to bring it to life!`
            ]
        },
        {
            filter: ['naturesaura:token_rage'],
            text: [
                `Drops from a Clockwork Vindicator.`,
                ` `,
                `Right-Click a Vindicator Trophy with an Antikythera Mechanism to bring it to life!`
            ]
        },
        {
            filter: ['naturesaura:token_terror'],
            text: [
                `Drops from a Clockwork Pillager.`,
                ` `,
                `Right-Click a Pillager Trophy with an Antikythera Mechanism to bring it to life!`
            ]
        },
        {
            filter: [
                Ingredient.of(['arts_and_crafts:lotus_pistils', 'minecraft:lily_pad', 'arts_and_crafts:bleachdew'])
            ],
            text: [
                `Lotus Pistils may be planted on Lily Pads to convert them into a Lotus Flower.`,
                ` `,
                `Use Bone Meal on a Lotus Flower to obtain Bleachdew.`
            ]
        },
        {
            filter: ['naturesaura:time_changer'],
            text: [
                `May be used to change to a specific time of day at the expense of Aura.`,
                ` `,
                `To set it up, place an Item Frame on the device and insert a Hand of Time.`,
                ` `,
                `The rotation of the Hand of Time denotes the time it will change to, with up being midnight and down being noon.`,
                ` `,
                `Drop a Clock nearby to trigger the effect.`
            ]
        },
        {
            filter: ['naturesaura:weather_changer'],
            text: [
                `May be used to change the weather at the expense of Aura.`,
                ` `,
                `Drop one of the following items nearby to trigger the effect:`,
                ` `,
                `● Sunflower - Clear Skies`,
                `● Dark Prismarine - Rain`,
                `● Fire Charge - Storm`
            ]
        },
        {
            filter: ['ae2:logic_processor', 'ae2:calculation_processor', 'ae2:engineering_processor'],
            text: [`Crafted using a Replicator.`, ` `, `Purchase a Blueprint from a Fluix Researcher.`]
        },
        {
            filter: [`enderio:wireless_charger_antenna`, `enderio:wireless_charger_antenna_advanced`],
            text: [`Place on top of an Enderio Wireless Charger to increase its range.`]
        },
        {
            filter: [
                'enigmatica:forest_essentia',
                'enigmatica:desert_essentia',
                'enigmatica:taiga_essentia',
                'enigmatica:tundra_essentia',
                'enigmatica:savanna_essentia',
                'enigmatica:plains_essentia',
                'enigmatica:swamp_essentia'
            ],
            text: [`Use on a Block of the Skies to convert the biome in a large area.`]
        },
        {
            filter: [
                'minecraft:brain_coral',
                'minecraft:tube_coral',
                'minecraft:horn_coral',
                'minecraft:bubble_coral',
                'minecraft:fire_coral',
                'minecraft:horn_coral_fan',
                'minecraft:tube_coral_fan',
                'minecraft:bubble_coral_fan',
                'minecraft:fire_coral_fan',
                'minecraft:brain_coral_fan'
            ],
            text: [
                `May be obtained by using Bone Meal on Gravel or Sand under water in an Ocean Biome.`,
                ` `,
                `The Cascading Islands count as an Ocean Biome.`
            ]
        },
        {
            filter: ['enigmatica:borrowed_flame', 'gateways:gate_pearl[gateways:gateway="gateways:catching_fire"]'],
            text: [
                `Create a Catching Fire Gate Pearl in the Particle Accelerator to summon a Gateway. `,
                ` `,
                `Defeat the Gateway to obtain "Borrowed" Flame.`
            ]
        }
    ];

    Object.keys(spiritEntities).forEach((type) => {
        let description = {
            filter: [`${type}_spirit`],
            text: ['Obtained with a Soul Shattering weapon from the following mobs:']
        };
        let previous_mod = '';

        spiritEntities[type].sort().forEach((entity) => {
            let current_mod = entity.split(':')[0];
            if (current_mod != previous_mod) {
                previous_mod = current_mod;

                if (current_mod == 'creeperoverhaul') {
                    current_mod = 'Creeper Overhaul';
                } else if (current_mod == 'sushigocrafting') {
                    current_mod = 'Sushi Go Crafting';
                } else {
                    current_mod = toTitleCase(current_mod.replace('_', ' '));
                }

                description.text.push(' ', `${current_mod}`);
            }
            description.text.push(Text.string(' ● ').append(Text.translate(`entity.${entity.replace(':', '.')}`)));
        });
        descriptions.push(description);
    });

    Object.keys(essenceEntities).forEach((type) => {
        let description = { filter: [type], text: ['Obtained with a Soul Shattering weapon from the following mobs:'] };
        let previous_mod = '';

        essenceEntities[type].sort().forEach((entity) => {
            let current_mod = entity.split(':')[0];
            if (current_mod != previous_mod) {
                previous_mod = current_mod;

                if (current_mod == 'creeperoverhaul') {
                    current_mod = 'Creeper Overhaul';
                } else if (current_mod == 'sushigocrafting') {
                    current_mod = 'Sushi Go Crafting';
                } else {
                    current_mod = toTitleCase(current_mod.replace('_', ' '));
                }

                description.text.push(' ', `${current_mod}`);
            }
            description.text.push(Text.string(' ● ').append(Text.translate(`entity.${entity.replace(':', '.')}`)));
        });
        descriptions.push(description);
    });

    const villagerTradesClient = { trades: [] };

    Object.keys(villagerTrades).forEach((profession) => {
        villagerTrades[profession].forEach((recipe) => {
            // "entity.minecraft.villager.farmer"
            // "entity.minecraft.villager.actuallyadditions.engineer"

            let lang_key = `entity.minecraft.villager.${profession.replace('minecraft:', '').replace(':', '.')}`;

            descriptions.push({
                filter: [Item.of(recipe.result.id)],
                text: [
                    Text.string(`Obtained by trading with `)
                        .append(Text.translate(lang_key))
                        .append(Text.string(' Villagers.')),
                    ` `,
                    Text.string(`Trade Level: `).append(Text.translate(`merchant.level.${recipe.level}`))
                ]
            });

            let payload = {
                left: [],
                right: [
                    {
                        type: 'item',
                        id: villagerWorkstations[profession],
                        nbt: `{"minecraft:lore":[\u0027[{"color":"green","text":"Trade with "},{"color":"green","translate":"merchant.level.${recipe.level}"},{"color":"green","text":" "},{"color":"green","translate":"${lang_key}"},{"color":"green","text":" Villagers!"}]\u0027]}`,
                        amount: 1
                    }
                ]
            };

            // Generate formatted JSON for EMI to display Villager Trades as World Interaction recipes
            let output_data = JSON.parse(Ingredient.of(recipe.result.id).toJson());

            payload.output = {
                type: 'item',
                id: output_data.items ? output_data.items : output_data.item,
                amount: recipe.result.count
            };

            if (recipe.id_suffix) {
                payload.id = `${profession}_tier_${recipe.level}_selling_${recipe.id_suffix}`;
            } else {
                payload.id = `${profession}_tier_${recipe.level}_selling_${output_data.items ? output_data.items : output_data.item}`;
            }

            if (output_data.components) {
                payload.output.nbt = JSON.stringify(output_data.components);
            }

            recipe.ingredients.forEach((input) => {
                payload.left.push({
                    type: 'item',
                    id: input.id,
                    count: input.count.min
                });
            });

            villagerTradesClient.trades.push(payload);
        });
    });

    JsonIO.write('kubejs/config/emi_villagers.json', villagerTradesClient);

    descriptions.forEach((description) => {
        event.add(description.filter, description.text);
    });
});
