ServerEvents.recipes(e => {
    // Get all item id's in the repair tag
    let repairItems = Ingredient.of('#kubejs:rocky_repair').itemIds.toArray()
    // An iterator to differentiate the recipe id just in case there is dupes in repair tag
    let recipeIter = 0

    for (let item of repairItems) {
        // Create the shapeless repairing recipe
        let recipe = e.shapeless(item, [
            item,
            ['minecraft:flint']
        ])

        // Modify the result to include nbt from the original input item
        recipe.modifyResult((grid, result) => {
            let input = grid.find(Ingredient.of('#kubejs:rocky_repair'))
            // Get existing NBT or create new NBT if it didn't exist for some reason somehow to be safe
            let finalNbt = input.nbt ? input.nbt : new CompoundTag()
            
            // Full repair
            // finalNbt.putInt('Damage', 0)

            // Repairs 50 durability
            finalNbt.putInt('Damage', Math.max(0, finalNbt.getInt('Damage') - 10))

            // Add the NBT to the modified result
            return result.withNBT(finalNbt)
        })

        // Set the recipe id
        recipe.id(`kubejs:rocky_repairing/${item.split(':')[1]}-${recipeIter++}`)
    }
})

ServerEvents.recipes(e => {
    // Get all item id's in the repair tag
    let repairItems = Ingredient.of('#kubejs:metallic_repair').itemIds.toArray()
    // An iterator to differentiate the recipe id just in case there is dupes in repair tag
    let recipeIter = 0

    for (let item of repairItems) {
        // Create the shapeless repairing recipe
        let recipe = e.shapeless(item, [
            item,
            ['kubejs:scrap_metal', 'minecraft:emerald', 'sortilege:limitite']
        ])

        // Modify the result to include nbt from the original input item
        recipe.modifyResult((grid, result) => {
            let input = grid.find(Ingredient.of('#kubejs:metallic_repair'))
            // Get existing NBT or create new NBT if it didn't exist for some reason somehow to be safe
            let finalNbt = input.nbt ? input.nbt : new CompoundTag()
            
            // Full repair
            // finalNbt.putInt('Damage', 0)

            // Repairs 50 durability
            finalNbt.putInt('Damage', Math.max(0, finalNbt.getInt('Damage') - 25))

            // Add the NBT to the modified result
            return result.withNBT(finalNbt)
        })

        // Set the recipe id
        recipe.id(`kubejs:metallic_repairing/${item.split(':')[1]}-${recipeIter++}`)
    }
})

ServerEvents.recipes(e => {
    // Get all item id's in the repair tag
    let repairItems = Ingredient.of(['#kubejs:diamond_repair']).itemIds.toArray()
    // An iterator to differentiate the recipe id just in case there is dupes in repair tag
    let recipeIter = 0

    for (let item of repairItems) {
        // Create the shapeless repairing recipe
        let recipe = e.shapeless(item, [
            item,
            ['kubejs:diamond_shard', "healpgood:crystal_heart"]
        ])

        // Modify the result to include nbt from the original input item
        recipe.modifyResult((grid, result) => {
            let input = grid.find(Ingredient.of('#kubejs:diamond_repair'))
            // Get existing NBT or create new NBT if it didn't exist for some reason somehow to be safe
            let finalNbt = input.nbt ? input.nbt : new CompoundTag()

            // Repairs 150 durability
            finalNbt.putInt('Damage', Math.max(0, finalNbt.getInt('Damage') - 150))

            // Add the NBT to the modified result
            return result.withNBT(finalNbt)
        })

        // Set the recipe id
        recipe.id(`kubejs:diamond_repairing/${item.split(':')[1]}-${recipeIter++}`)
    }
})

ServerEvents.recipes(e => {
    // Get all item id's in the repair tag
    let repairItems = Ingredient.of('#kubejs:loving_repair').itemIds.toArray()
    // An iterator to differentiate the recipe id just in case there is dupes in repair tag
    let recipeIter = 0

    for (let item of repairItems) {
        // Create the shapeless repairing recipe
        let recipe = e.shapeless(item, [
            item,
            ['healpgood:heart_container']
        ])

        // Modify the result to include nbt from the original input item
        recipe.modifyResult((grid, result) => {
            let input = grid.find(Ingredient.of('#kubejs:loving_repair'))
            // Get existing NBT or create new NBT if it didn't exist for some reason somehow to be safe
            let finalNbt = input.nbt ? input.nbt : new CompoundTag()
            
            // Full repair
            finalNbt.putInt('Damage', 0)

            // Add the NBT to the modified result
            return result.withNBT(finalNbt)
        })

        // Set the recipe id
        recipe.id(`kubejs:loving_repairing/${item.split(':')[1]}-${recipeIter++}`)
    }
})

