# How to get the sum of all enchantment levels equipped

## Recommended Posts

Hi!

I'm trying to get the total enchantment level of a specific enchantment equipped when wearing armor.

For example, if the player has:

Boots with CUSTOM_ENCH V

Helmet with CUSTOM_ENCH III

I will get the value 5 + 3 = 8.

I've figured out how to get the max level, (e.g. the example above would return 5 as it's larger than 3), however I haven't figured out how to get the cumulative value.

Edited by squidlex
Fixed my stupid maths
##### Share on other sites

To loop over the armor inventory use LivingEntity#getArmorInventoryList() and then iterate through it. Then use EnchantmentHelper#getEnchantments(stack) to get the enchantment data from an itemstack in form of  Map<Enchantment, Integer>.

##### Share on other sites

6 minutes ago, diesieben07 said:

EnchantmentHelper#getMaxEnchantmentLevel

Thanks Diesieben! I added this to my Utils class.

3 minutes ago, Tavi007 said:

To loop over the armor inventory use LivingEntity#getArmorInventoryList() and then iterate through it. Then use EnchantmentHelper#getEnchantments(stack) to get the enchantment data from an itemstack in form of  Map<Enchantment, Integer>.

I used this for reference whilst doing it, thanks Tavi!

##### Share on other sites

28 minutes ago, squidlex said:

I will get the value 5 + 3 = 7.

...8?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

DO NOT PM ME WITH PROBLEMS. No help will be given.

##### Share on other sites

Just now, Draco18s said:

...8?

hahaha I'm very tired. (and an idiot from the looks of things)

## 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.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

• ### Posts

• Hey did those crashes happen in the nether by any chance or when you teleported to some far off location within the nether?
• Ive encountered this issue before, however not to this scale. When i TP in the nether via Xaeros world Map my game sometimes just freezes, like i can still play however no blocks will drop, i cant hit mobs (they also wont move), my hunger and health stay the same even if im in lava or falling, and chunks wont load as if time itself just stopped. Previously after loading into my world id have a small interval where id be able to respawn or tp back to my base and avoid this crash, but now i don't, i just load into this frozen state, ive done everything, used NBTExplorer, tried to tp back, tried to use commands (don't even work), deleted config files, replaced config files, deleted JEI and all the other solutions I've seen people posting. The game would only crash if i force exited or spammed the save and quite button, where this error log appears:  https://paste.ee/p/QjcfN Theres more to the error report but i guess this should be enough to pin point my problem? if anyone knows how to fix this id be very thankful.
• Hello There! Today we are parkouring on a volcano, yes you heard me we are on a volcano now. Everything you love about the old parkour videos are back in this video the punching, the screaming, everything! This also has to be one of the coolest and best maps we ever played!
• https://pastebin.com/vgisYctb I basically put together a modpack and it worked, I added a couple of mods and it stopped working. Even if I remove the mods I added, it doesn't work imgur.com/a/IRnlmP0

• ### Who's Online (See full list)

×

• #### Activity

×
• Create New...