Skip to content

Commit 889d78a

Browse files
Add registry builders for SoundEvent and JukeboxSong (#11805)
1 parent 2f1c6f3 commit 889d78a

File tree

56 files changed

+831
-194
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+831
-194
lines changed

build-data/paper.at

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public net.minecraft.network.protocol.game.ServerboundMovePlayerPacket yRot
3535
public net.minecraft.network.protocol.game.ServerboundMovePlayerPacket z
3636
public net.minecraft.network.syncher.SynchedEntityData getItem(Lnet/minecraft/network/syncher/EntityDataAccessor;)Lnet/minecraft/network/syncher/SynchedEntityData$DataItem;
3737
public net.minecraft.resources.RegistryOps lookupProvider
38+
public net.minecraft.resources.RegistryOps$HolderLookupAdapter
3839
public net.minecraft.server.Main forceUpgrade(Lnet/minecraft/world/level/storage/LevelStorageSource$LevelStorageAccess;Lnet/minecraft/world/level/storage/WorldData;Lcom/mojang/datafixers/DataFixer;ZLjava/util/function/BooleanSupplier;Lnet/minecraft/core/RegistryAccess;Z)V
3940
public net.minecraft.server.MinecraftServer LOGGER
4041
public net.minecraft.server.MinecraftServer doRunTask(Lnet/minecraft/server/TickTask;)V

paper-api/src/main/java/io/papermc/paper/registry/TypedKeyImpl.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
package io.papermc.paper.registry;
22

33
import net.kyori.adventure.key.Key;
4+
import net.kyori.adventure.key.KeyPattern;
45
import org.jspecify.annotations.NullMarked;
56

67
@NullMarked
78
record TypedKeyImpl<T>(Key key, RegistryKey<T> registryKey) implements TypedKey<T> {
89
// Wrap key methods to make this easier to use
10+
@KeyPattern.Namespace
911
@Override
1012
public String namespace() {
1113
return this.key.namespace();
1214
}
1315

16+
@KeyPattern.Value
1417
@Override
1518
public String value() {
1619
return this.key.value();
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
package io.papermc.paper.registry.data;
2+
3+
import io.papermc.paper.registry.RegistryBuilder;
4+
import io.papermc.paper.registry.RegistryBuilderFactory;
5+
import io.papermc.paper.registry.TypedKey;
6+
import io.papermc.paper.registry.holder.RegistryHolder;
7+
import java.util.function.Consumer;
8+
import net.kyori.adventure.text.Component;
9+
import org.bukkit.JukeboxSong;
10+
import org.bukkit.Sound;
11+
import org.checkerframework.checker.index.qual.Positive;
12+
import org.jetbrains.annotations.ApiStatus;
13+
import org.jetbrains.annotations.Contract;
14+
import org.jetbrains.annotations.Range;
15+
16+
/**
17+
* A data-centric version-specific registry entry for the {@link JukeboxSong} type.
18+
*/
19+
@ApiStatus.Experimental
20+
@ApiStatus.NonExtendable
21+
public interface JukeboxSongRegistryEntry {
22+
23+
/**
24+
* Gets the sound event for this song.
25+
*
26+
* @return the sound event
27+
*/
28+
@Contract(pure = true)
29+
RegistryHolder<Sound, SoundEventRegistryEntry> soundEvent();
30+
31+
/**
32+
* Gets the description for this song.
33+
*
34+
* @return the description
35+
*/
36+
@Contract(pure = true)
37+
Component description();
38+
39+
/**
40+
* Gets the length in seconds for this song.
41+
*
42+
* @return the length in seconds
43+
*/
44+
@Contract(pure = true)
45+
@Positive float lengthInSeconds();
46+
47+
/**
48+
* Gets the comparator output for this song.
49+
*
50+
* @return the comparator output
51+
*/
52+
@Contract(pure = true)
53+
@Range(from = 0, to = 15) int comparatorOutput();
54+
55+
/**
56+
* A mutable builder for the {@link JukeboxSongRegistryEntry} plugins may change in applicable registry events.
57+
* <p>
58+
* The following values are required for each builder:
59+
* <ul>
60+
* <li>
61+
* {@link #soundEvent(TypedKey)}, {@link #soundEvent(Consumer)} or {@link #soundEvent(RegistryHolder)}
62+
* </li>
63+
* <li>{@link #description(Component)}</li>
64+
* <li>{@link #lengthInSeconds(float)}</li>
65+
* <li>{@link #comparatorOutput(int)}</li>
66+
* </ul>
67+
*/
68+
@ApiStatus.Experimental
69+
@ApiStatus.NonExtendable
70+
interface Builder extends JukeboxSongRegistryEntry, RegistryBuilder<JukeboxSong> {
71+
72+
/**
73+
* Sets the sound event for this song to a sound event present
74+
* in the {@link io.papermc.paper.registry.RegistryKey#SOUND_EVENT} registry.
75+
* <p>This will override both {@link #soundEvent(Consumer)} and {@link #soundEvent(RegistryHolder)}</p>
76+
*
77+
* @param soundEvent the sound event
78+
* @return this builder
79+
* @see #soundEvent(Consumer)
80+
*/
81+
@Contract(value = "_ -> this", mutates = "this")
82+
Builder soundEvent(TypedKey<Sound> soundEvent);
83+
84+
/**
85+
* Sets the sound event for this song to a new sound event.
86+
* <p>This will override both {@link #soundEvent(TypedKey)} and {@link #soundEvent(RegistryHolder)}</p>
87+
*
88+
* @param soundEvent the sound event
89+
* @return this builder
90+
* @see #soundEvent(TypedKey)
91+
*/
92+
@Contract(value = "_ -> this", mutates = "this")
93+
Builder soundEvent(Consumer<RegistryBuilderFactory<Sound, ? extends SoundEventRegistryEntry.Builder>> soundEvent);
94+
95+
/**
96+
* Sets the sound event for this song.
97+
* <p>This will override both {@link #soundEvent(Consumer)} and {@link #soundEvent(TypedKey)}</p>
98+
*
99+
* @param soundEvent the sound event
100+
* @return this builder
101+
* @see #soundEvent(TypedKey)
102+
* @see #soundEvent(Consumer)
103+
*/
104+
@Contract( value = "_ -> this", mutates = "this")
105+
Builder soundEvent(RegistryHolder<Sound, SoundEventRegistryEntry> soundEvent);
106+
107+
/**
108+
* Sets the description for this song.
109+
*
110+
* @param description the description
111+
* @return this builder
112+
*/
113+
@Contract(value = "_ -> this", mutates = "this")
114+
Builder description(Component description);
115+
116+
/**
117+
* Sets the length in seconds for this song.
118+
*
119+
* @param lengthInSeconds the length in seconds (positive)
120+
* @return this builder
121+
*/
122+
@Contract(value = "_ -> this", mutates = "this")
123+
Builder lengthInSeconds(@Positive float lengthInSeconds);
124+
125+
/**
126+
* Sets the comparator output for this song.
127+
*
128+
* @param comparatorOutput the comparator output [0-15]
129+
* @return this builder
130+
*/
131+
@Contract(value = "_ -> this", mutates = "this")
132+
Builder comparatorOutput(@Range(from = 0, to = 15) int comparatorOutput);
133+
}
134+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package io.papermc.paper.registry.data;
2+
3+
import io.papermc.paper.registry.RegistryBuilder;
4+
import net.kyori.adventure.key.Key;
5+
import org.bukkit.Sound;
6+
import org.jetbrains.annotations.ApiStatus;
7+
import org.jetbrains.annotations.Contract;
8+
import org.jspecify.annotations.Nullable;
9+
10+
/**
11+
* A data-centric version-specific registry entry for the {@link Sound} type.
12+
*/
13+
@ApiStatus.Experimental
14+
@ApiStatus.NonExtendable
15+
public interface SoundEventRegistryEntry {
16+
17+
/**
18+
* Gets the resource pack location for this sound event.
19+
*
20+
* @return the location
21+
*/
22+
@Contract(pure = true)
23+
Key location();
24+
25+
/**
26+
* Gets the fixed range for this sound event, if present.
27+
*
28+
* @return the fixed range, or {@code null} if not present
29+
*/
30+
@Contract(pure = true)
31+
@Nullable Float fixedRange();
32+
33+
/**
34+
* A mutable builder for the {@link SoundEventRegistryEntry} plugins may change in applicable registry events.
35+
* <p>
36+
* The following values are required for each builder:
37+
* <ul>
38+
* <li>{@link #location(Key)}</li>
39+
* </ul>
40+
*/
41+
@ApiStatus.Experimental
42+
@ApiStatus.NonExtendable
43+
interface Builder extends SoundEventRegistryEntry, RegistryBuilder<Sound> {
44+
45+
/**
46+
* Sets the resource pack location for this sound event.
47+
*
48+
* @param location the location
49+
* @return this builder
50+
*/
51+
@Contract(value = "_ -> this", mutates = "this")
52+
Builder location(Key location);
53+
54+
/**
55+
* Sets the fixed range for this sound event.
56+
*
57+
* @param fixedRange the fixed range
58+
* @return this builder
59+
*/
60+
@Contract(value = "_ -> this", mutates = "this")
61+
Builder fixedRange(@Nullable Float fixedRange);
62+
}
63+
}

paper-api/src/main/java/io/papermc/paper/registry/event/RegistryComposeEvent.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import io.papermc.paper.registry.tag.TagKey;
66
import org.bukkit.Keyed;
77
import org.jetbrains.annotations.ApiStatus;
8-
import org.jspecify.annotations.NullMarked;
98

109
/**
1110
* Event object for {@link RegistryEventProvider#compose()}. This
@@ -16,7 +15,6 @@
1615
* @param <B> registry entry builder type
1716
*/
1817
@ApiStatus.Experimental
19-
@NullMarked
2018
@ApiStatus.NonExtendable
2119
public interface RegistryComposeEvent<T, B extends RegistryBuilder<T>> extends RegistryEvent<T> {
2220

@@ -36,5 +34,5 @@ public interface RegistryComposeEvent<T, B extends RegistryBuilder<T>> extends R
3634
* @return the tag
3735
* @param <V> the tag value type
3836
*/
39-
<V extends Keyed> Tag<V> getOrCreateTag(TagKey<V> tagKey);
37+
<V extends Keyed> Tag<V> getOrCreateTag(TagKey<V> tagKey); // TODO remove Keyed
4038
}

paper-api/src/main/java/io/papermc/paper/registry/event/RegistryEntryAddEvent.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import io.papermc.paper.registry.tag.TagKey;
77
import org.bukkit.Keyed;
88
import org.jetbrains.annotations.ApiStatus;
9-
import org.jspecify.annotations.NullMarked;
109

1110
/**
1211
* Event object for {@link RegistryEventProvider#entryAdd()}. This
@@ -16,8 +15,6 @@
1615
* @param <T> registry entry type
1716
* @param <B> registry entry builder type
1817
*/
19-
@ApiStatus.Experimental
20-
@NullMarked
2118
@ApiStatus.NonExtendable
2219
public interface RegistryEntryAddEvent<T, B extends RegistryBuilder<T>> extends RegistryEvent<T> {
2320

paper-api/src/main/java/io/papermc/paper/registry/event/RegistryEvent.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
import io.papermc.paper.plugin.lifecycle.event.LifecycleEvent;
44
import io.papermc.paper.registry.RegistryKey;
55
import org.jetbrains.annotations.ApiStatus;
6-
import org.jspecify.annotations.NullMarked;
76

87
/**
98
* Base type for all registry events.
109
*
1110
* @param <T> registry entry type
1211
*/
13-
@ApiStatus.Experimental
14-
@NullMarked
1512
@ApiStatus.NonExtendable
1613
public interface RegistryEvent<T> extends LifecycleEvent {
1714

paper-api/src/main/java/io/papermc/paper/registry/event/RegistryEventProvider.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import io.papermc.paper.registry.RegistryKey;
88
import io.papermc.paper.registry.event.type.RegistryEntryAddEventType;
99
import org.jetbrains.annotations.ApiStatus;
10-
import org.jspecify.annotations.NullMarked;
1110

1211
/**
1312
* Provider for registry events for a specific registry.
@@ -21,8 +20,6 @@
2120
* @param <T> registry entry type
2221
* @param <B> registry entry builder type
2322
*/
24-
@ApiStatus.Experimental
25-
@NullMarked
2623
@ApiStatus.NonExtendable
2724
public interface RegistryEventProvider<T, B extends RegistryBuilder<T>> {
2825

paper-api/src/main/java/io/papermc/paper/registry/event/RegistryEventProviderImpl.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
import io.papermc.paper.registry.RegistryKey;
77
import io.papermc.paper.registry.event.type.RegistryEntryAddEventType;
88
import org.jetbrains.annotations.ApiStatus;
9-
import org.jspecify.annotations.NullMarked;
109

1110
@ApiStatus.Internal
12-
@NullMarked
1311
record RegistryEventProviderImpl<T, B extends RegistryBuilder<T>>(RegistryKey<T> registryKey) implements RegistryEventProvider<T, B> {
1412

1513
static <T, B extends RegistryBuilder<T>> RegistryEventProvider<T, B> create(final RegistryKey<T> registryKey) {

paper-api/src/main/java/io/papermc/paper/registry/event/RegistryEvents.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99
import io.papermc.paper.registry.data.EnchantmentRegistryEntry;
1010
import io.papermc.paper.registry.data.FrogVariantRegistryEntry;
1111
import io.papermc.paper.registry.data.GameEventRegistryEntry;
12+
import io.papermc.paper.registry.data.JukeboxSongRegistryEntry;
1213
import io.papermc.paper.registry.data.PaintingVariantRegistryEntry;
1314
import io.papermc.paper.registry.data.PigVariantRegistryEntry;
1415
import io.papermc.paper.registry.data.WolfVariantRegistryEntry;
1516
import org.bukkit.Art;
1617
import org.bukkit.GameEvent;
18+
import org.bukkit.JukeboxSong;
1719
import org.bukkit.block.banner.PatternType;
1820
import org.bukkit.damage.DamageType;
1921
import org.bukkit.enchantments.Enchantment;
@@ -23,17 +25,13 @@
2325
import org.bukkit.entity.Frog;
2426
import org.bukkit.entity.Pig;
2527
import org.bukkit.entity.Wolf;
26-
import org.jetbrains.annotations.ApiStatus;
27-
import org.jspecify.annotations.NullMarked;
2828

2929
import static io.papermc.paper.registry.event.RegistryEventProviderImpl.create;
3030

3131
/**
3232
* Holds providers for {@link RegistryEntryAddEvent} and {@link RegistryComposeEvent}
3333
* handlers for each applicable registry.
3434
*/
35-
@ApiStatus.Experimental
36-
@NullMarked
3735
public final class RegistryEvents {
3836

3937
// Start generate - RegistryEvents
@@ -42,6 +40,7 @@ public final class RegistryEvents {
4240
public static final RegistryEventProvider<DamageType, DamageTypeRegistryEntry.Builder> DAMAGE_TYPE = create(RegistryKey.DAMAGE_TYPE);
4341
public static final RegistryEventProvider<Wolf.Variant, WolfVariantRegistryEntry.Builder> WOLF_VARIANT = create(RegistryKey.WOLF_VARIANT);
4442
public static final RegistryEventProvider<Enchantment, EnchantmentRegistryEntry.Builder> ENCHANTMENT = create(RegistryKey.ENCHANTMENT);
43+
public static final RegistryEventProvider<JukeboxSong, JukeboxSongRegistryEntry.Builder> JUKEBOX_SONG = create(RegistryKey.JUKEBOX_SONG);
4544
public static final RegistryEventProvider<PatternType, BannerPatternRegistryEntry.Builder> BANNER_PATTERN = create(RegistryKey.BANNER_PATTERN);
4645
public static final RegistryEventProvider<Art, PaintingVariantRegistryEntry.Builder> PAINTING_VARIANT = create(RegistryKey.PAINTING_VARIANT);
4746
public static final RegistryEventProvider<Cat.Type, CatTypeRegistryEntry.Builder> CAT_VARIANT = create(RegistryKey.CAT_VARIANT);

0 commit comments

Comments
 (0)