#@ts-nocheck
#nowarn

import crafttweaker.api.recipe.Replacer;
import crafttweaker.api.data.IData;
import crafttweaker.api.data.MapData;
import crafttweaker.api.item.IItemStack;
import crafttweaker.api.item.IIngredient;
import crafttweaker.api.item.IIngredientTransformer;
import crafttweaker.api.data.INumberData;

var air = <item:minecraft:air>;
var menril_chunk = <item:integrateddynamics:crystalized_menril_chunk>;
var chorus_chunk = <item:integrateddynamics:crystalized_chorus_chunk>;

craftingTable.addShapeless(
    "paste", <item:kubejs:paste>*2, [<item:minecraft:clay_ball>, <item:minecraft:clay_ball>, <item:create:wheat_flour>, <item:emendatusenigmatica:wood_dust>]
);
craftingTable.addShapeless(
    "phytogro_4", <item:thermal:phytogro>*4, [<item:minecraft:bone_meal>, <item:create:wheat_flour>, <item:emendatusenigmatica:apatite_gem>, <item:emendatusenigmatica:potassium_nitrate_gem>]
);
craftingTable.addShapeless(
    "phytogro_8", <item:thermal:phytogro>*8, [<item:minecraft:bone_meal>, <item:create:wheat_flour>, <item:emendatusenigmatica:apatite_dust>, <item:emendatusenigmatica:potassium_nitrate_dust>]
);
craftingTable.addShapeless(
    "dielectric_block", <item:kubejs:dielectric_block>, [
        <item:powah:dielectric_paste>, <item:powah:dielectric_paste>, <item:powah:dielectric_paste>,
        <item:powah:dielectric_paste>, <item:powah:dielectric_paste>, <item:powah:dielectric_paste>,
        <item:powah:dielectric_paste>, <item:powah:dielectric_paste>, <item:powah:dielectric_paste>
]);
craftingTable.addShapeless(
    "dielectric_paste_from_block", <item:powah:dielectric_paste>*9, [<item:kubejs:dielectric_block>]
);
craftingTable.addShapeless(
    "aquamarine_from_block", <item:astralsorcery:aquamarine>*9, [<item:kubejs:aquamarine_block>]
);
craftingTable.addShapeless(
    "aquamarine_block", <item:kubejs:aquamarine_block>, [
        <item:astralsorcery:aquamarine>, <item:astralsorcery:aquamarine>, <item:astralsorcery:aquamarine>,
        <item:astralsorcery:aquamarine>, <item:astralsorcery:aquamarine>, <item:astralsorcery:aquamarine>,
        <item:astralsorcery:aquamarine>, <item:astralsorcery:aquamarine>, <item:astralsorcery:aquamarine>
]);
craftingTable.addShapeless(
    "flint_and_steel", <item:minecraft:flint_and_steel>, [<item:minecraft:flint>, <item:eidolon:pewter_inlay>]
);
craftingTable.addShapeless(
    "earth_charge", <item:thermal:earth_charge>*3, [<item:minecraft:gunpowder>, <item:thermal:basalz_powder>, <item:minecraft:coal>]
);
craftingTable.addShapeless(
    "depot", <item:create:depot>*2, [<item:kubejs:punch>, <item:create:andesite_casing>]
);
craftingTable.addShapeless(
    "sail_frame", <item:create:sail_frame>, [<item:create:white_sail>]
);
craftingTable.addShapeless(
    "andesite_from_block", <item:create:andesite_alloy>*9, [<item:kubejs:andesite_alloy_block>]
);
craftingTable.addShapeless(
    "cockroach_wing", <item:alexsmobs:cockroach_wing>, [<item:alexsmobs:cockroach_wing_fragment>,<item:alexsmobs:cockroach_wing_fragment>,<item:alexsmobs:cockroach_wing_fragment>,<item:alexsmobs:cockroach_wing_fragment>]
);
craftingTable.addShapeless(
    "quartz_crystal_from_pack", <item:emendatusenigmatica:quartz_crystal>*9, [<item:kubejs:quartz_crystal_pack>]
);
craftingTable.addShapeless(
    "quartz_crystal_pack", <item:kubejs:quartz_crystal_pack>, [
        <item:emendatusenigmatica:quartz_crystal>, <item:emendatusenigmatica:quartz_crystal>, <item:emendatusenigmatica:quartz_crystal>,
        <item:emendatusenigmatica:quartz_crystal>, <item:emendatusenigmatica:quartz_crystal>, <item:emendatusenigmatica:quartz_crystal>,
        <item:emendatusenigmatica:quartz_crystal>, <item:emendatusenigmatica:quartz_crystal>, <item:emendatusenigmatica:quartz_crystal>
]);

