Advertisement
supersaiyansubtlety

enchantement_calculations.java

Nov 30th, 2020
767
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. TradeOffers.SellEnchantedToolFactory toolFactory;
  2. try {
  3.     toolFactory = (TradeOffers.SellEnchantedToolFactory) tradeFactory;
  4. } catch(ClassCastException e) {
  5.     LOGGER.error("Enchanted ToolItem or ArmorItem does not have a SellEnchantedToolFactory! ");
  6.     return 0;
  7. }
  8.  
  9. int lvl = MAX_TOOL_ENCHANT_LVL;
  10.  
  11. int i = enchantedItem.getEnchantability();
  12. if (i <= 0) return 0;
  13. lvl += 1 + 2 * (i / 4 + 1);
  14. float f = 0.15F;
  15. lvl = Math.max(1, Math.round((float) lvl + (float) lvl * f));
  16. int numPossibleEnchants =  intLog(lvl, 2);
  17.  
  18. List<EnchantmentLevelEntry> possibleEntriesList = EnchantmentHelper.getPossibleEntries(lvl, enchantedStack, false);
  19. Set<EnchantmentLevelEntry> possibleEntriesSet = new HashSet<>(possibleEntriesList);
  20. if (lvl > MAX_TOOL_ENCHANT_LVL) {
  21.     return 0;
  22. }
  23.  
  24. for (Map.Entry<Enchantment, Integer> entry : enchantments) {
  25.     Enchantment enchantment = entry.getKey();
  26.     int actualLevel = entry.getValue();
  27.  
  28.     if (enchantment.isTreasure())
  29.         return 0;
  30.  
  31.     if (!possibleEntriesSet.contains(new EnchantmentLevelEntry(entry.getKey(), entry.getValue())))
  32.         return 0;
  33.  
  34.     return 0;
  35. }
  36.  
  37. int price = Math.min(toolFactory.basePrice + INDETERMINATE, 64);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement