Skip to content

Instantly share code, notes, and snippets.

@tryashtar
Last active April 7, 2022 21:25
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tryashtar/4e3917bbd59532463d280755a63705d0 to your computer and use it in GitHub Desktop.
Save tryashtar/4e3917bbd59532463d280755a63705d0 to your computer and use it in GitHub Desktop.
Max effective values for enchantments
Beta 1.9 Prerelease 5

⚠️ Any NBT tag type other than short for an item's enchantment level crashes Minecraft. Therefore, no enchantment can have a level above 32767 or below -32768.

Enchantment Formula Effective Range
  • Protection
  • Fire Protection
  • Feather Falling
  • Blast Protection
  • Projectile Protection
Start a running total. For each enchant, add (level² + 6) / 2 if the enchant protects against the taken damage. For feather falling, add twice. Cap the total at 25. Add one, then divide by two. Now add a random number between 0 and the total. Cap the new total at 20. If the total is one or greater, set the new incoming damage equal to (damage * (25 - total)) / 25.

Since the level gets squared, negative levels behave as their absolute value.
0 to 7
  • Lower levels are identical to their absolute value
  • Higher levels are identical to 7
Respiration Take the first respiration enchant on each piece of armor. If the largest one is greater than zero, has a one in 1 + level chance to still decrease the air level each tick while in water. 1 to 32767
  • Lower levels do nothing
Aqua Affinity Take the first aqua affinity enchant on each piece of armor. If the largest one is greater than zero, skip mining speed multiplier when underwater. 1
  • Lower levels do nothing
  • Higher levels are identical to 1
  • Sharpness
  • Smite
  • Bane of Arthropods
Start a running total. For each sharpness enchant, add level * 3. For each smite/bane enchant, add level * 4 if the target is undead/arthropod, respectively. If the total is one or greater, deal a random amount of bonus damage between 1 and the total.

Negative levels can offset the total. For example, Sharpness 5 with Smite -5 will deal 1-15 bonus damage to non-undead monsters, but no bonus damage to undead ones. You can never do less than zero bonus damage, however.
  • Single: -32768 to 32767
  • Stacked: -2147483648 to 2147483647
Knockback Take the first knockback enchant on the tool. Add level bonus knockback to the attack.

Bonus knockback is only applied when greater than zero. However, sprinting adds one bonus knockback. Therefore, negative levels can prevent sprinting knockback from working.
-1 to 32767
  • Lower levels are identical to -1
Fire Aspect Take the first fire aspect enchant on the tool. If it's greater than zero, set the mob on fire for level * 4 seconds (level * 80 ticks). 1 to 32767
  • Lower levels do nothing
Looting Take the first looting enchantment on the tool. Do something different for each mob:
MobFormula
SkeletonDrops between 0 and 2 + level bones,
and between 0 and 2 + level arrows.
⚠️ Levels -3 and below crash Minecraft.
SpiderIf killed by a player, has a one in three chance or
a one in 1 + level chance to drop one spider eye.
Also follow the steps below for string.
⚠️ Levels below zero crash Minecraft.
GhastDrops between 0 and 1 ghast tears,
plus between 0 and level more.
Also drops between 0 and 2 gunpowder,
plus between 0 and level more.
⚠️ Levels below zero crash Minecraft.
Zombie PigmanDrops between 0 and 2 + level rotten flesh,
and between 0 and 2 + level gold nuggets.
⚠️ Levels -3 and below crash Minecraft.
EndermanDrops between 0 and 1 + level ender pearls
⚠️ Levels -2 and below crash Minecraft.
BlazeDrops between 0 and 1 + level blaze rods.
⚠️ Levels -2 and below crash Minecraft.
CowDrops between 0 and 2 + level leather,
and between 1 and 3 + level beef.
⚠️ Levels -3 and below crash Minecraft.
ChickenDrops between 0 and 2 feathers,
plus between 0 and level more.
Also drops one chicken.
⚠️ Levels below zero crash Minecraft.
SquidDrops between 1 and 3 + level ink sacs.
⚠️ Levels -3 and below crash Minecraft.
For any other mobs that drop items, drop between 0 and 2 items. If level is greater than zero, drop between 0 and level more.
-3 to 32767
  • Lower levels are identical to -3
