Skip to content

Commit 36b13d7

Browse files
committed
Rework ShieldDamageReduction & ShieldItemDamageFunction to be more future proof
1 parent 631fc45 commit 36b13d7

File tree

2 files changed

+53
-51
lines changed

2 files changed

+53
-51
lines changed

src/main/java/org/spongepowered/api/data/type/ShieldDamageReduction.java

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@
2626

2727
import org.spongepowered.api.Sponge;
2828
import org.spongepowered.api.event.cause.entity.damage.DamageType;
29+
import org.spongepowered.api.event.cause.entity.damage.source.DamageSource;
2930
import org.spongepowered.api.tag.Tag;
3031
import org.spongepowered.api.util.ResettableBuilder;
3132

32-
import java.util.Optional;
3333
import java.util.Set;
3434

3535
/**
@@ -38,50 +38,53 @@
3838
*/
3939
public interface ShieldDamageReduction {
4040

41-
/**
42-
* Returns the {@link DamageType damage types} this reduction applies to.
43-
* {@link Optional#empty()} means this reduction is not restricted to any given damage type.
44-
*
45-
* @return the affected damage types
46-
*/
47-
Optional<Set<DamageType>> damageTypes();
48-
49-
/**
50-
* Returns the maximum angle between the users facing direction and the direction of the incoming attack.
51-
*
52-
* @return the maximum angle
53-
*/
54-
double horizontalBlockingAngle();
55-
56-
/**
57-
* Returns the constant amount of damage to be blocked.
58-
*
59-
* @return a constant amount of damage to block
60-
*/
61-
double constantReduction();
62-
63-
/**
64-
* Returns fractional amount of damage to block, where a factor of 1 means that all damage is blocked,
65-
* and a factor of 0 that no damage is blocked.
66-
*
67-
* @return fractional amount of damage to block
68-
*/
69-
double fractionalReduction();
41+
double resolve(DamageSource source, double damage, double angle);
7042

7143
static Builder builder() {
7244
return Sponge.game().builderProvider().provide(Builder.class);
7345
}
7446

7547
interface Builder extends ResettableBuilder<ShieldDamageReduction, Builder> {
7648

49+
/**
50+
* Limits the {@link DamageType damage types} this reduction applies to.
51+
*
52+
* @param damageTypes the affected damage types
53+
* @return This builder, for chaining
54+
*/
7755
Builder damageTypes(Set<DamageType> damageTypes);
7856

57+
/**
58+
* Limits the {@link DamageType damage types} this reduction applies to.
59+
*
60+
* @param tag the tag defining affected damage types
61+
* @return This builder, for chaining
62+
*/
7963
Builder damageTypes(Tag<DamageType> tag);
8064

65+
/**
66+
* Sets the maximum angle between the users facing direction and the direction of the incoming attack.
67+
*
68+
* @param angle the maximum angle
69+
* @return This builder, for chaining
70+
*/
8171
Builder horizontalBlockingAngle(double angle);
8272

73+
/**
74+
* Sets the constant amount of damage to be blocked.
75+
*
76+
* @param constant a constant amount of damage to block
77+
* @return This builder, for chaining
78+
*/
8379
Builder constantReduction(double constant);
8480

81+
/**
82+
* Sets fractional amount of damage to block, where a factor of 1 means that all damage is blocked,
83+
* and a factor of 0 that no damage is blocked.
84+
*
85+
* @param fraction fractional amount of damage to block
86+
* @return This builder, for chaining
87+
*/
8588
Builder fractionalReduction(double fraction);
8689

8790
ShieldDamageReduction build();

src/main/java/org/spongepowered/api/data/type/ShieldItemDamageFunction.java

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,38 +34,37 @@
3434
*/
3535
public interface ShieldItemDamageFunction {
3636

37-
/**
38-
* Returns the minimum amount of damage blocked attack must have had, for the item to take damage at all.
39-
*
40-
* @return minimum attack damage required for any durability loss
41-
*/
42-
double minAttackDamage();
43-
44-
/**
45-
* Returns the constant amount of damage taken.
46-
*
47-
* @return a constant amount of damage to take
48-
*/
49-
double constantDamage();
50-
51-
/**
52-
* Returns fractional amount of damage to take, where a factor of 1 means that the amount of durability lost is equal to attack damage,
53-
* and a factor of 0 that no durability is lost.
54-
*
55-
* @return fractional amount of damage to take
56-
*/
57-
double fractionalDamage();
37+
double resolve(double damage);
5838

5939
static Builder builder() {
6040
return Sponge.game().builderProvider().provide(Builder.class);
6141
}
6242

6343
interface Builder extends ResettableBuilder<ShieldItemDamageFunction, Builder> {
6444

45+
/**
46+
* Sets the minimum amount of damage blocked attack must have had, for the item to take damage at all.
47+
*
48+
* @param minDamage minimum attack damage required for any durability loss
49+
* @return This builder, for chaining
50+
*/
6551
Builder minAttackDamage(double minDamage);
6652

53+
/**
54+
* Sets the constant amount of damage taken.
55+
*
56+
* @param constantDamage a constant amount of damage to take
57+
* @return This builder, for chaining
58+
*/
6759
Builder constantDamage(double constantDamage);
6860

61+
/**
62+
* Sets fractional amount of damage to take, where a factor of 1 means that the amount of durability lost is equal to attack damage,
63+
* and a factor of 0 that no durability is lost.
64+
*
65+
* @param fractionalDamage fractional amount of damage to take
66+
* @return This builder, for chaining
67+
*/
6968
Builder fractionalDamage(double fractionalDamage);
7069

7170
ShieldItemDamageFunction build();

0 commit comments

Comments
 (0)