/**
   * Returns the enchantability of itemstack, it's uses a singular formula for each index (2nd
   * parameter: 0, 1 and 2), cutting to the max enchantability power of the table (3rd parameter)
   */
  public static int calcItemStackEnchantability(
      Random par0Random, int par1, int par2, ItemStack par3ItemStack) {
    Item item = par3ItemStack.getItem();
    int k = item.getItemEnchantability();

    if (k <= 0) {
      return 0;
    } else {
      if (par2 > 15) {
        par2 = 15;
      }

      int l = par0Random.nextInt(8) + 1 + (par2 >> 1) + par0Random.nextInt(par2 + 1);
      return par1 == 0 ? Math.max(l / 3, 1) : (par1 == 1 ? l * 2 / 3 + 1 : Math.max(l, par2 * 2));
    }
  }
  /**
   * Returns the enchantability of itemstack, it's uses a singular formula for each index (2nd
   * parameter: 0, 1 and 2), cutting to the max enchantability power of the table (3rd parameter)
   */
  public static int calcItemStackEnchantability(
      Random p_77514_0_, int p_77514_1_, int p_77514_2_, ItemStack p_77514_3_) {
    Item item = p_77514_3_.getItem();
    int k = item.getItemEnchantability(p_77514_3_);

    if (k <= 0) {
      return 0;
    } else {
      if (p_77514_2_ > 15) {
        p_77514_2_ = 15;
      }

      int l = p_77514_0_.nextInt(8) + 1 + (p_77514_2_ >> 1) + p_77514_0_.nextInt(p_77514_2_ + 1);
      return p_77514_1_ == 0
          ? Math.max(l / 3, 1)
          : (p_77514_1_ == 1 ? l * 2 / 3 + 1 : Math.max(l, p_77514_2_ * 2));
    }
  }
