package com.team.kalstuff.item; import com.google.common.collect.Multimap; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.creativetab.CreativeTabs; 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.inventory.EntityEquipmentSlot; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.DamageSource; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class ItemDagger extends Item { private float attackDamage; private final Item.ToolMaterial material; public ItemDagger(Item.ToolMaterial material) { this.material = material; this.maxStackSize = 1; this.setMaxDamage(material.getMaxUses()); this.setCreativeTab(CreativeTabs.COMBAT); this.attackDamage = 3.0F + material.getDamageVsEntity(); this.maxStackSize = 1; this.setMaxDamage(material.getMaxUses()); this.attackDamage = 1 + (material.getDamageVsEntity() / 2); } /** * Returns the amount of damage this item will deal. One heart of damage is equal to 2 damage points. */ public float getDamageVsEntity() { return this.material.getDamageVsEntity(); } public float getStrVsBlock(ItemStack stack, IBlockState state) { Block block = state.getBlock(); if (block == Blocks.WEB) { return 15.0F; } else { Material material = state.getMaterial(); return material != Material.PLANTS && material != Material.VINE && material != Material.CORAL && material != Material.LEAVES && material != Material.GOURD ? 1.0F : 1.5F; } } /** * 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 stack, EntityLivingBase target, EntityLivingBase attacker) { if (target.getHorizontalFacing() == attacker.getHorizontalFacing()) target.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) attacker), 1 + (attackDamage * 2)); return super.hitEntity(stack, target, attacker); } /** * Called when a Block is destroyed using this Item. Return true to trigger the "Use Item" statistic. */ public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving) { if ((double)state.getBlockHardness(worldIn, pos) != 0.0D) { stack.damageItem(2, entityLiving); } return true; } /** * Check whether this Item can harvest the given Block */ public boolean canHarvestBlock(IBlockState blockIn) { return blockIn.getBlock() == Blocks.WEB; } /** * Returns True is the item is rendered in full 3D when held. */ @SideOnly(Side.CLIENT) public boolean isFull3D() { return true; } /** * Return the enchantability factor of the item, most of the time is based on material. */ public int getItemEnchantability() { return this.material.getEnchantability(); } /** * Return the name for this tool's material. */ public String getToolMaterialName() { return this.material.toString(); } /** * Return whether this item is reparable in an anvil. */ public boolean getIsRepairable(ItemStack toRepair, ItemStack repair) { ItemStack mat = this.material.getRepairItemStack(); if (!mat.isEmpty() && net.minecraftforge.oredict.OreDictionary.itemMatches(mat, repair, false)) return true; return super.getIsRepairable(toRepair, repair); } @Override public Multimap<String, AttributeModifier> getAttributeModifiers(EntityEquipmentSlot slot, ItemStack stack) { Multimap<String, AttributeModifier> multimap = super.getAttributeModifiers(slot, stack); if (slot == EntityEquipmentSlot.MAINHAND) { // I'm not sure if these two lines are necessary. //multimap.removeAll(SharedMonsterAttributes.ATTACK_DAMAGE.getName()); //multimap.removeAll(SharedMonsterAttributes.ATTACK_SPEED.getName()); multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", (double)this.attackDamage, 0)); multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Weapon modifier", -1.2D, 0)); } return multimap; } }