Jump to content

[1.16.4] How do I give a custom enchantment an attribute modifier?


Recommended Posts

Posted

Hello!

 

I've already gotten both the custom attribute and the custom enchantment registered separately. I just need it so that when an item has the enchantment, it has a certain attribute modifier set to itself. I can't really show code as I don't have the foggiest on how to even begin. If you're curious as to why I've elected to use attributes instead of some stored capability value, it's mostly so I can use /attribute for debugging and have it shared across many entities but if there exists a solution that's so much easier I might have to go with that.

 

I don't think I can modify the EnchantmentHelper class to allow me to add attributes when adding the enchantment to an item and, as far as I can tell, there is no event call for item updating, item NBT modification, or item enchanting so I'm somewhat lost as to what to do. Is there some compatibility I can use? Any answer is helpful but coded examples (or examples of mods where this is done) would be especially appreciated.

 

Thank you.

Posted

Damn.

 

Simply put, I wanted certain items to increase your 'Bite' attribute by however much with the 'Biting' enchantment increasing it by some amount per level. I'm not a furry or anything, it's for a food mod. However, for some items I wanted a baseline amount of Bite on them before they're enchanted, with the ability to increase it if it were enchanted. Think like if the Protection enchantment gave you additional armour instead of what it actually does.

 

What sucks is I could certainly do this with a vanilla data pack, it's just so much harder to work around in Forge.

 

6 minutes ago, diesieben07 said:

I don't know what you mean by this.

I've given the attribute to all the entity types that can eat food. Not sure why I phrased it like that, my apologies.

 

If attributes are off the table, have you any suggestions as what to do instead? I assume setting up some forgecap on the entity's NBT would be best but then the attribute modifier ToolTip wouldn't appear.

Posted

In a data pack, I could just use a few functions and loot tables to loop through every entity's inventory and replace and instance of the un-attributed, enchanted item with the attributed, enchanted item. Problem is that means a lot of command processing and the whole point of mods is to be closer to the source so this method seems kinda trite. Actually, an issue that I only just remembered is that it would be incredibly difficult to modify the item in any containers, especially ones from other mods so perhaps not so easily done with vanilla data packs.

 

4 minutes ago, diesieben07 said:

What you could do is use LivingEquipmentChangeEvent to apply/unapply the attribute modifiers. However this will make it so the attribute modifiers are not part of the item, they are applied "dynamically" to any living entity that has it.

I was thinking that too. Any recommendation on how to fake the tool tip? I still want it to appear on the same level of the item's "information" as the other modifiers (below Lore, above Unbreakable/CanDestroy/CanPlace).

Posted

Thank you so much for your help, I can take it from here. When I started learning how to mod (like a week or two ago) seeing your responses on posts like this really got me through the harder parts of starting off. You were a great help to me and I am extraordinarily grateful.

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.