// priority: 12
// Visit the wiki for more info - https://kubejs.com/
// This script can be reloaded with the reload command.

/**
 * Including bossfight drops in items
 * The following bossfight drops are incorportated into items
 * 
 * thermal drill
 * - Witherite ingot
 * 
 * advanced combusiton chamber
 * - Monstrous ingot
 * 
 * warp stone
 * - Ancient ingot
 * - void ingot
 * - leviathan ingot
 * 
 * 
 * - End Guardian ingot
 * - Ender Dragon ingot
 */

ServerEvents.loaded((event) => {
    if (Platform.mods.worldedit) {
        console.log("WorldEdit is installed!");
    } else {
        console.log("WorldEdit is not installed.");
    }
    global.isWorldEditInstalled = Platform.mods.worldedit ? true : false;
});

const flintBlockID = 'supplementaries:flint_block';
const createDG = 'createdieselgenerators:';
const eureka = 'vs_eureka:';
const clockwork = 'vs_clockwork:'
const mowziesmobs = 'mowziesmobs:';

/**
 * 
 * 
 * 
 * New recipes
 * 
 */
ServerEvents.recipes((event) => {
    /**
     * 
     * 
     * 
     * Kubejs Wanderlite ingot
     */
    event.recipes.create.crushing(["kubejs:wanderlite_dust",], "kubejs:wanderlite_jewel").processingTime(1500);
    event.recipes.create.crushing(["kubejs:wanderlite_dust",], "vs_clockwork:wanderlite_matrix").processingTime(500);
    event.recipes.create.crushing([Item.of("kubejs:wanderlite_dust").withChance(0.5)], "vs_clockwork:wanderlite_crystal").processingTime(300);
    event.recipes.create.crushing([Item.of("kubejs:wanderlite_dust")], "kubejs:wanderlite_ingot").processingTime(700);

    event.recipes.create.compacting([Item.of('kubejs:wanderlite_jewel', 4)],
        [
            "kubejs:wanderlite_dust",
            // Item.of("create:powdered_obsidian", 4),
            Item.of("create:rose_quartz", 4),
            Fluid.of("create_enchantment_industry:experience", 500),
        ]).heated();



    event.recipes.create.mixing(['kubejs:wanderlite_ingot',],
        [
            "kubejs:wanderlite_dust",
            "create:rose_quartz",
        ]).heated();

    //Defeating ferros wroganaut has multiple advantages
    //You can melt the helmet and axe into netherite
    var netheritableItems = ['mowziesmobs:wrought_helmet', 'mowziesmobs:wrought_axe'];
    var netheriteYield = 4;
    for (var i = 0; i < netheritableItems.length; i++) {
        var input = [netheritableItems[i], "minecraft:iron_ingot"];
        var output = [
            Item.of('minecraft:netherite_ingot', netheriteYield),
            Item.of('thermal:netherite_nugget', 6).withChance(0.5),
            Item.of('thermal:silver_nugget', 8).withChance(0.9),
        ];
        var scrapOutput = [
            Item.of('minecraft:netherite_scrap', netheriteYield * 5),
            Item.of('thermal:netherite_nugget', 6).withChance(0.5),
        ];
        event.recipes.create.mixing(output, input).superheated();
        event.recipes.thermal.smelter(output, input);
        event.recipes.thermal.insolator(scrapOutput, input).water(400)
    }

    /**
     * 
     * 
     * 
     * Compressed blocks
     */
    event.shaped(Item.of("kubejs:compressed_cobblestone", 1), [
        "PPP",
        "PPP",
        "PPP",
    ], {
        P: "minecraft:cobblestone",
    });

    event.shapeless(Item.of("minecraft:cobblestone", 9), [
        "kubejs:compressed_cobblestone",
    ]);

    /**
     * 
     * 
     * Create components
     */
    event.shaped(Item.of("kubejs:brass_piston", 4), [
        "  G",
        " I ",
        "P  "
    ], {
        G: "create:brass_ingot",
        P: "create:brass_nugget",
        I: "createaddition:brass_rod",
    });

    event.shaped(Item.of("kubejs:brass_gear", 1), [
        " P ",
        "PIP",
        " P "
    ], {
        P: "create:brass_ingot",
        I: "minecraft:iron_nugget",
    });

    event.shaped(Item.of("kubejs:precision_component", 1),
        ["PPP", "PPP", "PPP"], {
        P: "create:precision_mechanism",
    });

    event.shaped(Item.of("kubejs:precision_machine", 1),
        ["PPP", "PPP", "PPP"], {
        P: "kubejs:precision_component",
    });


    event.shaped(Item.of("create:precision_mechanism", 9), ["kubejs:precision_component"]);
    event.shaped(Item.of("kubejs:precision_component", 9), ["kubejs:precision_machine"]);


    //Dirt
    var phantom_quantity = 32;
    event.shaped(Item.of("kubejs:phantom_dirt", phantom_quantity), ["BSB", "BFB", "BSB"], {
        B: "minecraft:dirt",
        F: "minecraft:phantom_membrane",
        S: "minecraft:string",
    });

    //Stone
    event.shaped(Item.of("kubejs:phantom_stone", phantom_quantity), ["BSB", "BFB", "BSB"], {
        B: "minecraft:stone",
        F: "minecraft:phantom_membrane",
        S: "minecraft:string",
    });

    //netherrack
    event.shaped(Item.of("kubejs:phantom_netherrack", phantom_quantity), ["BSB", "BFB", "BSB"], {
        B: "minecraft:netherrack",
        F: "minecraft:phantom_membrane",
        S: "minecraft:string",
    });

    //snow
    event.shaped(Item.of("kubejs:phantom_snow", phantom_quantity), ["BSB", "BFB", "BSB"], {
        B: "minecraft:snow_block",
        F: "minecraft:phantom_membrane",
        S: "minecraft:string",
    });

    //sandstone
    event.shaped(Item.of("kubejs:phantom_sandstone", phantom_quantity), ["BSB", "BFB", "BSB"], {
        B: "minecraft:sandstone",
        F: "minecraft:phantom_membrane",
        S: "minecraft:string",
    });

    //red sandstone
    event.shaped(Item.of("kubejs:phantom_red_sandstone", phantom_quantity), ["BSB", "BFB", "BSB"], {
        B: "minecraft:red_sandstone",
        F: "minecraft:phantom_membrane",
        S: "minecraft:string",
    });

    //cobblestone
    event.shaped(Item.of("kubejs:phantom_cobblestone", phantom_quantity), ["BSB", "BFB", "BSB"], {
        B: "minecraft:cobblestone",
        F: "minecraft:phantom_membrane",
        S: "minecraft:string",
    });

    //stone bricks
    event.shaped(Item.of("kubejs:phantom_stone_bricks", phantom_quantity), ["BSB", "BFB", "BSB"], {
        B: "minecraft:stone_bricks",
        F: "minecraft:phantom_membrane",
        S: "minecraft:string",
    });

    //end stone
    event.shaped(Item.of("kubejs:phantom_end_stone", phantom_quantity), ["BSB", "BFB", "BSB"], {
        B: "minecraft:end_stone",
        F: "minecraft:phantom_membrane",
        S: "minecraft:string",
    });


    //Steering mechanism
    let incomplete = 'kubejs:incomplete_steering_mechanism';

    event.recipes.create.sequenced_assembly([//The output
        Item.of('kubejs:steering_mechanism'),
    ], '#forge:plates/gold', // the input:   create:brass_sheet
        [
            event.recipes.createDeploying(incomplete, [incomplete, 'create:precision_mechanism']),
            event.recipes.createDeploying(incomplete, [incomplete, 'create:electron_tube']),
            event.recipes.createDeploying(incomplete, [incomplete, 'create:large_cogwheel']),
            event.recipes.createDeploying(incomplete, [incomplete, 'create:cogwheel']),
            event.recipes.createPressing(incomplete, incomplete),
        ]
    ).transitionalItem(incomplete).loops(3) // set the transitional item and the number of loops



});




