Override Item#getAttributeModifiers do do the same thing as ItemSword#getItemAttributeModifiers but use a lower value for the attack speed modifier.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
What you actually need to do is override Item#getAttributeModifiers to call the super method, check if the slot is EntityEquipmentSlot.MAINHAND, remove the existing attack speed modifier and add a new modifier with the same ID, name and operation but a different value.
Edit: My previous statement about the ATTACK_SPEED attribute was incorrect. Increasing the ATTACK_SPEED attribute's value does increase the player's attack speed.
I got confused because applying a larger multiplier to ItemSword's default ATTACK_SPEED modifier value decreased the attack speed. What I failed to notice is that this value is negative, so larger multipliers result in smaller values.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Yeah, so, java.util.Optional doesn't seem to exist. It says com.google.common.base.Optional or net.minecraftforge.fml.common.Optional.
My code targets Java 8, where java.util.Optional does exist. If you're targeting an earlier version of Java, you won't be able to use streams like I do; you'll need to iterate manually.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
My previous statement about the ATTACK_SPEED attribute was incorrect. Increasing the ATTACK_SPEED attribute's value does increase the player's attack speed.
I got confused because applying a larger multiplier to ItemSword's default ATTACK_SPEED modifier value decreased the attack speed. What I failed to notice is that this value is negative, so larger multipliers result in smaller values.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Choonster, I really love you because of all these really helpful posts about modding
Thanks, I'm glad you found them helpful.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
This is changing my attack damage but not my attack speed.
Then you're doing something wrong (probably adding a modifier for the wrong IAttribute).
Post your code with syntax highlighting on Gist or Pastebin. To get syntax highlighting on Gist, give each file the appropriate extension (.java for Java code). To get syntax highlighting on Pastebin, select the language from the dropdown at the bottom of the page.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Why do you override ItemTool#getItemAttributeModifiers to call the super method and then do exactly the same thing as it? You're adding the default modifiers twice.
All you need to do is override Item#getAttributeModifiers to call the super method and replace the existing modifiers.
There's no reason to replace the attack damage modifier if you're using a multiplier of 1, you'll just get a new modifier with the same value as the old one.
Rollback Post to RevisionRollBack
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
The ItemTool(ToolMaterial, Set<Block>) constructor calls the ItemTool(float, float, ToolMaterial, Set<Block>) constructor with 0 as the attack damage and speed arguments, setting ItemTool#damageVsEntity to ToolMaterial#getDamageVsEntity and ItemTool#attackSpeed to 0. These are the fields used by ItemTool#getItemAttributeModifiers as the values of the attack damage/speed modifiers.
Since the attack speed modifier has a value of 0, you're replacing it with another modifier with a value of 0 and the attack speed isn't being changed.
You need to use a non-zero value for the base speed.
Since you're extending ItemTool, you can just pass the desired attack damage and speed to the constructor directly instead of overriding Item#getAttributeModifiers and replacing the modifiers.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
So, my weapon extends ItemSword, making my attack speed 1.6 just like a sword. I would like to change this to a lower value. How would I do that?
Override Item#getAttributeModifiers do do the same thing as ItemSword#getItemAttributeModifiers but use a lower value for the attack speed modifier.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
That doesn't seem to be doing anything. Do I copy the code exactly from ItemSword#getItemAttributeModifiers and put it into getAttributeModifiers?
My previous post is incorrect.
What you actually need to do is override Item#getAttributeModifiers to call the super method, check if the slot is EntityEquipmentSlot.MAINHAND, remove the existing attack speed modifier and add a new modifier with the same ID, name and operation but a different value.
I have an example of this here.
Edit: My previous statement about the ATTACK_SPEED attribute was incorrect. Increasing the ATTACK_SPEED attribute's value does increase the player's attack speed.
I got confused because applying a larger multiplier to ItemSword's default ATTACK_SPEED modifier value decreased the attack speed. What I failed to notice is that this value is negative, so larger multipliers result in smaller values.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Yeah, so, java.util.Optional doesn't seem to exist. It says com.google.common.base.Optional or net.minecraftforge.fml.common.Optional.
My code targets Java 8, where java.util.Optional does exist. If you're targeting an earlier version of Java, you won't be able to use streams like I do; you'll need to iterate manually.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Okay, I got it working! Thanks!
My previous statement about the ATTACK_SPEED attribute was incorrect. Increasing the ATTACK_SPEED attribute's value does increase the player's attack speed.
I got confused because applying a larger multiplier to ItemSword's default ATTACK_SPEED modifier value decreased the attack speed. What I failed to notice is that this value is negative, so larger multipliers result in smaller values.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Yeah, I figured that out just by playing around with the value.
Choonster, I really love you because of all these really helpful posts about modding
Thanks, I'm glad you found them helpful.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
Which version of Java, Forge and MCP mappings are you using? What compilation errors are you getting?
IAttribute#getAttributeUnlocalizedName was recently renamed to IAttribute#getName in the MCP mappings for 1.11.
You can see the latest version of my ItemSlowSword class for 1.11 here.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
This is changing my attack damage but not my attack speed.
Then you're doing something wrong (probably adding a modifier for the wrong IAttribute).
Post your code with syntax highlighting on Gist or Pastebin. To get syntax highlighting on Gist, give each file the appropriate extension (.java for Java code). To get syntax highlighting on Pastebin, select the language from the dropdown at the bottom of the page.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
https://pastebin.com/Y39pnH53
Here is the class.
Why do you override ItemTool#getItemAttributeModifiers to call the super method and then do exactly the same thing as it? You're adding the default modifiers twice.
All you need to do is override Item#getAttributeModifiers to call the super method and replace the existing modifiers.
There's no reason to replace the attack damage modifier if you're using a multiplier of 1, you'll just get a new modifier with the same value as the old one.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
It still is not doing attack speed
Post your new code.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.
https://pastebin.com/LXJKQNXX
Here
The ItemTool(ToolMaterial, Set<Block>) constructor calls the ItemTool(float, float, ToolMaterial, Set<Block>) constructor with 0 as the attack damage and speed arguments, setting ItemTool#damageVsEntity to ToolMaterial#getDamageVsEntity and ItemTool#attackSpeed to 0. These are the fields used by ItemTool#getItemAttributeModifiers as the values of the attack damage/speed modifiers.
Since the attack speed modifier has a value of 0, you're replacing it with another modifier with a value of 0 and the attack speed isn't being changed.
You need to use a non-zero value for the base speed.
Since you're extending ItemTool, you can just pass the desired attack damage and speed to the constructor directly instead of overriding Item#getAttributeModifiers and replacing the modifiers.
Chisel Facades: For all your decorative pipe-hiding needs.
Please don't PM me to ask for help or to join your mod development team. Asking your question in a public thread preserves it for people who are having the same problem in the future. I'm not interested in developing mods with people.