Class DamageModifierHelper

java.lang.Object
io.artificial.enchantments.internal.DamageModifierHelper

public final class DamageModifierHelper extends Object
Pure functions for damage calculation and modification.

These helpers support both additive and multiplicative damage modifications, with proper handling for damage caps and minimum thresholds. All functions are pure (no side effects) and thread-safe.

Damage operations:

  • Additive: Adds a flat amount to damage (e.g., +5 damage)
  • Multiplicative: Multiplies damage by a factor (e.g., 1.5x damage)
  • Scaling: Uses LevelScaling to calculate bonus damage
  • Method Summary

    Modifier and Type
    Method
    Description
    static double
    applyAdditiveBonus(double baseDamage, double bonus, double minDamage, double maxDamage)
    Applies additive damage bonus with optional caps.
    static double
    applyMultiplicativeBonus(double baseDamage, double multiplier, double minDamage, double maxDamage)
    Applies multiplicative damage bonus with optional caps.
    static double
    calculateAbsorption(double damage, double absorptionAmount)
    Calculates damage absorption (like absorption hearts).
    static double
    calculateAdditiveDamage(double baseDamage, @NotNull LevelScaling scaling, int level)
    Calculates additive bonus damage using a scaling formula.
    static double
    calculateArmorPenetration(double baseDamage, double penetrationPercent)
    Calculates armor penetration damage bonus.
    static double
    calculateCriticalDamage(double baseDamage, double criticalMultiplier)
    Calculates critical hit damage.
    static double
    calculateDamageReduction(double damage, double reductionPercent)
    Calculates damage reduction percentage from armor/enchantments.
    static double
    calculateFinalDamage(double baseDamage, double additiveBonus, double multiplicativeMultiplier, boolean isCritical, double criticalMultiplier, double minDamage, double maxDamage)
    Calculates damage with all modifiers applied in correct order.
    static double
    calculateLifeSteal(double damageDealt, double lifeStealPercent)
    Calculates life steal amount from damage dealt.
    static double
    calculateMultiplicativeDamage(double baseDamage, @NotNull LevelScaling scaling, int level)
    Calculates multiplicative bonus damage using a scaling formula.
    static double
    calculateRecoil(double damageDealt, double recoilPercent)
    Calculates recoil/thorns damage to attacker.
    static double
    calculateScaledDamageReduction(double damage, @NotNull LevelScaling reductionScaling, int level)
    Calculates damage reduction using scaling formula.
    static double
    calculateScaledLifeSteal(double damageDealt, @NotNull LevelScaling lifeStealScaling, int level)
    Calculates life steal using a scaling formula.
    static double
    clampDamage(double damage, double minDamage, double maxDamage)
    Clamps damage to specified minimum and maximum bounds.
    static boolean
    isEnvironmentalDamage(org.bukkit.event.entity.EntityDamageEvent.DamageCause cause)
    Determines if damage type is environmental (fire, lava, drowning, etc.).
    static boolean
    isMagicalDamage(org.bukkit.event.entity.EntityDamageEvent.DamageCause cause)
    Determines if damage type is magical (ignores armor).
    static boolean
    isPhysicalDamage(org.bukkit.event.entity.EntityDamageEvent.DamageCause cause)
    Determines if damage type is physical (can be reduced by armor).
    static int
    toCeiledDamage(double damage)
    Calculates final damage rounded up (ceiling).
    static int
    toFlooredDamage(double damage)
    Calculates final damage rounded down (floor).
    static int
    toRoundedDamage(double damage)
    Calculates final damage rounded to nearest integer.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • calculateAdditiveDamage

      public static double calculateAdditiveDamage(double baseDamage, @NotNull @NotNull LevelScaling scaling, int level)
      Calculates additive bonus damage using a scaling formula.

      Formula: baseDamage + scaling.calculate(level)

      Parameters:
      baseDamage - the base damage amount
      scaling - the scaling formula for bonus damage
      level - the enchantment level
      Returns:
      the modified damage amount
    • calculateMultiplicativeDamage

      public static double calculateMultiplicativeDamage(double baseDamage, @NotNull @NotNull LevelScaling scaling, int level)
      Calculates multiplicative bonus damage using a scaling formula.

      Formula: baseDamage * (1 + scaling.calculate(level))

      The scaling result is treated as a percentage (e.g., 0.5 = +50% damage)

      Parameters:
      baseDamage - the base damage amount
      scaling - the scaling formula for damage multiplier
      level - the enchantment level
      Returns:
      the modified damage amount
    • applyAdditiveBonus

      public static double applyAdditiveBonus(double baseDamage, double bonus, double minDamage, double maxDamage)
      Applies additive damage bonus with optional caps.

      The result is clamped between minDamage and maxDamage if specified.

      Parameters:
      baseDamage - the base damage amount
      bonus - the flat bonus to add
      minDamage - minimum damage cap (0 for no minimum)
      maxDamage - maximum damage cap (0 for no maximum)
      Returns:
      the modified damage, clamped to limits
    • applyMultiplicativeBonus

      public static double applyMultiplicativeBonus(double baseDamage, double multiplier, double minDamage, double maxDamage)
      Applies multiplicative damage bonus with optional caps.

      The result is clamped between minDamage and maxDamage if specified.

      Parameters:
      baseDamage - the base damage amount
      multiplier - the damage multiplier (e.g., 1.5 for +50%)
      minDamage - minimum damage cap (0 for no minimum)
      maxDamage - maximum damage cap (0 for no maximum)
      Returns:
      the modified damage, clamped to limits
    • clampDamage

      public static double clampDamage(double damage, double minDamage, double maxDamage)
      Clamps damage to specified minimum and maximum bounds.

      A minDamage of 0 means no minimum. A maxDamage of 0 means no maximum.

      Parameters:
      damage - the damage to clamp
      minDamage - minimum bound (0 = no minimum)
      maxDamage - maximum bound (0 = no maximum)
      Returns:
      the clamped damage value
    • toRoundedDamage

      public static int toRoundedDamage(double damage)
      Calculates final damage rounded to nearest integer.

      Minecraft damage is typically represented as whole numbers.

      Parameters:
      damage - the calculated damage
      Returns:
      the rounded damage amount
    • toFlooredDamage

      public static int toFlooredDamage(double damage)
      Calculates final damage rounded down (floor).

      Useful for ensuring minimum damage thresholds.

      Parameters:
      damage - the calculated damage
      Returns:
      the floored damage amount
    • toCeiledDamage

      public static int toCeiledDamage(double damage)
      Calculates final damage rounded up (ceiling).

      Useful for ensuring at least 1 damage is dealt.

      Parameters:
      damage - the calculated damage
      Returns:
      the ceiled damage amount
    • calculateDamageReduction

      public static double calculateDamageReduction(double damage, double reductionPercent)
      Calculates damage reduction percentage from armor/enchantments.

      Formula: damage * (1 - reductionPercent / 100)

      Parameters:
      damage - the incoming damage
      reductionPercent - percentage of damage to reduce (e.g., 20 for 20%)
      Returns:
      the reduced damage amount
    • calculateScaledDamageReduction

      public static double calculateScaledDamageReduction(double damage, @NotNull @NotNull LevelScaling reductionScaling, int level)
      Calculates damage reduction using scaling formula.

      The scaling result is treated as reduction percentage.

      Parameters:
      damage - the incoming damage
      reductionScaling - the scaling formula for reduction percentage
      level - the enchantment level
      Returns:
      the reduced damage amount
    • calculateAbsorption

      public static double calculateAbsorption(double damage, double absorptionAmount)
      Calculates damage absorption (like absorption hearts).

      Returns the amount of damage that would be absorbed.

      Parameters:
      damage - the incoming damage
      absorptionAmount - available absorption points
      Returns:
      damage after absorption
    • calculateArmorPenetration

      public static double calculateArmorPenetration(double baseDamage, double penetrationPercent)
      Calculates armor penetration damage bonus.

      Ignores a percentage of the target's armor.

      Note: This calculates theoretical damage increase, actual armor penetration mechanics depend on Minecraft's damage calculation.

      Parameters:
      baseDamage - the base damage
      penetrationPercent - percentage of armor to ignore (e.g., 25 for 25%)
      Returns:
      damage with armor penetration bonus applied
    • isPhysicalDamage

      public static boolean isPhysicalDamage(@NotNull org.bukkit.event.entity.EntityDamageEvent.DamageCause cause)
      Determines if damage type is physical (can be reduced by armor).
      Parameters:
      cause - the damage cause
      Returns:
      true if the damage type is physical
    • isMagicalDamage

      public static boolean isMagicalDamage(@NotNull org.bukkit.event.entity.EntityDamageEvent.DamageCause cause)
      Determines if damage type is magical (ignores armor).
      Parameters:
      cause - the damage cause
      Returns:
      true if the damage type is magical
    • isEnvironmentalDamage

      public static boolean isEnvironmentalDamage(@NotNull org.bukkit.event.entity.EntityDamageEvent.DamageCause cause)
      Determines if damage type is environmental (fire, lava, drowning, etc.).
      Parameters:
      cause - the damage cause
      Returns:
      true if the damage type is environmental
    • calculateLifeSteal

      public static double calculateLifeSteal(double damageDealt, double lifeStealPercent)
      Calculates life steal amount from damage dealt.

      Formula: damageDealt * (lifeStealPercent / 100)

      Parameters:
      damageDealt - the damage dealt to the target
      lifeStealPercent - percentage of damage to convert to healing (e.g., 10 for 10%)
      Returns:
      the amount of health to restore
    • calculateScaledLifeSteal

      public static double calculateScaledLifeSteal(double damageDealt, @NotNull @NotNull LevelScaling lifeStealScaling, int level)
      Calculates life steal using a scaling formula.
      Parameters:
      damageDealt - the damage dealt to the target
      lifeStealScaling - the scaling formula for life steal percentage
      level - the enchantment level
      Returns:
      the amount of health to restore
    • calculateRecoil

      public static double calculateRecoil(double damageDealt, double recoilPercent)
      Calculates recoil/thorns damage to attacker.

      Formula: damageDealt * (recoilPercent / 100)

      Parameters:
      damageDealt - the damage dealt by the attacker
      recoilPercent - percentage of damage reflected (e.g., 15 for 15%)
      Returns:
      the damage to reflect back to attacker
    • calculateCriticalDamage

      public static double calculateCriticalDamage(double baseDamage, double criticalMultiplier)
      Calculates critical hit damage.

      Formula: baseDamage * criticalMultiplier

      Parameters:
      baseDamage - the base damage before critical
      criticalMultiplier - the critical hit multiplier (default MC is 1.5)
      Returns:
      the critical damage amount
    • calculateFinalDamage

      public static double calculateFinalDamage(double baseDamage, double additiveBonus, double multiplicativeMultiplier, boolean isCritical, double criticalMultiplier, double minDamage, double maxDamage)
      Calculates damage with all modifiers applied in correct order.

      Order of operations:

      1. Additive bonuses
      2. Multiplicative bonuses
      3. Critical multiplier
      4. Clamping
      Parameters:
      baseDamage - starting damage
      additiveBonus - flat damage bonus
      multiplicativeMultiplier - damage multiplier
      isCritical - whether this is a critical hit
      criticalMultiplier - critical hit multiplier
      minDamage - minimum damage cap (0 for none)
      maxDamage - maximum damage cap (0 for none)
      Returns:
      final calculated damage