ServerEvents.recipes(event => {
  
  event.shapeless(
    Item.of('minecraft:flint', 1),
    [
      '#kubejs:rocky_repair'
    ]
  );
})

ServerEvents.recipes(event => {
  
  event.shapeless(
    Item.of('kubejs:scrap_metal', 1),
    [
      '#kubejs:metallic_repair'
    ]
  );
})

ServerEvents.recipes(event => {
  
  event.shapeless(
    Item.of('kubejs:diamond_shard', 1),
    [
      '#kubejs:diamond_repair'
    ]
  );
})

ServerEvents.tags('item', e => {
    e.add('kubejs:rocky_repair', [

    'minecraft:stone_sword',
    'minecraft:stone_axe',
    'minecraft:stone_pickaxe',
    'minecraft:stone_shovel',
    'minecraft:stone_hoe',

    'minecraft:shield',
    'shieldexp:wooden_shield',
    
    'jaams_weaponry:stone_battle_axe',
    'jaams_weaponry:stone_broadsword',
    'jaams_weaponry:stone_buster_sword',
    'jaams_weaponry:stone_butterfly_sword',
    'jaams_weaponry:stone_claw',
    'jaams_weaponry:stone_cleaver',
    'jaams_weaponry:stone_dagger',
    'jaams_weaponry:stone_dagger_reverse',
    'jaams_weaponry:stone_greathammer',
    'jaams_weaponry:stone_greatsword',
    'jaams_weaponry:stone_hammer',
    'jaams_weaponry:stone_hook_sword',
    'jaams_weaponry:stone_kama',
    'jaams_weaponry:stone_katana',
    'jaams_weaponry:stone_katar',
    'jaams_weaponry:stone_knuckle',
    'jaams_weaponry:stone_longsword',
    'jaams_weaponry:stone_machete',
    'jaams_weaponry:stone_ring',
    'jaams_weaponry:stone_scattergun',
    'jaams_weaponry:stone_saw_cleaver',
    'jaams_weaponry:stone_saw_cleaver_unfolded',
    'jaams_weaponry:stone_scythe',
    'jaams_weaponry:stone_sickle',
    'jaams_weaponry:stone_spear',
    'jaams_weaponry:stone_twinblade',
    'jaams_weaponry:stone_zweihander',
    
    'jaams_weaponry:giant_shuriken',

    'archeryexp:wooden_bow',
    'minecraft:bow',
    'minecraft:arrow',

    'jaams_weaponry:tessen',

    'jaams_weaponry:short_bow',
    'jaams_weaponry:flat_bow',
    'jaams_weaponry:hunters_boomerang',
    'jaams_weaponry:hunters_bow',
    'jaams_weaponry:hunters_crossbow',
    'jaams_weaponry:compound_bow',

    'jaams_weaponry:war_pick',

    'clash:greatblade',


    ])
})

