// This File has been authored by AllTheMods Staff, or a Community contributor for use in AllTheMods.
// As all AllTheMods packs are licensed under All Rights Reserved, this file is not allowed to be used in any public packs not released by the AllTheMods Team, without explicit permission.

if (Platform.isLoaded("mekanism")) {
  ServerEvents.recipes((allthemods) => {
    const id = {
      alltheores: [
        "aluminum",
        "nickel",
        "platinum",
        "silver",
        "iridium",
        "zinc",
        "tin",
        "lead",
        "uranium",
        "osmium",
        "copper",
        "iron",
        "gold"
      ],
      allthemodium: ["allthemodium", "vibranium", "unobtainium"]
    }

    Object.entries(id).forEach(([mod, materials]) => {
      materials.forEach((material) => {
        if (mod === "allthemodium") {
          washing(
            `allthemodium:dirty_${material}`,
            `allthemodium:clean_${material}`,
            `allthemodium:processing/${material}/slurry/clean`
          )
          injecting(
            `c:crystals/${material}`,
            `allthemodium:${material}_shard`,
            `allthemodium:processing/${material}/shard/from_crystal`
          )
          crushing(
            `c:clumps/${material}`,
            `allthemodium:dirty_${material}_dust`,
            `allthemodium:processing/${material}/dirty_dust/from_clump`
          )
          enriching(
            `c:dirty_dusts/${material}`,
            `allthemodium:${material}_dust`,
            `allthemodium:processing/${material}/dust/from_dirty_dust`
          )
        }
        if (mod === "alltheores") {
          allthemods.remove({ id: `mekanism:processing/${material}/slurry/dirty/from_raw_block` })
          allthemods.remove({ id: `mekanism:processing/${material}/slurry/dirty/from_raw_ore` })
          allthemods.remove({ id: `mekanism:processing/${material}/slurry/dirty/from_ore` })
          allthemods.remove({ id: `mekanism:processing/${material}/crystal/from_slurry` })
          allthemods.remove({ id: `mekanism:processing/${material}/shard/from_crystal` })
          allthemods.remove({ id: `mekanism:processing/${material}/dirty_dust/from_clump` })
          allthemods.remove({ id: `mekanism:processing/${material}/dust/from_dirty_dust` })

          washing(
            `alltheores:dirty_${material}`,
            `alltheores:clean_${material}`,
            `alltheores:processing/${material}/slurry/from_dirty`
          )
          injecting(
            `c:crystals/${material}`,
            `alltheores:${material}_shard`,
            `alltheores:processing/${material}/shard/from_crystal`
          )
          crushing(
            `c:clumps/${material}`,
            `alltheores:dirty_${material}_dust`,
            `alltheores:processing/${material}/dirty_dust/from_clump`
          )
          enriching(
            `c:dirty_dusts/${material}`,
            `alltheores:${material}_dust`,
            `alltheores:processing/${material}/dust/from_dirty_dust`
          )
        }
      })
    })

    function washing(input, output, id) {
      allthemods
        .custom({
          type: "mekanism:washing",
          fluid_input: {
            amount: 25,
            tag: "minecraft:water"
          },
          chemical_input: {
            amount: 5,
            chemical: input
          },
          output: {
            amount: 3,
            id: output
          }
        })
        .id(id)
    }

    function injecting(input, output, id) {
      allthemods
        .custom({
          type: "mekanism:injecting",
          item_input: {
            count: 1,
            tag: input
          },
          chemical_input: {
            amount: 1,
            chemical: "mekanism:hydrogen_chloride"
          },
          output: {
            count: 2,
            id: output
          },
          per_tick_usage: true
        })
        .id(id)
    }

    function crushing(input, output, id) {
      allthemods
        .custom({
          type: "mekanism:crushing",
          input: {
            count: 1,
            tag: input
          },
          output: {
            count: 2,
            id: output
          }
        })
        .id(id)
    }

    function enriching(input, output, id) {
      allthemods
        .custom({
          type: "mekanism:enriching",
          input: {
            count: 4,
            tag: input
          },
          output: {
            count: 3,
            id: output
          }
        })
        .id(id)
    }
    allthemods.remove({ id: `xycraft_machines:compat/mek/processing/aluminum/slurry/dirty/from_raw_block` })
    allthemods.remove({ id: `xycraft_machines:compat/mek/processing/aluminum/slurry/dirty/from_raw_ore` })
    allthemods.remove({ id: `xycraft_machines:compat/mek/processing/aluminum/slurry/dirty/from_ore` })
    allthemods.remove({ id: `xycraft_machines:compat/mek/processing/aluminum/slurry/clean` })
    allthemods.remove({ id: `xycraft_machines:compat/mek/processing/aluminum/crystal/from_slurry` })
    allthemods.remove({ id: `xycraft_machines:compat/mek/processing/aluminum/clump/from_raw_block` })
    allthemods.remove({ id: `xycraft_machines:compat/mek/processing/aluminum/clump/from_raw_ore` })
    allthemods.remove({ id: `xycraft_machines:compat/mek/processing/aluminum/clump/from_ore` })
    allthemods.remove({ id: `xycraft_machines:compat/mek/processing/aluminum/clump/from_shard` })
    allthemods.remove({ id: `xycraft_machines:compat/mek/processing/aluminum/dirty_dust/from_clump` })
    allthemods.remove({ id: `xycraft_machines:compat/mek/processing/aluminum/shard/from_raw_block` })
    allthemods.remove({ id: `xycraft_machines:compat/mek/processing/aluminum/shard/from_raw_ore` })
    allthemods.remove({ id: `xycraft_machines:compat/mek/processing/aluminum/shard/from_ore` })
    allthemods.remove({ id: `xycraft_machines:compat/mek/processing/aluminum/shard/from_crystal` })
  })
}

// This File has been authored by AllTheMods Staff, or a Community contributor for use in AllTheMods.
// As all AllTheMods packs are licensed under All Rights Reserved, this file is not allowed to be used in any public packs not released by the AllTheMods Team, without explicit permission.
