
/*
dungeonsdelight:life_grasp doesnt work,ricochet,serrated_strike is treasure only
endlessbiomes:shared_pain, vwooping, altar only
mynethersdelight:poaching?
rootsclassic:druids_step, gaias_bolt, have been removed
supplementaries:stasis, treasure only 
bumblezone enchantments via crystalline flower
returning board in nether fortresses
*/

/*  BlockEvents.rightClicked("minecraft:enchanting_table", event => {
  // Stop vanilla enchanting table behavior entirely
  event.cancel();

  // Optional: open your custom GUI here
  // event.player.openGui("kubejs:custom_enchanting");
});  */
 BlockEvents.rightClicked("minecraft:brewing_stand", event => {
  // Stop vanilla enchanting table behavior entirely
  event.cancel();

  // Optional: open your custom GUI here
  // event.player.openGui("kubejs:custom_enchanting");
}); 
 BlockEvents.rightClicked("twilightforest:uncrafting_table", event => {
  // Stop vanilla enchanting table behavior entirely
  event.cancel();

  // Optional: open your custom GUI here
  // event.player.openGui("kubejs:custom_enchanting");
}); 

ServerEvents.recipes(event => {

  const enchants = [
  "minecraft:efficiency",
  "minecraft:unbreaking",
  "minecraft:fortune",
  "minecraft:looting",
  "minecraft:luck_of_the_sea",
  "minecraft:lure",
  "minecraft:power",
  "minecraft:punch",
  "minecraft:flame",
  "minecraft:knockback",
  "minecraft:fire_aspect",
  "minecraft:respiration",
  "minecraft:aqua_affinity",
  "minecraft:thorns",
  "minecraft:depth_strider",
  "minecraft:frost_walker",
  "minecraft:swift_sneak",
  "minecraft:feather_falling",
  "minecraft:blast_protection",
  "minecraft:projectile_protection",
  "minecraft:smite",
  "minecraft:bane_of_arthropods",
  "minecraft:impaling",
  "minecraft:loyalty",
  "minecraft:channeling",
  "minecraft:riptide",
  "minecraft:multishot",
  "minecraft:piercing",
  "minecraft:quick_charge",
  "minecraft:fire_protection",
  "minecraft:sweeping",
  "minecraft:silk_touch",
  "alexsmobs:straddle_jump",
  "alexsmobs:serpentfriend",
  "alexsmobs:lavawax",
  "farmersdelight:backstabbing",
  "foragersinsight:farmhand",
  "foragersinsight:concussive",
  "netherdepthsupgrade:hell_strider",
  "tameablebeasts:swarm",
  "tameablebeasts:sting",
  "undergarden:ricochet",
  "undergarden:longevity",
  "undergarden:self_sling",
  "deep_aether:gloves_reach",
  "call_of_yucutan:toxic_blade",
  "call_of_yucutan:ritual_slaught",
  "call_of_yucutan:double_edged",
  "foragersinsight:luck_of_the_trees",
  "twilightforest:fire_react",
  "twilightforest:chill_aura",
  "twilightforest:destruction",
  "dashenchentement:dash_enchentment",
  "kobolds:prospector",
  "diversity_better_bundle:capacity",
  "luminous_nether:soul_cleave"
  
	];//grimshade wither, herb of x, tree of x, golden amber, cockroach wing, rabbit foot, naga fang,
  const middleItems = [
  "vital_herbs:focusing_oil",      		// efficiency
  "vital_herbs:purifying_oil",     		// unbreaking
  "rootsclassic:radiant_daisy",    		// fortune
  "hexalia:morphora",            		// looting
  "aquaculture:neptunium_ingot",   		// luck of the sea
  "minecraft:scute",              		// lure
  "undergarden:forgotten_nugget",     	// power
  "iceandfire:amphithere_feather",   	// punch
  "minecraft:torchflower",          	// flame
  "alexsmobs:bear_fur", 	            // knockback
  "friendsandfoes:wildfire_crown_fragment",// fire aspect
  "hexalia:siren_kelp",     			// respiration
  "hexalia:nautilite",      			// aqua affinity
  "alchemists_garden:blood_rose",   	// thorns
  "iceandfire:hippocampus_fin",      	// depth strider
  "yungscavebiomes:frost_lily",      	// frost walker
  "minecraft:echo_shard",            	// swift sneak
  "aether:white_apple",  			 	// feather falling
  "vital_herbs:protective_oil",         // blast protection
  "hexalia:windsong",                	// projectile protection
  "rootsclassic:midnight_bloom",     	// smite
  "alchemists_garden:chrysite_cobweb",  // bane of arthropods
  "bettertridents:trident_fragment", 	// impaling
  "minecraft:nautilus_shell",      		// loyalty
  "iceandfire:lightning_dragon_flesh",  // channeling
  "alexsmobs:fish_bones",        		// riptide
  "minecraft:tripwire_hook",            // multishot
  "alexsmobs:gazelle_horn",             // piercing
  "alexsmobs:elastic_tendon",           // quick charge
  "rootsclassic:flare_orchid",         	// fire protection
  "vital_herbs:empowering_oil",			//sweeping edge
  "hexalia:astrylis",					//silk touch
  "alexsmobs:tarantula_hawk_wing",		//straddle jump
  "alexsmobs:bone_serpent_tooth",		//serpent charmer
  "netherdepthsupgrade:magmacubefish",	//lavawaxxed
  "twilightforest:steeleaf_ingot",		//backstabbing
  "rootsclassic:growth_powder",			//farmhand
  "alchemists_garden:creep_orchid_bundle",//concussive
  "netherdepthsupgrade:crimson_kelp_block",//hell strider
  "tameablebeasts:beetle_gem",			//swarm
  "tameablebeasts:egg_rests",			//sting
  "undergarden:blisterberry",			//ricochet	
  "undergarden:blood_globule",			//longevity
  "alexsmobs:soul_heart",				//self sling
  "aether_redux:mykapod_shell_chunk",	//gloves reach
  "call_of_yucutan:hematite",			//toxic blade
  "call_of_yucutan:mystic_vine",		//ritual slaught
  "call_of_yucutan:ancient_gold_ingot", //double edged
  "foragersinsight:birch_syrup_bottle",	//luck of the trees
  "twilightforest:red_thread",			//Fire React
  "twilightforest:ice_bomb",			//Chill aura
  "twilightforest:knightmetal_block",	//Destruction
  "rootsclassic:spell_powder",			//Dash
  "minecraft:emerald_block",			//prospector
  "alexsmobs:cockroach_wing",	//capacity
  "luminous_nether:ghost_block"
  
	];

  enchants.forEach((id, index) => {

    const middle = middleItems[index];

    const output = Item.of(
      Item.of("minecraft:enchanted_book").enchant(id, 1)
    ).strongNBT();

    event.shaped(
      output,
      [
        "LML",
        "CBC",
        "LML"
      ],
      {
        L: "minecraft:lapis_block",
        C: "vital_herbs:aura_crystal",
        B: "minecraft:book",
        M: middle
      }
    );
  });

});


