Jump to content

Recommended Posts

Posted

I have a few problems that I am stuck on.

 

Lately, I've asked a question about NBT on swords.

What I've accomplished is a whole system of NBT tags (that works), thanks to you guys for the advice.

 

Now, I need to know how to change the Sword's base damage (I have a custom ToolMaterial) I don't know how to change the sword damage corresponding to my NBT tag - "killCount"

Posted

There is no method - getAttributeModifiers

 

I have am using this:

@Override
public Multimap getItemAttributeModifiers() {
Multimap multimap = HashMultimap.create();
multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(field_111210_e, "Weapon modifier", (double) this.weaponDamage + 50D, 0));
return multimap;
}

 

The problem is that it only does 8 damage, however I change it, it stays like that. (Added 50D)

Posted

That's the correct method, but you say it's not working? I've used practically that exact same code just fine plenty of times; did you put the method in your Item class?

 

There is a version of the method added by Forge that takes an ItemStack parameter - this is what you'll need if NBT is to affect damage, but first you need to get the method to work.

Posted

I put it at the bottom of my ItemSword class.

 

I'm wondering, is it due to the fact that my "tool material" is overriding it?

Or - am I even suppose to have a tool material?

 

I can show code if absolutely necessary, thanks for the help everyone c:

Posted

Does it have something to do with my Forge version?

I decided to change my code around to see if it worked, nope.

I gave up, and tried using your "exact" code changing just the names and removing unnecessary methods from interfaces, etc., no luck.

 

Just. lol, I'm confuzzled.

 

I'll show my code, just in case I'm doing something wrong:

Main Class - cut down to what is necessary

public static Item sword_GAIN;
static ToolMaterial GAIN = EnumHelper.addToolMaterial("GAIN", 3, -1, 1.0F, 3, 9);	
@EventHandler
public void preInit(FMLPreInitializationEvent event) {
sword_GAIN = new GainSword(GAIN, 50D).setUnlocalizedName("gainSword");
}

 

SwordGain class - I didn't put my imports nor package in this code :P

//removed package / imports
public class SwordGain extends ItemSword
{	
    private float weaponDamage;
    private final ToolMaterial toolMaterial;

    public SwordGain(ToolMaterial material, float damage)
    {
    	super(material);
        maxStackSize = 1;
        setNoRepair();
        this.weaponDamage = damage;
        this.setCreativeTab(SMain.smTab);
    }
    
    @Override
    public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) {
	return bFull3D;	
    }
    
    @Override
    public String getUnlocalizedName(ItemStack par1ItemStack)
    {
    	int i = MathHelper.clamp_int(par1ItemStack.getItemDamage(), 0, 15);
    	return super.getUnlocalizedName();
    }
    
    @SideOnly(Side.CLIENT) 
    public void registerIcons(IIconRegister par1IconRegister)
    {
        this.itemIcon = par1IconRegister.registerIcon(SMain.modid + ":" + (this.getUnlocalizedName().substring(5)));
    }
    
    public float getStrVsBlock(ItemStack itemstack, Block block)
    {
        return block != Blocks.stone ? 1.5F : 5F;
    }
    
    public boolean onBlockDestroyed(ItemStack itemstack, int i, int j, int k, int l, EntityLiving entityliving)
    {
        return true;
    }
    
    public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    {
    	if (!par2World.isRemote)
    	{
    		par3EntityPlayer.addChatMessage(new ChatComponentText("need to add something here ><");
    	}
    	return par1ItemStack;
    }
    
    public boolean isFull3D()
    {
        return true;
    }

    public EnumAction getItemUseAction(ItemStack itemstack)
    {
        return EnumAction.block;
    }

    public int getMaxItemUseDuration(ItemStack itemstack)
    {
        return 0x11940;
    }

    public boolean canHarvestBlock(Block block)
    {
        return false;
    }

    public int getItemEnchantability()
    {  	
        return material.getEnchantability();    
    }

       @Override
    public Multimap getItemAttributeModifiers()
    {
        Multimap multimap = super.getItemAttributeModifiers();
        multimap.put(SharedMonsterAttributes.attackDamage.getAttributeUnlocalizedName(), new AttributeModifier(field_111210_e, "Weapon modifier", (double) this.weaponDamage, 0));
        return multimap;
    }
}

Posted

bump. :c

I've put a System.out.println method in my getItemAttributeModifiers() method.

 

It is however being called, but the bonus damage is "not" however being applied.

Any ideas?

 

EDIT:

Fixed it. A single little mistake destroys everything.

Posted

[New Question]

 

I have a new question I need to ask.

How would I call "NBT" integers and place it in getItemAttributeModifiers?

Would I create a new ItemStack and check for the item in the player's hand, or do I create a new instance of ItemStack.

 

You guys have suggested a method getAttributeModifiers(ItemStack) but I am unable to locate it in the source or any sort of code.

 

Any help would be greatly appreciated! c:

 

-Terraform

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.