Combine items with Enchanted books with higher level than vanilla cap

Discussion in 'Spigot Discussion' started by Coderzz, Jun 20, 2021.

  1. I tried to google for more than 15 day and still haven't got any way to combine level 10 enchants to my tools. Just like the screenshot attached.

    *The Enchanted Book there is POWER 10

    If you can help it'll we very helpful.
    Thanks.
     

    Attached Files:

    #1 Coderzz, Jun 20, 2021
    Last edited: Jun 21, 2021
  2. It seems to make an enchantment book with a plugin.
     
    • Like Like x 1
  3. Code (Java):
    package me.coderzz.mobsdropoploot;

    import org.bukkit.Material;
    import org.bukkit.enchantments.Enchantment;
    import org.bukkit.entity.*;
    import org.bukkit.entity.Creeper;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDeathEvent;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.inventory.meta.PotionMeta;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;

    import java.util.ArrayList;
    import java.util.Random;

    public class Tier_2_Loot implements Listener {
        @EventHandler
        public void MobKill(EntityDeathEvent mob) {

            ArrayList<PotionEffectType> RandomPotionEffects = new ArrayList<>();
            RandomPotionEffects.add(PotionEffectType.REGENERATION);
            RandomPotionEffects.add(PotionEffectType.DAMAGE_RESISTANCE);   // OVERALL RESISTANCE
            RandomPotionEffects.add(PotionEffectType.INCREASE_DAMAGE);
            RandomPotionEffects.add(PotionEffectType.FIRE_RESISTANCE);
            RandomPotionEffects.add(PotionEffectType.ABSORPTION);
            RandomPotionEffects.add(PotionEffectType.SPEED);
            RandomPotionEffects.add(PotionEffectType.FAST_DIGGING);        // Haste
            RandomPotionEffects.add(PotionEffectType.JUMP);                //JUMP BOOST
            RandomPotionEffects.add(PotionEffectType.WATER_BREATHING);


            ArrayList<Enchantment> Enchants = new ArrayList<>();
            Enchants.add(Enchantment.PROTECTION_ENVIRONMENTAL); // PROTECTION
            Enchants.add(Enchantment.DAMAGE_ALL);               // SHARPNESS
            Enchants.add(Enchantment.KNOCKBACK);                // KNOCKBACK
            Enchants.add(Enchantment.DURABILITY);               // UNBREAKING
            Enchants.add(Enchantment.FIRE_ASPECT);              // FIRE_ASPECT
            Enchants.add(Enchantment.DAMAGE_UNDEAD);            // SMITE
            Enchants.add(Enchantment.LOOT_BONUS_MOBS);          // LOOTING
            Enchants.add(Enchantment.LOOT_BONUS_BLOCKS);        // FORTUNE
            Enchants.add(Enchantment.ARROW_FIRE);               // FLAME
            Enchants.add(Enchantment.THORNS);                   // THORNS
            Enchants.add(Enchantment.DIG_SPEED);                // EFFICIENCY
            Enchants.add(Enchantment.ARROW_DAMAGE);             // POWER
            Enchants.add(Enchantment.ARROW_KNOCKBACK);          // PUNCH
            Enchants.add(Enchantment.ARROW_INFINITE);           // INFINITY

            Random random_enchant = new Random();
            int randomEnchantInt = random_enchant.nextInt(Enchants.size());

            ArrayList<ItemStack> Tier_2 = new ArrayList<>();


            ItemStack RandomEnchantedBook = new ItemStack(Material.ENCHANTED_BOOK, 1);
            ItemMeta RandomEnchantedBookMeta = RandomEnchantedBook.getItemMeta();
            RandomEnchantedBookMeta.addEnchant(Enchants.get(randomEnchantInt), 10, true);
            RandomEnchantedBook.setItemMeta(RandomEnchantedBookMeta);

            Random random_diamonds = new Random();
            int randomDiamondInt = random_diamonds.nextInt(5);

            Random random_potions = new Random();
            int randomPotionEffectInt = random_potions.nextInt(RandomPotionEffects.size());

            ItemStack RandomPotion = new ItemStack(Material.POTION);
            PotionMeta meta = (PotionMeta) RandomPotion.getItemMeta();
            meta.addCustomEffect(new PotionEffect(RandomPotionEffects.get(randomPotionEffectInt), 3600, 5), true);
            RandomPotion.setItemMeta(meta);

            Tier_2.add(RandomEnchantedBook);
            Tier_2.add(new ItemStack(Material.DIAMOND_BLOCK, randomDiamondInt));
            Tier_2.add(new ItemStack(Material.NETHERITE_BLOCK, 1));
            Tier_2.add(new ItemStack(Material.IRON_BLOCK, randomDiamondInt));
            Tier_2.add(new ItemStack(Material.GOLD_BLOCK, randomDiamondInt));
            Tier_2.add(new ItemStack(Material.LAPIS_BLOCK, randomDiamondInt));
            Tier_2.add(new ItemStack(Material.ENCHANTED_GOLDEN_APPLE, 1));
            Tier_2.add(new ItemStack(Material.GOLDEN_APPLE, randomDiamondInt));
            Tier_2.add(new ItemStack(Material.TOTEM_OF_UNDYING, 1));
            Tier_2.add(new ItemStack(RandomPotion));

            Random RandomOPLoot = new Random();
            int randomOPItem = RandomOPLoot.nextInt(Tier_2.size());

            LivingEntity KilledMob = mob.getEntity();

            if (KilledMob instanceof Zombie) {
                KilledMob.getLocation().getWorld().dropItemNaturally(KilledMob.getLocation(), Tier_2.get(randomOPItem));
            } else if (KilledMob instanceof Skeleton) {
                KilledMob.getLocation().getWorld().dropItemNaturally(KilledMob.getLocation(), Tier_2.get(randomOPItem));
            } else if (KilledMob instanceof Creeper) {
                KilledMob.getLocation().getWorld().dropItemNaturally(KilledMob.getLocation(), Tier_2.get(randomOPItem));
            } else if (KilledMob instanceof Enderman) {
                KilledMob.getLocation().getWorld().dropItemNaturally(KilledMob.getLocation(), Tier_2.get(randomOPItem));
                KilledMob.getLocation().getWorld().dropItemNaturally(KilledMob.getLocation(), new ItemStack(Material.ENDER_PEARL, 2));
            } else if (KilledMob instanceof Piglin) {
                KilledMob.getLocation().getWorld().dropItemNaturally(KilledMob.getLocation(), Tier_2.get(randomOPItem));
            } else if (KilledMob instanceof Witch) {
                KilledMob.getLocation().getWorld().dropItemNaturally(KilledMob.getLocation(), Tier_2.get(randomOPItem));
            }else if (KilledMob instanceof Cow) {
                KilledMob.getLocation().getWorld().dropItemNaturally(KilledMob.getLocation(), new ItemStack(Material.COOKED_BEEF, randomOPItem));
            }else if (KilledMob instanceof Pig) {
                KilledMob.getLocation().getWorld().dropItemNaturally(KilledMob.getLocation(), new ItemStack(Material.COOKED_PORKCHOP, randomOPItem));
            }else if (KilledMob instanceof Sheep) {
                KilledMob.getLocation().getWorld().dropItemNaturally(KilledMob.getLocation(), new ItemStack(Material.COOKED_MUTTON, randomOPItem));
            }else if (KilledMob instanceof Horse) {
                KilledMob.getLocation().getWorld().dropItemNaturally(KilledMob.getLocation(), new ItemStack(Material.LEATHER, randomOPItem));
            }else if (KilledMob instanceof Rabbit) {
                KilledMob.getLocation().getWorld().dropItemNaturally(KilledMob.getLocation(), new ItemStack(Material.RABBIT_HIDE, randomOPItem));
            }else if (KilledMob instanceof Donkey) {
                KilledMob.getLocation().getWorld().dropItemNaturally(KilledMob.getLocation(), new ItemStack(Material.LEATHER, randomOPItem));
            }
        }
    }
     
    I have made it so that on killing a mob it drops a random enchanted bookwith level 10 enchant on it.

    I am unable to figure out how to combine that same book with a tool or weapon.

    Hope you Understand.
     
    #3 Coderzz, Jun 21, 2021
    Last edited: Jun 21, 2021
  4. Are you saying that the enchantment book doesn't combine with an anvil?
     
  5. You could do a total override of enchanting using AnvilPrepareEvent so that it ultimately applies the right enchantment level.
     
  6. It isn't combining with items in anvil.

    ex) DIAMOND_SWORD + SHARPNESS doesn't give any result
     
  7. It's great. Thanks for sharing.
     
  8. Dosent it give a level 5 sharpness sword ?