ServerEvents.recipes((event) => {
  // =========================================
  // Create New Age
  // =========================================

  // Generator Coil
  event.recipes.create
    .mechanical_crafting("create_new_age:generator_coil", [
      "A B A", 
      " CCC ", 
      "BCDCB", 
      " CCC ", 
      "A B A"
    ],
    {
      A: "alexscaves:scarlet_magnet",
      B: "alexscaves:azure_magnet",
      C: "alexscaves:scrap_metal_plate",
      D: "create:encased_chain_drive",
    })
    .id("create_new_age:shaped/generator_coil");

  // Carbon Brushes
  event
    .shaped("create_new_age:carbon_brushes", [
      "ABA", 
      "CDC", 
      "ABA"
    ], 
    {
      A: "alexscaves:scrap_metal_plate",
      B: "alexscaves:ferrouslime_ball",
      C: "minecraft:coal",
      D: "alexscaves:heart_of_iron",
    })
    .id("create_new_age:shaped/carbon_brushes");

  // Basic Energizer
  event
    .shapeless("create_new_age:energiser_t1", [
      "thermal:charge_bench",
      "minecraft:lightning_rod",
    ])
    .id("create_new_age:shapeless/energiser_t1");

  // Basic Motor
  event
    .shaped("create_new_age:basic_motor", [
      "AAA", 
      "BCD", 
      "AAA"
    ], 
    {
      A: "#forge:nuggets/steel",
      B: "create_new_age:electrical_connector",
      C: "create_new_age:magnetite_block",
      D: "create:shaft",
    })
    .id("create_new_age:shaped/basic_motor");

  // Strong (Advanced) Motor
  event
    .shaped("create_new_age:advanced_motor", [
      "AAA", 
      "BCD", 
      "AAA"
    ], 
    {
      A: "#forge:nuggets/steel",
      B: "create_new_age:electrical_connector",
      C: "create_new_age:layered_magnet",
      D: "create:shaft",
    })
    .id("create_new_age:shaped/advanced_motor");

  // Generator Coil
  event.recipes.create
    .mechanical_crafting("create_new_age:reinforced_motor", [
      "ABCCA", 
      "DBEFF", 
      "ABCCA"
    ],
    {
      A: "alexscaves:scrap_metal_plate",
      B: "create_new_age:fluxuated_magnetite",
      C: "#forge:plates/steel",
      D: "create_new_age:electrical_connector",
      E: "alexscaves:magnetic_activator",
      F: "create:shaft",
    })
    .id("create_new_age:reinforced_motor");

  // Electrical Connector

  event.remove({ output: `create_new_age:electrical_connector` });
  event
    .shaped("2x create_new_age:electrical_connector", [
      "A", 
      "B", 
      "C"
    ], 
    {
      A: "#forge:nuggets/copper",
      B: "#forge:plates/steel",
      C: "minecraft:terracotta",
    })
    .id("create_new_age:shaped/electrical_connector");

  // Neodymized Magnet
  event
    .shaped("2x create_new_age:neodymized_magnet", [
      "AAA", 
      "ABA", 
      "AAA"
    ], 
    {
      A: "alexscaves:raw_scarlet_neodymium",
      B: "create_new_age:magnetite_block",
    })
    .id("create_new_age:shaped/neodymized_magnet");

  // Overcharged Magnet
  event
    .shaped("2x create_new_age:overcharged_magnet", [
      "ABA", 
      "BCB", 
      "ABA"
    ], 
    {
      A: "create_new_age:overcharged_iron",
      B: "create_new_age:overcharged_gold",
      C: "create_new_age:neodymized_magnet",
    })
    .id("create_new_age:shaped/overcharged_magnet");

  // Sculked Magnet
  event
    .shaped("2x create_new_age:sculked_magnet", [
      "ABA", 
      "BCB", 
      "ABA"
    ], 
    {
      A: "deeperdarker:chiseled_sculk_stone",
      B: "create_new_age:overcharged_diamond",
      C: "create_new_age:overcharged_magnet",
    })
    .id("create_new_age:shaped/sculked_magnet");

  // Lunar Magnet
  event
    .shaped("2x create_new_age:lunar_magnet", [
      "ABA", 
      "BCB", 
      "ABA"
    ], 
    {
      A: "#forge:storage_blocks/sapphire",
      B: "#forge:ingots/desh",
      C: "create_new_age:sculked_magnet",
    })
    .id("create_new_age:shaped/lunar_magnet");

  // Martian Magnet
  event
    .shaped("2x create_new_age:martian_magnet", [
      "ABA", 
      "BCB", 
      "ABA"
    ], 
    {
      A: "#forge:storage_blocks/ruby",
      B: "#forge:ingots/ostrum",
      C: "create_new_age:lunar_magnet",
    })
    .id("create_new_age:shaped/martian_magnet");

  // =========================================
  // Create Enchantment Industry
  // =========================================

  // Ink
  event.replaceInput(
    { id: "create_enchantment_industry:mixing/ink" },
    "#create_enchantment_industry:ink_ingredient", 
    "undergarden:seeping_ink" 
  );

  // =========================================
  // Create Sifters
  // =========================================

  // Sifter
  event
    .shaped("createsifter:sifter", [
      "AAA", 
      "BCB", 
      "DED"
    ], 
    {
      A: "#forge:fences/wooden",
      B: "create:cogwheel",
      C: "minecraft:brush",
      D: "minecraft:polished_andesite",
      E: "create:andesite_casing",
    })
    .id("createsifter:sifter");

  // Custom Sea Pig Mesh
  event
    .shaped("createsifter:sea_pig_mesh", [
      "ABA", 
      "BCB", 
      "ABA"
    ], 
    {
      A: "seadwellers:depth_ingot",
      B: "undergarden:mushroom_veil",
      C: "alexscaves:sea_pig_bucket",
    })
    .id("createsifter:sea_pig_mesh");

  // Using Custom Sea Pig Mesh
  event.recipes
    .createsifterSifting(
      [
        Item.of("refinedstorage:silicon").withChance(0.25),
        Item.of("alexscaves:marine_snow").withChance(0.7),
        Item.of("alexscaves:pearl").withChance(0.1),
      ],
      ["#alexscaves:sea_pig_digests", "createsifter:sea_pig_mesh"]
    )
    .waterlogged();

  // Gravel Sifting
  event.recipes.createsifterSifting(
    [
      Item.of("twigs:pebble").withChance(0.5),
      Item.of("minecraft:flint").withChance(0.2),
      Item.of("#minecraft:decorated_pot_sherds").withChance(0.05),
    ],
    ["#forge:gravel", "createsifter:string_mesh"]
  );

  // Dirt Sifting
  event.recipes.createsifterSifting(
    [
      Item.of("naturalist:snail_shell").withChance(0.2),
      Item.of("spawn:snail_shell").withChance(0.2),
      Item.of("betterarcheology:artifact_shards").withChance(0.05),
    ],
    ["#minecraft:dirt", "createsifter:string_mesh"]
  );

  // Sand Sifting
  event.recipes
    .createsifterSifting(
      [
        Item.of("ecologics:seashell").withChance(0.25),
        Item.of("minecraft:nautilus_shell").withChance(0.05),
        Item.of("#twigs:seashells").withChance(0.05),
      ],
      ["#forge:sand", "createsifter:string_mesh"]
    )
    .waterlogged();

  // Guano Sifting
  event.recipes.createsifterSifting(
    [
      Item.of("waterloggedchests:cricket_bait").withChance(0.05),
      Item.of("waterloggedchests:glow_worm_bait").withChance(0.05),
      Item.of("waterloggedchests:worm_bait").withChance(0.05),
      Item.of("rats:garbage_pile").withChance(0.2),
      Item.of("rats:tiny_coin").withChance(0.1),
      Item.of("create_confectionery:full_black_chocolate_bar").withChance(0.05),
    ],
    ["alexscaves:guano_block", "createsifter:brass_mesh"]
  );

  // =========================================
  // Create Confectionery
  // =========================================

  // Ginger Dough
  event.remove({ id: "create_confectionery:gingerdough_recipe" });

  // White Chocolate Sheet (Custom Item)
  event.recipes.create.pressing(
    "create_confectionery:white_chocolate_sheet",
    "create_confectionery:bar_of_white_chocolate"
  );
  event.recipes.thermal.press(
    `create_confectionery:white_chocolate_sheet`,
    `create_confectionery:bar_of_white_chocolate`
  );

  // Caramel Sheet (Custom Item)
  event.recipes.create.pressing(
    "create_confectionery:caramel_sheet",
    "create_confectionery:bar_of_caramel"
  );
  event.recipes.thermal.press(
    `create_confectionery:caramel_sheet`,
    `create_confectionery:bar_of_caramel`
  );

  // Caramel Block Melt in Mixer
  event.recipes.create
    .mixing(Fluid.of("create_confectionery:caramel", 250), [
      "create_confectionery:bar_of_caramel",
    ])
    .heated()
    .id("create_confectionery:caramel_recipe");
  event.recipes.create
    .mixing(Fluid.of("create_confectionery:caramel", 250), [
      "2x minecraft:sugar",
      Fluid.of("minecraft:water", 250),
    ])
    .heated()
    .id("create_confectionery:caramel_recipe_2");
  event.recipes.create
    .mixing(Fluid.of("create_confectionery:caramel", 1000), [
      "create_confectionery:caramel_bricks",
    ])
    .heated()
    .id("create_confectionery:caramel_recipe_3");

  // "Early Game" Cocoa Butter Recipe
  // Moved to /kubejs/data/create_confectionery/cocoa_butter_fermenter.json due to sugar water tags
  


  event
    .shapeless("9x create_confectionery:white_chocolate_nugget", [
      "create_confectionery:bar_of_white_chocolate",
    ])
    .id("create_confectionery:white_chocolate_nugget");
  event.shapeless("create_confectionery:bar_of_white_chocolate", [
    "9x create_confectionery:white_chocolate_nugget",
  ]);

  // =========================================
  // Create Diesel Generators
  // =========================================

  // Diesel Engine
  event
    .shaped("createdieselgenerators:diesel_engine", [
      " A ", 
      "BCB", 
      "DED"
    ], 
    {
      A: "minecraft:flint_and_steel",
      B: "createdieselgenerators:engine_piston",
      C: "create_connected:brass_gearbox",
      D: "#forge:ingots/steel",
      E: "thermal:fluid_cell",
    })
    .id("createdieselgenerators:crafting/diesel_engine");

  // Modular (Large) Diesel Engine
  event
    .shaped("createdieselgenerators:large_diesel_engine", [
      " A ", 
      "BCB", 
      "DED"
    ],
    {
      A: "create:smart_fluid_pipe",
      B: "createdieselgenerators:engine_piston",
      C: "createdieselgenerators:diesel_engine",
      D: "#forge:ingots/steel",
      E: "modularrouters:modular_router",
    })
    .id("createdieselgenerators:crafting/large_diesel_engine");

  // Huge Diesel Engine
  event
    .shaped("createdieselgenerators:huge_diesel_engine", [
      " A ", 
      "BCB", 
      "DED"
    ],
    {
      A: "create:steam_engine",
      B: "createdieselgenerators:engine_piston",
      C: "createdieselgenerators:large_diesel_engine",
      D: "#forge:gears/steel",
      E: "create:blaze_burner",
    })
    .id("createdieselgenerators:crafting/huge_diesel_engine");

  // Pumpjack Head
  event
    .shaped("createdieselgenerators:pumpjack_head", [
      "A A", 
      "BCB", 
      "A A"
    ], 
    {
      A: "create:andesite_alloy_block",
      B: "alexscaves:heavyweight",
      C: "create:encased_chain_drive",
    })
    .id("createdieselgenerators:crafting/pumpjack_head");

  // Pumpjack Bearing
  event
    .shaped("createdieselgenerators:pumpjack_bearing", [
      "ABA", 
      "BCB", 
      "ABA"
    ], 
    {
      A: "create:andesite_alloy_block",
      B: "#forge:gears/steel",
      C: "create:mechanical_bearing",
    })
    .id("createdieselgenerators:crafting/pumpjack_bearing");

  // Distillation Controller
  event
    .shaped("createdieselgenerators:distillation_controller", [
      "ABA", 
      "CDC"
    ], 
    {
      A: "create:fluid_pipe",
      B: "embers:atmospheric_gauge",
      C: "#forge:tar",
      D: "#forge:plates/steel",
    })
    .id("createdieselgenerators:crafting/distillation_controller");

  // Pumpjack Crank
  event.recipes.create
    .mechanical_crafting("createdieselgenerators:pumpjack_crank",[
      "A A", 
      "B B", 
      "C C", 
      "DED", 
      "C C"
    ],
    {
      A: "#forge:plates/steel",
      B: "createdieselgenerators:engine_piston",
      C: "create:andesite_alloy_block",
      D: "#forge:gears/steel",
      E: "create:encased_chain_drive",
    })
    .id("createdieselgenerators:mechanical_crafting/pumpjack_crank");

  // Custom Lubricant Recipe
  event.custom({
    type: "createdieselgenerators:basin_fermenting",
    heatRequirement: "heated",
    ingredients: [
      {
        fluid: "createdieselgenerators:gasoline",
        amount: 500,
      },
    ],
    processingTime: 100,
    results: [
      {
        fluid: "createdieselgenerators:lubricant",
        amount: 1000,
      },
    ],
  });

  // =========================================
  // Create Utilities
  // =========================================

  // Void Steel Ingot
  event.recipes.thermal
    .smelter("createutilities:void_steel_ingot", [
      "#forge:ingots/shadow_steel",
      "#forge:ingots/enderium",
    ])
    .energy(800)
    .id("createutilities:void_steel_ingot");
  event.replaceInput(
    { id: "createutilities:mixing/void_steel_ingot" },
    "#forge:ingots/netherite",
    "#forge:ingots/shadow_steel"
  );
  event.replaceInput(
    { id: "createutilities:mixing/void_steel_ingot" },
    "#forge:ender_pearls",
    "#forge:ingots/enderium"
  );
  event.replaceInput(
    { output: "createutilities:void_casing" },
    "#forge:obsidian",
    "thermal:device_collector"
  );

  // Graviton Tube
  event
    .shaped("createutilities:graviton_tube", [
      "A", 
      "B", 
      "C"
    ], 
    {
      A: "createutilities:polished_amethyst",
      B: "createutilities:void_steel_sheet",
      C: "alexscaves:occult_gem",
    })
    .id("createutilities:shaped/graviton_tube");

  // =========================================
  // Create Dreams and Desires
  // =========================================

  // Create DD Steel only for decoration
  event.replaceInput(
    { mod: "create_dd" },
    "#forge:ingots/steel",
    "create_dd:steel_ingot"
  );
  event.replaceInput(
    { mod: "create_dd" },
    "#forge:nuggets/steel",
    "create_dd:steel_nugget"
  );
  event.replaceInput(
    { mod: "create_dd" },
    "#forge:storage_blocks/steel",
    "create_dd:steel_block"
  );
  event
    .custom({
      type: "create:sequenced_assembly",
      ingredient: {
        tag: "forge:plates/lapis_alloy",
      },
      transitionalItem: {
        item: "create_dd:incomplete_integrated_circuit",
      },
      sequence: [
        {
          type: "create:deploying",
          ingredients: [
            {
              item: "create_dd:incomplete_integrated_circuit",
            },
            {
              item: "minecraft:redstone",
            },
          ],
          results: [
            {
              item: "create_dd:incomplete_integrated_circuit",
            },
          ],
        },
        {
          type: "create:deploying",
          ingredients: [
            {
              item: "create_dd:incomplete_integrated_circuit",
            },
            {
              item: "minecraft:quartz",
            },
          ],
          results: [
            {
              item: "create_dd:incomplete_integrated_circuit",
            },
          ],
        },
        {
          type: "create:deploying",
          ingredients: [
            {
              item: "create_dd:incomplete_integrated_circuit",
            },
            {
              item: "create_confectionery:white_chocolate_nugget",
            },
          ],
          results: [
            {
              item: "create_dd:incomplete_integrated_circuit",
            },
          ],
        },
      ],
      results: [
        {
          item: "create_dd:integrated_circuit",
          chance: 160.0,
        },
        {
          item: "create_dd:lapis_sheet",
          chance: 5.0,
        },
        {
          item: "minecraft:redstone",
          chance: 2.5,
        },
        {
          item: "minecraft:quartz",
          chance: 2.5,
        },
        {
          item: "create_confectionery:white_chocolate_nugget",
          chance: 2.5,
        },
      ],
      loops: 4,
    })
    .id("create_dd:sequenced_assembly/integrated_circuit");

  // Sealed Mechanism also takes Thermal rubber
  event.replaceInput(
    { id: "create_dd:sequenced_assembly/sealed_mechanism" },
    "create_dd:rubber",
    ["create_dd:rubber", "thermal:cured_rubber"]
  );

  // Coal Pieces
  event
    .shapeless("32x create_dd:coal_piece", [
      "minecraft:coal",
      "hostilenetworks:nether_prediction",
    ])
    .id("create_dd:coal_piece");

  // =========================================
  // Create Jetpacks
  // =========================================

  event.replaceInput(
    { id: "create_sa:andesite_jetpack_recipe" },
    "create:belt_connector",
    "create_sa:copper_jetpack_chestplate"
  );
  event.replaceInput(
    { id: "create_sa:brass_jetpack_recipe" },
    "create:andesite_alloy",
    "create_sa:andesite_jetpack_chestplate"
  );
  event
    .custom({
      type: "create_jetpack:copy_nbt_mechanical_crafting",
      pattern: [
        " PSP ", 
        "PYXYP", 
        "PCECP", 
        " C C "
      ],
      key: {
        E: {
          item: "minecraft:elytra",
        },
        C: {
          item: "create:chute",
        },
        X: {
          item: "create:copper_backtank",
        },
        S: {
          item: "create_sa:brass_jetpack_chestplate",
        },
        Y: {
          item: "create:precision_mechanism",
        },
        P: {
          item: "create_confectionery:white_chocolate_sheet",
        },
      },
      result: {
        item: "create_jetpack:jetpack",
      },
    })
    .id("create_jetpack:jetpack");
  event
    .custom({
      type: "create_jetpack:copy_nbt_mechanical_crafting",
      pattern: [
        " PSP ", 
        "PYXYP", 
        "PCECP", 
        " C C "
      ],
      key: {
        E: {
          item: "minecraft:elytra",
        },
        C: {
          item: "create:chute",
        },
        X: {
          item: "create:netherite_backtank",
        },
        S: {
          item: "create:shaft",
        },
        Y: {
          item: "create:precision_mechanism",
        },
        P: {
          item: "create_confectionery:white_chocolate_sheet",
        },
      },
      result: {
        item: "create_jetpack:netherite_jetpack",
      },
    })
    .id("create_jetpack:netherite_jetpack");
});