//UPGRADING BOOKS ------------------------------------------------------------------
ServerEvents.recipes(event => {

  // All vanilla tiered enchantments except sharpness, protection, and non-tiered ones
  const enchants = [
    "minecraft:efficiency",
    "minecraft:unbreaking",
    "minecraft:fortune",
    "minecraft:looting",
    "minecraft:luck_of_the_sea",
    "minecraft:lure",
    "minecraft:power",
    "minecraft:punch",
    "minecraft:flame",
    "minecraft:knockback",
    "minecraft:fire_aspect",
    "minecraft:respiration",
    "minecraft:aqua_affinity",
    "minecraft:thorns",
    "minecraft:depth_strider",
    "minecraft:frost_walker",
    "minecraft:swift_sneak",
    "minecraft:feather_falling",
    "minecraft:blast_protection",
    "minecraft:projectile_protection",
    "minecraft:smite",
    "minecraft:bane_of_arthropods",
    "minecraft:impaling",
    "minecraft:loyalty",
    "minecraft:channeling",
    "minecraft:riptide",
    "minecraft:multishot",
    "minecraft:piercing",
    "minecraft:quick_charge",
    "minecraft:fire_protection",
	"minecraft:sweeping",
	"minecraft:silk_touch",
	"alexsmobs:straddle_jump",
	"alexsmobs:serpentfriend",
	"alexsmobs:lavawax",
	"farmersdelight:backstabbing",
	"foragersinsight:farmhand",
	"foragersinsight:concussive",
	"netherdepthsupgrade:hell_strider",
	"tameablebeasts:swarm",
	"tameablebeasts:sting",
	"undergarden:ricochet",
	"undergarden:longevity",
	"undergarden:self_sling",
	"deep_aether:gloves_reach",
	"call_of_yucutan:toxic_blade",
	"call_of_yucutan:ritual_slaught",
	"call_of_yucutan:double_edged",
	"foragersinsight:luck_of_the_trees",
	"twilightforest:fire_react",
	"twilightforest:chill_aura",
	"twilightforest:destruction",
	"dashenchentement:dash_enchentment",
	"kobolds:prospector",
	"minecraft:soul_speed",
	"diversity_better_bundle:capacity",
	"dungeonsdelight:ricochet",
	"dungeonsdelight:serrated_strike",
	"luminous_nether:soul_cleave"
  ];

  // Max vanilla levels for each enchantment
  const maxLevels = {
    "minecraft:efficiency": 5,
    "minecraft:unbreaking": 3,
    "minecraft:fortune": 3,
    "minecraft:looting": 3,
    "minecraft:luck_of_the_sea": 3,
    "minecraft:lure": 3,
    "minecraft:power": 5,
    "minecraft:punch": 2,
    "minecraft:flame": 1,
    "minecraft:knockback": 2,
    "minecraft:fire_aspect": 2,
    "minecraft:respiration": 3,
    "minecraft:aqua_affinity": 1,
    "minecraft:thorns": 3,
    "minecraft:depth_strider": 3,
    "minecraft:frost_walker": 2,
    "minecraft:swift_sneak": 3,
    "minecraft:feather_falling": 4,
    "minecraft:blast_protection": 4,
    "minecraft:projectile_protection": 4,
    "minecraft:smite": 5,
    "minecraft:bane_of_arthropods": 5,
    "minecraft:impaling": 5,
    "minecraft:loyalty": 3,
    "minecraft:channeling": 1,
    "minecraft:riptide": 3,
    "minecraft:multishot": 1,
    "minecraft:piercing": 4,
    "minecraft:quick_charge": 3,
    "minecraft:fire_protection": 4,
	"minecraft:sweeping": 3,
	"minecraft:silk_touch": 1,
	"alexsmobs:straddle_jump": 3,
	"alexsmobs:serpentfriend": 1,
	"alexsmobs:lavawax": 1,
	"farmersdelight:backstabbing": 3,
	"foragersinsight:farmhand": 1,
	"foragersinsight:concussive": 3,
	"netherdepthsupgrade:hell_strider": 2,
	"tameablebeasts:swarm": 2,
	"tameablebeasts:sting": 2,
	"undergarden:ricochet": 3,
	"undergarden:longevity": 3,
	"undergarden:self_sling": 1,
	"deep_aether:gloves_reach": 3,
	"call_of_yucutan:toxic_blade": 2,
	"call_of_yucutan:ritual_slaught": 3,
	"call_of_yucutan:double_edged": 3,
	"foragersinsight:luck_of_the_trees": 3,
	"twilightforest:fire_react": 3,
	"twilightforest:chill_aura": 3,
	"twilightforest:destruction": 3,
	"dashenchentement:dash_enchentment": 4,
	"kobolds:prospector": 3,
	"minecraft:soul_speed": 3,
	"diversity_better_bundle:capacity": 3,
	"dungeonsdelight:ricochet": 3,
	"dungeonsdelight:serrated_strike": 1,
	"luminous_nether:soul_cleave": 2
  };

  // -------------------------
  // LEVEL 1 → LEVEL 2
  // -------------------------
  enchants
    .filter(id => maxLevels[id] >= 2)
    .forEach(id => {
      const output = Item.of(Item.of('minecraft:enchanted_book').enchant(id, 2)).strongNBT();
      const input = Item.of(Item.of('minecraft:enchanted_book').enchant(id, 1)).strongNBT();

      event.shaped(
        Item.of(output, 1),
        ['OAO', 'ABA', 'OAO'],
        {
          O: 'undergarden:utherium_block',
		  A: 'vital_herbs:aura_crystal',
          B: input
        }
      );
    });

  // -------------------------
  // LEVEL 2 → LEVEL 3
  // -------------------------
  enchants
    .filter(id => maxLevels[id] >= 3)
    .forEach(id => {
      const output = Item.of(Item.of('minecraft:enchanted_book').enchant(id, 3)).strongNBT();
      const input = Item.of(Item.of('minecraft:enchanted_book').enchant(id, 2)).strongNBT();

      event.shaped(
        Item.of(output, 1),
        ['OAO', 'ABA', 'OAO'],
        {
          O: 'aether_redux:gravitite_block',
		  A: 'vital_herbs:aura_crystal',
          B: input
        }
      );
    });

  // -------------------------
  // LEVEL 3 → LEVEL 4
  // -------------------------
  enchants
    .filter(id => maxLevels[id] >= 4)
    .forEach(id => {
      const output = Item.of(Item.of('minecraft:enchanted_book').enchant(id, 4)).strongNBT();
      const input = Item.of(Item.of('minecraft:enchanted_book').enchant(id, 3)).strongNBT();

      event.shaped(
        Item.of(output, 1),
        ['OAO', 'ABA', 'OAO'],
        {
          O: 'deep_aether:stratus_ingot',
		  A: 'vital_herbs:aura_crystal',
          B: input
        }
      );
    });

});


