Skip to content

Commit 214a97c

Browse files
authored
Expose minecraft:blocks_attacks and minecraft:weapon (#2604)
1 parent 9b0d678 commit 214a97c

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
@@ -90,6 +90,8 @@
9090
import org.spongepowered.api.data.type.RailDirection;
9191
import org.spongepowered.api.data.type.SalmonSize;
9292
import org.spongepowered.api.data.type.SculkSensorState;
93+
import org.spongepowered.api.data.type.ShieldDamageReduction;
94+
import org.spongepowered.api.data.type.ShieldItemDamageFunction;
9395
import org.spongepowered.api.data.type.SkinPart;
9496
import org.spongepowered.api.data.type.SlabPortion;
9597
import org.spongepowered.api.data.type.SpellType;
@@ -224,6 +226,7 @@
224226
import org.spongepowered.api.entity.vehicle.minecart.Minecart;
225227
import org.spongepowered.api.entity.vehicle.minecart.MinecartLike;
226228
import org.spongepowered.api.entity.weather.LightningBolt;
229+
import org.spongepowered.api.event.cause.entity.damage.DamageType;
227230
import org.spongepowered.api.event.cause.entity.damage.source.DamageSource;
228231
import org.spongepowered.api.event.cause.entity.damage.source.DamageSources;
229232
import org.spongepowered.api.fluid.FluidStackSnapshot;
@@ -639,6 +642,11 @@ public final class Keys {
639642
*/
640643
public static final Key<Value<Integer>> BURN_TIME = Keys.key(ResourceKey.sponge("burn_time"), Integer.class);
641644

645+
/**
646+
* The {@link DamageType} tag that bypasses a shield-like {@link ItemStack}.
647+
*/
648+
public static final Key<Value<Tag<DamageType>>> BYPASS_DAMAGE_TAG = Keys.key(ResourceKey.sponge("bypass_damage_tag"), new TypeToken<>() {});
649+
642650
/**
643651
* Whether an {@link ItemStack} can always be eaten.
644652
*/
@@ -976,6 +984,17 @@ public final class Keys {
976984
*/
977985
public static final Key<Value<Direction>> DIRECTION = Keys.key(ResourceKey.sponge("direction"), Direction.class);
978986

987+
/**
988+
* The amount of {@link Ticks} this {@link ItemStack} disables blocking with a shield-like {@link ItemStack} on a successful attack.
989+
*/
990+
public static final Key<Value<Ticks>> DISABLE_SHIELD_TICKS = Keys.key(ResourceKey.sponge("disable_shield_ticks"), Ticks.class);
991+
992+
/**
993+
* The multiplier applied to the cooldown time during which blocking using this shield-like {@link ItemStack} is disabled.
994+
* If set to 0, this item can never be disabled by attacks.
995+
*/
996+
public static final Key<Value<Double>> DISABLE_SHIELD_TICKS_SCALE = Keys.key(ResourceKey.sponge("disable_shield_ticks_scale"), Double.class);
997+
979998
/**
980999
* The display name of an {@link Entity}, {@link ItemStack} or {@link BlockEntity}.
9811000
*
@@ -3046,6 +3065,31 @@ public final class Keys {
30463065
*/
30473066
public static final Key<Value<Double>> SHADOW_STRENGTH = Keys.key(ResourceKey.sponge("shadow_strength"), Double.class);
30483067

3068+
/**
3069+
* The sound played when blocking an attack with a shield-like {@link ItemStack}.
3070+
*/
3071+
public static final Key<Value<SoundType>> SHIELD_BLOCK_SOUND = Keys.key(ResourceKey.sponge("shield_block_sound"), SoundType.class);
3072+
3073+
/**
3074+
* The amount of attack damage a shield-like {@link ItemStack} reduces for certain {@link DamageType}s
3075+
*/
3076+
public static final Key<ListValue<ShieldDamageReduction<?>>> SHIELD_DAMAGE_REDUCTIONS = Keys.listKey(ResourceKey.sponge("shield_damage_reductions"), new TypeToken<>() {});
3077+
3078+
/**
3079+
* The amount of {@link Ticks} player must use this shield-like {@link ItemStack} for to block attacks successfully.
3080+
*/
3081+
public static final Key<Value<Ticks>> SHIELD_DEPLOY_TICKS = Keys.key(ResourceKey.sponge("shield_deploy_ticks"), Ticks.class);
3082+
3083+
/**
3084+
* The sound played when a shield-like {@link ItemStack} is disabled.
3085+
*/
3086+
public static final Key<Value<SoundType>> SHIELD_DISABLE_SOUND = Keys.key(ResourceKey.sponge("shield_disable_sound"), SoundType.class);
3087+
3088+
/**
3089+
* Function for the amount of {@link Keys#ITEM_DURABILITY} damage a shield-like {@link ItemStack} takes when blocking an attack.
3090+
*/
3091+
public static final Key<Value<ShieldItemDamageFunction<?>>> SHIELD_ITEM_DAMAGE_FUNCTION = Keys.key(ResourceKey.sponge("shield_item_damage_function"), new TypeToken<>() {});
3092+
30493093
/**
30503094
* The shooter of a {@link Projectile}.
30513095
*/
@@ -3534,6 +3578,11 @@ public final class Keys {
35343578
*/
35353579
public static final Key<Value<Color>> WATER_FOG_COLOR = Keys.key(ResourceKey.sponge("water_fog_color"), Color.class);
35363580

3581+
/**
3582+
* The {@link #ITEM_DURABILITY} damage an {@link ItemStack} takes per attack.
3583+
*/
3584+
public static final Key<Value<Integer>> WEAPON_DAMAGE_PER_ATTACK = Keys.key(ResourceKey.sponge("weapon_damage_per_attack"), Integer.class);
3585+
35373586
/**
35383587
* The weather of a {@link ServerWorldProperties}.
35393588
*/
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)