craftingTable.addShapeless(
    "exporter_world_item", <item:integratedtunnels:part_exporter_world_item>, [
        <item:integratedtunnels:part_interface_item>, <item:integrateddynamics:variable_transformer_input>, <item:integrateddynamics:logic_director>, <item:create:brass_funnel>
]);
craftingTable.addShapeless(
    "importer_world_item", <item:integratedtunnels:part_importer_world_item>, [
        <item:integratedtunnels:part_interface_item>, <item:integrateddynamics:variable_transformer_output>, <item:integrateddynamics:logic_director>, <item:create:brass_funnel>
]);
craftingTable.addShapeless(
    "exporter_world_fluid", <item:integratedtunnels:part_exporter_world_fluid>, [
        <item:integratedtunnels:part_interface_fluid>, <item:integrateddynamics:variable_transformer_input>, <item:integrateddynamics:logic_director>, <item:create:mechanical_pump>
]);
craftingTable.addShapeless(
    "importer_world_fluid", <item:integratedtunnels:part_importer_world_fluid>, [
        <item:integratedtunnels:part_interface_fluid>, <item:integrateddynamics:variable_transformer_output>, <item:integrateddynamics:logic_director>, <item:create:mechanical_pump>
]);
craftingTable.addShapeless(
    "exporter_world_block", <item:integratedtunnels:part_exporter_world_block>, [
        <item:integratedtunnels:part_exporter_world_item>, <item:create:deployer>
]);
craftingTable.addShapeless(
    "importer_world_block", <item:integratedtunnels:part_importer_world_block>, [
        <item:integratedtunnels:part_importer_world_item>, <item:create:mechanical_drill>
]);

craftingTable.addShapeless(
    "module_entity", <item:scannable:module_entity>, [
        <item:scannable:module_animal>, <item:scannable:module_monster>
]);
craftingTable.addShapeless(
    "module_animal", <item:scannable:module_animal>, [
        <item:scannable:module_blank>, <item:farmersdelight:horse_feed>
]);
craftingTable.addShapeless(
    "module_monster", <item:scannable:module_monster>, [
        <item:scannable:module_blank>, <item:minecraft:skeleton_skull>
]);
craftingTable.addShapeless(
    "module_ore_common", <item:scannable:module_ore_common>, [
        <item:scannable:module_blank>, <item:minecraft:lodestone>
]);
craftingTable.addShapeless(
    "module_ore_rare", <item:scannable:module_ore_rare>, [
        <item:scannable:module_blank>, <item:quark:diamond_heart>
]);
craftingTable.addShapeless(
    "module_fluid", <item:scannable:module_fluid>, [
        <item:scannable:module_blank>, <item:bloodmagic:reagentwater>
]);

craftingTable.addShapeless(
    "pedestal_upgrade_import", <item:pedestals:coin/import>, [
        <item:pedestals:coin/default>, <item:engineersdecor:factory_hopper>, <item:integrateddynamics:variable_transformer_input>
]);
craftingTable.addShapeless(
    "pedestal_upgrade_export", <item:pedestals:coin/export>, [
        <item:pedestals:coin/default>, <item:engineersdecor:factory_hopper>, <item:integrateddynamics:variable_transformer_output>
]);
craftingTable.addShapeless(
    "pedestal_upgrade_restock", <item:pedestals:coin/restock>, [
        <item:pedestals:coin/default>, <item:engineersdecor:factory_hopper>, <item:integrateddynamics:variable_transformer_input>, <tag:items:storagedrawers:drawers>
]);
craftingTable.addShapeless(
    "pedestal_upgrade_breaker", <item:pedestals:coin/breaker>, [
        <item:pedestals:coin/default>, <item:engineersdecor:small_block_breaker>
]);
craftingTable.addShapeless(
    "pedestal_upgrade_chopper", <item:pedestals:coin/chopper>, [
        <item:pedestals:coin/default>, <item:engineersdecor:small_tree_cutter>
]);
craftingTable.addShapeless(
    "pedestal_upgrade_crafter1", <item:pedestals:coin/crafter1>, [
        <item:pedestals:coin/default>, <item:create:mechanical_crafter>, <item:immersiveengineering:electron_tube>
]);
craftingTable.addShapeless(
    "pedestal_upgrade_itemtank", <item:pedestals:coin/itemtank>, [
        <item:pedestals:coin/default>, <tag:items:storagedrawers:drawers>, <item:immersiveengineering:electron_tube>
]);
craftingTable.addShapeless(
    "pedestal_upgrade_teleporter", <item:pedestals:coin/teleporter>, [
        <item:pedestals:coin/default>, <item:bloodmagic:reinforcedteleposerfocus>, <item:immersiveengineering:electron_tube>
]);
craftingTable.addShapeless(
    "pedestal_upgrade_fluidtank", <item:pedestals:coin/fluidtank>, [
        <item:pedestals:coin/default>, <item:mob_grinding_utils:tank>, <item:immersiveengineering:toolupgrade_drill_capacity>
]);
craftingTable.addShapeless(
    "pedestal_upgrade_attack", <item:pedestals:coin/attack>, [
        <item:pedestals:coin/default>, <item:immersiveengineering:toolupgrade_revolver_bayonet>, <item:bloodmagic:melee_anointment_2>
]);
craftingTable.addShapeless(
    "pedestal_upgrade_magnet", <item:pedestals:coin/magnet>, [
        <item:pedestals:coin/default>, <item:bloodmagic:reagentmagnetism>, <item:immersiveengineering:electron_tube>
]);