//crystalline flower blacklist

ServerEvents.tags('enchantment',event => {

	event.add('the_bumblezone:crystalline_flower/disallowed_enchantments',[
    "minecraft:efficiency",
    "minecraft:unbreaking",
    "minecraft:fortune",
    "minecraft:looting",
    "minecraft:luck_of_the_sea",
    "minecraft:lure",
    "minecraft:power",
    "minecraft:punch",
    "minecraft:flame",
    "minecraft:knockback",
    "minecraft:fire_aspect",
    "minecraft:respiration",
    "minecraft:aqua_affinity",
    "minecraft:thorns",
    "minecraft:depth_strider",
    "minecraft:frost_walker",
    "minecraft:swift_sneak",
    "minecraft:feather_falling",
    "minecraft:blast_protection",
    "minecraft:projectile_protection",
    "minecraft:smite",
    "minecraft:bane_of_arthropods",
    "minecraft:impaling",
    "minecraft:loyalty",
    "minecraft:channeling",
    "minecraft:riptide",
    "minecraft:multishot",
    "minecraft:piercing",
    "minecraft:quick_charge",
    "minecraft:fire_protection",
	"minecraft:sweeping",
	"minecraft:silk_touch",
	"alexsmobs:straddle_jump",
	"alexsmobs:serpentfriend",
	"alexsmobs:lavawax",
	"farmersdelight:backstabbing",
	"foragersinsight:farmhand",
	"foragersinsight:concussive",
	"netherdepthsupgrade:hell_strider",
	"tameablebeasts:swarm",
	"tameablebeasts:sting",
	"undergarden:self_sling",
	"dungeonsdelight:serrated_strike",
	"minecraft:sharpness",
	"dungeonsdelight:ricochet",
	"undergarden:ricochet",
	"alexsmobs:board_return",
	"minecraft:protection",
	"minecraft:mending",
	"undergarden:longevity",
	"dungeonsdelight:life_grasp",
	"minecraft:infinity",
	"deep_aether:gloves_reach",
	"call_of_yucutan:toxic_blade",
	"call_of_yucutan:ritual_slaught",
	"call_of_yucutan:double_edged",
	"foragersinsight:luck_of_the_trees",
	"twilightforest:fire_react",
	"twilightforest:chill_aura",
	"twilightforest:destruction",
	"dashenchentement:dash_enchentment",
	"kobolds:prospector",
	"diversity_better_bundle:vacuum",
	"diversity_better_bundle:selective_vacuum",
	"diversity_better_bundle:refill",
	"diversity_better_bundle:capacity",
	"minecraft:binding_curse",
	"minecraft:vanishing_curse",
	"luminous_nether:soul_cleave"
	
	
		]);
});




 //ARMOUR--------------------------------------------------------------------------------
