CombatRules .java

net.minecraft.world.damagesource.CombatRules (class, 39 lines): members: ARMOR_PROTECTION_DIVIDER, BASE_ARMOR_TOUGHNESS, getDamageAfterAbsorb, totalArmor.

net.minecraft.world.damagesourceclass39 linescommon1.5 KB

API Surface (2)

float getDamageAfterAbsorb(final LivingEntity victim, final float damage, final DamageSource source, final float totalArmor, final float armorToughness)
float getDamageAfterMagicAbsorb(final float damage, final float totalMagicArmor)

Fields & Constants (6)

MAX_ARMOR
ARMOR_PROTECTION_DIVIDER
BASE_ARMOR_TOUGHNESS
MIN_ARMOR_RATIO
NUM_ARMOR_ITEMS
totalArmor

Code Graph: Dependencies (6)

Edges (calls / imports / inherits / references) resolved by graphify from the AST. Every chip opens the class source.

Full Source

CombatRules.java39 lines · Minecraft 26.3 · verbatim
1
package net.minecraft.world.damagesource;
2
3
import net.minecraft.server.level.ServerLevel;
4
import net.minecraft.util.Mth;
5
import net.minecraft.world.entity.LivingEntity;
6
import net.minecraft.world.item.ItemStack;
7
import net.minecraft.world.item.enchantment.EnchantmentHelper;
8
9
public class CombatRules {
10
	public static final float MAX_ARMOR = 20.0F;
11
	public static final float ARMOR_PROTECTION_DIVIDER = 25.0F;
12
	public static final float BASE_ARMOR_TOUGHNESS = 2.0F;
13
	public static final float MIN_ARMOR_RATIO = 0.2F;
14
	private static final int NUM_ARMOR_ITEMS = 4;
15
16
	public static float getDamageAfterAbsorb(
17
		final LivingEntity victim, final float damage, final DamageSource source, final float totalArmor, final float armorToughness
18
	) {
19
		float toughness = 2.0F + armorToughness / 4.0F;
20
		float realArmor = Mth.clamp(totalArmor - damage / toughness, totalArmor * 0.2F, 20.0F);
21
		float armorFraction = realArmor / 25.0F;
22
		ItemStack weaponItem = source.getWeaponItem();
23
		float modifiedArmorFraction;
24
		if (weaponItem != null && victim.level() instanceof ServerLevel level) {
25
			modifiedArmorFraction = Mth.clamp(EnchantmentHelper.modifyArmorEffectiveness(level, weaponItem, victim, source, armorFraction), 0.0F, 1.0F);
26
		} else {
27
			modifiedArmorFraction = armorFraction;
28
		}
29
30
		float damageMultiplier = 1.0F - modifiedArmorFraction;
31
		return damage * damageMultiplier;
32
	}
33
34
	public static float getDamageAfterMagicAbsorb(final float damage, final float totalMagicArmor) {
35
		float realArmor = Mth.clamp(totalMagicArmor, 0.0F, 20.0F);
36
		return damage * (1.0F - realArmor / 25.0F);
37
	}
38
}
39

Decompiled Minecraft 26.3 source of CombatRules (net/minecraft/world/damagesource/CombatRules.java) with Mojang official mappings, stored verbatim on the site.