Skip to content

Commit 0823c6a

Browse files
committed
Add history to view previous root steps during the calculation
1 parent d6f9fbf commit 0823c6a

File tree

3 files changed

+54
-5
lines changed

3 files changed

+54
-5
lines changed

src/main/java/org/spongepowered/api/event/cause/entity/damage/DamageStep.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ default void skip() {
9595
*/
9696
OptionalDouble damageAfterChildren();
9797

98+
/**
99+
* Gets the {@link DamageStepHistory} this step belongs to.
100+
*
101+
* @return The history containing this step.
102+
*/
103+
DamageStepHistory history();
104+
98105
/**
99106
* Gets the parent of this step.
100107
* Returns empty if this step is the root of its tree.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* This file is part of SpongeAPI, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) SpongePowered <https://www.spongepowered.org>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package org.spongepowered.api.event.cause.entity.damage;
26+
27+
import java.util.List;
28+
29+
/**
30+
* Captures the root steps occurring during a damage calculation.
31+
*/
32+
public interface DamageStepHistory {
33+
34+
/**
35+
* Gets the list of the captured root steps during the damage calculation in the order they have been applied.
36+
* Note that this list is not an exhaustive representation of all the operations applied,
37+
* especially in a modded environment.
38+
* The list is unmodifiable and will gradually grow during the damage calculation.
39+
*
40+
* @return The root steps.
41+
*/
42+
List<DamageStep> rootSteps();
43+
}

src/main/java/org/spongepowered/api/event/entity/DamageCalculationEvent.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.spongepowered.api.event.Event;
3131
import org.spongepowered.api.event.cause.entity.damage.DamageModifier;
3232
import org.spongepowered.api.event.cause.entity.damage.DamageStep;
33+
import org.spongepowered.api.event.cause.entity.damage.DamageStepHistory;
3334
import org.spongepowered.api.event.cause.entity.damage.DamageStepType;
3435
import org.spongepowered.api.event.cause.entity.damage.DamageStepTypes;
3536
import org.spongepowered.api.event.impl.entity.AbstractDamageCalculationEventPre;
@@ -138,12 +139,10 @@ interface Post extends DamageCalculationEvent {
138139
double finalDamage();
139140

140141
/**
141-
* Gets the list of the captured root steps during the damage calculation in the order they have been applied.
142-
* Note that this list is not an exhaustive representation of all the operations applied,
143-
* especially in a modded environment.
142+
* Gets the {@link DamageStepHistory} of this damage calculation.
144143
*
145-
* @return The list of root steps
144+
* @return The history.
146145
*/
147-
List<DamageStep> steps();
146+
DamageStepHistory history();
148147
}
149148
}

0 commit comments

Comments
 (0)