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

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:';

/**
 * 
 * 
 * 
 * 
 *
 * 
 * 
 * 
 * 
 * Custom item and block recipes
 * 
 */
ServerEvents.recipes((event) => {

    //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",
    ]);


    /**
     * 
     * 
     * Kubejs Wanderlite ingot
     */
    event.recipes.create.crushing([
        "kubejs:wanderlite_dust",
        // Item.of("kubejs:wanderlite_dust").withChance(0.1)
    ], "vs_clockwork:wanderlite_matrix").processingTime(500);

    event.recipes.create.crushing([
        Item.of("kubejs:wanderlite_dust").withChance(0.5)
    ], "vs_clockwork:wanderlite_crystal").processingTime(300);



    //We want to encourage the use of mining wanderlite

    event.recipes.create.crushing([ //A wanderlite ingot can be crushed into wanderlite dust
        Item.of("kubejs:wanderlite_dust")
    ], "kubejs:wanderlite_ingot").processingTime(700);

    event.recipes.create.mixing(
        [
            'kubejs:wanderlite_ingot',
            'kubejs:wanderlite_ingot'
        ],
        [
            "kubejs:wanderlite_dust",
            //1 enderium ingot requires 0.5 diamonds, 1 ender pearls, 1.5 lead
            "thermal:enderium_ingot",
            "create:powdered_obsidian", "create:powdered_obsidian",
            "create:powdered_obsidian", "create:powdered_obsidian",
            "create:rose_quartz", "create:rose_quartz", 
            "create:rose_quartz", "create:rose_quartz",
        ]).superheated();

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

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


    /**
     * 
     * 
     * Create components
     */
    event.shaped(Item.of("kubejs:brass_piston", 2), [
        "  G",
        " I ",
        "P  "
    ], {
        //top
        G: "kubejs:brass_gear",
        // G: "create:brass_ingot",
        //end
        P: "create:brass_nugget",
        //rod
        // I: "createaddition:iron_rod",
        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
    event.shaped(Item.of("kubejs:phantom_dirt", 24), ["BSB", "BFB", "BSB"], {
        B: "minecraft:dirt",
        F: "minecraft:phantom_membrane",
        S: "minecraft:string",
    });

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

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

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

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

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

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

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

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


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

    event.recipes.create.sequenced_assembly([
        Item.of('kubejs:steering_mechanism').withChance(125.0), // this is the item that will appear in JEI as the result
        Item.of('create:brass_sheet').withChance(8.0), // the rest of these items will be part of the scrap
        Item.of('create:andesite_alloy').withChance(15.0),
        Item.of('create:cogwheel').withChance(5.0),
        Item.of('create:shaft').withChance(2.0),
        Item.of('create:crushed_gold_ore').withChance(2.0),
        Item.of('2x minecraft:gold_nugget').withChance(2.0),
        'minecraft:iron_ingot',

        //create:brass_sheet
    ], 'northstar:circuit', [ // the input #forge:plates/iron
        // the transitional item set by `transitionalItem('create:incomplete_large_cogwheel')` is the item used during the intermediate stages of the assembly
        // like a normal recipe function, is used as a sequence step in this array. Input and output have the transitional item
        event.recipes.createDeploying(incomplete, [incomplete, 'create:brass_sheet']),
        event.recipes.createPressing(incomplete, incomplete),
        event.recipes.createDeploying(incomplete, [incomplete, 'create:large_cogwheel']),
        event.recipes.createDeploying(incomplete, [incomplete, 'create:cogwheel']),
        // event.recipes.createDeploying(incomplete, [incomplete, 'minecraft:iron_nugget']),
        // event.recipes.createCutting(incomplete, incomplete), 
        event.recipes.createDeploying(incomplete, [incomplete, 'create:precision_mechanism'])
    ]).transitionalItem(incomplete).loops(5) // set the transitional item and the number of loops



});




/**
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * 
 * Misc Recipe Changes
 */
ServerEvents.recipes((event) => {
    //Replacement
    event.remove([
        { output: "quark:gunpowder_sack" },
        { 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" },
    ]);

    //Last recipe required 6
    //Create copper pipes yield 4 per 3 copper
    //We want to encourage the use of belts
    event.shaped(Item.of("quark:pipe", 1), [
        " C ",
        " B ",
        " C ",
    ],
        {
            C: "create:copper_sheet",
            B: "#forge:glass",
        }
    );

    //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("northstar:lunar_sapphire_crystal", 1), [
        " C ",
        "RCR",
        "ICI"
    ],
        {
            I: "minecraft:iron_ingot",
            R: "minecraft:redstone",
            C: "northstar:polished_lunar_sapphire",
        }
    );

    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',
    ]);

});