Java Code Examples for net.minecraft.item.Item.getItemEnchantability()

The following are Jave code examples for showing how to use getItemEnchantability() of the net.minecraft.item.Item class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: BaseClient   File: EnchantmentHelper.java   Source Code and License Vote up 6 votes
/**
 * 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 i = item.getItemEnchantability();

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

        int j = 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(j / 3, 1) : (p_77514_1_ == 1 ? j * 2 / 3 + 1 : Math.max(j, p_77514_2_ * 2));
    }
}
 
Example 2
Project: BaseClient   File: EnchantmentHelper.java   Source Code and License Vote up 6 votes
/**
 * 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 i = item.getItemEnchantability();

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

        int j = 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(j / 3, 1) : (p_77514_1_ == 1 ? j * 2 / 3 + 1 : Math.max(j, p_77514_2_ * 2));
    }
}
 
Example 3
Project: Backmemed   File: EnchantmentHelper.java   Source Code and License Vote up 6 votes
/**
 * Returns the enchantability of itemstack, using a separate calculation for each enchantNum (0, 1 or 2), cutting to
 * the max enchantability power of the table, which is locked to a max of 15.
 */
public static int calcItemStackEnchantability(Random rand, int enchantNum, int power, ItemStack stack)
{
    Item item = stack.getItem();
    int i = item.getItemEnchantability();

    if (i <= 0)
    {
        return 0;
    }
    else
    {
        if (power > 15)
        {
            power = 15;
        }

        int j = rand.nextInt(8) + 1 + (power >> 1) + rand.nextInt(power + 1);
        return enchantNum == 0 ? Math.max(j / 3, 1) : (enchantNum == 1 ? j * 2 / 3 + 1 : Math.max(j, power * 2));
    }
}
 
Example 4
Project: CustomWorldGen   File: EnchantmentHelper.java   Source Code and License Vote up 6 votes
/**
 * Returns the enchantability of itemstack, using a separate calculation for each enchantNum (0, 1 or 2), cutting to
 * the max enchantability power of the table, which is locked to a max of 15.
 */
public static int calcItemStackEnchantability(Random rand, int enchantNum, int power, ItemStack stack)
{
    Item item = stack.getItem();
    int i = item.getItemEnchantability(stack);

    if (i <= 0)
    {
        return 0;
    }
    else
    {
        if (power > 15)
        {
            power = 15;
        }

        int j = rand.nextInt(8) + 1 + (power >> 1) + rand.nextInt(power + 1);
        return enchantNum == 0 ? Math.max(j / 3, 1) : (enchantNum == 1 ? j * 2 / 3 + 1 : Math.max(j, power * 2));
    }
}
 
Example 5
Project: Backmemed   File: EnchantmentHelper.java   Source Code and License Vote up 5 votes
public static List<EnchantmentData> buildEnchantmentList(Random randomIn, ItemStack itemStackIn, int p_77513_2_, boolean allowTreasure)
{
    List<EnchantmentData> list = Lists.<EnchantmentData>newArrayList();
    Item item = itemStackIn.getItem();
    int i = item.getItemEnchantability();

    if (i <= 0)
    {
        return list;
    }
    else
    {
        p_77513_2_ = p_77513_2_ + 1 + randomIn.nextInt(i / 4 + 1) + randomIn.nextInt(i / 4 + 1);
        float f = (randomIn.nextFloat() + randomIn.nextFloat() - 1.0F) * 0.15F;
        p_77513_2_ = MathHelper.clamp(Math.round((float)p_77513_2_ + (float)p_77513_2_ * f), 1, Integer.MAX_VALUE);
        List<EnchantmentData> list1 = getEnchantmentDatas(p_77513_2_, itemStackIn, allowTreasure);

        if (!list1.isEmpty())
        {
            list.add(WeightedRandom.getRandomItem(randomIn, list1));

            while (randomIn.nextInt(50) <= p_77513_2_)
            {
                removeIncompatible(list1, (EnchantmentData)Util.getLastElement(list));

                if (list1.isEmpty())
                {
                    break;
                }

                list.add(WeightedRandom.getRandomItem(randomIn, list1));
                p_77513_2_ /= 2;
            }
        }

        return list;
    }
}
 
