|
32 | 32 |
|
33 | 33 | import java.util.Set; |
34 | 34 |
|
| 35 | + |
35 | 36 | /** |
36 | 37 | * Defines the amount of damage reduced when blocking with a shield-like {@link org.spongepowered.api.item.inventory.ItemStack}. |
37 | | - * The final amount of blocked damage will be {@code constantReduction + fractionalReduction * damage} |
38 | 38 | */ |
39 | | -public interface ShieldDamageReduction { |
| 39 | +public interface ShieldDamageReduction<T> { |
40 | 40 |
|
41 | 41 | double resolve(DamageSource source, double damage, double angle); |
42 | 42 |
|
43 | | - static Builder builder() { |
44 | | - return Sponge.game().builderProvider().provide(Builder.class); |
| 43 | + static ShieldDamageReduction<MultiplyAdd> of(MultiplyAdd config) { |
| 44 | + return Sponge.game().factoryProvider().provide(Factory.class).create(config); |
| 45 | + } |
| 46 | + |
| 47 | + interface Factory { |
| 48 | + |
| 49 | + ShieldDamageReduction<MultiplyAdd> create(MultiplyAdd config); |
| 50 | + |
45 | 51 | } |
46 | 52 |
|
47 | | - interface Builder extends ResettableBuilder<ShieldDamageReduction, Builder> { |
48 | | - |
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 | | - */ |
55 | | - Builder damageTypes(Set<DamageType> damageTypes); |
56 | | - |
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 | | - */ |
63 | | - Builder damageTypes(Tag<DamageType> tag); |
64 | | - |
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 | | - */ |
71 | | - Builder horizontalBlockingAngle(double angle); |
72 | | - |
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 | | - */ |
79 | | - Builder constantReduction(double constant); |
80 | | - |
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 | | - */ |
88 | | - Builder fractionalReduction(double fraction); |
89 | | - |
90 | | - ShieldDamageReduction build(); |
| 53 | + /** |
| 54 | + * The final amount of blocked damage will be {@code constantReduction + fractionalReduction * damage} |
| 55 | + */ |
| 56 | + interface MultiplyAdd { |
| 57 | + |
| 58 | + double resolve(DamageSource source, double damage, double angle); |
| 59 | + |
| 60 | + static Builder builder() { |
| 61 | + return Sponge.game().builderProvider().provide(Builder.class); |
| 62 | + } |
| 63 | + |
| 64 | + interface Builder extends ResettableBuilder<MultiplyAdd, Builder> { |
| 65 | + |
| 66 | + /** |
| 67 | + * Limits the {@link DamageType damage types} this reduction applies to. |
| 68 | + * |
| 69 | + * @param damageTypes the affected damage types |
| 70 | + * @return This builder, for chaining |
| 71 | + */ |
| 72 | + Builder damageTypes(Set<DamageType> damageTypes); |
| 73 | + |
| 74 | + /** |
| 75 | + * Limits the {@link DamageType damage types} this reduction applies to. |
| 76 | + * |
| 77 | + * @param tag the tag defining affected damage types |
| 78 | + * @return This builder, for chaining |
| 79 | + */ |
| 80 | + Builder damageTypes(Tag<DamageType> tag); |
| 81 | + |
| 82 | + /** |
| 83 | + * Sets the maximum angle between the users facing direction and the direction of the incoming attack. |
| 84 | + * |
| 85 | + * @param angle the maximum angle |
| 86 | + * @return This builder, for chaining |
| 87 | + */ |
| 88 | + Builder horizontalBlockingAngle(double angle); |
| 89 | + |
| 90 | + /** |
| 91 | + * Sets the constant amount of damage to be blocked. |
| 92 | + * |
| 93 | + * @param constant a constant amount of damage to block |
| 94 | + * @return This builder, for chaining |
| 95 | + */ |
| 96 | + Builder constantReduction(double constant); |
| 97 | + |
| 98 | + /** |
| 99 | + * Sets fractional amount of damage to block, where a factor of 1 means that all damage is blocked, |
| 100 | + * and a factor of 0 that no damage is blocked. |
| 101 | + * |
| 102 | + * @param fraction fractional amount of damage to block |
| 103 | + * @return This builder, for chaining |
| 104 | + */ |
| 105 | + Builder fractionalReduction(double fraction); |
| 106 | + |
| 107 | + MultiplyAdd build(); |
| 108 | + |
| 109 | + } |
91 | 110 |
|
92 | 111 | } |
93 | 112 |
|
|
0 commit comments