Damage Calculations - yeelp/Distinct-Damage-Descriptions GitHub Wiki

This page breaks down DDD's damage calculations. It's a rather technical breakdown. But this is how the following graphic is effectively done in game:

DDD does a bunch of things at each individual step of damage calculation. Damage calculation can be broken down into 3 steps: Attack, Hurt, and Damage. At every stage, DDD checks if the damage has been altered by something that modifies the damage outside of DDD's calculations. DDD will apply the increase or decrease proportionally across the currently used Damage Distribution.

Attack Stage

  • DDD First classifies damage. It does this by seeing if there is a valid Damage Distribution applicable to the current context (The context contains things such as the damage source, attacker and defender). Custom Damage Distributions are thus checked first. If no distributions are applicable, then DDD will get the distribution that either the current projectile (if there is one) or the attacking entity is using. It will then distribute the damage across the weighted distribution to create a damage map. A damage map is a map that maps damage types to the actual amount of damage inflicted of that type.
    • A DetermineDamageEvent is fired at the end, which allows altering of the damage map.
  • DDD then checks if a shield is being used to block the damage. It fires a ShieldBlockEvent, which can change if the shield is applicable or not. If the shield can block some damage and is allowed by the ShieldBlockEvent, DDD keeps track of the shield's Shield Distribution to use later, and has Minecraft run the code to block with the shield (this doesn't actually block the damage, this just runs the shield knockback)

Hurt Stage

  • DDD applies the Shield Distribution here, if there is one.
  • DDD then selects a type used in the Damage Distribution for use in death messages.
  • DDD then classifies what armor pieces are applicable. Something like an Anvil will only use helmets, for example. DDD then computes the effective armor and armor toughness of all applicable pieces. DDD compares this against the currently used Damage Distribution to determine how much armor and armor toughness is actually applicable, and gives the player a temporary attribute modifier to modify their armor appropriately, and then passes execution back to Minecraft to run regular armor, potion and absorption calculations.

Damage Stage

  • DDD removes the attribute modifiers for armor and armor toughness that was granted to the player earlier.
  • DDD then gather mob resistances. It fires a GatherDefensesEvent which allows these resistances to be altered for this calculation. DDD then notes all DDD specific enchantments. It first applies immunities and removes any damage from the damage map for immunities the defender has. It then applies the resistances to the remaining damage. an 80% Slashing resistance will reduce remaining Slashing damage by 80% for example.
    • Brute Force will reduce resistances by 10% per level of Brute Force for this part of the calculation.

    • Sly Strike will ignore immunities.

  • DDD will have the final damage at this point. It fires an UpdateAdaptiveResistanceEvent to see if DDD should run the adaptive resistance calculations.
    • If DDD should run adaptive resistance calculations, it passes the damage types being inflicted to the mob resistances, which updates the adaptive resistances of the mob accordingly; increasing the resistance to each type by the adaptive amount, which may have been altered by the event. This example shows a Silverfish with a 75% adaptive amount.

  • DDD notes the resulting damage and whether weaknesses, resistances, or immunities were hit. It uses these for creating sounds and particles, which it creates now. If the mob's adaptability was triggered, it plays an additional sound (distinctdamagedescriptions:adaptability_change)
Type of Hit Particles Spawned Sound Resource Played
Weakness distintdamagedescriptions:weakness_hit
Resistance distinctdamagedescriptions:resist_ding or distinctdamagedescriptions:high_resist_hit if resistance reduced damage for at least one damage type to zero
Immunity distinctdamagedescriptions:immunity_hit

By default, if a mob took no damage from an attack and was immune to some damage type inflicted, the mob takes no knockback.