Mantoes Posted May 21, 2020 Share Posted May 21, 2020 (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 May 21, 2020 by Mantoes Fixed some information Quote Link to comment Share on other sites More sharing options...
ChampionAsh5357 Posted May 22, 2020 Share Posted May 22, 2020 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. 1 Quote Link to comment Share on other sites More sharing options...
Mantoes Posted May 22, 2020 Author Share Posted May 22, 2020 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 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.