File size: 1,478 Bytes
d46f4a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package net.minecraft.world.damagesource;

import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.enchantment.EnchantmentHelper;

public class CombatRules {
    public static final float MAX_ARMOR = 20.0F;
    public static final float ARMOR_PROTECTION_DIVIDER = 25.0F;
    public static final float BASE_ARMOR_TOUGHNESS = 2.0F;
    public static final float MIN_ARMOR_RATIO = 0.2F;
    private static final int NUM_ARMOR_ITEMS = 4;

    public static float getDamageAfterAbsorb(LivingEntity p_344681_, float p_19273_, DamageSource p_328919_, float p_19274_, float p_19275_) {
        float f = 2.0F + p_19275_ / 4.0F;
        float f1 = Mth.clamp(p_19274_ - p_19273_ / f, p_19274_ * 0.2F, 20.0F);
        float f2 = f1 / 25.0F;
        ItemStack itemstack = p_328919_.getWeaponItem();
        float f3;
        if (itemstack != null && p_344681_.level() instanceof ServerLevel serverlevel) {
            f3 = Mth.clamp(EnchantmentHelper.modifyArmorEffectiveness(serverlevel, itemstack, p_344681_, p_328919_, f2), 0.0F, 1.0F);
        } else {
            f3 = f2;
        }

        float f4 = 1.0F - f3;
        return p_19273_ * f4;
    }

    public static float getDamageAfterMagicAbsorb(float p_19270_, float p_19271_) {
        float f = Mth.clamp(p_19271_, 0.0F, 20.0F);
        return p_19270_ * (1.0F - f / 25.0F);
    }
}