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

/**
 * 
 * 
 * 
 * New recipes
 * 
 */
ServerEvents.recipes((event) => {
    /**
     * 
     * 
     * 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);

    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",
            "create:powdered_obsidian", "create:powdered_obsidian",
            "create:powdered_obsidian", "create:powdered_obsidian",
            "create:powdered_obsidian", "create:powdered_obsidian",
            "create:rose_quartz", "create:rose_quartz",
            "create:rose_quartz", "create:rose_quartz",
        ]).heated();//Superheated or double the price

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

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


    /**
     * 
     * 
     * Create components
     */
    event.shaped(Item.of("kubejs:brass_piston", 4), [
        "  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
    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.createPressing(incomplete, incomplete),
            event.recipes.createDeploying(incomplete, [incomplete, 'create:large_cogwheel']),
            event.recipes.createDeploying(incomplete, [incomplete, 'create:cogwheel']),
        ]
    ).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" },
    ]);

    //We want to encourage the use of rails
    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", 1), [
        " C ",
        " B ",
        " C ",
    ],
        {
            C: "#forge:plates/copper",
            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("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',
    ]);

});
