ItemToolStarTreckMod.java (4405B)
1 package mtrnord.StarTreckMod; 2 3 import com.google.common.collect.Multimap; 4 import cpw.mods.fml.relauncher.Side; 5 import cpw.mods.fml.relauncher.SideOnly; 6 import net.minecraft.block.Block; 7 import net.minecraft.creativetab.CreativeTabs; 8 import net.minecraft.entity.EntityLivingBase; 9 import net.minecraft.entity.SharedMonsterAttributes; 10 import net.minecraft.entity.ai.attributes.AttributeModifier; 11 import net.minecraft.item.Item; 12 import net.minecraft.item.ItemStack; 13 import net.minecraft.world.World; 14 import net.minecraftforge.common.ForgeHooks; 15 16 public class ItemToolStarTreckMod extends Item 17 { 18 /** Array of blocks the tool has extra effect against. */ 19 private Block[] blocksEffectiveAgainst; 20 public float efficiencyOnProperMaterial = 4.0F; 21 22 /** Damage versus entities. */ 23 public float damageVsEntity; 24 25 /** The material this tool is made from. */ 26 protected EnumToolMaterialStarTreck toolMaterial; 27 28 protected ItemToolStarTreckMod(int par1, float par2, EnumToolMaterialStarTreck par3EnumToolMaterial, Block[] par4ArrayOfBlock) 29 { 30 super(par1); 31 this.toolMaterial = par3EnumToolMaterial; 32 this.blocksEffectiveAgainst = par4ArrayOfBlock; 33 this.maxStackSize = 1; 34 this.setMaxDamage(par3EnumToolMaterial.getMaxUses()); 35 this.efficiencyOnProperMaterial = par3EnumToolMaterial.getEfficiencyOnProperMaterial(); 36 this.damageVsEntity = par2 + par3EnumToolMaterial.getDamageVsEntity(); 37 this.setCreativeTab(CreativeTabs.tabTools); 38 } 39 40 /** 41 * Returns the strength of the stack against a given block. 1.0F base, (Quality+1)*2 if correct blocktype, 1.5F if 42 * sword 43 */ 44 public float getStrVsBlock(ItemStack par1ItemStack, Block par2Block) 45 { 46 for (int i = 0; i < this.blocksEffectiveAgainst.length; ++i) 47 { 48 if (this.blocksEffectiveAgainst[i] == par2Block) 49 { 50 return this.efficiencyOnProperMaterial; 51 } 52 } 53 54 return 1.0F; 55 } 56 57 /** 58 * Current implementations of this method in child classes do not use the entry argument beside ev. They just raise 59 * the damage on the stack. 60 */ 61 public boolean hitEntity(ItemStack par1ItemStack, EntityLivingBase par2EntityLivingBase, EntityLivingBase par3EntityLivingBase) 62 { 63 par1ItemStack.damageItem(2, par3EntityLivingBase); 64 return true; 65 } 66 67 public boolean onBlockDestroyed(ItemStack par1ItemStack, World par2World, int par3, int par4, int par5, int par6, EntityLivingBase par7EntityLivingBase) 68 { 69 if ((double)Block.blocksList[par3].getBlockHardness(par2World, par4, par5, par6) != 0.0D) 70 { 71 par1ItemStack.damageItem(1, par7EntityLivingBase); 72 } 73 74 return true; 75 } 76 77 @SideOnly(Side.CLIENT) 78 79 /** 80 * Returns True is the item is renderer in full 3D when hold. 81 */ 82 public boolean isFull3D() 83 { 84 return true; 85 } 86 87 /** 88 * Return the enchantability factor of the item, most of the time is based on material. 89 */ 90 public int getItemEnchantability() 91 { 92 return this.toolMaterial.getEnchantability(); 93 } 94 95 /** 96 * Return the name for this tool's material. 97 */ 98 public String getToolMaterialName() 99 { 100 return this.toolMaterial.toString(); 101 } 102 103 /** 104 * Return whether this item is repairable in an anvil. 105 */ 106 public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack) 107 { 108 return this.toolMaterial.getToolCraftingMaterial() == par2ItemStack.itemID ? true : super.getIsRepairable(par1ItemStack, par2ItemStack); 109 } 110 111 /** 112 * Gets a map of item attribute modifiers, used by ItemSword to increase hit damage. 113 */ 114 public Multimap getItemAttributeModifiers() 115 { 116 Multimap multimap = super.getItemAttributeModifiers(); 117 multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(field_111210_e, "Tool modifier", (double)this.damageVsEntity, 0)); 118 return multimap; 119 } 120 121 /** FORGE: Overridden to allow custom tool effectiveness */ 122 @Override 123 public float getStrVsBlock(ItemStack stack, Block block, int meta) 124 { 125 if (ForgeHooks.isToolEffective(stack, block, meta)) 126 { 127 return efficiencyOnProperMaterial; 128 } 129 return getStrVsBlock(stack, block); 130 } 131 }