ServerEvents.tags('item', e => {
    e.add('kubejs:metallic_repair', [

    '#kubejs:rocky_repair',
    
    'minecraft:iron_ingot',
    'minecraft:gold_ingot',
    'minecraft:netherite_ingot',
    
    'minecraft:chainmail_helmet',
    'minecraft:chainmail_chestplate',
    'minecraft:chainmail_leggings',
    'minecraft:chainmail_boots',

    'minecraft:iron_sword',
    'minecraft:iron_axe',
    'minecraft:iron_pickaxe',
    'minecraft:iron_shovel',
    'minecraft:iron_hoe',
    
    'minecraft:iron_helmet',
    'minecraft:iron_chestplate',
    'minecraft:iron_leggings',
    'minecraft:iron_boots',

    'shieldexp:iron_shield',
    'archeryexp:iron_bow',
    'archeryexp:iron_arrow',
    
    'minecraft:crossbow',

    'jaams_weaponry:hunters_crossbow',
    'jaams_weaponry:great_crossbow',
    
    'jaams_weaponry:iron_battle_axe',
    'jaams_weaponry:iron_broadsword',
    'jaams_weaponry:iron_buster_sword',
    'jaams_weaponry:iron_butterfly_sword',
    'jaams_weaponry:iron_claw',
    'jaams_weaponry:iron_cleaver',
    'jaams_weaponry:iron_dagger',
    'jaams_weaponry:iron_dagger_reverse',
    'jaams_weaponry:iron_greathammer',
    'jaams_weaponry:iron_greatsword',
    'jaams_weaponry:iron_hammer',
    'jaams_weaponry:iron_hook_sword',
    'jaams_weaponry:iron_kama',
    'jaams_weaponry:iron_katana',
    'jaams_weaponry:iron_katar',
    'jaams_weaponry:iron_knuckle',
    'jaams_weaponry:iron_longsword',
    'jaams_weaponry:iron_machete',
    'jaams_weaponry:iron_ring',
    'jaams_weaponry:iron_scattergun',
    'jaams_weaponry:iron_saw_cleaver',
    'jaams_weaponry:iron_saw_cleaver_unfolded',
    'jaams_weaponry:iron_scythe',
    'jaams_weaponry:iron_sickle',
    'jaams_weaponry:iron_spear',
    'jaams_weaponry:iron_twinblade',
    'jaams_weaponry:iron_zweihander',

    'minecraft:golden_sword',
    'minecraft:golden_axe',
    'minecraft:golden_pickaxe',
    'minecraft:golden_shovel',
    'minecraft:golden_hoe',

    'minecraft:golden_helmet',
    'minecraft:golden_chestplate',
    'minecraft:golden_leggings',
    'minecraft:golden_boots',

    'shieldexp:golden_shield',
    'archeryexp:gold_bow',
    'archeryexp:gold_arrow',

    'jaams_weaponry:golden_battle_axe',
    'jaams_weaponry:golden_broadsword',
    'jaams_weaponry:golden_buster_sword',
    'jaams_weaponry:golden_butterfly_sword',
    'jaams_weaponry:golden_claw',
    'jaams_weaponry:golden_cleaver',
    'jaams_weaponry:golden_dagger',
    'jaams_weaponry:golden_dagger_reverse',
    'jaams_weaponry:golden_greathammer',
    'jaams_weaponry:golden_greatsword',
    'jaams_weaponry:golden_hammer',
    'jaams_weaponry:golden_hook_sword',
    'jaams_weaponry:golden_kama',
    'jaams_weaponry:golden_katana',
    'jaams_weaponry:golden_katar',
    'jaams_weaponry:golden_knuckle',
    'jaams_weaponry:golden_longsword',
    'jaams_weaponry:golden_machete',
    'jaams_weaponry:golden_pistol',
    'jaams_weaponry:golden_ring',
    'jaams_weaponry:golden_saw_cleaver',
    'jaams_weaponry:golden_saw_cleaver_unfolded',
    'jaams_weaponry:golden_scythe',
    'jaams_weaponry:golden_sickle',
    'jaams_weaponry:golden_spear',
    'jaams_weaponry:golden_twinblade',
    'jaams_weaponry:golden_zweihander',

    'minecraft:netherite_sword',
    'minecraft:netherite_axe',
    'minecraft:netherite_pickaxe',
    'minecraft:netherite_shovel',
    'minecraft:netherite_hoe',

    'minecraft:netherite_helmet',
    'minecraft:netherite_chestplate',
    'minecraft:netherite_leggings',
    'minecraft:netherite_boots',

    'shieldexp:netherite_shield',
    'archeryexp:netherite_bow',

    'jaams_weaponry:netherite_battle_axe',
    'jaams_weaponry:netherite_broadsword',
    'jaams_weaponry:netherite_buster_sword',
    'jaams_weaponry:netherite_butterfly_sword',
    'jaams_weaponry:netherite_claw',
    'jaams_weaponry:netherite_cleaver',
    'jaams_weaponry:netherite_dagger',
    'jaams_weaponry:netherite_dagger_reverse',
    'jaams_weaponry:netherite_greathammer',
    'jaams_weaponry:netherite_greatsword',
    'jaams_weaponry:netherite_hammer',
    'jaams_weaponry:netherite_hook_sword',
    'jaams_weaponry:netherite_kama',
    'jaams_weaponry:netherite_katana',
    'jaams_weaponry:netherite_katar',
    'jaams_weaponry:netherite_knuckle',
    'jaams_weaponry:netherite_longsword',
    'jaams_weaponry:netherite_machete',
    'jaams_weaponry:netherite_ring',
    'jaams_weaponry:netherite_saw_cleaver',
    'jaams_weaponry:netherite_saw_cleaver_unfolded',
    'jaams_weaponry:netherite_scythe',
    'jaams_weaponry:netherite_sickle',
    'jaams_weaponry:netherite_spear',
    'jaams_weaponry:netherite_twinblade',
    'jaams_weaponry:netherite_zweihander',

    'jaams_weaponry:nunchaku',
    
    'jaams_weaponry:royal_sword',
    'jaams_weaponry:royal_axe',
    'jaams_weaponry:royal_spear',
    'jaams_weaponry:royal_rapier',
    'jaams_weaponry:royal_bow',
    'jaams_weaponry:royal_crossbow',

    'cataclysm:black_steel_pickaxe',
    'cataclysm:black_steel_shovel',
    'cataclysm:black_steel_axe',
    'cataclysm:black_steel_hoe',
    'cataclysm:black_steel_sword',
    'cataclysm:black_steel_targe',

    'caverns_and_chasms:necromium_boots',
    'caverns_and_chasms:necromium_chestplate',
    'caverns_and_chasms:necromium_helmet',
    'caverns_and_chasms:necromium_leggings',
    'caverns_and_chasms:sanguine_boots',
    'caverns_and_chasms:sanguine_chestplate',
    'caverns_and_chasms:sanguine_helmet',
    'caverns_and_chasms:sanguine_leggings',
    'caverns_and_chasms:silver_boots',
    'caverns_and_chasms:silver_chestplate',
    'caverns_and_chasms:silver_helmet',
    'caverns_and_chasms:silver_leggings',

    'clash:spear',

    'species:crankbow', 
    'species:birt_egg',

    'block_factorys_bosses:dragon_guard_shield',
    'block_factorys_bosses:frozen_fist',
    'minecells:assault_shield',
    'minecells:ice_shield',
    'minecells:bloodthirsty_shield'

    ])
})

