supersaiyansubtlety

EnchantmentHelper#generateEnchantments.java

Nov 30th, 2020
993
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public static List<EnchantmentLevelEntry> generateEnchantments(Random random, ItemStack stack, int level, boolean treasureAllowed) {
  2.       List<EnchantmentLevelEntry> list = Lists.newArrayList();
  3.       Item item = stack.getItem();
  4.       int i = item.getEnchantability();
  5.       if (i <= 0) {
  6.          return list;
  7.       } else {
  8.          level += 1 + random.nextInt(i / 4 + 1) + random.nextInt(i / 4 + 1);
  9.          float f = (random.nextFloat() + random.nextFloat() - 1.0F) * 0.15F;
  10.          level = MathHelper.clamp(Math.round((float)level + (float)level * f), 1, Integer.MAX_VALUE);
  11.          List<EnchantmentLevelEntry> list2 = getPossibleEntries(level, stack, treasureAllowed);
  12.          if (!list2.isEmpty()) {
  13.             list.add(WeightedPicker.getRandom(random, list2));
  14.  
  15.             while(random.nextInt(50) <= level) {
  16.                removeConflicts(list2, (EnchantmentLevelEntry)Util.getLast(list));
  17.                if (list2.isEmpty()) {
  18.                   break;
  19.                }
  20.  
  21.                list.add(WeightedPicker.getRandom(random, list2));
  22.                level /= 2;
  23.             }
  24.          }
  25.  
  26.          return list;
  27.       }
  28.    }
RAW Paste Data