Jump to content

[1.15.2] movementSpeed attribute affecting attack speed and damage


Recommended Posts

Posted (edited)

Currently I am just applying an AttributeModifier to one of my items to change through these lines of code (Pulled from actual code because everything around it is irrelevant);

 

//Modifier
public static AttributeModifier MAINSP = new AttributeModifier(UUID.fromString("6e1c0233-8b3b-4592-b944-a1756fa62a40"), "HandSpeed", 0.05D, 1);

//AttributeModifier adding
output.addAttributeModifier("generic.movementSpeed", AMods.MAINSP, EntityEquipmentSlot.MAINHAND);

 

This works, my item now causes me to run faster when held, however it also affects my items attack speed / damage.

When applied to a sword, it takes ~20 attacks to kill a zombie, meaning it is doing fist damage, rather than the swords actual damage, along with the attackspeed being the same as my bare fist.

It works the other way around, modifying attack speed does not affect movement speed and keeps the correct attack damage 

Does anyone know what is going wrong here?

 

Edited by Mantoes
Fixed some information
Posted

After doing a quick look, it has to do with how attributes are stored on itemsstacks. By default, itemstacks have no attributes stored on them. What attributes are determined on an item is based on a method called Item#getAttributeModifiers. This is what ItemStack#getAttributeModifiers defaults to if there are no attributes added on as nbt data. What you are doing adds on an attribute as an nbt tag, causing the program to not default back to Item#getAttributeModifiers but rather execute only what is currently on the item, your only added attribute.

 

For a semi-complex problem, there is a simple solution since this is an item. Just simply add the modifier by overriding Item#getAttributeModifiers in your class and add to the previous multimap by storing the super call of the method.

  • Thanks 1
Posted
1 hour ago, ChampionAsh5357 said:

Just simply add the modifier by overriding Item#getAttributeModifiers in your class and add to the previous multimap by storing the super call of the method.

This worked perfectly, thanks a lot for the help :)

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.