craftingTable.addShapeless(
    "blazing_powder", <item:kubejs:blazing_powder>*2, [
        <item:rftoolspower:blazing_rod>
]);

craftingTable.addShapeless(
    "camouflage_upgrade", <item:modularrouters:camouflage_upgrade>, [
        <item:modularrouters:blank_upgrade>, <item:xnet:facade>
]);
craftingTable.addShapeless(
    "security_upgrade", <item:modularrouters:security_upgrade>, [
        <item:modularrouters:blank_upgrade>, <item:supplementaries:key>, <item:thermal:lock>
]);
craftingTable.addShapeless(
    "sync_upgrade", <item:modularrouters:sync_upgrade>*4, [
        <item:modularrouters:blank_upgrade>, <item:minecraft:clock>, <item:create:redstone_link>
]);

craftingTable.addShapeless(
    "crafting_card", <item:appliedenergistics2:crafting_card>, [
        <item:minecraft:crafting_table>, <item:appliedenergistics2:basic_card>, <item:appliedenergistics2:level_emitter>
]);
craftingTable.addShapeless(
    "pattern_terminal", <item:appliedenergistics2:pattern_terminal>, [
        <item:appliedenergistics2:terminal>, <item:appliedenergistics2:blank_pattern>, <item:appliedenergistics2:engineering_processor>
]);
craftingTable.addShapeless(
    "fluid_terminal", <item:appliedenergistics2:fluid_terminal>, [
        <item:appliedenergistics2:terminal>, <item:botania:dark_quartz>, <item:appliedenergistics2:logic_processor>
]);
craftingTable.addShapeless(
    "identity_annihilation_plane", <item:appliedenergistics2:identity_annihilation_plane>, [
        <item:appliedenergistics2:annihilation_plane>, <item:appliedenergistics2:fluix_pearl>, <item:mininggadgets:upgrade_silk>
]);

craftingTable.addShapeless(
    "silk_touch_upgrade", <item:refinedstorage:silk_touch_upgrade>, [
        <item:appliedenergistics2:advanced_card>, <item:appliedenergistics2:fluix_pearl>, <item:mininggadgets:upgrade_silk>
]);
craftingTable.addShapeless(
    "fortune_3_upgrade", <item:refinedstorage:fortune_3_upgrade>, [
        <item:appliedenergistics2:advanced_card>, <item:appliedenergistics2:fluix_pearl>, <item:mininggadgets:upgrade_fortune_3>
]);

function consumeOneBrew(container as IItemStack, brew as string) as IIngredientTransformer<IIngredient> {
    if(container==<item:botania:brew_vial>){
        return container.transformCustom("consumeOneBrewVial", (stack) => {
            var left as int = 3;
            var nbt as IData[string] = stack.tag.asMap();
            for key in nbt {
                if(key=="swigsLeft"){
                    left = nbt["swigsLeft"].asNumber().getInt()-1;
                    if(left<=0){
                        return <item:botania:vial>;
                    }
                    break;
                }
            }
            return stack.withTag({brewKey: brew as string, swigsLeft: left as int});
        }).transformer;
    }else{
        return container.transformCustom("consumeOneBrewFlask", (stack) => {
            var left as int = 5;
            var nbt as IData[string] = stack.tag.asMap();
            for key in nbt {
                if(key=="swigsLeft"){
                    left = nbt["swigsLeft"].asNumber().getInt()-1;
                    if(left<=0){
                        return <item:botania:flask>;
                    }
                    break;
                }
            }
            return stack.withTag({brewKey: brew as string, swigsLeft: left as int});
        }).transformer;
    }
}

