Jump to content

[1.19.2] How to set properly getMinCost and getMaxCost on Enchantment

Adil Yilan

Recommended Posts

I've been reading about enchanting mechanics here: https://minecraft.fandom.com/wiki/Enchanting_mechanics

Table says that if you have 15 bookshelves, following rules should be applied:

Level range of top slot -> 2 - 10

Level range of middle slot -> 6 - 21

Level range of bottom slot -> 30

I have defined following values for minCost and maxCost for my item (just for the sake of the testing):

	public int getMinCost(int pLevel) {
		return 11;

	public int getMaxCost(int pLevel) {
		return 21;

Enchantment has only 1 level.

And I ended up with having enchantment shown in two slots at the same time on the enchanting table:

* At top slot with cost of 8

* At middle slot with cost of 14

At first I thought you configure how much item might cost - but how did I end up with having option with cost of 8 when min value is 11?

Then I thought it has to do with levels, but if top slot is 2-10, why is it shown if min value is set to 11?

What exactly are these getMinCost and getMaxCost values used for?

Thanks for any assistance in advance. :)





Link to comment
Share on other sites

@vemerion I did, but still can't figure out exactly how to set these values and what is exact meaning of them.

Some enchantments have these values set to very large values that I didn't see anywhere in the game.

For example, BLOCK_EFFICIENCY for level 5 returns following values:

getMinCost => 41

getMaxCost => 101

So it's most likely some type of range - but how and where is it used is what I don't understand...

I am supposed to set these values in my enchantments to something meaningful, but don't know how.

Link to comment
Share on other sites

I don't really understand all the details of this, it is based on random numbers and a weird algorithm. 🙂

I think most people just choose a vanilla enchantment they want to be similar to and tweak its cost calculation?


If you really want to understand it:

The basic idea is that it calculates an enchantment cost for each slot in EnchantmentHelper.getEnchantmentCost() - uses some random numbers.

p_220289_ is the slot number (0 to 2) and p_220290_ is the enchanting power of the "bookshelves".


Then it runs selectEnchantment() for each slot

p_220300_ is the cost(s) from above, but it gets modified using some more random numbers.


This then uses getAvailableEnchanmentResults() with the modified p_220300_ to compare against your min/max costs.


That wiki has a link to a table that has values from 1.14



If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Link to comment
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.
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.
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.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use.