2727import org .spongepowered .api .event .Cause ;
2828
2929import java .util .List ;
30+ import java .util .OptionalDouble ;
3031
3132/**
32- * Represents a step in the damage calculation.
33+ * Represents a tree of steps in the damage calculation.
34+ * A damage calculation is made of multiple trees of steps.
3335 */
3436public interface DamageStep {
3537
3638 /**
37- * Gets the {@link DamageStepType} for this {@link DamageStep} .
39+ * Gets the {@link DamageStepType} for this step .
3840 *
3941 * @return The damage step type
4042 */
4143 DamageStepType type ();
4244
43- /**
44- * Gets the cause of this {@link DamageStep}.
45- *
46- * @return The cause of this step
47- */
48- Cause cause ();
49-
5045 /**
5146 * Gets whether this step is skipped.
52- * When skipped, only the step and its side effects are ignored, modifiers are still applied.
53- * A modifier willing to ignore every previous modifiers should revert the damage to {@link #damageBeforeModifiers()}.
47+ * When skipped, only the step itself and its side effects are ignored, children are still applied.
48+ * A modifier willing to ignore every previous children should revert the damage to {@link #damageBeforeChildren()},
49+ * or call {@link #skip} on each child.
5450 *
5551 * @return Whether this step is skipped
5652 */
@@ -75,47 +71,74 @@ default void skip() {
7571 }
7672
7773 /**
78- * The damage just before the modifiers of this step.
74+ * The damage just before the children of this step.
75+ * Returns empty if the value is not known yet.
7976 *
80- * @return The damage before this step
77+ * @return The damage before the children of this step
8178 */
82- double damageBeforeModifiers ();
79+ OptionalDouble damageBeforeChildren ();
8380
8481 /**
8582 * The damage just before this step.
83+ * Returns empty if the value is not known yet.
8684 *
8785 * @return The damage before this step
88- * @throws IllegalStateException if called before the "before" modifiers have finished.
8986 */
90- double damageBeforeStep ();
87+ OptionalDouble damageBeforeSelf ();
9188
9289 /**
9390 * The damage just after this step.
91+ * Returns empty if the value is not known yet.
9492 *
9593 * @return The damage after this step
96- * @throws IllegalStateException if called before this step has finished
9794 */
98- double damageAfterStep ();
95+ OptionalDouble damageAfterSelf ();
9996
10097 /**
101- * The damage just after the modifiers of this step.
98+ * The damage just after the children of this step.
99+ * Returns empty if the value is not known yet.
102100 *
103101 * @return The damage after this step
104- * @throws IllegalStateException if called before the modifiers have finished.
105102 */
106- double damageAfterModifiers ();
103+ OptionalDouble damageAfterChildren ();
107104
108105 /**
109- * Gets an immutable list of all modifiers that applies just before this step.
106+ * Gets an immutable list of all children steps that applies just before this step.
110107 *
111- * @return The list of modifiers
108+ * @return The list of children steps
112109 */
113- List <DamageModifier > modifiersBefore ();
110+ List <DamageStep . Child > childrenBefore ();
114111
115112 /**
116- * Gets an immutable list of all modifiers that applies just after this step.
113+ * Gets an immutable list of all children steps that applies just after this step.
117114 *
118- * @return The list of modifiers
115+ * @return The list of children steps
116+ */
117+ List <DamageStep .Child > childrenAfter ();
118+
119+ /**
120+ * Represents a step made by the platform (vanilla and mods).
119121 */
120- List <DamageModifier > modifiersAfter ();
122+ interface Root extends DamageStep {
123+
124+ /**
125+ * Gets the {@link Cause} of this step.
126+ *
127+ * @return The cause of this step
128+ */
129+ Cause cause ();
130+ }
131+
132+ /**
133+ * Represents a step made by a plugin (a modifier).
134+ */
135+ interface Child extends DamageStep , DamageModifier {
136+
137+ /**
138+ * Gets the parent of this step.
139+ *
140+ * @return The parent of this step
141+ */
142+ DamageStep parent ();
143+ }
121144}
0 commit comments