ItemTool .java

net.minecraft.item.ItemTool (class): members: efficiencyOnProperMaterial, effectiveBlocks, getToolMaterial, damageVsEntity, toolMaterial, getIsRepairable.

net.minecraft.itemclass107 linescommonextends Item3.3 KB

API Surface (9)

float getStrVsBlock(ItemStack stack, Block state)
boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker)
boolean onBlockDestroyed(ItemStack stack, World worldIn, Block blockIn, BlockPos pos, EntityLivingBase playerIn)
boolean isFull3D()
Item.ToolMaterial getToolMaterial()
int getItemEnchantability()
String getToolMaterialName()
boolean getIsRepairable(ItemStack toRepair, ItemStack repair)
Multimap<String, AttributeModifier> getItemAttributeModifiers()

Fields & Constants (4)

effectiveBlocks
efficiencyOnProperMaterial
damageVsEntity
toolMaterial

String literals (1)

"Tool modifier"

Full Source

ItemTool.java107 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.item;
2
3
import com.google.common.collect.Multimap;
4
import java.util.Set;
5
import net.minecraft.block.Block;
6
import net.minecraft.creativetab.CreativeTabs;
7
import net.minecraft.entity.EntityLivingBase;
8
import net.minecraft.entity.SharedMonsterAttributes;
9
import net.minecraft.entity.ai.attributes.AttributeModifier;
10
import net.minecraft.util.BlockPos;
11
import net.minecraft.world.World;
12
13
public class ItemTool extends Item
14
{
15
    private Set<Block> effectiveBlocks;
16
    protected float efficiencyOnProperMaterial = 4.0F;
17
18
    /** Damage versus entities. */
19
    private float damageVsEntity;
20
21
    /** The material this tool is made from. */
22
    protected Item.ToolMaterial toolMaterial;
23
24
    protected ItemTool(float attackDamage, Item.ToolMaterial material, Set<Block> effectiveBlocks)
25
    {
26
        this.toolMaterial = material;
27
        this.effectiveBlocks = effectiveBlocks;
28
        this.maxStackSize = 1;
29
        this.setMaxDamage(material.getMaxUses());
30
        this.efficiencyOnProperMaterial = material.getEfficiencyOnProperMaterial();
31
        this.damageVsEntity = attackDamage + material.getDamageVsEntity();
32
        this.setCreativeTab(CreativeTabs.tabTools);
33
    }
34
35
    public float getStrVsBlock(ItemStack stack, Block state)
36
    {
37
        return this.effectiveBlocks.contains(state) ? this.efficiencyOnProperMaterial : 1.0F;
38
    }
39
40
    /**
41
     * Current implementations of this method in child classes do not use the entry argument beside ev. They just raise
42
     * the damage on the stack.
43
     */
44
    public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker)
45
    {
46
        stack.damageItem(2, attacker);
47
        return true;
48
    }
49
50
    /**
51
     * Called when a Block is destroyed using this Item. Return true to trigger the "Use Item" statistic.
52
     */
53
    public boolean onBlockDestroyed(ItemStack stack, World worldIn, Block blockIn, BlockPos pos, EntityLivingBase playerIn)
54
    {
55
        if ((double)blockIn.getBlockHardness(worldIn, pos) != 0.0D)
56
        {
57
            stack.damageItem(1, playerIn);
58
        }
59
60
        return true;
61
    }
62
63
    /**
64
     * Returns True is the item is renderer in full 3D when hold.
65
     */
66
    public boolean isFull3D()
67
    {
68
        return true;
69
    }
70
71
    public Item.ToolMaterial getToolMaterial()
72
    {
73
        return this.toolMaterial;
74
    }
75
76
    /**
77
     * Return the enchantability factor of the item, most of the time is based on material.
78
     */
79
    public int getItemEnchantability()
80
    {
81
        return this.toolMaterial.getEnchantability();
82
    }
83
84
    /**
85
     * Return the name for this tool's material.
86
     */
87
    public String getToolMaterialName()
88
    {
89
        return this.toolMaterial.toString();
90
    }
91
92
    /**
93
     * Return whether this item is repairable in an anvil.
94
     */
95
    public boolean getIsRepairable(ItemStack toRepair, ItemStack repair)
96
    {
97
        return this.toolMaterial.getRepairItem() == repair.getItem() ? true : super.getIsRepairable(toRepair, repair);
98
    }
99
100
    public Multimap<String, AttributeModifier> getItemAttributeModifiers()
101
    {
102
        Multimap<String, AttributeModifier> multimap = super.getItemAttributeModifiers();
103
        multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(itemModifierUUID, "Tool modifier", (double)this.damageVsEntity, 0));
104
        return multimap;
105
    }
106
}
107

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