// Priority: 2
/**
  
  █▀▄▀█ █▀█ █▄░█ █░█ █▀▄▀█ █▀▀ █▄░█ ▀█▀ ▄▀█ █░░   █▀▀ ▀▄▀ █▀█ █▀▀ █▀█ █ █▀▀ █▄░█ █▀▀ █▀▀
  █░▀░█ █▄█ █░▀█ █▄█ █░▀░█ ██▄ █░▀█ ░█░ █▀█ █▄▄   ██▄ █░█ █▀▀ ██▄ █▀▄ █ ██▄ █░▀█ █▄▄ ██▄

  ☻/  * @file Tag additions and fixes
  /▌  * @copyright KnightDexx's Modded Minecraft World | ModernGamingWorld | GeekTechMedia
  /▌  * Modified by @Cyn-SolveroftheAbsoluteGremlins on Discord
  /\
*/
ServerEvents.tags('item', e => {

  // ─────────────────────────────────────────────────────────
  // Cheese tags
  // ─────────────────────────────────────────────────────────
  e.add('c:cheese', '#c:cheeses')
  const cheeseItems = []
  if (Platform.isLoaded('tconstruct')) cheeseItems.push('tconstruct:cheese_ingot')
  if (Platform.isLoaded('ad_astra')) cheeseItems.push('ad_astra:cheese')
  if (Platform.isLoaded('croptopia')) cheeseItems.push('croptopia:cheese')
  if (Platform.isLoaded('thermal')) cheeseItems.push('thermal:cheese_wedge')
  if (Platform.isLoaded('refurbished_furniture')) cheeseItems.push('refurbished_furniture:cheese')
  if (Platform.isLoaded('brewinandchewin')) cheeseItems.push('brewinandchewin:flaxen_cheese_wedge', 'brewinandchewin:scarlet_cheese_wedge')
  if (cheeseItems.length > 0) e.add('c:cheese/sweet', cheeseItems)

  // ─────────────────────────────────────────────────────────
  // Vanilla / always-present
  // ─────────────────────────────────────────────────────────
  e.add('c:sugar', 'minecraft:sugar')
  e.add('minecraft:prismarine_shard', 'minecraft:prismarine_shard')
  e.add('minecraft:crimson_logs', '#minecraft:crimson_stems')
  e.add('minecraft:warped_logs', '#minecraft:warped_stems')
  e.add('c:planks/mangrove', 'minecraft:mangrove_planks')

  // ─────────────────────────────────────────────────────────
  // Mod-specific single additions
  // ─────────────────────────────────────────────────────────
  if (Platform.isLoaded('extendedcrafting'))
    e.add('c:ingots/crystaltine', 'extendedcrafting:crystaltine_ingot')

  if (Platform.isLoaded('thermal')) {
    e.add('c:storage_blocks/raw_cinnabar', '#c:storage_blocks/cinnabar')
    e.add('thermal:rubberwood_logs', '#c:rubberwood_logs')
    e.add('c:hot_spice', 'thermal:tomato_sauce')
  }

  if (Platform.isLoaded('immersiveengineering'))
    e.add('c:wooden_grip', 'immersiveengineering:wooden_grip')

  if (Platform.isLoaded('letsdo_addon_compat'))
    e.add('letsdo_addon_compat:tools/knives', '#c:tools/knives')

  if (Platform.isLoaded('inventorypets') || Platform.isLoaded('opolisutilities')) {
    var enderNuggets = []
    if (Platform.isLoaded('inventorypets')) enderNuggets.push('inventorypets:nugget_ender')
    if (Platform.isLoaded('opolisutilities')) enderNuggets.push('opolisutilities:ender_pearl_fragment')
    e.add('c:nuggets/ender_pearl', enderNuggets)
  }

  if (Platform.isLoaded('vinery'))
    e.add('vinery:dark_cherry_logs', [
      'vinery:stripped_dark_cherry_log',
      'vinery:dark_cherry_log',
      'vinery:stripped_dark_cherry_wood',
      'vinery:dark_cherry_wood'
    ])

  if (Platform.isLoaded('alexscaves'))
    e.add('alexscaves:cave_paintings', /alexscaves:cave_painting_.*/)

  if (Platform.isLoaded('alexsmobs')) {
    e.add('c:foods/boiled_egg', 'alexscaves:boiled_emu_egg')
    e.add('c:foods/cooked_egg', 'alexscaves:boiled_emu_egg')

  }

  // ─────────────────────────────────────────────────────────
  // AllTheOres / Mekanism — removeAllTagsFrom cleanup
  // ─────────────────────────────────────────────────────────
  if (Platform.isLoaded('alltheores')) {
    e.removeAllTagsFrom(/alltheores:dirty_(copper||nickel||osmium||platinum||tin||uranium||zinc)_dust/)
    e.removeAllTagsFrom(/alltheores:(copper||nickel||osmium||platinum||tin||uranium||zinc)_shard/)
    e.removeAllTagsFrom(/alltheores:(copper||nickel||osmium||platinum||tin||uranium||zinc)_crystal/)
    e.removeAllTagsFrom(/alltheores:(copper||nickel||osmium||platinum||tin||uranium||zinc)_clump/)
  }

  if (Platform.isLoaded('mekanism')) {
    e.removeAllTagsFrom(/mekanism:crystal_lead/)
    e.removeAllTagsFrom(/mekanism:shard_lead/)
    e.removeAllTagsFrom(/mekanism:clump_lead/)
    e.removeAllTagsFrom(/mekanism:dirty_dust_lead/)
  }

  if (Platform.isLoaded('moremekanismprocessing')) {
    ['aluminum', 'iridium', 'silver'].forEach(mat => {
      e.removeAllTagsFrom(`moremekanismprocessing:crystal_${mat}`)
      e.removeAllTagsFrom(`moremekanismprocessing:shard_${mat}`)
      e.removeAllTagsFrom(`moremekanismprocessing:clump_${mat}`)
      e.removeAllTagsFrom(`moremekanismprocessing:dirty_dust_${mat}`)
    })
  }

  if (Platform.isLoaded('enderio'))
    e.removeAllTagsFrom('enderio:powdered_cobalt')

  // ─────────────────────────────────────────────────────────
  // Ore processing — crystals, shards, clumps, dusts
  // ─────────────────────────────────────────────────────────
  const ore = [
    { mat: 'copper', modAdd: 'mekanism' },
    { mat: 'gold', modAdd: 'mekanism' },
    { mat: 'iron', modAdd: 'mekanism' },
    { mat: 'osmium', modAdd: 'mekanism' },
    { mat: 'tin', modAdd: 'mekanism' },
    { mat: 'uranium', modAdd: 'mekanism' },
    { mat: 'allthemodium', modAdd: 'allthemodium' },
    { mat: 'unobtainium', modAdd: 'allthemodium' },
    { mat: 'vibranium', modAdd: 'allthemodium' },
    { mat: 'lead', modAdd: 'alltheores' },
    { mat: 'aluminum', modAdd: 'alltheores' },
    { mat: 'iridium', modAdd: 'alltheores' },
    { mat: 'silver', modAdd: 'alltheores' },
    { mat: 'platinum', modAdd: 'moremekanismprocessing' },
    { mat: 'zinc', modAdd: 'moremekanismprocessing' },
    { mat: 'nickel', modAdd: 'moremekanismprocessing' },
    { mat: 'desh', modAdd: 'moremekanismprocessing' },
    { mat: 'ostrum', modAdd: 'moremekanismprocessing' },
    { mat: 'calorite', modAdd: 'moremekanismprocessing' },
    { mat: 'cobalt', modAdd: 'moremekanismprocessing' },
    { mat: 'sapphire', modAdd: 'moremekanismprocessing' },
    { mat: 'ruby', modAdd: 'moremekanismprocessing' },
    { mat: 'peridot', modAdd: 'moremekanismprocessing' },
    { mat: 'sulfur', modAdd: 'moremekanismprocessing' },
    { mat: 'apatite', modAdd: 'moremekanismprocessing' },
    { mat: 'cinnabar', modAdd: 'moremekanismprocessing' },
    { mat: 'niter', modAdd: 'moremekanismprocessing' },
  ]

  ore.forEach(o => {
    if (!Platform.isLoaded(o.modAdd)) return

    e.add('c:crystals', `${o.modAdd}:crystal_${o.mat}`)
    e.add(`c:crystals/${o.mat}`, `${o.modAdd}:crystal_${o.mat}`)
    e.add('c:shards', `${o.modAdd}:shard_${o.mat}`)
    e.add(`c:shards/${o.mat}`, `${o.modAdd}:shard_${o.mat}`)
    e.add('c:clumps', `${o.modAdd}:clump_${o.mat}`)
    e.add(`c:clumps/${o.mat}`, `${o.modAdd}:clump_${o.mat}`)
    e.add('c:dirty_dusts', `${o.modAdd}:dirty_dust_${o.mat}`)
    e.add(`c:dirty_dusts/${o.mat}`, `${o.modAdd}:dirty_dust_${o.mat}`)
    e.add('c:dusts', `${o.modAdd}:dust_${o.mat}`)
    e.add(`c:dusts/${o.mat}`, `${o.modAdd}:dust_${o.mat}`)

    e.add('c:crystals', `${o.modAdd}:${o.mat}_crystal`)
    e.add(`c:crystals/${o.mat}`, `${o.modAdd}:${o.mat}_crystal`)
    e.add('c:shards', `${o.modAdd}:${o.mat}_shard`)
    e.add(`c:shards/${o.mat}`, `${o.modAdd}:${o.mat}_shard`)
    e.add('c:clumps', `${o.modAdd}:${o.mat}_clump`)
    e.add(`c:clumps/${o.mat}`, `${o.modAdd}:${o.mat}_clump`)
    e.add('c:dirty_dusts', `${o.modAdd}:dirty_${o.mat}_dust`)
    e.add(`c:dirty_dusts/${o.mat}`, `${o.modAdd}:dirty_${o.mat}_dust`)
    e.add('c:dusts', `${o.modAdd}:${o.mat}_dust`)
    e.add(`c:dusts/${o.mat}`, `${o.modAdd}:${o.mat}_dust`)
  })

  // ─────────────────────────────────────────────────────────
  // Immersive Engineering
  // ─────────────────────────────────────────────────────────
  if (Platform.isLoaded('immersiveengineering')) {
    e.remove('minecraft:coals', 'immersiveengineering:coal_coke')
    e.remove('c:all_hammers', ['#immersiveengineering:tools/hammers'])
    e.remove('c:tools/wrench', ['immersiveengineering:hammer'])
  }

  // ─────────────────────────────────────────────────────────
  // Stones — Rechiseled & Chipped variants
  // ─────────────────────────────────────────────────────────
  if (Platform.isLoaded('rechiseled') || Platform.isLoaded('chipped')) {
    var endStones = []
    if (Platform.isLoaded('chipped')) endStones.push('#chipped:end_stone')
    if (Platform.isLoaded('rechiseled')) endStones.push(
      'rechiseled:end_stone_blobs', 'rechiseled:end_stone_chiseled', 'rechiseled:end_stone_crushed',
      'rechiseled:end_stone_diagonal_bricks', 'rechiseled:end_stone_mesh', 'rechiseled:end_stone_paving',
      'rechiseled:end_stone_polished', 'rechiseled:end_stone_scales', 'rechiseled:end_stone_small_tiles',
      'rechiseled:end_stone_spiral_pattern', 'rechiseled:end_stone_squares', 'rechiseled:end_stone_tiles'
    )
    if (endStones.length > 0) e.add('c:end_stones', endStones)

    var netherrack = []
    if (Platform.isLoaded('quark')) netherrack.push('quark:netherrack_bricks')
    if (Platform.isLoaded('rechiseled')) netherrack.push(
      'rechiseled:netherrack_beams', 'rechiseled:netherrack_bricks', 'rechiseled:netherrack_dented',
      'rechiseled:netherrack_small_tiles', 'rechiseled:netherrack_stripes', 'rechiseled:netherrack_tiles'
    )
    if (Platform.isLoaded('chipped')) netherrack.push('#chipped:netherrack')
    if (netherrack.length > 0) e.add('c:netherrack', netherrack)

    var obsidian = []
    if (Platform.isLoaded('rechiseled')) obsidian.push(
      'rechiseled:obsidian_bordered', 'rechiseled:obsidian_bricks', 'rechiseled:obsidian_chiseled',
      'rechiseled:obsidian_chiseled_circles', 'rechiseled:obsidian_chiseled_creeper',
      'rechiseled:obsidian_chiseled_skeleton', 'rechiseled:obsidian_dark', 'rechiseled:obsidian_large_tiles',
      'rechiseled:obsidian_spots', 'rechiseled:obsidian_squares', 'rechiseled:obsidian_stripes',
      'rechiseled:obsidian_tiles'
    )
    if (Platform.isLoaded('chipped')) obsidian.push('#chipped:obsidian')
    if (obsidian.length > 0) e.add('c:obsidian', obsidian)
  }

  // ─────────────────────────────────────────────────────────
  // Extra pickaxes
  // ─────────────────────────────────────────────────────────
  const extraPickaxes = []
  if (Platform.isLoaded('blue_skies')) extraPickaxes.push(
    'blue_skies:bluebright_pickaxe', 'blue_skies:lunar_pickaxe', 'blue_skies:starlit_pickaxe',
    'blue_skies:dusk_pickaxe', 'blue_skies:frostbright_pickaxe', 'blue_skies:maple_pickaxe',
    'blue_skies:turquoise_stone_pickaxe', 'blue_skies:lunar_stone_pickaxe', 'blue_skies:pyrope_pickaxe',
    'blue_skies:aquite_pickaxe', 'blue_skies:diopside_pickaxe', 'blue_skies:charoite_pickaxe',
    'blue_skies:horizonite_pickaxe'
  )
  if (Platform.isLoaded('gobber2')) extraPickaxes.push(
    'gobber2:gobber2_pickaxe', 'gobber2:gobber2_pickaxe_nether', 'gobber2:gobber2_pickaxe_end'
  )
  if (extraPickaxes.length > 0) e.add('c:tools/pickaxes', extraPickaxes)

  // ─────────────────────────────────────────────────────────
  // Clocks
  // ─────────────────────────────────────────────────────────
  const clockTypes = ['oak', 'spruce', 'birch', 'jungle', 'acacia', 'dark_oak', 'mangrove', 'cherry', 'cuckoo', 'clock']
  clockTypes.forEach(type => {
    var clocks = []
    if (Platform.isLoaded('furniture')) clocks.push(`furniture:${type}_clock`, `furniture:${type}_grandfather_clock`)
    if (Platform.isLoaded('cyclic')) clocks.push(`cyclic:${type}`)
    if (Platform.isLoaded('create')) clocks.push(`create:${type}_clock`)
    if (Platform.isLoaded('supplementaries')) clocks.push(`supplementaries:${type}_block`)
    if (clocks.length > 0) e.add('c:clocks', clocks)
  })

  // ─────────────────────────────────────────────────────────
  // Twilight Forest planks & logs
  // ─────────────────────────────────────────────────────────
  if (Platform.isLoaded('twilightforest')) {
    var TwilightWoodTypes = ['transformation', 'dark', 'sorting', 'twilight_oak', 'canopy', 'time', 'mining']
    TwilightWoodTypes.forEach(type => e.add(`c:planks/${type}`, `twilightforest:${type}_planks`))
    e.add('twilightforest:dark_logs', '#twilightforest:darkwood_logs')
    e.add('twilightforest:time_logs', '#twilightforest:timewood_logs')
    e.add('twilightforest:transformation_logs', '#twilightforest:transwood_logs')
    e.add('twilightforest:sorting_logs', '#twilightforest:sortwood_logs')
  }

  // ─────────────────────────────────────────────────────────
  // Hexerei logs
  // ─────────────────────────────────────────────────────────
  if (Platform.isLoaded('hexerei')) {
    ['mahogany', 'willow', 'witch_hazel'].forEach(log => e.add(`hexerei:${log}_logs`, [
      `hexerei:${log}_log`, `hexerei:stripped_${log}_log`,
      `hexerei:${log}_wood`, `hexerei:stripped_${log}_wood`
    ]))
  }

  // ─────────────────────────────────────────────────────────
  // Botania quartz
  // ─────────────────────────────────────────────────────────
  if (Platform.isLoaded('botania'))
    ['dark', 'mana', 'blaze', 'lavender', 'red', 'elven', 'sunny']
      .forEach(type => e.add('botania:all_quartz', `botania:quartz_${type}`))

  // ─────────────────────────────────────────────────────────
  // MythicBotany
  // ─────────────────────────────────────────────────────────
  if (Platform.isLoaded('mythicbotany')) {
    e.add('c:raw_materials/elementium', 'mythicbotany:raw_elementium')
    e.add('c:storage_blocks/raw_elementium', 'mythicbotany:raw_elementium_block')
  }

  // ─────────────────────────────────────────────────────────
  // SecurityCraft log aliases
  // ─────────────────────────────────────────────────────────
  if (Platform.isLoaded('securitycraft')) {
    e.add('securitycraft:reinforced/crimson_logs', '#securitycraft:reinforced/crimson_stems')
    e.add('securitycraft:reinforced/warped_logs', '#securitycraft:reinforced/warped_stems')
  }

  // ─────────────────────────────────────────────────────────
  // Pebbles
  // ─────────────────────────────────────────────────────────
  if (Platform.isLoaded('exdeorum') || Platform.isLoaded('havenpebbles')) {
    pebble.forEach(peb => {
      var pebItems = []
      if (Platform.isLoaded('exdeorum')) pebItems.push(`exdeorum:${peb}_pebble`)
      if (Platform.isLoaded('havenpebbles')) pebItems.push(`havenpebbles:${peb}_pebble`)
      if (pebItems.length > 0) e.add(`kubejs:${peb}_pebbles`, pebItems)
    })
  }

  if (Platform.isLoaded('actuallyadditions')) {
    var tinyCoal = []
    if (Platform.isLoaded('opolisutilities')) tinyCoal.push('opolisutilities:mini_charcoal')
    if (Platform.isLoaded('inventorypets')) tinyCoal.push('inventorypets:nugget_coal')
    if (tinyCoal.length > 0) e.add('actuallyadditions:tinycoal', tinyCoal)
  }

  if (Platform.isLoaded('strainers')) {
    e.add('c:stone_pebbles', 'strainers:stone_pebble')
    e.add('c:deepslate_pebbles', 'strainers:deepslate_pebble')
  }

})

