EnchantmentDamage .java

net.minecraft.enchantment.EnchantmentDamage (class, 118 lines): members: thresholdEnchantability, calcDamageByCreature, levelEnchantability, damageType.

net.minecraft.enchantmentclass118 linescommonextends Enchantment4.0 KB

API Surface (8)

int getMinEnchantability(int enchantmentLevel)
int getMaxEnchantability(int enchantmentLevel)
int getMaxLevel()
float calcDamageByCreature(int level, EnumCreatureAttribute creatureType)
String getName()
boolean canApplyTogether(Enchantment ench)
boolean canApply(ItemStack stack)
void onEntityDamaged(EntityLivingBase user, Entity target, int level)

Fields & Constants (5)

protectionName
baseEnchantability
levelEnchantability
thresholdEnchantability
damageType

String literals (3)

"undead"
"arthropods"
"enchantment.damage."

Full Source

EnchantmentDamage.java118 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.enchantment;
2
3
import net.minecraft.entity.Entity;
4
import net.minecraft.entity.EntityLivingBase;
5
import net.minecraft.entity.EnumCreatureAttribute;
6
import net.minecraft.item.ItemAxe;
7
import net.minecraft.item.ItemStack;
8
import net.minecraft.potion.Potion;
9
import net.minecraft.potion.PotionEffect;
10
import net.minecraft.util.ResourceLocation;
11
12
public class EnchantmentDamage extends Enchantment
13
{
14
    /** Holds the name to be translated of each protection type. */
15
    private static final String[] protectionName = new String[] {"all", "undead", "arthropods"};
16
17
    /**
18
     * Holds the base factor of enchantability needed to be able to use the enchant.
19
     */
20
    private static final int[] baseEnchantability = new int[] {1, 5, 5};
21
22
    /**
23
     * Holds how much each level increased the enchantability factor to be able to use this enchant.
24
     */
25
    private static final int[] levelEnchantability = new int[] {11, 8, 8};
26
27
    /**
28
     * Used on the formula of base enchantability, this is the 'window' factor of values to be able to use thing
29
     * enchant.
30
     */
31
    private static final int[] thresholdEnchantability = new int[] {20, 20, 20};
32
33
    /**
34
     * Defines the type of damage of the enchantment, 0 = all, 1 = undead, 3 = arthropods
35
     */
36
    public final int damageType;
37
38
    public EnchantmentDamage(int enchID, ResourceLocation enchName, int enchWeight, int classification)
39
    {
40
        super(enchID, enchName, enchWeight, EnumEnchantmentType.WEAPON);
41
        this.damageType = classification;
42
    }
43
44
    /**
45
     * Returns the minimal value of enchantability needed on the enchantment level passed.
46
     */
47
    public int getMinEnchantability(int enchantmentLevel)
48
    {
49
        return baseEnchantability[this.damageType] + (enchantmentLevel - 1) * levelEnchantability[this.damageType];
50
    }
51
52
    /**
53
     * Returns the maximum value of enchantability nedded on the enchantment level passed.
54
     */
55
    public int getMaxEnchantability(int enchantmentLevel)
56
    {
57
        return this.getMinEnchantability(enchantmentLevel) + thresholdEnchantability[this.damageType];
58
    }
59
60
    /**
61
     * Returns the maximum level that the enchantment can have.
62
     */
63
    public int getMaxLevel()
64
    {
65
        return 5;
66
    }
67
68
    /**
69
     * Calculates the additional damage that will be dealt by an item with this enchantment. This alternative to
70
     * calcModifierDamage is sensitive to the targets EnumCreatureAttribute.
71
     */
72
    public float calcDamageByCreature(int level, EnumCreatureAttribute creatureType)
73
    {
74
        return this.damageType == 0 ? (float)level * 1.25F : (this.damageType == 1 && creatureType == EnumCreatureAttribute.UNDEAD ? (float)level * 2.5F : (this.damageType == 2 && creatureType == EnumCreatureAttribute.ARTHROPOD ? (float)level * 2.5F : 0.0F));
75
    }
76
77
    /**
78
     * Return the name of key in translation table of this enchantment.
79
     */
80
    public String getName()
81
    {
82
        return "enchantment.damage." + protectionName[this.damageType];
83
    }
84
85
    /**
86
     * Determines if the enchantment passed can be applyied together with this enchantment.
87
     */
88
    public boolean canApplyTogether(Enchantment ench)
89
    {
90
        return !(ench instanceof EnchantmentDamage);
91
    }
92
93
    /**
94
     * Determines if this enchantment can be applied to a specific ItemStack.
95
     */
96
    public boolean canApply(ItemStack stack)
97
    {
98
        return stack.getItem() instanceof ItemAxe ? true : super.canApply(stack);
99
    }
100
101
    /**
102
     * Called whenever a mob is damaged with an item that has this enchantment on it.
103
     */
104
    public void onEntityDamaged(EntityLivingBase user, Entity target, int level)
105
    {
106
        if (target instanceof EntityLivingBase)
107
        {
108
            EntityLivingBase entitylivingbase = (EntityLivingBase)target;
109
110
            if (this.damageType == 2 && entitylivingbase.getCreatureAttribute() == EnumCreatureAttribute.ARTHROPOD)
111
            {
112
                int i = 20 + user.getRNG().nextInt(10 * level);
113
                entitylivingbase.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, i, 3));
114
            }
115
        }
116
    }
117
}
118

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