craftingTable.addShapeless(
    "fiery_blood_from_vial", <item:twilightforest:fiery_blood>, [
        <item:twilightforest:hydra_trophy>.reuse(), 
        <item:botania:brew_vial>.withTag({brewKey: "botania:bloodthirst" as string}).transform(consumeOneBrew(<item:botania:brew_vial>,"botania:bloodthirst")),
        <item:kubejs:blazing_powder>
]);
craftingTable.addShapeless(
    "fiery_blood_from_flask", <item:twilightforest:fiery_blood>, [
        <item:twilightforest:hydra_trophy>.reuse(), 
        <item:botania:brew_flask>.withTag({brewKey: "botania:bloodthirst" as string}).transform(consumeOneBrew(<item:botania:brew_flask>,"botania:bloodthirst"))
]);
craftingTable.addShapeless(
    "fiery_tears_from_vial", <item:twilightforest:fiery_tears>, [
        <item:twilightforest:ur_ghast_trophy>.reuse(), 
        <item:botania:brew_vial>.withTag({brewKey: "botania:bloodthirst" as string}).transform(consumeOneBrew(<item:botania:brew_vial>,"botania:bloodthirst")),
        <item:kubejs:blazing_powder>
]);
craftingTable.addShapeless(
    "fiery_tears_from_flask", <item:twilightforest:fiery_tears>, [
        <item:twilightforest:ur_ghast_trophy>.reuse(), 
        <item:botania:brew_flask>.withTag({brewKey: "botania:bloodthirst" as string}).transform(consumeOneBrew(<item:botania:brew_flask>,"botania:bloodthirst"))
]);

craftingTable.addShapeless(
    "charm_of_life_1_from_vial", <item:twilightforest:charm_of_life_1>, [
        <item:twilightforest:charm_of_keeping_1>,
        <item:bhc:red_heart>,
        <item:botania:brew_vial>.withTag({brewKey: "botania:regen" as string}).transform(consumeOneBrew(<item:botania:brew_vial>,"botania:regen"))
]);
craftingTable.addShapeless(
    "charm_of_life_1_from_flask", <item:twilightforest:charm_of_life_1>*2, [
        <item:twilightforest:charm_of_keeping_1>,
        <item:bhc:red_heart>, <item:bhc:red_heart>,
        <item:botania:brew_flask>.withTag({brewKey: "botania:regen" as string}).transform(consumeOneBrew(<item:botania:brew_flask>,"botania:regen"))
]);

var twilight_creatures = ["minotaur", "deer", "bighorn_sheep", "wild_boar", "raven", "hostile_wolf", "penguin", "hedge_spider", "swarm_spider", "wraith", "redcap", "skeleton_druid", "bunny", "tiny_bird", "mini_ghast", "tower_termite", "maze_slime"] as string[];

for creature in twilight_creatures {
    craftingTable.addShapeless(
        "transformation_powder_from_"+creature, <item:twilightforest:transformation_powder>*4, [
            <item:botania:mana_powder>, <item:botania:mana_powder>, <item:botania:mana_powder>, <item:botania:mana_powder>, 
            <item:rftoolsutility:syringe>.withTag({mobName: "twilightforest:"+creature as string, mobId: "twilightforest:"+creature as string, level: 10 as int})
    ]);
}

craftingTable.addShapeless(
    "cicada", <item:twilightforest:cicada>, [
        <item:alexsmobs:maggot>, <item:twilightforest:transformation_powder>, <item:botania:cacophonium>.reuse()
]);

craftingTable.addShapeless(
    "gm_chicken_feed", <item:mob_grinding_utils:gm_chicken_feed>, [
        <item:supplementaries:fodder>, <item:mob_grinding_utils:mob_swab_used>, <item:naturesaura:birth_spirit>, <item:mob_grinding_utils:fluid_xp_bucket>
    ], (out as IItemStack, ins as IItemStack[]) => {
        return ins[1].hasTag? out.withTag(ins[1].tag) : out;
    }
);

craftingTable.addShapeless(
    "tiab_addtime", <item:tiab:timeinabottle>, [
        <item:tiab:timeinabottle>, <item:kubejs:temporal_shard>
    ], (out as IItemStack, ins as IItemStack[]) => {
        var nbt as IData[string] = ins[0].tag.asMap();
        var nbt2 as IData[string] = nbt["timeData"].asMap();
        var time as int = nbt2["storedTime"].asNumber().getInt()+1200;
        return ins[0].withTag({timeData: {storedTime: time }});
    }
);