Example 6
Project: CustomWorldGen   File: EnchantmentHelper.java   Source Code and License Vote up 5 votes
public static List<EnchantmentData> buildEnchantmentList(Random randomIn, ItemStack itemStackIn, int p_77513_2_, boolean allowTreasure)
{
    List<EnchantmentData> list = Lists.<EnchantmentData>newArrayList();
    Item item = itemStackIn.getItem();
    int i = item.getItemEnchantability(itemStackIn);

    if (i <= 0)
    {
        return list;
    }
    else
    {
        p_77513_2_ = p_77513_2_ + 1 + randomIn.nextInt(i / 4 + 1) + randomIn.nextInt(i / 4 + 1);
        float f = (randomIn.nextFloat() + randomIn.nextFloat() - 1.0F) * 0.15F;
        p_77513_2_ = MathHelper.clamp_int(Math.round((float)p_77513_2_ + (float)p_77513_2_ * f), 1, Integer.MAX_VALUE);
        List<EnchantmentData> list1 = getEnchantmentDatas(p_77513_2_, itemStackIn, allowTreasure);

        if (!list1.isEmpty())
        {
            list.add(WeightedRandom.getRandomItem(randomIn, list1));

            while (randomIn.nextInt(50) <= p_77513_2_)
            {
                removeIncompatible(list1, (EnchantmentData)Util.getLastElement(list));

                if (list1.isEmpty())
                {
                    break;
                }

                list.add(WeightedRandom.getRandomItem(randomIn, list1));
                p_77513_2_ /= 2;
            }
        }

        return list;
    }
}
 
Example 7
Project: BaseClient   File: EnchantmentHelper.java   Source Code and License Vote up 4 votes
public static List<EnchantmentData> buildEnchantmentList(Random randomIn, ItemStack itemStackIn, int p_77513_2_)
{
    Item item = itemStackIn.getItem();
    int i = item.getItemEnchantability();

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

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

        List<EnchantmentData> list = null;
        Map<Integer, EnchantmentData> map = mapEnchantmentData(k, itemStackIn);

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

            if (enchantmentdata != null)
            {
                list = Lists.<EnchantmentData>newArrayList();
                list.add(enchantmentdata);

                for (int l = k; randomIn.nextInt(50) <= l; l >>= 1)
                {
                    Iterator<Integer> iterator = map.keySet().iterator();

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

                        for (EnchantmentData enchantmentdata1 : list)
                        {
                            if (!enchantmentdata1.enchantmentobj.canApplyTogether(Enchantment.getEnchantmentById(integer.intValue())))
                            {
                                flag = false;
                                break;
                            }
                        }

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

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

        return list;
    }
}
 
Example 8
Project: BaseClient   File: EnchantmentHelper.java   Source Code and License Vote up 4 votes
public static List<EnchantmentData> buildEnchantmentList(Random randomIn, ItemStack itemStackIn, int p_77513_2_)
{
    Item item = itemStackIn.getItem();
    int i = item.getItemEnchantability();

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

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

        List<EnchantmentData> list = null;
        Map<Integer, EnchantmentData> map = mapEnchantmentData(k, itemStackIn);

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

            if (enchantmentdata != null)
            {
                list = Lists.<EnchantmentData>newArrayList();
                list.add(enchantmentdata);

                for (int l = k; randomIn.nextInt(50) <= l; l >>= 1)
                {
                    Iterator<Integer> iterator = map.keySet().iterator();

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

                        for (EnchantmentData enchantmentdata1 : list)
                        {
                            if (!enchantmentdata1.enchantmentobj.canApplyTogether(Enchantment.getEnchantmentById(integer.intValue())))
                            {
                                flag = false;
                                break;
                            }
                        }

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

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

        return list;
    }
}