Skip to content

Commit b4fc87b

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

File tree

7 files changed

+333
-2
lines changed

7 files changed

+333
-2
lines changed

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171
import org.spongepowered.api.data.type.HorseColor;
7272
import org.spongepowered.api.data.type.HorseStyle;
7373
import org.spongepowered.api.data.type.InstrumentType;
74+
import org.spongepowered.api.data.type.ItemAction;
7475
import org.spongepowered.api.data.type.ItemTier;
7576
import org.spongepowered.api.data.type.LlamaType;
7677
import org.spongepowered.api.data.type.MatterType;
@@ -784,6 +785,11 @@ public final class Keys {
784785
*/
785786
public static final Key<SetValue<Direction>> CONNECTED_DIRECTIONS = Keys.setKey(ResourceKey.sponge("connected_directions"), Direction.class);
786787

788+
/**
789+
* The {@link ItemAction}s an {@link ItemStack} will apply when consumed.
790+
*/
791+
public static final Key<ListValue<ItemAction>> CONSUME_ACTIONS = Keys.listKey(ResourceKey.sponge("consume_effects"), ItemAction.class);
792+
787793
/**
788794
* The container {@link ItemType} of an {@link ItemStack}.
789795
* e.g. {@link ItemTypes#BUCKET} for a {@link ItemTypes#WATER_BUCKET} stack.
@@ -941,6 +947,11 @@ public final class Keys {
941947
*/
942948
public static final Key<Value<Double>> DAMAGE_PER_BLOCK = Keys.key(ResourceKey.sponge("damage_per_block"), Double.class);
943949

950+
/**
951+
* The {@link ItemAction}s an {@link ItemStack} will apply on death.
952+
*/
953+
public static final Key<ListValue<ItemAction>> DEATH_PROTECTION_ACTIONS = Keys.listKey(ResourceKey.sponge("death_protection_effects"), ItemAction.class);
954+
944955
/**
945956
* The distance at which a {@link BlockState} will decay.
946957
* This usually applies to leaves, for example {@link BlockTypes#OAK_LEAVES}.
@@ -3382,6 +3393,15 @@ public final class Keys {
33823393
*/
33833394
public static final Key<Value<ItemTier>> TOOL_TYPE = Keys.key(ResourceKey.sponge("tool_type"), ItemTier.class);
33843395

3396+
/**
3397+
* For a given {@link ResourceKey}, the textures for the tooltip of an {@link ItemStack} will be looked up from the following locations in the
3398+
* active resource packs:
3399+
*
3400+
* <p>Background: {@literal /assets/<namespace>/textures/gui/sprites/tooltip/<id>_background}
3401+
* <p>Frame: {@literal /assets/<namespace>/textures/gui/sprites/tooltip/<id>_frame}
3402+
*/
3403+
public static final Key<Value<ResourceKey>> TOOLTIP_STYLE = Keys.key(ResourceKey.sponge("tooltip_style"), ResourceKey.class);
3404+
33853405
/**
33863406
* Whether a {@link CommandBlock} does track its output.
33873407
*
Lines changed: 202 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,202 @@
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.data.Keys;
29+
import org.spongepowered.api.effect.potion.PotionEffect;
30+
import org.spongepowered.api.effect.potion.PotionEffectType;
31+
import org.spongepowered.api.effect.sound.SoundType;
32+
import org.spongepowered.api.entity.living.Living;
33+
import org.spongepowered.api.item.inventory.ItemStack;
34+
import org.spongepowered.api.item.inventory.ItemStackLike;
35+
import org.spongepowered.api.tag.Tag;
36+
37+
import java.util.Arrays;
38+
import java.util.Collection;
39+
import java.util.List;
40+
import java.util.Set;
41+
import java.util.function.Supplier;
42+
import java.util.stream.Collectors;
43+
44+
/**
45+
* Represents an action an {@link ItemStack} can apply to {@link Living} in different circumstances.
46+
*
47+
* @see Keys#CONSUME_ACTIONS
48+
* @see Keys#DEATH_PROTECTION_ACTIONS
49+
*/
50+
public interface ItemAction {
51+
52+
static ApplyEffects applyEffects(final Collection<PotionEffect> effects) {
53+
return ItemAction.applyEffects(1.0D, effects);
54+
}
55+
56+
static ApplyEffects applyEffects(final PotionEffect... effects) {
57+
return ItemAction.applyEffects(1.0D, effects);
58+
}
59+
60+
static ApplyEffects applyEffects(final double chance, final Collection<PotionEffect> effects) {
61+
return ItemAction.factory().applyEffects(chance, List.copyOf(effects));
62+
}
63+
64+
static ApplyEffects applyEffects(final double chance, final PotionEffect... effects) {
65+
return ItemAction.factory().applyEffects(chance, List.of(effects));
66+
}
67+
68+
static RemoveEffects removeEffects(final Collection<PotionEffectType> effectTypes) {
69+
return ItemAction.factory().removeEffects(Set.copyOf(effectTypes));
70+
}
71+
72+
static RemoveEffects removeEffects(final PotionEffectType... effectTypes) {
73+
return ItemAction.factory().removeEffects(Set.of(effectTypes));
74+
}
75+
76+
@SafeVarargs
77+
static RemoveEffects removeEffects(final Supplier<PotionEffectType>... effectTypes) {
78+
return ItemAction.factory().removeEffects(Arrays.stream(effectTypes).map(Supplier::get).collect(Collectors.toSet()));
79+
}
80+
81+
static RemoveEffects removeEffects(final Tag<PotionEffectType> effectTypeTag) {
82+
return ItemAction.factory().removeEffects(effectTypeTag);
83+
}
84+
85+
static ClearEffects clearEffects() {
86+
return ItemAction.factory().clearEffects();
87+
}
88+
89+
static PlaySound playSound(final SoundType soundType) {
90+
return ItemAction.factory().playSound(soundType);
91+
}
92+
93+
static PlaySound playSound(final Supplier<SoundType> soundType) {
94+
return ItemAction.factory().playSound(soundType.get());
95+
}
96+
97+
static TeleportRandomly teleportRandomly(final double distance) {
98+
return ItemAction.factory().teleportRandomly(distance);
99+
}
100+
101+
private static Factory factory() {
102+
return Sponge.game().factoryProvider().provide(Factory.class);
103+
}
104+
105+
/**
106+
* Returns the type of this effect.
107+
* @return The type of this effect
108+
*/
109+
ItemActionType type();
110+
111+
/**
112+
* Tries to apply this effect and returns whether it was successfully applied.
113+
* The definition of success is purely left up to the implementation.
114+
*
115+
* @param entity The entity to apply effect to
116+
* @param stack The item to apply effect with
117+
* @return true if effect was successfully applied
118+
*/
119+
boolean apply(Living entity, ItemStackLike stack);
120+
121+
/**
122+
* Applies this effect with {@link ItemStack#empty()}.
123+
*
124+
* @param entity The entity to apply effect to
125+
* @return true if effect was successfully applied
126+
* @see #apply(Living, ItemStackLike)
127+
*/
128+
default boolean apply(final Living entity) {
129+
return this.apply(entity, ItemStack.empty());
130+
}
131+
132+
/**
133+
* Applies {@link PotionEffect}s with chance.
134+
*/
135+
interface ApplyEffects extends ItemAction {
136+
/**
137+
* Returns the probability for effects to be applied.
138+
* @return The probability for effects to be applied
139+
*/
140+
double chance();
141+
142+
/**
143+
* Returns {@link PotionEffect}s that will be applied.
144+
* @return {@link PotionEffect}s that will be applied
145+
*/
146+
List<PotionEffect> effects();
147+
}
148+
149+
/**
150+
* Removes {@link PotionEffect}s with matching {@link PotionEffectType}s.
151+
*/
152+
interface RemoveEffects extends ItemAction {
153+
/**
154+
* Returns {@link PotionEffectType}s that will be removed.
155+
* @return {@link PotionEffectType}s that will be removed
156+
*/
157+
Set<PotionEffectType> effectTypes();
158+
}
159+
160+
/**
161+
* Clears all {@link PotionEffect}s.
162+
*/
163+
interface ClearEffects extends ItemAction {
164+
}
165+
166+
/**
167+
* Plays {@link SoundType}.
168+
*/
169+
interface PlaySound extends ItemAction {
170+
/**
171+
* Returns the {@link SoundType} to be played.
172+
* @return The {@link SoundType}
173+
*/
174+
SoundType soundType();
175+
}
176+
177+
/**
178+
* Teleports randomly within maximum distance.
179+
*/
180+
interface TeleportRandomly extends ItemAction {
181+
/**
182+
* Returns the maximum distance entity can be teleported.
183+
* @return The maximum distance entity can be teleported
184+
*/
185+
double distance();
186+
}
187+
188+
interface Factory {
189+
190+
ApplyEffects applyEffects(double chance, List<PotionEffect> effects);
191+
192+
RemoveEffects removeEffects(Set<PotionEffectType> effectTypes);
193+
194+
RemoveEffects removeEffects(Tag<PotionEffectType> effectTypeTag);
195+
196+
ClearEffects clearEffects();
197+
198+
PlaySound playSound(SoundType soundType);
199+
200+
TeleportRandomly teleportRandomly(double distance);
201+
}
202+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
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.registry.DefaultedRegistryValue;
28+
import org.spongepowered.api.util.annotation.CatalogedBy;
29+
30+
/**
31+
* Represents a possible type of {@link ItemAction}.
32+
*/
33+
@CatalogedBy(ItemActionTypes.class)
34+
public interface ItemActionType extends DefaultedRegistryValue {
35+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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.ResourceKey;
28+
import org.spongepowered.api.Sponge;
29+
import org.spongepowered.api.registry.DefaultedRegistryReference;
30+
import org.spongepowered.api.registry.Registry;
31+
import org.spongepowered.api.registry.RegistryKey;
32+
import org.spongepowered.api.registry.RegistryScope;
33+
import org.spongepowered.api.registry.RegistryScopes;
34+
import org.spongepowered.api.registry.RegistryTypes;
35+
36+
/**
37+
* <!-- This file is automatically generated. Any manual changes will be overwritten. -->
38+
*/
39+
@SuppressWarnings("unused")
40+
@RegistryScopes(scopes = RegistryScope.GAME)
41+
public final class ItemActionTypes {
42+
43+
public static final DefaultedRegistryReference<ItemActionType> APPLY_EFFECTS = ItemActionTypes.key(ResourceKey.minecraft("apply_effects"));
44+
45+
public static final DefaultedRegistryReference<ItemActionType> CLEAR_ALL_EFFECTS = ItemActionTypes.key(ResourceKey.minecraft("clear_all_effects"));
46+
47+
public static final DefaultedRegistryReference<ItemActionType> PLAY_SOUND = ItemActionTypes.key(ResourceKey.minecraft("play_sound"));
48+
49+
public static final DefaultedRegistryReference<ItemActionType> REMOVE_EFFECTS = ItemActionTypes.key(ResourceKey.minecraft("remove_effects"));
50+
51+
public static final DefaultedRegistryReference<ItemActionType> TELEPORT_RANDOMLY = ItemActionTypes.key(ResourceKey.minecraft("teleport_randomly"));
52+
53+
private ItemActionTypes() {
54+
}
55+
56+
public static Registry<ItemActionType> registry() {
57+
return Sponge.game().registry(RegistryTypes.ITEM_ACTION_TYPE);
58+
}
59+
60+
private static DefaultedRegistryReference<ItemActionType> key(final ResourceKey location) {
61+
return RegistryKey.of(RegistryTypes.ITEM_ACTION_TYPE, location).asDefaultedReference(Sponge::game);
62+
}
63+
}

src/main/java/org/spongepowered/api/effect/Viewer.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.spongepowered.api.effect.particle.ParticleEffect;
3232
import org.spongepowered.api.effect.sound.SoundType;
3333
import org.spongepowered.api.effect.sound.music.MusicDisc;
34+
import org.spongepowered.api.item.inventory.ItemStackLike;
3435
import org.spongepowered.api.world.World;
3536
import org.spongepowered.api.world.WorldType;
3637
import org.spongepowered.api.world.WorldTypes;
@@ -57,6 +58,13 @@ public interface Viewer extends Audience {
5758
*/
5859
void sendWorldType(WorldType worldType);
5960

61+
/**
62+
* Plays the totem of undying effect with the texture of the given item.
63+
*
64+
* @param stack The item to display
65+
*/
66+
void playTotemOfUndyingEffect(ItemStackLike stack);
67+
6068
/**
6169
* Spawn the given {@link ParticleEffect} at the given position.
6270
*

src/main/java/org/spongepowered/api/effect/potion/PotionEffectType.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
package org.spongepowered.api.effect.potion;
2626

2727
import net.kyori.adventure.text.ComponentLike;
28-
import org.spongepowered.api.registry.DefaultedRegistryValue;
28+
import org.spongepowered.api.tag.Taggable;
2929
import org.spongepowered.api.util.annotation.CatalogedBy;
3030

3131
/**
3232
* Represents a possible type of {@link PotionEffect}.
3333
*/
3434
@CatalogedBy(PotionEffectTypes.class)
35-
public interface PotionEffectType extends DefaultedRegistryValue<PotionEffectType>, ComponentLike {
35+
public interface PotionEffectType extends Taggable<PotionEffectType>, ComponentLike {
3636

3737
/**
3838
* Gets whether this potion effect is applied instantly or over time.

0 commit comments

Comments
 (0)