ServerEvents.tags('block', e => {

  if (Platform.isLoaded('buildinggadgets') || Platform.isLoaded('waystones')) {
    if (Platform.isLoaded('buildinggadgets'))
      e.add('buildinggadgets:blacklist/generic', '#c:relocation_not_supported')
    var notSupported = ['minecraft:beehive', 'minecraft:bee_nest']
    if (Platform.isLoaded('waystones')) notSupported.push('@waystones')
    e.add('c:relocation_not_supported', notSupported)
  }

  if (Platform.isLoaded('entangled')) {
    var invalidTargets = []
    if (Platform.isLoaded('ae2')) invalidTargets.push('@ae2')
    if (Platform.isLoaded('refinedstorage')) invalidTargets.push('@refinedstorage')
    if (Platform.isLoaded('extrastorage')) invalidTargets.push('@extrastorage')
    if (invalidTargets.length > 0) e.add('entangled:invalid_targets', invalidTargets)
  }

})

ServerEvents.tags('fluid', e => {
  if (Platform.isLoaded('createaddition'))
    e.remove('minecraft:water', ['createaddition:flowing_seed_oil', 'createaddition:seed_oil'])
})

ServerEvents.tags('entity_type', e => {
  const mobBlacklist = ['minecraft:iron_golem']
  if (Platform.isLoaded('artifacts')) mobBlacklist.push('artifacts:mimic')
  e.add('kubejs:mob_blacklist', mobBlacklist)

  if (Platform.isLoaded('industrialforegoing'))
    e.add('industrialforegoing:mob_duplicator_blacklist', '#kubejs:mob_blacklist')

  if (Platform.isLoaded('ars_nouveau') && Platform.isLoaded('artifacts'))
    e.add('ars_nouveau:drygmy_blacklist', 'artifacts:mimic')
})

ServerEvents.tags('worldgen/biome', e => {
  if (Platform.isLoaded('botania') && Platform.isLoaded('allthemodium')) {
    e.add('botania:mystical_flower_spawnlist', 'allthemodium:mining')
    e.add('botania:mystical_mushroom_spawnlist', [
      'allthemodium:the_other', 'allthemodium:soul_sand_valley',
      'allthemodium:warped_forest', 'allthemodium:desert_hills',
      'allthemodium:desert', 'allthemodium:crimson_forest',
      'allthemodium:basalt_deltas'
    ])
  }
})
