Java tutorial
/** * AbyssalCraft * Copyright 2012-2015 Shinoow * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.shinoow.abyssalcraft.common.items; import net.minecraft.block.Block; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.attributes.AttributeModifier; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; import net.minecraft.item.EnumAction; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemSword; import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.StatCollector; import net.minecraft.world.World; import com.google.common.collect.Multimap; import com.shinoow.abyssalcraft.common.util.EnumToolMaterialAC; public class ItemDreadiumSword extends ItemSword { private float weaponDamage; private final EnumToolMaterialAC toolMaterial; public ItemDreadiumSword(EnumToolMaterialAC dreadium) { super(ToolMaterial.valueOf("DREADIUM")); toolMaterial = dreadium; maxStackSize = 1; setMaxDamage(dreadium.getMaxUses()); weaponDamage = 4 + dreadium.getDamageVsEntity(); } @Override public String getItemStackDisplayName(ItemStack par1ItemStack) { return EnumChatFormatting.DARK_RED + StatCollector.translateToLocal(this.getUnlocalizedName() + ".name"); } /** * Returns the strength of the stack against a given block. 1.0F base, (Quality+1)*2 if correct blocktype, 1.5F if * sword */ @Override public float func_150893_a(ItemStack par1ItemStack, Block par2Block) { return par2Block != Blocks.web ? 1.5F : 15F; } /** * Current implementations of this method in child classes do not use the entry argument beside ev. They just raise * the damage on the stack. */ @Override public boolean hitEntity(ItemStack par1ItemStack, EntityLivingBase par2EntityLivingBase, EntityLivingBase par3EntityLivingBase) { par1ItemStack.damageItem(1, par3EntityLivingBase); return true; } @Override public boolean onBlockDestroyed(ItemStack par1ItemStack, World par2World, Block par3, int par4, int par5, int par6, EntityLivingBase par7EntityLivingBase) { if (par3.getBlockHardness(par2World, par4, par5, par6) != 0.0D) par1ItemStack.damageItem(1, par7EntityLivingBase); return true; } /** * Returns True is the item is renderer in full 3D when hold. */ @Override public boolean isFull3D() { return true; } /** * returns the action that specifies what animation to play when the items is being used */ @Override public EnumAction getItemUseAction(ItemStack par1ItemStack) { return EnumAction.block; } /** * How long it takes to use or consume an item */ @Override public int getMaxItemUseDuration(ItemStack par1ItemStack) { return 0x11940; } /** * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer */ @Override public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer) { par3EntityPlayer.setItemInUse(par1ItemStack, getMaxItemUseDuration(par1ItemStack)); return par1ItemStack; } /** * Returns if the item (tool) can harvest results from the block type. */ @Override public boolean func_150897_b(Block par1Block) { return par1Block == Blocks.web; } /** * Return the enchantability factor of the item, most of the time is based on material. */ @Override public int getItemEnchantability() { return toolMaterial.getEnchantability(); } /** * Return whether this item is repairable in an anvil. */ @Override public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack) { return toolMaterial.getToolCraftingMaterial() == par2ItemStack.getItem() ? true : super.getIsRepairable(par1ItemStack, par2ItemStack); } @Override @SuppressWarnings({ "rawtypes", "unchecked" }) public Multimap getItemAttributeModifiers() { Multimap multimap = super.getItemAttributeModifiers(); multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(field_111210_e, "Weapon modifier", weaponDamage, 0)); return multimap; } }