Setting final damage

I am having trouble finding a way to modify the final damage.
I can see the getter for final damage
getOriginalFinalDamage();
getFinalDamage();

But I am not seeing a way to modify this. I only see a way to modify the base damage.
I only see a way to modify
setBaseDamage(double baseDamage);
Set DamageModifierType before);

You can’t set the final damage like that.
The way the event works is that there is a base damage, then modifiers are applied to create the final damage.

You can either set the base damage, or add your own modifier to the event that gets applied when the final damage is calculated.

So to in a way set the final damage I would have to use the modifiers that deal with damage reduction. My goal here is to bypass all armour etc that reduce the base damage.

Such as:
GENERAL_ARMOR = “GeneralArmor”;
RESISTANCE = “Resistance”;
ABSORPTION = “AbsorptionPotion”;
BLOCKING = “Blocking”;

Armor doesn’t reduce the base damage, it’s a modifier.
Here it is in the implementation:
https://github.com/SpongePowered/SpongeCommon/blob/master/src/main/java/org/spongepowered/common/mixin/core/entity/MixinEntityLivingBase.java#L466-L478

What you could try doing is looping through the modifiers and replace the armor modifiers

I’ve already thought of this for you!
I present addModifierAfter. What this method does is add a new DamageModifier and Function after the desired DamageModifierTypes, what you can essentially do is explicitly come in after all other modifiers and simply return the negated damage afterwards (since damage modifiers are an additive modification of the base damage).

What this would look like in code:

@Listener
public void onDamage(DamageEntityEvent event) {
  Set<DamageModifierType> types = Sets.newHashSet(DamageModifierTypes.ABSORPTION, DamageModifierTypes.ARMOR,
     DamageModifierTypes.ARMOR_ENCHANTMENT, DamageModifierTypes.MAGIC);
  DamageModifier modifier = DamageModifier.builder()
      .type(DamageModifierTypes.BLOCKING)
      .cause(Cause.of(NamedCause.source(this)))
      .build();
  event.addModifierAfter(modifier, (damage) -> - damage, types);
}
1 Like

Lol @gabizou, I can feel your excitement from my room.

2 Likes

@gabizou
@simon816

Thanks both of you, this is really helpful.

Why is @gabizou in your room?

3 Likes

That is not what i meant at all.

I meant that I, sitting in my room, can feel his excitement pouring out into the universe at high intensity from many miles away.

Although if he were in my room that could be cool too.

3 Likes

^^^^^^^^^^^^^^
gravityfox & gabizou :wink:

Sorry, no.

Not happening.