Efficiency Take the first efficiency enchant on the tool. If greater than zero, add level² + 1 to your mining speed. 1 to 32767
  • Lower levels do nothing
Silk Touch Take the first silk touch enchant on the tool. If greater than zero, broken blocks drop themselves instead of the normal drops. 1
  • Lower levels do nothing
  • Higher levels are identical to 1
Unbreaking Take the first unbreaking enchant on the tool. If greater than zero, has a one in level + 1 chance to still take durability damage when used. 1 to 32767
  • Lower levels do nothing
Fortune Take the first fortune enchantment on the tool. Do something different for each block:
BlockFormula
MelonDrops between between 3 and 7 items,
plus between 0 and level more.
Can't drop more than 9.
⚠️ Levels below zero crash Minecraft.
Tall GrassHas a one in eight chance of dropping
between 1 and (level * 2) + 1 seeds.
⚠️ Levels below zero crash Minecraft.
  • Coal Ore
  • Diamond Ore
    If level is greater than zero, drop between
    0 and 1 + level items, minimum of 1.
    Lapis OreDrop between 4 and 8 items.
    If level is greater than zero, multiply
    the drops by between 0 and 1 + level.
    Multiply by 1 instead of 0 if possible.
    GravelHas a one in 10 - (level * 3) chance
    of dropping flint, otherwise gravel.
    ⚠️ Levels 4 and above crash Minecraft.
    Nether WartDrop between 2 and 4 items.
    If level is greater than zero,
    add between 1 and level more.
    WheatPick 3 + level random numbers between 0 and 15.
    For each one that's less than or equal to the
    crop's growth stage, drop one seed item.
    The only difference between negative levels is the difficulty in obtaining flint from gravel.
    -32768 to 32767

    Relevant pieces of code:

    EnchantmentHelper.getEnchantmentLevel: Finds the level of a specific enchantment on an item. If the item has multiple copies of the enchantment, it always takes the first one. It's used directly by these helper functions:

    • getKnockbackModifier
      • Called by EntityPlayer.attackTargetEntityWithCurrentItem
    • getFireAspectModifier
      • Called by EntityPlayer.attackTargetEntityWithCurrentItem
      • Ultimately passed to Entity.setFire
    • getEfficiencyModifier
      • Called by EntityPlayer.getCurrentPlayerStrVsBlock
    • getUnbreakingModifier
      • Called by ItemStack.damageItem
    • getSilkTouchModifier (boolean)
      • Called by Block.harvestBlock (overridden by many blocks)
    • getFortuneModifier
      • Called by Block.harvestBlock (overridden by many blocks)
      • Ultimately passed to Block.dropBlockAsItemWithChance, Block.quantityDroppedWithBonus, and Block.idDropped (each of which are overridden by some blocks)
    • getLootingModifier
      • Called by EntityLiving.onDeath
      • Ultimately passed to EntityLiving.dropFewItems (overridden by many entities)

    EnchantmentHelper.getMaxEnchantmentLevel: Takes multiple items, and finds the highest level of a specific enchantment present among those items. This ues getEnchantmentLevel, so again only the first copy of each enchantment is considered for each item. It's used directly by these helper functions:

    • getRespiration
      • Called by EntityPlayer.decreaseAirSupply
    • getAquaAffinityModifier (boolean)
      • Called by EntityPlayer.getCurrentPlayerStrVsBlock

    EnchantmentHelper.getEnchantmentModifierDamage: Formula for reducing damage with protection enchantments.

    • Called by EntityPlayer.applyPotionDamageCalculations

    EnchantmentHelper.getEnchantmentModifierLiving: Formula for increasing damage with damage enchantments.

    • Called by EntityPlayer.attackTargetEntityWithCurrentItem

    All of these EnchantmentHelper methods ultimately call CompoundTag.getShort.

    Information for later versions will follow

    @1-too-many
    Copy link

    Is this planned to be updated for 1.17?

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment