When you click the button for a level 17 enchantment, how does Minecraft decide to apply Sharpness II? Here's an explanation. But first, some terminology:
- "Enchantment level" is the cost of the enchantment in experience levels (the green number on the button).
- "Enchantment power" is the strength of the particular enchantment. For example, "Sharpness IV" has power 4.
The enchantment algorithm uses a three-step process.
Apply modifiers to the enchantment level
The first thing that Minecraft does is apply two modifiers to the base enchantment level (the green number, and the number of experience levels you actually pay). Each modifier is restricted to a certain range, with numbers close to the middle of the range more common than those near the ends.
The first modifier is based on the item's "enchantability," which depends on the material and the type of the item (see the table below). Minecraft picks a number between 0 and half of the enchantability (with enchantability / 4 the most probable result), then adds that number plus one to the enchantment level.
Bows and books have enchantability 1.
Next, Minecraft picks a value between 0.85 and 1.15, with values closer to 1.0 being more likely. The enchantment level is multiplied by this value (so it increases or decreases by up to 15%) and then rounded to the nearest integer.
Find possible enchantments
Now, based on the modified level, Minecraft makes a list of all enchantment types that can be applied to the target item along with the power that each enchantment will have.
The power of each enchantment type is determined by the level and the values in the table below. For each power value of an enchantment type, there is a minimum and maximum level that can produce the enchantment at that power. If the modified enchantment level is within the range, then the enchantment will be assigned that power. If the level is within two overlapping ranges for the same enchantment type, the higher power value is used.
|Bane of Arthropods||5||25||13||33||21||41||29||49||37||57|
An example: Suppose we are enchanting a sword with a modified enchantment level of 21. If the sword gets the Sharpness enchantment, it will get Sharpness II because 21 is in the power-II range for Sharpness (12-32). 21 is also in the power-I range (1-21), but the higher power value will win over the lower. If the sword gets Smite, then it will be Smite III, because 21 is in the power-III range for Smite (21-41).
Note that extremely high modified enchantment levels can fall outside the ranges of all valid enchantments for the item. If this happens, the item is left unenchanted, but you are not charged any experience levels and can try enchanting it again.
Select a set of enchantments from the list
Now that it's got a list of the possible enchantments for the item, Minecraft has to pick some of them that will actually be applied.
You always get at least one enchantment. The first enchantment is picked from the list based on the weights below.
|Bane of Arthropods||5|
For example, suppose the item is a piece of armor with both Protection and Respiration available. Protection has 10 chances to be selected compared to 2 for Respiration, so the probability of getting Protection is about 5 times higher than the probability of Respiration.
After the first element is selected, there is a chance of receiving more, based on this algorithm:
- With probability (modified level + 1) / 50, keep going. Otherwise, stop picking bonus enchantments.
- Remove from the list of possible enchantments anything that conflicts with previously-chosen enchantments. For example, if Smite was already picked, Sharpness and Bane of Arthropods will be removed at this step. See below for more info on conflicts.
- Pick one enchantment from the remaining possible enchantments (based on the weights, as before) and apply it to the item.
- Divide the modified level in half (rounded down) and repeat from step 1.
When enchanting a book, if this process selects more than one enchantment, the game chooses one enchantment at random to keep and discards the rest.
Here are the rules for enchantment conflicts:
- Every enchantment conflicts with itself. (So you can't get a weapon with two copies of the Efficiency enchantment.)
- All protection enchantments conflict with each other, so an item can only have one at a time. (In the code, Feather Fall is implemented as a protection enchantment, but it doesn't conflict with the others.)
- All damage enchantments (Sharpness, Smite, and Bane of Arthropods) conflict with each other.