1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- package me.km.items;
- import com.google.common.collect.Multimap;
- 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.inventory.EntityEquipmentSlot;
- import net.minecraft.item.Item;
- import net.minecraft.item.ItemStack;
- 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 ItemWeapon extends ItemBase
- {
- private final float attackDamage;
- private final double speed;
- private final Item.ToolMaterial material;
- public ItemWeapon(String name, String local, Item.ToolMaterial material, float attackDamage, double speed)
- {
- super(name, local);
- this.material = material;
- this.maxStackSize = 1;
- super.setMaxDamage(material.getMaxUses());
- super.setCreativeTab(CreativeTabs.COMBAT);
- this.attackDamage = attackDamage + material.getDamageVsEntity();
- this.speed = speed;
- }
-
- public ItemWeapon(String name, String local, Item.ToolMaterial material, float attackDamage)
- {
- this(name, local, material, attackDamage, -2.4d);
- }
- @Override
- public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker)
- {
- stack.damageItem(1, attacker);
- return true;
- }
- @Override
- public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving)
- {
- if(state.getBlockHardness(worldIn, pos) != 0)
- {
- stack.damageItem(2, entityLiving);
- }
- return true;
- }
-
- @SideOnly(Side.CLIENT)
- @Override
- public boolean isFull3D()
- {
- return true;
- }
- @Override
- public int getItemEnchantability()
- {
- return this.material.getEnchantability();
- }
- @Override
- 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> getItemAttributeModifiers(EntityEquipmentSlot equipmentSlot)
- {
- Multimap<String, AttributeModifier> multimap = super.getItemAttributeModifiers(equipmentSlot);
- if (equipmentSlot == EntityEquipmentSlot.MAINHAND)
- {
- multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", this.attackDamage, 0));
- multimap.put(SharedMonsterAttributes.ATTACK_SPEED.getName(), new AttributeModifier(ATTACK_SPEED_MODIFIER, "Weapon modifier", speed, 0));
- }
- return multimap;
- }
- }
|