Skip to content

Commit 492c754

Browse files
committed
Expose minecraft:blocks_attacks related Keys
1 parent bb4d583 commit 492c754

File tree

3 files changed

+158
-0
lines changed

3 files changed

+158
-0
lines changed

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@
8989
import org.spongepowered.api.data.type.RailDirection;
9090
import org.spongepowered.api.data.type.SalmonSize;
9191
import org.spongepowered.api.data.type.SculkSensorState;
92+
import org.spongepowered.api.data.type.ShieldDamageReduction;
93+
import org.spongepowered.api.data.type.ShieldItemDamageFunction;
9294
import org.spongepowered.api.data.type.SkinPart;
9395
import org.spongepowered.api.data.type.SlabPortion;
9496
import org.spongepowered.api.data.type.SpellType;
@@ -223,6 +225,7 @@
223225
import org.spongepowered.api.entity.vehicle.minecart.Minecart;
224226
import org.spongepowered.api.entity.vehicle.minecart.MinecartLike;
225227
import org.spongepowered.api.entity.weather.LightningBolt;
228+
import org.spongepowered.api.event.cause.entity.damage.DamageType;
226229
import org.spongepowered.api.event.cause.entity.damage.source.DamageSource;
227230
import org.spongepowered.api.event.cause.entity.damage.source.DamageSources;
228231
import org.spongepowered.api.fluid.FluidStackSnapshot;
@@ -3655,6 +3658,43 @@ public final class Keys {
36553658
*/
36563659
public static final Key<Value<Ticks>> DISABLE_BLOCKING_TICKS = Keys.key(ResourceKey.sponge("disable_blocking_ticks"), Ticks.class);
36573660

3661+
/**
3662+
* The amount of {@link Ticks} player must use this {@link ItemStack} for to block attacks successfully.
3663+
*/
3664+
public static final Key<Value<Ticks>> BLOCK_DELAY_TICKS = Keys.key(ResourceKey.sponge("block_delay_ticks"), Ticks.class);
3665+
3666+
/**
3667+
* Multiplier applied to the cooldown during which blocking using this item is disabled.
3668+
*
3669+
* @see <a href="https://minecraft.wiki/w/Data_component_format#blocks_attacks">blocks_attacks</a>
3670+
*/
3671+
public static final Key<Value<Float>> DISABLED_BLOCKING_COOLDOWN_SCALE = Keys.key(ResourceKey.sponge("disabled_blocking_cooldown_scale"), Float.class);
3672+
3673+
/**
3674+
* The amount of attack damage a shield-like {@link ItemStack} reduces for certain {@link DamageType}s
3675+
*/
3676+
public static final Key<ListValue<ShieldDamageReduction>> SHIELD_DAMAGE_REDUCTIONS = Keys.listKey(ResourceKey.sponge("shield_damage_reductions"), ShieldDamageReduction.class);
3677+
3678+
/**
3679+
* Function for the amount of {@link Keys#ITEM_DURABILITY} damage a shield-like {@link ItemStack} takes when blocking an attack.
3680+
*/
3681+
public static final Key<Value<ShieldItemDamageFunction>> SHIELD_ITEM_DAMAGE_FUNCTION = Keys.key(ResourceKey.sponge("shield_item_damage_function"), ShieldItemDamageFunction.class);
3682+
3683+
/**
3684+
* The {@link DamageType} tag that bypasses a shield-like {@link ItemStack}.
3685+
*/
3686+
public static final Key<Value<Tag<DamageType>>> BYPASS_DAMAGE_TAG = Keys.key(ResourceKey.sponge("bypass_damage_tag"), new TypeToken<>() {});
3687+
3688+
/**
3689+
* The sound played when blocking an attack with a shield-like {@link ItemStack}.
3690+
*/
3691+
public static final Key<Value<SoundType>> SHIELD_BLOCK_SOUND = Keys.key(ResourceKey.sponge("shield_block_sound"), SoundType.class);
3692+
3693+
/**
3694+
* The sound played when a shield-like {@link ItemStack} is disabled.
3695+
*/
3696+
public static final Key<Value<SoundType>> SHIELD_DISABLE_SOUND = Keys.key(ResourceKey.sponge("shield_disable_sound"), SoundType.class);
3697+
36583698
// SORTFIELDS:OFF
36593699

36603700
// @formatter:on
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package org.spongepowered.api.data.type;
2+
3+
import org.spongepowered.api.Sponge;
4+
import org.spongepowered.api.event.cause.entity.damage.DamageType;
5+
import org.spongepowered.api.tag.Tag;
6+
import org.spongepowered.api.util.ResettableBuilder;
7+
8+
import java.util.Optional;
9+
import java.util.Set;
10+
11+
/**
12+
* Defines the amount of damage reduced when blocking with a shield-like {@link org.spongepowered.api.item.inventory.ItemStack}.
13+
* The final amount of blocked damage will be {@code constantReduction + fractionalReduction * damage}
14+
*/
15+
public interface ShieldDamageReduction {
16+
17+
/**
18+
* Returns the {@link DamageType damage types} this reduction applies to.
19+
* {@link Optional#empty()} means this reduction is not restricted to any given damage type.
20+
*
21+
* @return the affected damage types
22+
*/
23+
Optional<Set<DamageType>> damageTypes();
24+
25+
/**
26+
* Returns the maximum angle between the users facing direction and the direction of the incoming attack.
27+
*
28+
* @return the maximum angle
29+
*/
30+
double horizontalBlockingAngle();
31+
32+
/**
33+
* Returns the constant amount of damage to be blocked.
34+
*
35+
* @return a constant amount of damage to block
36+
*/
37+
double constantReduction();
38+
39+
/**
40+
* Returns fractional amount of damage to block, where a factor of 1 means that all damage is blocked,
41+
* and a factor of 0 that no damage is blocked.
42+
*
43+
* @return fractional amount of damage to block
44+
*/
45+
double fractionalReduction();
46+
47+
static Builder builder() {
48+
return Sponge.game().builderProvider().provide(Builder.class);
49+
}
50+
51+
interface Builder extends ResettableBuilder<ShieldDamageReduction, Builder> {
52+
53+
Builder damageTypes(Set<DamageType> damageTypes);
54+
55+
Builder damageTypes(Tag<DamageType> tag);
56+
57+
Builder horizontalBlockingAngle(double angle);
58+
59+
Builder constantReduction(double constant);
60+
61+
Builder fractionalReduction(double fraction);
62+
63+
ShieldDamageReduction build();
64+
65+
}
66+
67+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package org.spongepowered.api.data.type;
2+
3+
import org.spongepowered.api.Sponge;
4+
import org.spongepowered.api.util.ResettableBuilder;
5+
6+
/**
7+
* Defines the amount of {@link org.spongepowered.api.data.Keys#ITEM_DURABILITY} damage a shield-like
8+
* {@link org.spongepowered.api.item.inventory.ItemStack} takes, when blocking an attack.
9+
* The final amount of damage will be {@code constantDamage + fractionalDamage * attackDamage}
10+
*/
11+
public interface ShieldItemDamageFunction {
12+
13+
/**
14+
* Returns the minimum amount of damage blocked attack must have had, for the item to take damage at all.
15+
*
16+
* @return minimum attack damage required for any durability loss
17+
*/
18+
double minAttackDamage();
19+
20+
/**
21+
* Returns the constant amount of damage taken.
22+
*
23+
* @return a constant amount of damage to take
24+
*/
25+
double constantDamage();
26+
27+
/**
28+
* Returns fractional amount of damage to take, where a factor of 1 means that the amount of durability lost is equal to attack damage,
29+
* and a factor of 0 that no durability is lost.
30+
*
31+
* @return fractional amount of damage to take
32+
*/
33+
double fractionalDamage();
34+
35+
static Builder builder() {
36+
return Sponge.game().builderProvider().provide(Builder.class);
37+
}
38+
39+
interface Builder extends ResettableBuilder<ShieldItemDamageFunction, Builder> {
40+
41+
Builder minAttackDamage(double minDamage);
42+
43+
Builder constantDamage(double constantDamage);
44+
45+
Builder fractionalDamage(double fractionalDamage);
46+
47+
ShieldItemDamageFunction build();
48+
49+
}
50+
51+
}

0 commit comments

Comments
 (0)