EnchantmentDurability .java

net.minecraft.enchantment.EnchantmentDurability (class): members: negateDamage, canApply, getMaxEnchantability, getMinEnchantability, getMaxLevel.

net.minecraft.enchantmentclass58 linescommonextends Enchantment1.8 KB

API Surface (5)

int getMinEnchantability(int enchantmentLevel)
int getMaxEnchantability(int enchantmentLevel)
int getMaxLevel()
boolean canApply(ItemStack stack)
boolean negateDamage(ItemStack p_92097_0_, int p_92097_1_, Random p_92097_2_)

String literals (1)

"durability"

Code Graph: Dependencies (4)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

EnchantmentDurability.java58 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.enchantment;
2
3
import java.util.Random;
4
import net.minecraft.item.ItemArmor;
5
import net.minecraft.item.ItemStack;
6
import net.minecraft.util.ResourceLocation;
7
8
public class EnchantmentDurability extends Enchantment
9
{
10
    protected EnchantmentDurability(int enchID, ResourceLocation enchName, int enchWeight)
11
    {
12
        super(enchID, enchName, enchWeight, EnumEnchantmentType.BREAKABLE);
13
        this.setName("durability");
14
    }
15
16
    /**
17
     * Returns the minimal value of enchantability needed on the enchantment level passed.
18
     */
19
    public int getMinEnchantability(int enchantmentLevel)
20
    {
21
        return 5 + (enchantmentLevel - 1) * 8;
22
    }
23
24
    /**
25
     * Returns the maximum value of enchantability nedded on the enchantment level passed.
26
     */
27
    public int getMaxEnchantability(int enchantmentLevel)
28
    {
29
        return super.getMinEnchantability(enchantmentLevel) + 50;
30
    }
31
32
    /**
33
     * Returns the maximum level that the enchantment can have.
34
     */
35
    public int getMaxLevel()
36
    {
37
        return 3;
38
    }
39
40
    /**
41
     * Determines if this enchantment can be applied to a specific ItemStack.
42
     */
43
    public boolean canApply(ItemStack stack)
44
    {
45
        return stack.isItemStackDamageable() ? true : super.canApply(stack);
46
    }
47
48
    /**
49
     * Used by ItemStack.attemptDamageItem. Randomly determines if a point of damage should be negated using the
50
     * enchantment level (par1). If the ItemStack is Armor then there is a flat 60% chance for damage to be negated no
51
     * matter the enchantment level, otherwise there is a 1-(par/1) chance for damage to be negated.
52
     */
53
    public static boolean negateDamage(ItemStack p_92097_0_, int p_92097_1_, Random p_92097_2_)
54
    {
55
        return p_92097_0_.getItem() instanceof ItemArmor && p_92097_2_.nextFloat() < 0.6F ? false : p_92097_2_.nextInt(p_92097_1_ + 1) > 0;
56
    }
57
}
58

Deobfuscated MCP 1.8.9 source of EnchantmentDurability from Marcelektro/MavenMCP-1.8.9 (net/minecraft/enchantment/EnchantmentDurability.java), stored verbatim.