Posted July 29, 201411 yr I was testing the damage of my tools to entities, when i notice they where always where killed by one hit so i tested it with the wither, and... well, better if you see it: *.mp4 PD: That was Eclipse not Launcher Does anyone knows why this is happening and how to solve it??
July 29, 201411 yr Author Here is my code: package com.sackcastellon.betterwood.item; import java.util.List; import java.util.Random; import java.util.Set; import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IIconRegister; 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.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.IIcon; import net.minecraft.world.World; import net.minecraftforge.common.ForgeHooks; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Multimap; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class NBT extends Item { private String toolClass = "pickaxe"; private Random random = new Random(); public NBT() { super(); this.setUnlocalizedName("nbt"); this.setCreativeTab(CreativeTabs.tabBlock); } /** * Initialization of NBT Tags * @param item Total number of items based on NBT Tags * @return <b>ItemStack</b> The ItemStack with the proper NBT Tags */ private ItemStack getItemStack(int item) { ItemStack itemStack = new ItemStack(this); itemStack.stackTagCompound = new NBTTagCompound(); NBTTagCompound nbt = itemStack.getTagCompound(); nbt.setString("info", "lore " + item); switch(item) { case 0: nbt.setFloat("EfficiencyOnProperMaterial", 2.0F); nbt.setInteger("Enchantability", 15); nbt.setString("ToolMaterial", "WOOD"); nbt.setString("itemRepair", "wood"); nbt.setFloat("damageVsEntity", 2.0F + 0.0F); nbt.setInteger("HarvestLevel", 0); nbt.setInteger("MaxDamage", 59); break; case 1: nbt.setFloat("EfficiencyOnProperMaterial", 4.0F); nbt.setInteger("Enchantability", 5); nbt.setString("ToolMaterial", "STONE"); nbt.setString("itemRepair", "stone"); nbt.setFloat("damageVsEntity", 2.0F + 1.0F); nbt.setInteger("HarvestLevel", 1); nbt.setInteger("MaxDamage", 131); break; case 2: nbt.setFloat("EfficiencyOnProperMaterial", 6.0F); nbt.setInteger("Enchantability", 14); nbt.setString("ToolMaterial", "IRON"); nbt.setString("itemRepair", "iron"); nbt.setFloat("damageVsEntity", 2.0F + 2.0F); nbt.setInteger("HarvestLevel", 2); nbt.setInteger("MaxDamage", 250); break; case 3: nbt.setFloat("EfficiencyOnProperMaterial", 8.0F); nbt.setInteger("Enchantability", 10); nbt.setString("ToolMaterial", "EMERALD"); nbt.setString("itemRepair", "diamond"); nbt.setFloat("damageVsEntity", 2.0F + 3.0F); nbt.setInteger("HarvestLevel", 3); nbt.setInteger("MaxDamage", 1561); break; default: break; } return itemStack; } /** * Add information based on NBT Tags<br> * <b>Tag:</b> "info" */ @SuppressWarnings({ "unchecked", "rawtypes" }) @Override public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean flag) { if(itemStack.stackTagCompound != null) { if(itemStack.stackTagCompound.hasKey("info")) { list.add(itemStack.stackTagCompound.getString("info")); } if(itemStack.stackTagCompound.hasKey("id")) { list.add("ID is " + itemStack.stackTagCompound.getShort("id")); } } } /** * Sub items to be shown on Creative Tabs, based on NBT Tags<br> * Initialization of NBT Tags */ @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void getSubItems(Item item, CreativeTabs tabs, List list) { for(int i = 0; i < 4; ++i) { list.add(this.getItemStack(i)); } } /** * Get maximum item damage based on NBT Tags<br> * <b>Tag:</b> "MaxDamage" */ @Override public int getMaxDamage(ItemStack stack) { return stack.stackTagCompound.getInteger("MaxDamage"); } @Override public boolean onBlockDestroyed(ItemStack stack, World world, Block block, int x, int y, int z, EntityLivingBase entity) { if ((double)block.getBlockHardness(world, x, y, z) != 0.0D) { stack.damageItem(1, entity); } return true; } /** * Returns True is the item is renderer in full 3D when hold. */ @Override @SideOnly(Side.CLIENT) public boolean isFull3D() { return true; } @Override public boolean getIsRepairable(ItemStack p_82789_1_, ItemStack p_82789_2_) { // TODO return false; } @SuppressWarnings({ "unchecked", "rawtypes", "deprecation" }) @Override public Multimap getAttributeModifiers(ItemStack stack) { Multimap multimap = super.getItemAttributeModifiers(); multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(field_111210_e, "Tool modifier", (double)stack.stackTagCompound.getFloat("damageVsEntity"), 0)); return multimap; } @Override public float getDigSpeed(ItemStack stack, Block block, int meta) { if (ForgeHooks.isToolEffective(stack, block, meta)) { return 4.0F; } return super.getDigSpeed(stack, block, meta); } @Override public int getHarvestLevel(ItemStack stack, String toolClass) { int level = super.getHarvestLevel(stack, toolClass); if (level == -1 && toolClass != null && toolClass.equals(this.toolClass )) { return stack.stackTagCompound.getInteger("HarvestLevel"); } else { return level; } } @Override public Set<String> getToolClasses(ItemStack stack) { return toolClass != null ? ImmutableSet.of(toolClass) : super.getToolClasses(stack); } } PD: This is the code of the "tools" i was testing. PD2: I've notice that if i remove the method "getAttributeModifiers" the OP strength goes away, but then my tool have an item default damage to mobs
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.