ItemArmor .java

net.minecraft.item.ItemArmor (class): members: damageReduceAmount, dispenserBehavior, EMPTY_SLOT_NAMES, getArmorMaterial, maxDamageArray, ArmorMaterial.

net.minecraft.itemclass282 linescommonextends Item9.3 KB

API Surface (15)

ItemStack dispenseStack(IBlockSource source, ItemStack stack)
int getColorFromItemStack(ItemStack stack, int renderPass)
int getItemEnchantability()
ItemArmor.ArmorMaterial getArmorMaterial()
boolean hasColor(ItemStack stack)
int getColor(ItemStack stack)
void removeColor(ItemStack stack)
void setColor(ItemStack stack, int color)
boolean getIsRepairable(ItemStack toRepair, ItemStack repair)
ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
int getDurability(int armorType)
int getDamageReductionAmount(int armorType)
int getEnchantability()
Item getRepairItem()
String getName()

Fields & Constants (7)

maxDamageArray
EMPTY_SLOT_NAMES
dispenserBehavior
armorType
damageReduceAmount
renderIndex
material

String literals (12)

"minecraft:items/empty_armor_slot_helmet"
"minecraft:items/empty_armor_slot_chestplate"
"minecraft:items/empty_armor_slot_leggings"
"minecraft:items/empty_armor_slot_boots"
"display"
"color"
"Can\'t dye non-leather!"
"leather"
"chainmail"
"iron"
"gold"
"diamond"

Full Source

