Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • How to get the sum of all enchantment levels equipped
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 1
squidlex

How to get the sum of all enchantment levels equipped

By squidlex, January 27 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

squidlex    4

squidlex

squidlex    4

  • Creeper Killer
  • squidlex
  • Members
  • 4
  • 166 posts
Posted January 27 (edited)

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.

Thanks for your help!

 

Edited January 27 by squidlex
Fixed my stupid maths
  • Quote

Share this post


Link to post
Share on other sites

diesieben07    7690

diesieben07

diesieben07    7690

  • Reality Controller
  • diesieben07
  • Forum Team
  • 7690
  • 56283 posts
Posted January 27

Do the same as EnchantmentHelper#getMaxEnchantmentLevel, but do a sum instead of a max calculation.

  • Thanks 1
  • Quote

Share this post


Link to post
Share on other sites

Tavi007    2

Tavi007

Tavi007    2

  • Creeper Killer
  • Tavi007
  • Members
  • 2
  • 107 posts
Posted January 27

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

  • Thanks 1
  • Quote

Share this post


Link to post
Share on other sites

squidlex    4

squidlex

squidlex    4

  • Creeper Killer
  • squidlex
  • Members
  • 4
  • 166 posts
Posted January 27
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!

  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2414

Draco18s

Draco18s    2414

  • Reality Controller
  • Draco18s
  • Members
  • 2414
  • 15994 posts
Posted January 27
28 minutes ago, squidlex said:

I will get the value 5 + 3 = 7.

...8?

  • Haha 1
  • Quote

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.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

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

Share this post


Link to post
Share on other sites

squidlex    4

squidlex

squidlex    4

  • Creeper Killer
  • squidlex
  • Members
  • 4
  • 166 posts
Posted January 27
Just now, Draco18s said:

...8?

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

  • Quote

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • KKarmagician
      (Solved) Forge Crashes after FML Early Loading Process

      By KKarmagician · Posted 42 minutes ago

      how though? is there a file we are supposed to put it in? We aren't all computer nerds so some of us have no idea what to do. 
    • NullDev
      Detect entity in Fluid

      By NullDev · Posted 57 minutes ago

      I have created and registered a fluid, and I want to give entities effects while they are in the fluid, so how do I detect what entities are in the fluid?
    • NullDev
      Detect Bottle use on fluid

      By NullDev · Posted 1 hour ago

      I have added and registered a fluid, and I need to detect when the player right clicks the fluid with a bottle, but there is no way to detect that within the class extending FlowingFluid, and if I use onBlockActivated in the class extending FlowingFluidBlock, nothing happens. It seems vanilla Minecraft detects it within the bottle itself, so where would I detect a bottle clicking my fluid at?
    • milkman69
      My game keeps crashing and I haven't even added any mods on yet

      By milkman69 · Posted 1 hour ago

      what do you mean?
    • ehbean
      1.16.x Custom Furnace/Brewing Stand

      By ehbean · Posted 2 hours ago

      It's been a while since I've worked on a mod of mine, but I want to start again, and I need to make a few different custom crafting stations that act in similar way to brewing stands and furnaces. I've done some digging and I can't seem to find a straight forward example of doing so in 1.16.x. How would I go about making something like that? Is there any way to force slots inside the gui to only take certain items?
  • Topics

    • GL1TT3RTR1P!
      9
      (Solved) Forge Crashes after FML Early Loading Process

      By GL1TT3RTR1P!
      Started May 22, 2020

    • NullDev
      0
      Detect entity in Fluid

      By NullDev
      Started 57 minutes ago

    • NullDev
      0
      Detect Bottle use on fluid

      By NullDev
      Started 1 hour ago

    • milkman69
      4
      My game keeps crashing and I haven't even added any mods on yet

      By milkman69
      Started Wednesday at 11:53 PM

    • ehbean
      0
      1.16.x Custom Furnace/Brewing Stand

      By ehbean
      Started 2 hours ago

  • Who's Online (See full list)

    • brok4d
    • DeamLupus
    • ThiagoVarela7w7
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • How to get the sum of all enchantment levels equipped
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community