/**
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * Important Recipe Changes
 */
ServerEvents.recipes((event) => {
    //Replacement
    event.remove([
        { output: "quark:gunpowder_sack" },
        { output: "createdeco:industrial_iron_ingot" },
        { output: "minecraft:lodestone" },
        { output: "quark:pipe" },
        { output: "createaddition:electrum_amulet" },
        { output: "cyclic:shield_obsidian" },
        { output: "cyclic:shield_bone" },
        { output: "cyclic:snowflake" },
        { output: "cyclic:gem_prismarine" },
        { output: "minecraft:iron_block" },
        { output: "minecraft:iron_trapdoor" },
        { output: "createbigcannons:cast_iron_block" },
        { output: "createdeco:industrial_iron_trapdoor" },
        { output: "create:industrial_iron_block" },
        { output: "minecraft:rail" },
        { output: "minecraft:powered_rail" },
        // { output: "bigger_ender_chests:emerald_ender_chest" },
    ]);


    //Sand bar, sand tile
    event.recipes.create.compacting('kubejs:compressed_sand_bar', [
        Item.of('#minecraft:sand', 64),
        Fluid.of("minecraft:water", 500),
    ]);
    event.recipes.create.pressing(Item.of('kubejs:sand_tile', 1), ['kubejs:compressed_sand_bar']);

    //Pyrotide shard (only 3 ingredients allowed)
    var shardInput = ['cyclic:tanzanite_shard', 'mowziesmobs:glowing_jelly', 'minecraft:blaze_powder'
    ];
    event.recipes.create.compacting(Item.of('kubejs:pyrotide_shard', 3), shardInput).heated();
    event.recipes.thermal.smelter(Item.of('kubejs:pyrotide_shard', 3), shardInput);

    //Hydronite shard
    shardInput = ["northstar:lunar_sapphire_shard", "kubejs:abyssal_ingot", "kubejs:pyrotide_shard"];
    event.recipes.create.compacting(Item.of('kubejs:hydronite_shard', 6), shardInput).heated();
    event.recipes.thermal.smelter(Item.of('kubejs:hydronite_shard', 6), shardInput);

    // event.shaped(Item.of("bigger_ender_chests:emerald_ender_chest", 1), [
    //     "IEI",
    //     "EDE",
    //     "IEI"
    // ], {
    //     D: "bigger_ender_chests:diamond_ender_chest",
    //     E: "minecraft:emerald",
    //     I: "kubejs:abyssal_ingot",
    // });


    event.shaped(Item.of("createaddition:electrum_amulet", 1), [
        " s ",
        "s s",
        "Is "
    ], {
        I: "kubejs:abyssal_ingot",
        s: "createaddition:electrum_wire"
    });

    event.shaped(Item.of("minecraft:rail", 32), [
        "I I",
        "IsI",
        "I I"
    ], {
        I: "minecraft:iron_ingot",
        s: "minecraft:stick"
    });

    event.shaped(Item.of("minecraft:powered_rail", 16), [
        "I I",
        "IsI",
        "IRI"
    ], {
        I: "minecraft:gold_ingot",
        s: "minecraft:stick",
        R: "minecraft:redstone"
    });

    //Fix Create adding automatic recipes to the iron block and iron trapdoor (We need to make cast iron)
    event.shapeless('minecraft:iron_block', [
        'minecraft:iron_ingot', 'minecraft:iron_ingot', 'minecraft:iron_ingot',
        'minecraft:iron_ingot', 'minecraft:iron_ingot', 'minecraft:iron_ingot',
        'minecraft:iron_ingot', 'minecraft:iron_ingot', 'minecraft:iron_ingot'
    ]).id('kubejs:iron_block2_manual_only');

    event.shapeless('createbigcannons:cast_iron_block', [
        'createbigcannons:cast_iron_ingot', 'createbigcannons:cast_iron_ingot', 'createbigcannons:cast_iron_ingot',
        'createbigcannons:cast_iron_ingot', 'createbigcannons:cast_iron_ingot', 'createbigcannons:cast_iron_ingot',
        'createbigcannons:cast_iron_ingot', 'createbigcannons:cast_iron_ingot', 'createbigcannons:cast_iron_ingot'
    ]).id('kubejs:cast_iron_block_manual_only');

    event.shapeless('create:industrial_iron_block', [
        'createdeco:industrial_iron_ingot', 'createdeco:industrial_iron_ingot', 'createdeco:industrial_iron_ingot',
        'createdeco:industrial_iron_ingot', 'createdeco:industrial_iron_ingot', 'createdeco:industrial_iron_ingot',
        'createdeco:industrial_iron_ingot', 'createdeco:industrial_iron_ingot', 'createdeco:industrial_iron_ingot'
    ]).id('kubejs:industrial_iron_block_manual_only');

    event.shaped(Item.of("createdeco:industrial_iron_trapdoor", 1), [
        "ii",
        "ii",
    ], {
        i: "createbigcannons:cast_iron_ingot",
    }).id('kubejs:industrial_iron_trapdoor_manual_only');


    event.shaped(Item.of("minecraft:iron_trapdoor", 1), [
        "ii",
        "ii",
    ], {
        i: "minecraft:iron_ingot",
    }).id('kubejs:iron_trapdoor2_manual_only');

    //Industrial iron
    event.recipes.create.pressing('createdeco:industrial_iron_ingot', 'createbigcannons:cast_iron_ingot');

    //Remove the slime ball nametag recipes
    event.remove([
        { output: "minecraft:slime_ball" },
    ]);

    event.shapeless(Item.of("minecraft:slime_ball", 1), [
        "create:dough",
        "minecraft:lime_dye",
    ]);
    event.shapeless(Item.of("minecraft:slime_ball", 9), [
        "minecraft:slime_block",
    ]);

    //Belts are better than pipes
    event.shaped(Item.of("quark:pipe", 2), [
        " C ",
        " B ",
        " C ",
    ],
        {
            C: "#forge:plates/copper",
            B: "#forge:glass",
        }
    );

    //Belts are better than pipes
    event.shaped(Item.of("quark:pipe", 1), [
        " C ",
        " B ",
        " C ",
    ],
        {
            C: "#forge:plates/copper",
            B: "#forge:glass_panes",
        }
    );

    //Add nametag recipe
    event.shaped(Item.of("minecraft:name_tag", 1), [
        "BCC",
        "BSC",
        "ABB"
    ],
        {
            A: "minecraft:writable_book",
            B: "minecraft:paper",
            C: "minecraft:string",
            S: "minecraft:slime_ball",
        }
    );


    event.shaped(Item.of("minecraft:lodestone", 1), [
        "CCC",
        "CBC",
        "CCC"
    ],
        {
            C: "minecraft:chiseled_stone_bricks",
            B: "minecraft:iron_ingot",
            //B: 'kubejs:black_gold_ingot',
        }
    );

    event.shaped(Item.of('cyclic:gem_prismarine', 1), [
        ' O ',
        'OSO',
        ' O ',
    ], {
        S: 'kubejs:abyssal_pearl',
        O: 'minecraft:prismarine_crystals',
    });

    event.shaped(Item.of('cyclic:shield_bone', 1), [
        'OOO',
        'OSO',
        ' O ',
    ], {
        S: 'cyclic:shield_leather',
        O: 'minecraft:bone_block',
    });

    // event.recipes.create.mechanical_crafting('cyclic:shield_obsidian', [
    event.shaped(Item.of('cyclic:shield_obsidian', 1), [
        'OOO',
        'OSO',
        'OOO',
    ], {
        S: 'cyclic:shield_bone',
        O: 'create:sturdy_sheet',
    });

    //The snowflake is obtained from a boss
    event.shaped(Item.of('cyclic:snowflake', 2), [
        ' P ',
        'POP',
        ' P ',
    ], {
        P: 'minecraft:packed_ice',
        O: 'mowziesmobs:ice_crystal',
    });

    event.shaped(Item.of('cyclic:snowflake', 2), [
        'pPp',
        'POP',
        'pPp',
    ], {
        p: 'minecraft:packed_ice',
        P: 'northstar:polished_amethyst',
        O: 'cyclic:blue_snowflake',
    });

    //Mind as well
    event.shapeless(Item.of('minecraft:glowstone_dust', 12 * 6), [
        'mowziesmobs:glowing_jelly',
    ]);


    event.shaped(Item.of('kubejs:super_xp_housing', 1), [
        'BBB',
        'BBB',
        'BBB',
    ], {
        B: 'create_enchantment_industry:hyper_experience_bottle',
    });

    event.shapeless(Item.of('create_enchantment_industry:hyper_experience_bottle', 9), [
        'kubejs:super_xp_housing',
    ]);

});
