Skip to content

Commit 2d23b87

Browse files
committed
Revise based on feedback
1 parent b00c427 commit 2d23b87

File tree

3 files changed

+63
-10
lines changed

3 files changed

+63
-10
lines changed

src/main/java/org/spongepowered/api/data/Keys.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3073,7 +3073,7 @@ public final class Keys {
30733073
/**
30743074
* The amount of attack damage a shield-like {@link ItemStack} reduces for certain {@link DamageType}s
30753075
*/
3076-
public static final Key<ListValue<ShieldDamageReduction<?>>> SHIELD_DAMAGE_REDUCTIONS = Keys.listKey(ResourceKey.sponge("shield_damage_reductions"), ShieldDamageReduction.class);
3076+
public static final Key<ListValue<ShieldDamageReduction<?>>> SHIELD_DAMAGE_REDUCTIONS = Keys.listKey(ResourceKey.sponge("shield_damage_reductions"), new TypeToken<>() {});
30773077

30783078
/**
30793079
* The amount of {@link Ticks} player must use this shield-like {@link ItemStack} for to block attacks successfully.
@@ -3088,7 +3088,7 @@ public final class Keys {
30883088
/**
30893089
* Function for the amount of {@link Keys#ITEM_DURABILITY} damage a shield-like {@link ItemStack} takes when blocking an attack.
30903090
*/
3091-
public static final Key<Value<ShieldItemDamageFunction<?>>> SHIELD_ITEM_DAMAGE_FUNCTION = Keys.key(ResourceKey.sponge("shield_item_damage_function"), ShieldItemDamageFunction.class);
3091+
public static final Key<Value<ShieldItemDamageFunction<?>>> SHIELD_ITEM_DAMAGE_FUNCTION = Keys.key(ResourceKey.sponge("shield_item_damage_function"), new TypeToken<>() {});
30923092

30933093
/**
30943094
* The shooter of a {@link Projectile}.

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

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.spongepowered.api.tag.Tag;
3131
import org.spongepowered.api.util.ResettableBuilder;
3232

33+
import java.util.Optional;
3334
import java.util.Set;
3435

3536

@@ -38,12 +39,14 @@
3839
*/
3940
public interface ShieldDamageReduction<T> {
4041

41-
double resolve(DamageSource source, double damage, double angle);
42-
4342
static ShieldDamageReduction<MultiplyAdd> of(MultiplyAdd config) {
4443
return Sponge.game().factoryProvider().provide(Factory.class).create(config);
4544
}
4645

46+
T configuration();
47+
48+
double resolve(DamageSource source, double damage, double angle);
49+
4750
interface Factory {
4851

4952
ShieldDamageReduction<MultiplyAdd> create(MultiplyAdd config);
@@ -55,12 +58,40 @@ interface Factory {
5558
*/
5659
interface MultiplyAdd {
5760

58-
double resolve(DamageSource source, double damage, double angle);
59-
6061
static Builder builder() {
6162
return Sponge.game().builderProvider().provide(Builder.class);
6263
}
6364

65+
/**
66+
* Returns the {@link DamageType damage types} this reduction applies to.
67+
* {@link Optional#empty()} means this reduction is not restricted to any given damage type.
68+
*
69+
* @return the affected damage types
70+
*/
71+
Optional<Set<DamageType>> damageTypes();
72+
73+
/**
74+
* Returns the maximum angle between the users facing direction and the direction of the incoming attack.
75+
*
76+
* @return the maximum angle
77+
*/
78+
double horizontalBlockingAngle();
79+
80+
/**
81+
* Returns the constant amount of damage to be blocked.
82+
*
83+
* @return a constant amount of damage to block
84+
*/
85+
double constantReduction();
86+
87+
/**
88+
* Returns fractional amount of damage to block, where a factor of 1 means that all damage is blocked,
89+
* and a factor of 0 that no damage is blocked.
90+
*
91+
* @return fractional amount of damage to block
92+
*/
93+
double fractionalReduction();
94+
6495
interface Builder extends ResettableBuilder<MultiplyAdd, Builder> {
6596

6697
/**

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@
3333
*/
3434
public interface ShieldItemDamageFunction<T> {
3535

36-
double resolve(double damage);
37-
3836
static ShieldItemDamageFunction<MultiplyAdd> of(MultiplyAdd config) {
3937
return Sponge.game().factoryProvider().provide(Factory.class).create(config);
4038
}
4139

40+
T configuration();
41+
42+
double resolve(double damage);
43+
4244
interface Factory {
4345

4446
ShieldItemDamageFunction<MultiplyAdd> create(MultiplyAdd config);
@@ -50,12 +52,32 @@ interface Factory {
5052
*/
5153
interface MultiplyAdd {
5254

53-
double resolve(double damage);
54-
5555
static Builder builder() {
5656
return Sponge.game().builderProvider().provide(Builder.class);
5757
}
5858

59+
/**
60+
* Returns the minimum amount of damage blocked attack must have had, for the item to take damage at all.
61+
*
62+
* @return minimum attack damage required for any durability loss
63+
*/
64+
double minAttackDamage();
65+
66+
/**
67+
* Returns the constant amount of damage taken.
68+
*
69+
* @return a constant amount of damage to take
70+
*/
71+
double constantDamage();
72+
73+
/**
74+
* Returns fractional amount of damage to take, where a factor of 1 means that the amount of durability lost is equal to attack damage,
75+
* and a factor of 0 that no durability is lost.
76+
*
77+
* @return fractional amount of damage to take
78+
*/
79+
double fractionalDamage();
80+
5981
interface Builder extends ResettableBuilder<MultiplyAdd, Builder> {
6082

6183
/**

0 commit comments

Comments
 (0)