Skip to content

Commit

Permalink
Replace setBaseDamage and setFinalDamage with damage steps
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeregorix committed Jan 27, 2025
1 parent e6ea6db commit 6fc2a58
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ public final class DamageStepTypes {
*/
public static final DefaultedRegistryReference<DamageStepType> ENCHANTMENT_COOLDOWN = DamageStepTypes.key(ResourceKey.sponge("enchantment_cooldown"));

/**
* Represents the last {@link DamageStep} applied during a damage calculation.
* This step happens just before the {@link org.spongepowered.api.event.entity.DamageCalculationEvent.Post}.
* This step does nothing but can be used to add modifiers to the final damage.
*/
public static final DefaultedRegistryReference<DamageStepType> END = DamageStepTypes.key(ResourceKey.sponge("end"));

/**
* Represents a {@link DamageStep} that will modify freezing damage.
* E.g. {@link org.spongepowered.api.entity.living.monster.Blaze} take more damage from freezing sources.
Expand Down Expand Up @@ -152,6 +159,13 @@ public final class DamageStepTypes {
*/
public static final DefaultedRegistryReference<DamageStepType> SHIELD = DamageStepTypes.key(ResourceKey.sponge("shield"));

/**
* Represents the first {@link DamageStep} applied during a damage calculation.
* This step happens just after the {@link org.spongepowered.api.event.entity.DamageCalculationEvent.Pre}.
* This step does nothing but can be used to add modifiers to the base damage.
*/
public static final DefaultedRegistryReference<DamageStepType> START = DamageStepTypes.key(ResourceKey.sponge("start"));

/**
* Represents a {@link DamageStep} that is applied for a sweeping attack.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.spongepowered.api.event.cause.entity.damage.DamageModifier;
import org.spongepowered.api.event.cause.entity.damage.DamageStep;
import org.spongepowered.api.event.cause.entity.damage.DamageStepType;
import org.spongepowered.api.event.cause.entity.damage.DamageStepTypes;
import org.spongepowered.api.event.impl.entity.AbstractDamageCalculationEventPre;
import org.spongepowered.api.item.inventory.ItemStack;
import org.spongepowered.api.world.difficulty.Difficulty;
Expand All @@ -48,7 +49,7 @@
*
* <p>Optimally, these steps can be traced to a
* particular object, be it an {@link ItemStack}, {@link Difficulty}, or
* simply an an attribute. Given that {@link Cause} has a unique capability of
* simply an attribute. Given that {@link Cause} has a unique capability of
* storing any and every {@link Object} willing to be passed into it, we
* can easily represent these "sources" of "steps" in a {@link Cause}.
* Now, knowing the "source" will not provide enough information, so a
Expand All @@ -65,17 +66,10 @@ public interface DamageCalculationEvent extends Event, Cancellable {
*/
Entity entity();

/**
* Gets the original base damage to deal to the targeted {@link Entity}.
*
* @see #baseDamage()
* @return The original base damage
*/
double originalBaseDamage();

/**
* Gets the base damage to deal to the targeted {@link Entity}.
* The base damage is the value before the calculation and its {@link DamageStep}s.
* To modify the base damage, add a modifier to the step associated to {@link DamageStepTypes#START}.
*
* @return The base damage
*/
Expand All @@ -88,14 +82,6 @@ public interface DamageCalculationEvent extends Event, Cancellable {
@ImplementedBy(AbstractDamageCalculationEventPre.class)
interface Pre extends DamageCalculationEvent {

/**
* Sets the base damage to deal to the targeted {@link Entity}.
*
* @see #baseDamage()
* @param baseDamage The base damage
*/
void setBaseDamage(double baseDamage);

/**
* Gets a mutable list of all modifiers that applies just before the step.
*
Expand All @@ -120,31 +106,16 @@ interface Pre extends DamageCalculationEvent {
*/
interface Post extends DamageCalculationEvent {

/**
* Gets the original final damage to deal to the targeted {@link Entity}.
*
* @see #finalDamage()
* @return The final amount of damage to originally deal
*/
double originalFinalDamage();

/**
* Gets the final damage to deal to the targeted {@link Entity}.
* The final damage is the value after the calculation and its {@link DamageStep}s.
* The final damage is the amount of health being lost by the {@link Entity}, if health is tracked.
* To modify the final damage, add a modifier to the step associated to {@link DamageStepTypes#END}.
*
* @return The final damage
*/
double finalDamage();

/**
* Sets the final damage to deal to the targeted {@link Entity}.
*
* @see #finalDamage()
* @param finalDamage The base damage
*/
void setFinalDamage(double finalDamage);

/**
* Gets the list of the captured steps during the damage calculation in the order they have been applied.
* Note that this list is not an exhaustive representation of all the operations applied,
Expand Down

0 comments on commit 6fc2a58

Please sign in to comment.