Skip to content

Commit 1e5c916

Browse files
committed
chore(git): merge upstream changes
Signed-off-by: Gabriel Harris-Rouquette <[email protected]>
2 parents b4fc87b + 917a38e commit 1e5c916

File tree

3 files changed

+307
-0
lines changed

3 files changed

+307
-0
lines changed

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

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@
9191
import org.spongepowered.api.data.type.RailDirection;
9292
import org.spongepowered.api.data.type.SalmonSize;
9393
import org.spongepowered.api.data.type.SculkSensorState;
94+
import org.spongepowered.api.data.type.ShieldDamageReduction;
95+
import org.spongepowered.api.data.type.ShieldItemDamageFunction;
9496
import org.spongepowered.api.data.type.SkinPart;
9597
import org.spongepowered.api.data.type.SlabPortion;
9698
import org.spongepowered.api.data.type.SpellType;
@@ -226,6 +228,7 @@
226228
import org.spongepowered.api.entity.vehicle.minecart.Minecart;
227229
import org.spongepowered.api.entity.vehicle.minecart.MinecartLike;
228230
import org.spongepowered.api.entity.weather.LightningBolt;
231+
import org.spongepowered.api.event.cause.entity.damage.DamageType;
229232
import org.spongepowered.api.event.cause.entity.damage.source.DamageSource;
230233
import org.spongepowered.api.event.cause.entity.damage.source.DamageSources;
231234
import org.spongepowered.api.fluid.FluidStackSnapshot;
@@ -642,6 +645,11 @@ public final class Keys {
642645
*/
643646
public static final Key<Value<Integer>> BURN_TIME = Keys.key(ResourceKey.sponge("burn_time"), Integer.class);
644647

648+
/**
649+
* The {@link DamageType} tag that bypasses a shield-like {@link ItemStack}.
650+
*/
651+
public static final Key<Value<Tag<DamageType>>> BYPASS_DAMAGE_TAG = Keys.key(ResourceKey.sponge("bypass_damage_tag"), new TypeToken<>() {});
652+
645653
/**
646654
* Whether an {@link ItemStack} can always be eaten.
647655
*/
@@ -986,6 +994,17 @@ public final class Keys {
986994
*/
987995
public static final Key<Value<Direction>> DIRECTION = Keys.key(ResourceKey.sponge("direction"), Direction.class);
988996

997+
/**
998+
* The amount of {@link Ticks} this {@link ItemStack} disables blocking with a shield-like {@link ItemStack} on a successful attack.
999+
*/
1000+
public static final Key<Value<Ticks>> DISABLE_SHIELD_TICKS = Keys.key(ResourceKey.sponge("disable_shield_ticks"), Ticks.class);
1001+
1002+
/**
1003+
* The multiplier applied to the cooldown time during which blocking using this shield-like {@link ItemStack} is disabled.
1004+
* If set to 0, this item can never be disabled by attacks.
1005+
*/
1006+
public static final Key<Value<Double>> DISABLE_SHIELD_TICKS_SCALE = Keys.key(ResourceKey.sponge("disable_shield_ticks_scale"), Double.class);
1007+
9891008
/**
9901009
* The display name of an {@link Entity}, {@link ItemStack} or {@link BlockEntity}.
9911010
*
@@ -3056,6 +3075,31 @@ public final class Keys {
30563075
*/
30573076
public static final Key<Value<Double>> SHADOW_STRENGTH = Keys.key(ResourceKey.sponge("shadow_strength"), Double.class);
30583077

3078+
/**
3079+
* The sound played when blocking an attack with a shield-like {@link ItemStack}.
3080+
*/
3081+
public static final Key<Value<SoundType>> SHIELD_BLOCK_SOUND = Keys.key(ResourceKey.sponge("shield_block_sound"), SoundType.class);
3082+
3083+
/**
3084+
* The amount of attack damage a shield-like {@link ItemStack} reduces for certain {@link DamageType}s
3085+
*/
3086+
public static final Key<ListValue<ShieldDamageReduction<?>>> SHIELD_DAMAGE_REDUCTIONS = Keys.listKey(ResourceKey.sponge("shield_damage_reductions"), new TypeToken<>() {});
3087+
3088+
/**
3089+
* The amount of {@link Ticks} player must use this shield-like {@link ItemStack} for to block attacks successfully.
3090+
*/
3091+
public static final Key<Value<Ticks>> SHIELD_DEPLOY_TICKS = Keys.key(ResourceKey.sponge("shield_deploy_ticks"), Ticks.class);
3092+
3093+
/**
3094+
* The sound played when a shield-like {@link ItemStack} is disabled.
3095+
*/
3096+
public static final Key<Value<SoundType>> SHIELD_DISABLE_SOUND = Keys.key(ResourceKey.sponge("shield_disable_sound"), SoundType.class);
3097+
3098+
/**
3099+
* Function for the amount of {@link Keys#ITEM_DURABILITY} damage a shield-like {@link ItemStack} takes when blocking an attack.
3100+
*/
3101+
public static final Key<Value<ShieldItemDamageFunction<?>>> SHIELD_ITEM_DAMAGE_FUNCTION = Keys.key(ResourceKey.sponge("shield_item_damage_function"), new TypeToken<>() {});
3102+
30593103
/**
30603104
* The shooter of a {@link Projectile}.
30613105
*/
@@ -3550,6 +3594,11 @@ public final class Keys {
35503594
*/
35513595
public static final Key<Value<Boolean>> WAXED = Keys.key(ResourceKey.sponge("waxed"), Boolean.class);
35523596

3597+
/**
3598+
* The {@link #ITEM_DURABILITY} damage an {@link ItemStack} takes per attack.
3599+
*/
3600+
public static final Key<Value<Integer>> WEAPON_DAMAGE_PER_ATTACK = Keys.key(ResourceKey.sponge("weapon_damage_per_attack"), Integer.class);
3601+
35533602
/**
35543603
* The weather of a {@link ServerWorldProperties}.
35553604
*/
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
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.data.type;
26+
27+
import org.spongepowered.api.Sponge;
28+
import org.spongepowered.api.event.cause.entity.damage.DamageType;
29+
import org.spongepowered.api.event.cause.entity.damage.source.DamageSource;
30+
import org.spongepowered.api.tag.Tag;
31+
import org.spongepowered.api.util.ResettableBuilder;
32+
33+
import java.util.Optional;
34+
import java.util.Set;
35+
36+
37+
/**
38+
* Defines the amount of damage reduced when blocking with a shield-like {@link org.spongepowered.api.item.inventory.ItemStack}.
39+
*/
40+
public interface ShieldDamageReduction<T> {
41+
42+
static ShieldDamageReduction<MultiplyAdd> of(MultiplyAdd config) {
43+
return Sponge.game().factoryProvider().provide(Factory.class).create(config);
44+
}
45+
46+
T configuration();
47+
48+
double resolve(DamageSource source, double damage, double angle);
49+
50+
interface Factory {
51+
52+
ShieldDamageReduction<MultiplyAdd> create(MultiplyAdd config);
53+
54+
}
55+
56+
/**
57+
* The final amount of blocked damage will be {@code constantReduction + fractionalReduction * damage}
58+
*/
59+
interface MultiplyAdd {
60+
61+
static Builder builder() {
62+
return Sponge.game().builderProvider().provide(Builder.class);
63+
}
64+
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+
95+
interface Builder extends ResettableBuilder<MultiplyAdd, Builder> {
96+
97+
/**
98+
* Limits the {@link DamageType damage types} this reduction applies to.
99+
*
100+
* @param damageTypes the affected damage types
101+
* @return This builder, for chaining
102+
*/
103+
Builder damageTypes(Set<DamageType> damageTypes);
104+
105+
/**
106+
* Limits the {@link DamageType damage types} this reduction applies to.
107+
*
108+
* @param tag the tag defining affected damage types
109+
* @return This builder, for chaining
110+
*/
111+
Builder damageTypes(Tag<DamageType> tag);
112+
113+
/**
114+
* Sets the maximum angle between the users facing direction and the direction of the incoming attack.
115+
*
116+
* @param angle the maximum angle
117+
* @return This builder, for chaining
118+
*/
119+
Builder horizontalBlockingAngle(double angle);
120+
121+
/**
122+
* Sets the constant amount of damage to be blocked.
123+
*
124+
* @param constant a constant amount of damage to block
125+
* @return This builder, for chaining
126+
*/
127+
Builder constantReduction(double constant);
128+
129+
/**
130+
* Sets fractional amount of damage to block, where a factor of 1 means that all damage is blocked,
131+
* and a factor of 0 that no damage is blocked.
132+
*
133+
* @param fraction fractional amount of damage to block
134+
* @return This builder, for chaining
135+
*/
136+
Builder fractionalReduction(double fraction);
137+
138+
MultiplyAdd build();
139+
140+
}
141+
142+
}
143+
144+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
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.data.type;
26+
27+
import org.spongepowered.api.Sponge;
28+
import org.spongepowered.api.util.ResettableBuilder;
29+
30+
/**
31+
* Defines the amount of {@link org.spongepowered.api.data.Keys#ITEM_DURABILITY} damage a shield-like
32+
* {@link org.spongepowered.api.item.inventory.ItemStack} takes, when blocking an attack.
33+
*/
34+
public interface ShieldItemDamageFunction<T> {
35+
36+
static ShieldItemDamageFunction<MultiplyAdd> of(MultiplyAdd config) {
37+
return Sponge.game().factoryProvider().provide(Factory.class).create(config);
38+
}
39+
40+
T configuration();
41+
42+
double resolve(double damage);
43+
44+
interface Factory {
45+
46+
ShieldItemDamageFunction<MultiplyAdd> create(MultiplyAdd config);
47+
48+
}
49+
50+
/**
51+
* The final amount of damage will be {@code constantDamage + fractionalDamage * attackDamage}
52+
*/
53+
interface MultiplyAdd {
54+
55+
static Builder builder() {
56+
return Sponge.game().builderProvider().provide(Builder.class);
57+
}
58+
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+
81+
interface Builder extends ResettableBuilder<MultiplyAdd, Builder> {
82+
83+
/**
84+
* Sets the minimum amount of damage blocked attack must have had, for the item to take damage at all.
85+
*
86+
* @param minDamage minimum attack damage required for any durability loss
87+
* @return This builder, for chaining
88+
*/
89+
Builder minAttackDamage(double minDamage);
90+
91+
/**
92+
* Sets the constant amount of damage taken.
93+
*
94+
* @param constantDamage a constant amount of damage to take
95+
* @return This builder, for chaining
96+
*/
97+
Builder constantDamage(double constantDamage);
98+
99+
/**
100+
* Sets fractional amount of damage to take, where a factor of 1 means that the amount of durability lost is equal to attack damage,
101+
* and a factor of 0 that no durability is lost.
102+
*
103+
* @param fractionalDamage fractional amount of damage to take
104+
* @return This builder, for chaining
105+
*/
106+
Builder fractionalDamage(double fractionalDamage);
107+
108+
MultiplyAdd build();
109+
110+
}
111+
112+
}
113+
114+
}

0 commit comments

Comments
 (0)