Example #3
0
  public void updateEnchantmentOptions() {
    int numoptions = slotEnchantment.size();
    slotEnchantment.clear();

    ItemStack toolstack = getSlot(0).getStack();
    if (toolstack == null) {
      percentscrolled = 0;
      return;
    }

    boolean validate = NEIClientConfig.validateEnchantments();

    Item item = toolstack.getItem();
    int enchantablity = item.getItemEnchantability();
    if (enchantablity == 0 && validate) {
      percentscrolled = 0;
      return;
    }

    for (Enchantment e : Enchantment.enchantmentsList) {
      if (e == null || e.type == null || (!e.type.canEnchantItem(item) && validate)) {
        continue;
      }
      int state = 0;
      int level = -1;
      if (NEIServerUtils.stackHasEnchantment(toolstack, e.effectId)) {
        state = 2;
        level = NEIServerUtils.getEnchantmentLevel(toolstack, e.effectId);
      } else if (NEIServerUtils.doesEnchantmentConflict(
              NEIServerUtils.getEnchantments(toolstack), e)
          && validate) {
        state = 1;
      }
      slotEnchantment.add(new EnchantmentHash(e, state, level));
    }
    if (numoptions != slotEnchantment.size()) {
      percentscrolled = 0;
    }
  }
  /**
   * Create a list of random EnchantmentData (enchantments) that can be added together to the
   * ItemStack, the 3rd parameter is the total enchantability level.
   */
  public static List buildEnchantmentList(Random p_77513_0_, ItemStack p_77513_1_, int p_77513_2_) {
    Item item = p_77513_1_.getItem();
    int j = item.getItemEnchantability(p_77513_1_);

    if (j <= 0) {
      return null;
    } else {
      j /= 2;
      j = 1 + p_77513_0_.nextInt((j >> 1) + 1) + p_77513_0_.nextInt((j >> 1) + 1);
      int k = j + p_77513_2_;
      float f = (p_77513_0_.nextFloat() + p_77513_0_.nextFloat() - 1.0F) * 0.15F;
      int l = (int) ((float) k * (1.0F + f) + 0.5F);

      if (l < 1) {
        l = 1;
      }

      ArrayList arraylist = null;
      Map map = mapEnchantmentData(l, p_77513_1_);

      if (map != null && !map.isEmpty()) {
        EnchantmentData enchantmentdata =
            (EnchantmentData) WeightedRandom.getRandomItem(p_77513_0_, map.values());

        if (enchantmentdata != null) {
          arraylist = new ArrayList();
          arraylist.add(enchantmentdata);

          for (int i1 = l; p_77513_0_.nextInt(50) <= i1; i1 >>= 1) {
            Iterator iterator = map.keySet().iterator();

            while (iterator.hasNext()) {
              Integer integer = (Integer) iterator.next();
              boolean flag = true;
              Iterator iterator1 = arraylist.iterator();

              while (true) {
                if (iterator1.hasNext()) {
                  EnchantmentData enchantmentdata1 = (EnchantmentData) iterator1.next();

                  Enchantment e1 = enchantmentdata1.enchantmentobj;
                  Enchantment e2 = Enchantment.enchantmentsList[integer.intValue()];
                  if (e1.canApplyTogether(e2)
                      && e2.canApplyTogether(
                          e1)) // Forge BugFix: Let Both enchantments veto being together
                  {
                    continue;
                  }

                  flag = false;
                }

                if (!flag) {
                  iterator.remove();
                }

                break;
              }
            }

            if (!map.isEmpty()) {
              EnchantmentData enchantmentdata2 =
                  (EnchantmentData) WeightedRandom.getRandomItem(p_77513_0_, map.values());
              arraylist.add(enchantmentdata2);
            }
          }
        }
      }

      return arraylist;
    }
  }
  /**
   * Create a list of random EnchantmentData (enchantments) that can be added together to the
   * ItemStack, the 3rd parameter is the total enchantability level.
   */
  public static List buildEnchantmentList(Random par0Random, ItemStack par1ItemStack, int par2) {
    Item item = par1ItemStack.getItem();
    int j = item.getItemEnchantability();

    if (j <= 0) {
      return null;
    } else {
      j /= 2;
      j = 1 + par0Random.nextInt((j >> 1) + 1) + par0Random.nextInt((j >> 1) + 1);
      int k = j + par2;
      float f = (par0Random.nextFloat() + par0Random.nextFloat() - 1.0F) * 0.15F;
      int l = (int) ((float) k * (1.0F + f) + 0.5F);

      if (l < 1) {
        l = 1;
      }

      ArrayList arraylist = null;
      Map map = mapEnchantmentData(l, par1ItemStack);

      if (map != null && !map.isEmpty()) {
        EnchantmentData enchantmentdata =
            (EnchantmentData) WeightedRandom.getRandomItem(par0Random, map.values());

        if (enchantmentdata != null) {
          arraylist = new ArrayList();
          arraylist.add(enchantmentdata);

          for (int i1 = l; par0Random.nextInt(50) <= i1; i1 >>= 1) {
            Iterator iterator = map.keySet().iterator();

            while (iterator.hasNext()) {
              Integer integer = (Integer) iterator.next();
              boolean flag = true;
              Iterator iterator1 = arraylist.iterator();

              while (true) {
                if (iterator1.hasNext()) {
                  EnchantmentData enchantmentdata1 = (EnchantmentData) iterator1.next();

                  if (enchantmentdata1.enchantmentobj.canApplyTogether(
                      Enchantment.enchantmentsList[integer.intValue()])) {
                    continue;
                  }

                  flag = false;
                }

                if (!flag) {
                  iterator.remove();
                }

                break;
              }
            }

            if (!map.isEmpty()) {
              EnchantmentData enchantmentdata2 =
                  (EnchantmentData) WeightedRandom.getRandomItem(par0Random, map.values());
              arraylist.add(enchantmentdata2);
            }
          }
        }
      }

      return arraylist;
    }
  }