Add registry builder for Instrument (#12682)

Co-authored-by: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com>
This commit is contained in:
Pedro
2025-06-30 15:33:02 -04:00
committed by GitHub
parent 6e021c8272
commit 5661fbbab9
8 changed files with 315 additions and 15 deletions
@@ -2,16 +2,32 @@ package org.bukkit;
import com.google.common.collect.Lists;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryBuilderFactory;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.InlinedRegistryBuilderProvider;
import io.papermc.paper.registry.data.InstrumentRegistryEntry;
import java.util.Collection;
import java.util.Collections;
import java.util.function.Consumer;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
@NullMarked
public abstract class MusicInstrument implements Keyed, net.kyori.adventure.translation.Translatable {
/**
* Creates an inlined music instrument.
*
* @param value a consumer for the builder factory
* @return the created music instrument
*/
@ApiStatus.Experimental
public static MusicInstrument create(final Consumer<RegistryBuilderFactory<MusicInstrument, ? extends InstrumentRegistryEntry.Builder>> value) {
return InlinedRegistryBuilderProvider.instance().createInstrument(value);
}
// Start generate - MusicInstrument
// @GeneratedFrom 1.21.7
public static final MusicInstrument ADMIRE_GOAT_HORN = getInstrument("admire_goat_horn");
@@ -31,12 +47,16 @@ public abstract class MusicInstrument implements Keyed, net.kyori.adventure.tran
public static final MusicInstrument YEARN_GOAT_HORN = getInstrument("yearn_goat_horn");
// End generate - MusicInstrument
private static MusicInstrument getInstrument(final String key) {
return RegistryAccess.registryAccess().getRegistry(RegistryKey.INSTRUMENT).getOrThrow(NamespacedKey.minecraft(key));
}
/**
* Returns a {@link MusicInstrument} by a {@link NamespacedKey}.
*
* @param namespacedKey the key
* @return the event or null
* @deprecated Use {@link Registry#get(NamespacedKey)} instead.
* @deprecated use {@link Registry#get(NamespacedKey)} instead
*/
@Nullable
@Deprecated(since = "1.20.1")
@@ -45,38 +65,34 @@ public abstract class MusicInstrument implements Keyed, net.kyori.adventure.tran
}
/**
* Returns all known MusicInstruments.
* Returns all known music instruments.
*
* @return the memoryKeys
* @deprecated use {@link Registry#iterator()}.
* @return the music instruments
* @deprecated use {@link Registry#iterator()}
*/
@Deprecated(since = "1.20.1")
public static Collection<MusicInstrument> values() {
return Collections.unmodifiableCollection(Lists.newArrayList(Registry.INSTRUMENT));
}
private static MusicInstrument getInstrument(final String key) {
return RegistryAccess.registryAccess().getRegistry(RegistryKey.INSTRUMENT).getOrThrow(NamespacedKey.minecraft(key));
}
/**
* Gets the use duration of this music instrument.
*
* @return the duration expressed in seconds.
* @return the duration expressed in seconds
*/
public abstract float getDuration();
/**
* Gets the range of the sound.
*
* @return the range of the sound.
* @return the range of the sound
*/
public abstract float getRange();
/**
* Provides the description of this instrument as displayed to the client.
* Gets the description of this instrument as displayed to the client.
*
* @return the description component.
* @return the description component
*/
public abstract Component description();