ServerEvents.tags('item', e => {
    e.add('kubejs:diamond_repair', [

    'minecraft:diamond',

    'minecraft:diamond_sword',
    'minecraft:diamond_axe',
    'minecraft:diamond_pickaxe',
    'minecraft:diamond_shovel',
    'minecraft:diamond_hoe',
    
    'minecraft:diamond_helmet',
    'minecraft:diamond_chestplate',
    'minecraft:diamond_leggings',
    'minecraft:diamond_boots',

    'shieldexp:diamond_shield',
    'archeryexp:diamond_bow',
    'archeryexp:diamond_arrow',

    'jaams_weaponry:diamond_battle_axe',
    'jaams_weaponry:diamond_broadsword',
    'jaams_weaponry:diamond_buster_sword',
    'jaams_weaponry:diamond_butterfly_sword',
    'jaams_weaponry:diamond_claw',
    'jaams_weaponry:diamond_cleaver',
    'jaams_weaponry:diamond_dagger',
    'jaams_weaponry:diamond_dagger_reverse',
    'jaams_weaponry:diamond_greathammer',
    'jaams_weaponry:diamond_greatsword',
    'jaams_weaponry:diamond_hammer',
    'jaams_weaponry:diamond_hook_sword',
    'jaams_weaponry:diamond_kama',
    'jaams_weaponry:diamond_katana',
    'jaams_weaponry:diamond_katar',
    'jaams_weaponry:diamond_knuckle',
    'jaams_weaponry:diamond_longsword',
    'jaams_weaponry:diamond_machete',
    'jaams_weaponry:diamond_ring',
    'jaams_weaponry:diamond_scattergun',
    'jaams_weaponry:diamond_saw_cleaver',
    'jaams_weaponry:diamond_saw_cleaver_unfolded',
    'jaams_weaponry:diamond_scythe',
    'jaams_weaponry:diamond_sickle',
    'jaams_weaponry:diamond_spear',
    'jaams_weaponry:diamond_twinblade',
    'jaams_weaponry:diamond_zweihander',

    'mowziesmobs:naga_fang_dagger',
    'clash:echoing_spear',

    'cataclysm:the_annihilator',
    'cataclysm:soul_render',
    'cataclysm:void_forge',
    'cataclysm:wither_assault_shoulder_weapon',
    'cataclysm:void_assault_shoulder_weapon',
    'cataclysm:gauntlet_of_bulwark',
    'cataclysm:coral_spear',
    'cataclysm:tidal_claws',
    'cataclysm:laser_gatling',
    'cataclysm:ancient_spear',
    'cataclysm:gauntlet_of_maelstrom',
    'cataclysm:blazing_grips',
    'cataclysm:wrath_of_the_desert',
    'cataclysm:the_immolator',
    'cataclysm:chitin_claw',

    '#kubejs:metallic_repair'
    ])
})

ServerEvents.tags('item', e => {
    e.add('kubejs:loving_repair', [
    
    '#kubejs:rocky_repair',
    '#kubejs:metallic_repair',
    '#kubejs:diamond_repair'
    ])
})