Class DamageContainer
java.lang.Object
net.neoforged.neoforge.common.damagesource.DamageContainer
DamageContainer encapsulates aspects of the entity damage sequence so that
relevant context related to damage dealt is accessible throughout the entire
sequence.
Note: certain values will be defaults until the stage in the sequence when they are set.
The Damage Sequence
Entity.hurt(net.minecraft.world.damagesource.DamageSource, float)is invoked on the recipient from the source of the attack.-
is invoked and fires
invalid reference
Entity#isInvulnerableToEntityInvulnerabilityCheckEvent. - After determining the entity is vulnerable, the
DamageContainerin instantiated for the entity. LivingIncomingDamageEventis fired.LivingShieldBlockEventfires and the result determines if shield effects apply.LivingEntity.actuallyHurt(net.minecraft.server.level.ServerLevel, net.minecraft.world.damagesource.DamageSource, float)is called.- armor, magic, and mob_effect reductions are captured in the DamageContainer.
LivingDamageEvent.Preis fired.- absorption reductions are captured in the DamageContainer.
- if the damage is not zero, entity health is modified and recorded and
LivingDamageEvent.Postis fired.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate floatprivate intprivate floatprivate final floatprivate final EnumMap<DamageContainer.Reduction, List<IReductionFunction>> private final EnumMap<DamageContainer.Reduction, Float> private floatprivate final DamageSource -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddModifier(DamageContainer.Reduction type, IReductionFunction reductionFunction) Adds a callback modifier to the vanilla damage reductions.floatReturns the damage blocked during theLivingShieldBlockEvent.floatReturns the current amount expected to be applied to the entity or used in subsequent damage calculations.floatReturns the value passed intoEntity.hurt(DamageSource, float)before any modifications are made.intReturns the number of ticks this entity will be invulnerable after damage is applied.floatThis provides a post-reduction value for the reduction and modifiers.floatReturns the durability applied to the applicable shield afterLivingShieldBlockEventreturned a successful block.Returns the damage source for this damage sequence.private floatmodifyReduction(DamageContainer.Reduction type, float reduction) voidvoidsetNewDamage(float damage) This sets the current damage value for the entity at the stage of the damage sequence in which it is set.voidsetPostAttackInvulnerabilityTicks(int ticks) Explicitly sets the invulnerability ticks after the damage has been applied.voidsetReduction(DamageContainer.Reduction reduction, float amount)
-
Field Details
-
reductionFunctions
-
originalDamage
private final float originalDamage -
source
-
newDamage
private float newDamage -
reductions
-
blockedDamage
private float blockedDamage -
shieldDamage
private float shieldDamage -
invulnerabilityTicksAfterAttack
private int invulnerabilityTicksAfterAttack
-
-
Constructor Details
-
DamageContainer
-
-
Method Details
-
getOriginalDamage
public float getOriginalDamage()Returns the value passed intoEntity.hurt(DamageSource, float)before any modifications are made.- Returns:
- the value passed into
Entity.hurt(DamageSource, float)before any modifications are made
-
getSource
Returns the damage source for this damage sequence.- Returns:
- the damage source for this damage sequence
-
setNewDamage
public void setNewDamage(float damage) This sets the current damage value for the entity at the stage of the damage sequence in which it is set. Subsequent steps in the damage sequence will use and modify this value accordingly. If this is called in the final step of the sequence, this value will be applied against the entity's health.- Parameters:
damage- the amount to harm this entity at the end of the damage sequence
-
getNewDamage
public float getNewDamage()Returns the current amount expected to be applied to the entity or used in subsequent damage calculations.- Returns:
- the current amount expected to be applied to the entity or used in subsequent damage calculations
-
addModifier
Adds a callback modifier to the vanilla damage reductions. Each function will be performed in sequence on the vanilla value at the time theDamageContainer.Reductiontype is set by vanilla.- only the
EntityPreDamageEventhappens early enough in the sequence for this method to have any effect. - if the vanilla reduction is not triggered, the reduction function will not execute.
- Parameters:
type- The reduction type your function will apply toreductionFunction- takes the current reduction from vanilla and any preceding functions and returns a new value for the reduction. These are always executed in insertion order. if sequence matters, useEventPriorityto order your function.
- only the
-
getBlockedDamage
public float getBlockedDamage()Returns the damage blocked during theLivingShieldBlockEvent.- Returns:
- the damage blocked during the
LivingShieldBlockEvent
-
getShieldDamage
public float getShieldDamage()Returns the durability applied to the applicable shield afterLivingShieldBlockEventreturned a successful block.- Returns:
- the durability applied to the applicable shield after
LivingShieldBlockEventreturned a successful block
-
setPostAttackInvulnerabilityTicks
public void setPostAttackInvulnerabilityTicks(int ticks) Explicitly sets the invulnerability ticks after the damage has been applied.- Parameters:
ticks- Ticks of invulnerability after this damage sequence
-
getPostAttackInvulnerabilityTicks
public int getPostAttackInvulnerabilityTicks()Returns the number of ticks this entity will be invulnerable after damage is applied.- Returns:
- the number of ticks this entity will be invulnerable after damage is applied
-
getReduction
This provides a post-reduction value for the reduction and modifiers. This will always return zero beforeLivingDamageEvent.Preand will consume all modifiers prior to the event.- Parameters:
type- the specific source type of the damage reduction- Returns:
- The amount of damage reduced by armor after vanilla armor reductions and added modifiers
-
setBlockedDamage
-
setReduction
-
modifyReduction
-