ItemArmor.java282 lines · MCP 1.8.9 · verbatimOriginal ↗
1
package net.minecraft.item;
2
3
import com.google.common.base.Predicates;
4
import java.util.List;
5
import net.minecraft.block.BlockDispenser;
6
import net.minecraft.creativetab.CreativeTabs;
7
import net.minecraft.dispenser.BehaviorDefaultDispenseItem;
8
import net.minecraft.dispenser.IBehaviorDispenseItem;
9
import net.minecraft.dispenser.IBlockSource;
10
import net.minecraft.entity.EntityLiving;
11
import net.minecraft.entity.EntityLivingBase;
12
import net.minecraft.entity.player.EntityPlayer;
13
import net.minecraft.init.Items;
14
import net.minecraft.nbt.NBTTagCompound;
15
import net.minecraft.util.AxisAlignedBB;
16
import net.minecraft.util.BlockPos;
17
import net.minecraft.util.EntitySelectors;
18
import net.minecraft.world.World;
19
20
public class ItemArmor extends Item
21
{
22
    /** Holds the 'base' maxDamage that each armorType have. */
23
    private static final int[] maxDamageArray = new int[] {11, 16, 15, 13};
24
    public static final String[] EMPTY_SLOT_NAMES = new String[] {"minecraft:items/empty_armor_slot_helmet", "minecraft:items/empty_armor_slot_chestplate", "minecraft:items/empty_armor_slot_leggings", "minecraft:items/empty_armor_slot_boots"};
25
    private static final IBehaviorDispenseItem dispenserBehavior = new BehaviorDefaultDispenseItem()
26
    {
27
        protected ItemStack dispenseStack(IBlockSource source, ItemStack stack)
28
        {
29
            BlockPos blockpos = source.getBlockPos().offset(BlockDispenser.getFacing(source.getBlockMetadata()));
30
            int i = blockpos.getX();
31
            int j = blockpos.getY();
32
            int k = blockpos.getZ();
33
            AxisAlignedBB axisalignedbb = new AxisAlignedBB((double)i, (double)j, (double)k, (double)(i + 1), (double)(j + 1), (double)(k + 1));
34
            List<EntityLivingBase> list = source.getWorld().<EntityLivingBase>getEntitiesWithinAABB(EntityLivingBase.class, axisalignedbb, Predicates.<EntityLivingBase> and (EntitySelectors.NOT_SPECTATING, new EntitySelectors.ArmoredMob(stack)));
35
36
            if (list.size() > 0)
37
            {
38
                EntityLivingBase entitylivingbase = (EntityLivingBase)list.get(0);
39
                int l = entitylivingbase instanceof EntityPlayer ? 1 : 0;
40
                int i1 = EntityLiving.getArmorPosition(stack);
41
                ItemStack itemstack = stack.copy();
42
                itemstack.stackSize = 1;
43
                entitylivingbase.setCurrentItemOrArmor(i1 - l, itemstack);
44
45
                if (entitylivingbase instanceof EntityLiving)
46
                {
47
                    ((EntityLiving)entitylivingbase).setEquipmentDropChance(i1, 2.0F);
48
                }
49
50
                --stack.stackSize;
51
                return stack;
52
            }
53
            else
54
            {
55
                return super.dispenseStack(source, stack);
56
            }
57
        }
58
    };
59
60
    /**
61
     * Stores the armor type: 0 is helmet, 1 is plate, 2 is legs and 3 is boots
62
     */
63
    public final int armorType;
64
65
    /** Holds the amount of damage that the armor reduces at full durability. */
66
    public final int damageReduceAmount;
67
68
    /**
69
     * Used on RenderPlayer to select the correspondent armor to be rendered on the player: 0 is cloth, 1 is chain, 2 is
70
     * iron, 3 is diamond and 4 is gold.
71
     */
72
    public final int renderIndex;
73
74
    /** The EnumArmorMaterial used for this ItemArmor */
75
    private final ItemArmor.ArmorMaterial material;
76
77
    public ItemArmor(ItemArmor.ArmorMaterial material, int renderIndex, int armorType)
78
    {
79
        this.material = material;
80
        this.armorType = armorType;
81
        this.renderIndex = renderIndex;
82
        this.damageReduceAmount = material.getDamageReductionAmount(armorType);
83
        this.setMaxDamage(material.getDurability(armorType));
84
        this.maxStackSize = 1;
85
        this.setCreativeTab(CreativeTabs.tabCombat);
86
        BlockDispenser.dispenseBehaviorRegistry.putObject(this, dispenserBehavior);
87
    }
88
89
    public int getColorFromItemStack(ItemStack stack, int renderPass)
90
    {
91
        if (renderPass > 0)
92
        {
93
            return 16777215;
94
        }
95
        else
96
        {
97
            int i = this.getColor(stack);
98
99
            if (i < 0)
100
            {
101
                i = 16777215;
102
            }
103
104
            return i;
105
        }
106
    }
107
108
    /**
109
     * Return the enchantability factor of the item, most of the time is based on material.
110
     */
111
    public int getItemEnchantability()
112
    {
113
        return this.material.getEnchantability();
114
    }
115
116
    /**
117
     * Return the armor material for this armor item.
118
     */
119
    public ItemArmor.ArmorMaterial getArmorMaterial()
120
    {
121
        return this.material;
122
    }
123
124
    /**
125
     * Return whether the specified armor ItemStack has a color.
126
     */
127
    public boolean hasColor(ItemStack stack)
128
    {
129
        return this.material != ItemArmor.ArmorMaterial.LEATHER ? false : (!stack.hasTagCompound() ? false : (!stack.getTagCompound().hasKey("display", 10) ? false : stack.getTagCompound().getCompoundTag("display").hasKey("color", 3)));
130
    }
131
132
    /**
133
     * Return the color for the specified armor ItemStack.
134
     */
135
    public int getColor(ItemStack stack)
136
    {
137
        if (this.material != ItemArmor.ArmorMaterial.LEATHER)
138
        {
139
            return -1;
140
        }
141
        else
142
        {
143
            NBTTagCompound nbttagcompound = stack.getTagCompound();
144
145
            if (nbttagcompound != null)
146
            {
147
                NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display");
148
149
                if (nbttagcompound1 != null && nbttagcompound1.hasKey("color", 3))
150
                {
151
                    return nbttagcompound1.getInteger("color");
152
                }
153
            }
154
155
            return 10511680;
156
        }
157
    }
158
159
    /**
160
     * Remove the color from the specified armor ItemStack.
161
     */
162
    public void removeColor(ItemStack stack)
163
    {
164
        if (this.material == ItemArmor.ArmorMaterial.LEATHER)
165
        {
166
            NBTTagCompound nbttagcompound = stack.getTagCompound();
167
168
            if (nbttagcompound != null)
169
            {
170
                NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display");
171
172
                if (nbttagcompound1.hasKey("color"))
173
                {
174
                    nbttagcompound1.removeTag("color");
175
                }
176
            }
177
        }
178
    }
179
180
    /**
181
     * Sets the color of the specified armor ItemStack
182
     */
183
    public void setColor(ItemStack stack, int color)
184
    {
185
        if (this.material != ItemArmor.ArmorMaterial.LEATHER)
186
        {
187
            throw new UnsupportedOperationException("Can\'t dye non-leather!");
188
        }
189
        else
190
        {
191
            NBTTagCompound nbttagcompound = stack.getTagCompound();
192
193
            if (nbttagcompound == null)
194
            {
195
                nbttagcompound = new NBTTagCompound();
196
                stack.setTagCompound(nbttagcompound);
197
            }
198
199
            NBTTagCompound nbttagcompound1 = nbttagcompound.getCompoundTag("display");
200
201
            if (!nbttagcompound.hasKey("display", 10))
202
            {
203
                nbttagcompound.setTag("display", nbttagcompound1);
204
            }
205
206
            nbttagcompound1.setInteger("color", color);
207
        }
208
    }
209
210
    /**
211
     * Return whether this item is repairable in an anvil.
212
     */
213
    public boolean getIsRepairable(ItemStack toRepair, ItemStack repair)
214
    {
215
        return this.material.getRepairItem() == repair.getItem() ? true : super.getIsRepairable(toRepair, repair);
216
    }
217
218
    /**
219
     * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer
220
     */
221
    public ItemStack onItemRightClick(ItemStack itemStackIn, World worldIn, EntityPlayer playerIn)
222
    {
223
        int i = EntityLiving.getArmorPosition(itemStackIn) - 1;
224
        ItemStack itemstack = playerIn.getCurrentArmor(i);
225
226
        if (itemstack == null)
227
        {
228
            playerIn.setCurrentItemOrArmor(i, itemStackIn.copy());
229
            itemStackIn.stackSize = 0;
230
        }
231
232
        return itemStackIn;
233
    }
234
235
    public static enum ArmorMaterial
236
    {
237
        LEATHER("leather", 5, new int[]{1, 3, 2, 1}, 15),
238
        CHAIN("chainmail", 15, new int[]{2, 5, 4, 1}, 12),
239
        IRON("iron", 15, new int[]{2, 6, 5, 2}, 9),
240
        GOLD("gold", 7, new int[]{2, 5, 3, 1}, 25),
241
        DIAMOND("diamond", 33, new int[]{3, 8, 6, 3}, 10);
242
243
        private final String name;
244
        private final int maxDamageFactor;
245
        private final int[] damageReductionAmountArray;
246
        private final int enchantability;
247
248
        private ArmorMaterial(String name, int maxDamage, int[] reductionAmounts, int enchantability)
249
        {
250
            this.name = name;
251
            this.maxDamageFactor = maxDamage;
252
            this.damageReductionAmountArray = reductionAmounts;
253
            this.enchantability = enchantability;
254
        }
255
256
        public int getDurability(int armorType)
257
        {
258
            return ItemArmor.maxDamageArray[armorType] * this.maxDamageFactor;
259
        }
260
261
        public int getDamageReductionAmount(int armorType)
262
        {
263
            return this.damageReductionAmountArray[armorType];
264
        }
265
266
        public int getEnchantability()
267
        {
268
            return this.enchantability;
269
        }
270
271
        public Item getRepairItem()
272
        {
273
            return this == LEATHER ? Items.leather : (this == CHAIN ? Items.iron_ingot : (this == GOLD ? Items.gold_ingot : (this == IRON ? Items.iron_ingot : (this == DIAMOND ? Items.diamond : null))));
274
        }
275
276
        public String getName()
277
        {
278
            return this.name;
279
        }
280
    }
281
}
282

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