Class DamageModifierHelper
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 TypeMethodDescriptionstatic doubleapplyAdditiveBonus(double baseDamage, double bonus, double minDamage, double maxDamage) Applies additive damage bonus with optional caps.static doubleapplyMultiplicativeBonus(double baseDamage, double multiplier, double minDamage, double maxDamage) Applies multiplicative damage bonus with optional caps.static doublecalculateAbsorption(double damage, double absorptionAmount) Calculates damage absorption (like absorption hearts).static doublecalculateAdditiveDamage(double baseDamage, @NotNull LevelScaling scaling, int level) Calculates additive bonus damage using a scaling formula.static doublecalculateArmorPenetration(double baseDamage, double penetrationPercent) Calculates armor penetration damage bonus.static doublecalculateCriticalDamage(double baseDamage, double criticalMultiplier) Calculates critical hit damage.static doublecalculateDamageReduction(double damage, double reductionPercent) Calculates damage reduction percentage from armor/enchantments.static doublecalculateFinalDamage(double baseDamage, double additiveBonus, double multiplicativeMultiplier, boolean isCritical, double criticalMultiplier, double minDamage, double maxDamage) Calculates damage with all modifiers applied in correct order.static doublecalculateLifeSteal(double damageDealt, double lifeStealPercent) Calculates life steal amount from damage dealt.static doublecalculateMultiplicativeDamage(double baseDamage, @NotNull LevelScaling scaling, int level) Calculates multiplicative bonus damage using a scaling formula.static doublecalculateRecoil(double damageDealt, double recoilPercent) Calculates recoil/thorns damage to attacker.static doublecalculateScaledDamageReduction(double damage, @NotNull LevelScaling reductionScaling, int level) Calculates damage reduction using scaling formula.static doublecalculateScaledLifeSteal(double damageDealt, @NotNull LevelScaling lifeStealScaling, int level) Calculates life steal using a scaling formula.static doubleclampDamage(double damage, double minDamage, double maxDamage) Clamps damage to specified minimum and maximum bounds.static booleanisEnvironmentalDamage(org.bukkit.event.entity.EntityDamageEvent.DamageCause cause) Determines if damage type is environmental (fire, lava, drowning, etc.).static booleanisMagicalDamage(org.bukkit.event.entity.EntityDamageEvent.DamageCause cause) Determines if damage type is magical (ignores armor).static booleanisPhysicalDamage(org.bukkit.event.entity.EntityDamageEvent.DamageCause cause) Determines if damage type is physical (can be reduced by armor).static inttoCeiledDamage(double damage) Calculates final damage rounded up (ceiling).static inttoFlooredDamage(double damage) Calculates final damage rounded down (floor).static inttoRoundedDamage(double damage) Calculates final damage rounded to nearest integer.
-
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 amountscaling- the scaling formula for bonus damagelevel- 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 amountscaling- the scaling formula for damage multiplierlevel- 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 amountbonus- the flat bonus to addminDamage- 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 amountmultiplier- 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 clampminDamage- 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 damagereductionPercent- 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 damagereductionScaling- the scaling formula for reduction percentagelevel- 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 damageabsorptionAmount- 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 damagepenetrationPercent- 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 targetlifeStealPercent- 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 targetlifeStealScaling- the scaling formula for life steal percentagelevel- 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 attackerrecoilPercent- 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 criticalcriticalMultiplier- 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:
- Additive bonuses
- Multiplicative bonuses
- Critical multiplier
- Clamping
- Parameters:
baseDamage- starting damageadditiveBonus- flat damage bonusmultiplicativeMultiplier- damage multiplierisCritical- whether this is a critical hitcriticalMultiplier- critical hit multiplierminDamage- minimum damage cap (0 for none)maxDamage- maximum damage cap (0 for none)- Returns:
- final calculated damage
-