An "easy" way to add attribute Modifiers to items

Started by Teapot5000 on

Topic category: Help with modding (Java Edition)

Last seen on 00:55, 26. Apr 2024
Joined May 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
An "easy" way to add attribute Modifiers to items

I wanted to do something very very simple in words, adding extra attribute modifiers to items when the item gets an enchantment and updating this modifier according to the level of the enchantment, however every time i tried to do this it only caused weird bugs like removing the rest of the modifier or being unable to update the modifier because the way minecraft handles attributes is very very very horrible.
After looking around i found that there is an specific event in forge that allows you to modify how item attributes are added to items, while the method still bugs me a lot since it works weirdly, i have been testing around a way to do this without ruining any other attribute modifier and I finally solved it
I will share the code here so if someone needs to add an attribute modifier. I have been testing it in case it could cause weird buggy interactions but as for now it seems to work perfectly fine.

https://pastebin.com/TwNabuKF

this is my first time making code in java so if someone has a better way to do this
im all ears.