//aqua affinity
/* ServerEvents.recipes(event => {
  event.shaped(
    Item.of('minecraft:enchanted_book', {
      StoredEnchantments: [
        { id: 'minecraft:aqua_affinity', lvl: 1 }
      ]
    }),
    [
      'AOA',
      'RBR',
      'AOA'
    ],
    {
      A: 'vital_herbs:aura_crystal',
      B: 'minecraft:book',
	  R: 'hexalia:nautilite',
	  O: 'undergarden:utherium_crystal'
    }
  );
}); */

//Blast Protection
/* ServerEvents.recipes(event => {
  event.shaped(
    Item.of('minecraft:enchanted_book', {
      StoredEnchantments: [
        { id: 'minecraft:blast_protection', lvl: 3 }
      ]
    }),
    [
      'AOA',
      'RBR',
      'AOA'
    ],
    {
      A: 'vital_herbs:aura_crystal',
      B: 'minecraft:book',
	  R: 'alchemists_garden:creep_orchid_bundle',
	  O: 'aether:zanite_gemstone'
    }
  );

}); */


//Swords------------------------------------------------------------------
//smite
/* ServerEvents.recipes(event => {
  // Single-enchant enchanted book (Smite IV)
  event.shaped(
    Item.of('minecraft:enchanted_book', {
      StoredEnchantments: [
        { id: 'minecraft:smite', lvl: 4 }
      ]
    }),
    [
      'AOA',
      'RBR',
      'AOA'
    ],
    {
      A: 'vital_herbs:aura_crystal',
      B: 'minecraft:book',
	  R: 'rootsclassic:midnight_bloom',
	  O: 'aether:enchanted_gravitite'
    }
  );
   // Single-enchant enchanted book (Smite I)
   event.shaped(
    Item.of('minecraft:enchanted_book', {
      StoredEnchantments: [
        { id: 'minecraft:smite', lvl: 1 }
      ]
    }),
    [
      'AOA',
      'RBR',
      'AOA'
    ],
    {
      A: 'vital_herbs:aura_crystal',
      B: 'minecraft:book',
	  R: 'minecraft:wither_rose',
	  O: 'aether:enchanted_gravitite'
    }
  );
}); */