EnchantmentThorns .java

net.minecraft.enchantment.EnchantmentThorns (class): members: func_92094_a, func_92095_b, onUserHurt, canApply, getMaxEnchantability, getMinEnchantability.

net.minecraft.enchantmentclass89 linescommonextends Enchantment2.6 KB

API Surface (7)

int getMinEnchantability(int enchantmentLevel)
int getMaxEnchantability(int enchantmentLevel)
int getMaxLevel()
boolean canApply(ItemStack stack)
void onUserHurt(EntityLivingBase user, Entity attacker, int level)
boolean func_92094_a(int p_92094_0_, Random p_92094_1_)
int func_92095_b(int p_92095_0_, Random p_92095_1_)

String literals (2)

"thorns"
"damage.thorns"

Full Source

EnchantmentThorns.java89 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.enchantment;
2
3
import java.util.Random;
4
import net.minecraft.entity.Entity;
5
import net.minecraft.entity.EntityLivingBase;
6
import net.minecraft.item.ItemArmor;
7
import net.minecraft.item.ItemStack;
8
import net.minecraft.util.DamageSource;
9
import net.minecraft.util.ResourceLocation;
10
11
public class EnchantmentThorns extends Enchantment
12
{
13
    public EnchantmentThorns(int p_i45764_1_, ResourceLocation p_i45764_2_, int p_i45764_3_)
14
    {
15
        super(p_i45764_1_, p_i45764_2_, p_i45764_3_, EnumEnchantmentType.ARMOR_TORSO);
16
        this.setName("thorns");
17
    }
18
19
    /**
20
     * Returns the minimal value of enchantability needed on the enchantment level passed.
21
     */
22
    public int getMinEnchantability(int enchantmentLevel)
23
    {
24
        return 10 + 20 * (enchantmentLevel - 1);
25
    }
26
27
    /**
28
     * Returns the maximum value of enchantability nedded on the enchantment level passed.
29
     */
30
    public int getMaxEnchantability(int enchantmentLevel)
31
    {
32
        return super.getMinEnchantability(enchantmentLevel) + 50;
33
    }
34
35
    /**
36
     * Returns the maximum level that the enchantment can have.
37
     */
38
    public int getMaxLevel()
39
    {
40
        return 3;
41
    }
42
43
    /**
44
     * Determines if this enchantment can be applied to a specific ItemStack.
45
     */
46
    public boolean canApply(ItemStack stack)
47
    {
48
        return stack.getItem() instanceof ItemArmor ? true : super.canApply(stack);
49
    }
50
51
    /**
52
     * Whenever an entity that has this enchantment on one of its associated items is damaged this method will be
53
     * called.
54
     */
55
    public void onUserHurt(EntityLivingBase user, Entity attacker, int level)
56
    {
57
        Random random = user.getRNG();
58
        ItemStack itemstack = EnchantmentHelper.getEnchantedItem(Enchantment.thorns, user);
59
60
        if (func_92094_a(level, random))
61
        {
62
            if (attacker != null)
63
            {
64
                attacker.attackEntityFrom(DamageSource.causeThornsDamage(user), (float)func_92095_b(level, random));
65
                attacker.playSound("damage.thorns", 0.5F, 1.0F);
66
            }
67
68
            if (itemstack != null)
69
            {
70
                itemstack.damageItem(3, user);
71
            }
72
        }
73
        else if (itemstack != null)
74
        {
75
            itemstack.damageItem(1, user);
76
        }
77
    }
78
79
    public static boolean func_92094_a(int p_92094_0_, Random p_92094_1_)
80
    {
81
        return p_92094_0_ <= 0 ? false : p_92094_1_.nextFloat() < 0.15F * (float)p_92094_0_;
82
    }
83
84
    public static int func_92095_b(int p_92095_0_, Random p_92095_1_)
85
    {
86
        return p_92095_0_ > 10 ? p_92095_0_ - 10 : 1 + p_92095_1_.nextInt(4);
87
    }
88
}
89

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