Compare commits

..
167 changed files with 1520 additions and 639 deletions

No files matched your search

@@ -1,9 +1,11 @@
package io.papermc.paper.block.pot;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.data.DecoratedPotPatternRegistryEntry;
import org.bukkit.Keyed;
/**
* A pot pattern on a decorated pot.
*/
public interface PotPatternType extends Keyed {
public interface PotPatternType extends RegistryElement.Buildable<PotPatternType, DecoratedPotPatternRegistryEntry, DecoratedPotPatternRegistryEntry.Builder>, Keyed {
}
@@ -1,12 +1,13 @@
package io.papermc.paper.datacomponent;
import io.papermc.paper.registry.RegistryElement;
import org.bukkit.Keyed;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
@NullMarked
@ApiStatus.NonExtendable
public interface DataComponentType extends Keyed {
public interface DataComponentType extends RegistryElement<DataComponentType>, Keyed {
/**
* Checks if this data component type is persistent, or
@@ -60,6 +60,7 @@ import org.bukkit.DyeColor;
import org.bukkit.FireworkEffect;
import org.bukkit.MusicInstrument;
import org.bukkit.Registry;
import org.bukkit.Sound;
import org.bukkit.block.banner.PatternType;
import org.bukkit.damage.DamageType;
import org.bukkit.entity.Axolotl;
@@ -365,7 +366,7 @@ public final class DataComponentTypes {
* Holds the unresolved loot table and seed of a container-like block.
*/
public static final DataComponentType.Valued<SeededContainerLoot> CONTAINER_LOOT = valued("container_loot");
public static final DataComponentType.Valued<Key> BREAK_SOUND = valued("break_sound");
public static final DataComponentType.Valued<Sound> BREAK_SOUND = valued("break_sound");
public static final DataComponentType.Valued<MobVisibility> MOB_VISIBILITY = valued("mob_visibility");
public static final DataComponentType.Valued<Villager.Type> VILLAGER_VARIANT = valued("villager/variant");
public static final DataComponentType.Valued<Wolf.Variant> WOLF_VARIANT = valued("wolf/variant");
@@ -6,6 +6,7 @@ import io.papermc.paper.datacomponent.item.blocksattacks.ItemDamageFunction;
import io.papermc.paper.registry.set.RegistryKeySet;
import java.util.List;
import net.kyori.adventure.key.Key;
import org.bukkit.Sound;
import org.bukkit.damage.DamageType;
import org.checkerframework.checker.index.qual.NonNegative;
import org.jetbrains.annotations.ApiStatus;
@@ -68,20 +69,20 @@ public interface BlocksAttacks {
@Nullable RegistryKeySet<DamageType> bypassedBy();
/**
* Gets the key sound to play when an attack is successfully blocked.
* Gets the sound to play when an attack is successfully blocked.
*
* @return a key of the sound
* @return the sound
*/
@Contract(pure = true)
@Nullable Key blockSound();
@Nullable Sound blockSound();
/**
* Gets the key sound to play when the item goes on its disabled cooldown due to an attack.
* Gets the sound to play when the item goes on its disabled cooldown due to an attack.
*
* @return a key of the sound
* @return the sound
*/
@Contract(pure = true)
@Nullable Key disableSound();
@Nullable Sound disableSound();
/**
* Builder for {@link BlocksAttacks}.
@@ -107,10 +108,26 @@ public interface BlocksAttacks {
@Contract(value = "_ -> this", mutates = "this")
Builder bypassedBy(@Nullable RegistryKeySet<DamageType> bypassedBy);
/**
* Sets the sound to play when an attack is successfully blocked.
*
* @param sound the sound, or null to play no sound
* @return the builder for chaining
* @see Sound#create(net.kyori.adventure.key.Key, Float)
* @see Sound#create(java.util.function.Consumer)
*/
@Contract(value = "_ -> this", mutates = "this")
Builder blockSound(@Nullable Key sound);
Builder blockSound(@Nullable Sound sound);
/**
* Sets the sound to play when the item goes on its disabled cooldown due to an attack.
*
* @param sound the sound, or null to play no sound
* @return the builder for chaining
* @see Sound#create(net.kyori.adventure.key.Key, Float)
* @see Sound#create(java.util.function.Consumer)
*/
@Contract(value = "_ -> this", mutates = "this")
Builder disableSound(@Nullable Key sound);
Builder disableSound(@Nullable Sound sound);
}
}
@@ -6,6 +6,7 @@ import io.papermc.paper.datacomponent.item.consumable.ConsumeEffect;
import io.papermc.paper.datacomponent.item.consumable.ItemUseAnimation;
import java.util.List;
import net.kyori.adventure.key.Key;
import org.bukkit.Sound;
import org.checkerframework.checker.index.qual.NonNegative;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
@@ -30,7 +31,7 @@ public interface Consumable extends BuildableDataComponent<Consumable, Consumabl
ItemUseAnimation animation();
@Contract(pure = true)
Key sound();
Sound sound();
@Contract(pure = true)
boolean hasConsumeParticles();
@@ -65,11 +66,11 @@ public interface Consumable extends BuildableDataComponent<Consumable, Consumabl
/**
* Sets the sound played when consuming the item.
*
* @param sound the {@link Key} representing the sound to be used
* @param sound the sound to be used
* @return the builder for chaining
*/
@Contract(value = "_ -> this", mutates = "this")
Builder sound(Key sound);
Builder sound(Sound sound);
/**
* Sets whether consuming the item results in particle effects.
@@ -4,6 +4,7 @@ import io.papermc.paper.datacomponent.BuildableDataComponent;
import io.papermc.paper.datacomponent.DataComponentBuilder;
import io.papermc.paper.registry.set.RegistryKeySet;
import net.kyori.adventure.key.Key;
import org.bukkit.Sound;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.EquipmentSlot;
import org.jetbrains.annotations.ApiStatus;
@@ -37,12 +38,12 @@ public interface Equippable extends BuildableDataComponent<Equippable, Equippabl
EquipmentSlot slot();
/**
* Gets the equip sound key.
* Gets the equip sound.
*
* @return the equip sound key
* @return the equip sound
*/
@Contract(pure = true)
Key equipSound();
Sound equipSound();
/**
* Gets the asset id if present.
@@ -115,7 +116,7 @@ public interface Equippable extends BuildableDataComponent<Equippable, Equippabl
* @return shear sound
*/
@Contract(pure = true)
Key shearSound();
Sound shearSound();
/**
* Builder for {@link Equippable}.
@@ -124,13 +125,13 @@ public interface Equippable extends BuildableDataComponent<Equippable, Equippabl
interface Builder extends DataComponentBuilder<Equippable> {
/**
* Sets the equip sound key for this item.
* Sets the equip sound for this item.
*
* @param sound the equip sound key
* @param sound the equip sound
* @return the builder for chaining
*/
@Contract(value = "_ -> this", mutates = "this")
Builder equipSound(Key sound);
Builder equipSound(Sound sound);
/**
* Sets the asset id for this item.
@@ -207,10 +208,10 @@ public interface Equippable extends BuildableDataComponent<Equippable, Equippabl
/**
* Sets the sound that is played when shearing this equipment off an entity.
*
* @param shearSound the shear sound key
* @param shearSound the shear sound
* @return the builder for chaining
*/
@Contract(value = "_ -> this", mutates = "this")
Builder shearSound(Key shearSound);
Builder shearSound(Sound shearSound);
}
}
@@ -2,6 +2,7 @@ package io.papermc.paper.datacomponent.item;
import io.papermc.paper.datacomponent.DataComponentBuilder;
import net.kyori.adventure.key.Key;
import org.bukkit.Sound;
import org.checkerframework.checker.index.qual.NonNegative;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
@@ -48,10 +49,10 @@ public interface KineticWeapon {
float damageMultiplier();
@Contract(pure = true)
@Nullable Key sound();
@Nullable Sound sound();
@Contract(pure = true)
@Nullable Key hitSound();
@Nullable Sound hitSound();
interface Condition {
@@ -92,10 +93,26 @@ public interface KineticWeapon {
@Contract(value = "_ -> this", mutates = "this")
Builder damageMultiplier(float damageMultiplier);
/**
* Sets the sound to play while this weapon is active.
*
* @param sound the sound, or null to play no sound
* @return the builder for chaining
* @see Sound#create(net.kyori.adventure.key.Key, Float)
* @see Sound#create(java.util.function.Consumer)
*/
@Contract(value = "_ -> this", mutates = "this")
Builder sound(@Nullable Key sound);
Builder sound(@Nullable Sound sound);
/**
* Sets the sound to play when this weapon hits an entity.
*
* @param sound the sound, or null to play no sound
* @return the builder for chaining
* @see Sound#create(net.kyori.adventure.key.Key, Float)
* @see Sound#create(java.util.function.Consumer)
*/
@Contract(value = "_ -> this", mutates = "this")
Builder hitSound(@Nullable Key sound);
Builder hitSound(@Nullable Sound sound);
}
}
@@ -2,6 +2,7 @@ package io.papermc.paper.datacomponent.item;
import io.papermc.paper.datacomponent.DataComponentBuilder;
import net.kyori.adventure.key.Key;
import org.bukkit.Sound;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jspecify.annotations.Nullable;
@@ -22,9 +23,9 @@ public interface PiercingWeapon {
boolean dismounts();
@Nullable Key sound();
@Nullable Sound sound();
@Nullable Key hitSound();
@Nullable Sound hitSound();
/**
* Builder for {@link PiercingWeapon}.
@@ -38,10 +39,26 @@ public interface PiercingWeapon {
@Contract(value = "_ -> this", mutates = "this")
Builder dismounts(boolean dismounts);
/**
* Sets the sound to play while this weapon is active.
*
* @param sound the sound, or null to play no sound
* @return the builder for chaining
* @see Sound#create(net.kyori.adventure.key.Key, Float)
* @see Sound#create(java.util.function.Consumer)
*/
@Contract(value = "_ -> this", mutates = "this")
Builder sound(@Nullable Key sound);
Builder sound(@Nullable Sound sound);
/**
* Sets the sound to play when this weapon hits an entity.
*
* @param sound the sound, or null to play no sound
* @return the builder for chaining
* @see Sound#create(net.kyori.adventure.key.Key, Float)
* @see Sound#create(java.util.function.Consumer)
*/
@Contract(value = "_ -> this", mutates = "this")
Builder hitSound(@Nullable Key sound);
Builder hitSound(@Nullable Sound sound);
}
}
@@ -2,6 +2,7 @@ package io.papermc.paper.datacomponent.item;
import io.papermc.paper.datacomponent.DataComponentBuilder;
import io.papermc.paper.datacomponent.DataComponentType;
import io.papermc.paper.registry.set.RegistryKeySet;
import java.util.Set;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
@@ -37,5 +38,8 @@ public interface TooltipDisplay {
@Contract(value = "_ -> this", mutates = "this")
Builder hiddenComponents(Set<DataComponentType> components);
@Contract(value = "_ -> this", mutates = "this")
Builder hiddenComponents(RegistryKeySet<DataComponentType> components);
}
}
@@ -5,6 +5,7 @@ import java.util.List;
import java.util.Optional;
import java.util.ServiceLoader;
import net.kyori.adventure.key.Key;
import org.bukkit.Sound;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@@ -22,7 +23,7 @@ interface ConsumableTypesBridge {
ConsumeEffect.ClearAllStatusEffects clearAllStatusEffects();
ConsumeEffect.PlaySound playSoundEffect(Key sound);
ConsumeEffect.PlaySound playSoundEffect(Sound sound);
ConsumeEffect.TeleportRandomly teleportRandomlyEffect(float diameter, boolean directionalParticles);
}
@@ -3,6 +3,7 @@ package io.papermc.paper.datacomponent.item.consumable;
import io.papermc.paper.registry.set.RegistryKeySet;
import java.util.List;
import net.kyori.adventure.key.Key;
import org.bukkit.Sound;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.jetbrains.annotations.ApiStatus;
@@ -52,12 +53,12 @@ public interface ConsumeEffect {
/**
* Creates a consume effect that plays a sound on consumption.
*
* @param key the key sound effect to play
* @param sound the sound effect to play
* @return the effect instance
*/
@Contract(value = "_ -> new", pure = true)
static PlaySound playSoundConsumeEffect(final Key key) {
return ConsumableTypesBridge.bridge().playSoundEffect(key);
static PlaySound playSoundConsumeEffect(final Sound sound) {
return ConsumableTypesBridge.bridge().playSoundEffect(sound);
}
/**
@@ -128,7 +129,7 @@ public interface ConsumeEffect {
*
* @return sound effect
*/
Key sound();
Sound sound();
}
/**
@@ -2,8 +2,9 @@ package io.papermc.paper.dialog;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryBuilderFactory;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.InlinedRegistryBuilderProvider;
import io.papermc.paper.registry.data.RegistryBuilderProvider;
import io.papermc.paper.registry.data.dialog.DialogRegistryEntry;
import java.util.function.Consumer;
import net.kyori.adventure.dialog.DialogLike;
@@ -19,7 +20,7 @@ import org.jetbrains.annotations.ApiStatus;
* Can also be created during bootstrap via {@link io.papermc.paper.registry.event.RegistryEvents#DIALOG}.
*/
@ApiStatus.NonExtendable
public interface Dialog extends Keyed, DialogLike {
public interface Dialog extends RegistryElement.Inlineable<Dialog, DialogRegistryEntry, DialogRegistryEntry.Builder>, Keyed, DialogLike {
/**
* Creates a new dialog using the provided builder.
@@ -28,7 +29,7 @@ public interface Dialog extends Keyed, DialogLike {
* @return a new dialog instance
*/
static Dialog create(final Consumer<RegistryBuilderFactory<Dialog, ? extends DialogRegistryEntry.Builder>> value) {
return InlinedRegistryBuilderProvider.instance().createDialog(value);
return RegistryBuilderProvider.instance().create(RegistryKey.DIALOG, value);
}
// Start generate - Dialog
@@ -1,6 +1,7 @@
package io.papermc.paper.entity.poi;
import io.papermc.paper.InternalAPIBridge;
import io.papermc.paper.registry.RegistryElement;
import org.bukkit.Keyed;
import org.bukkit.block.data.BlockData;
import org.jspecify.annotations.NullMarked;
@@ -15,7 +16,7 @@ import org.jspecify.annotations.NullMarked;
* @see PoiTypes
*/
@NullMarked
public interface PoiType extends Keyed {
public interface PoiType extends RegistryElement<PoiType>, Keyed {
/**
* Determines whether the provided BlockState is relevant to this
@@ -0,0 +1,70 @@
package io.papermc.paper.registry;
import io.papermc.paper.registry.tag.TagKey;
import net.kyori.adventure.key.Key;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
/**
* An element tied to a registry.
* <p>
* For unregistered element, the equality methods exposed here will always return {@code false}
* as there's no way to identify them with a key.
*
* @see RegistryKey
* @see org.bukkit.Registry
* @see org.bukkit.Registry#getKey(org.bukkit.Keyed)
*/
@NullMarked
@ApiStatus.Experimental
public interface RegistryElement<T> {
/**
* Checks whether this element is identified by the given key.
*
* @param type the key
* @return whether this element is identified by the given key.
*/
boolean is(TypedKey<T> type);
/**
* Checks whether this element is identified by the given key.
*
* @param type the key
* @return whether this element is identified by the given key
*/
boolean is(Key type);
/**
* Checks whether this element is contained in the
* tag identified by the given tag key.
*
* @param type the tag key
* @return whether this element is contained in the tag
*/
boolean is(TagKey<T> type);
/**
* Marker interface for registered types that link an API type to its
* registry entry and builder types.
*
* @param <T> the API type
* @param <E> the registry entry type
* @param <B> the builder type
*/
@SuppressWarnings("unused")
@ApiStatus.Experimental
interface Buildable<T, E, B extends RegistryBuilder<T>> extends RegistryElement<T> {
}
/**
* Marker interface for registered types that are valid to be constructed inline.
*
* @param <T> the API type
* @param <E> the registry entry type
* @param <B> the builder type
*/
@ApiStatus.Experimental
interface Inlineable<T, E, B extends RegistryBuilder<T>> extends RegistryElement.Buildable<T, E, B> {
}
}
@@ -2,8 +2,6 @@ package io.papermc.paper.registry;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
import net.kyori.adventure.key.Keyed;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
/**
@@ -12,14 +10,13 @@ import org.jspecify.annotations.NullMarked;
* @param <T> the value type for the registry
*/
@NullMarked
public sealed interface TypedKey<T> extends Key permits TypedKeyImpl {
public sealed interface TypedKey<T> permits TypedKeyImpl {
/**
* Gets the key for the value in the registry.
*
* @return the value's key
*/
@Override
Key key();
/**
@@ -1,26 +1,8 @@
package io.papermc.paper.registry;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
import org.jspecify.annotations.NullMarked;
@NullMarked
record TypedKeyImpl<T>(Key key, RegistryKey<T> registryKey) implements TypedKey<T> {
// Wrap key methods to make this easier to use
@KeyPattern.Namespace
@Override
public String namespace() {
return this.key.namespace();
}
@KeyPattern.Value
@Override
public String value() {
return this.key.value();
}
@Override
public String asString() {
return this.key.asString();
}
}
@@ -161,6 +161,7 @@ public interface EnchantmentRegistryEntry {
* @param supportedItems the registry key set representing the supported items
* @return this builder instance
* @see RegistrySet#keySet(RegistryKey, TypedKey[])
* @see RegistrySet#keySet(TypedKey, TypedKey[])
* @see RegistryComposeEvent#getOrCreateTag(TagKey)
*/
@Contract(value = "_ -> this", mutates = "this")
@@ -182,6 +183,7 @@ public interface EnchantmentRegistryEntry {
* @param primaryItems the registry key set representing the primary items.
* @return this builder instance.
* @see RegistrySet#keySet(RegistryKey, TypedKey[])
* @see RegistrySet#keySet(TypedKey, TypedKey[])
* @see RegistryComposeEvent#getOrCreateTag(TagKey)
*/
@Contract(value = "_ -> this", mutates = "this")
@@ -285,6 +287,7 @@ public interface EnchantmentRegistryEntry {
* @param exclusiveWith a registry set of enchantments exclusive to this one
* @return this builder instance
* @see RegistrySet#keySet(RegistryKey, TypedKey[])
* @see RegistrySet#keySet(TypedKey, TypedKey[])
* @see RegistryComposeEvent#getOrCreateTag(TagKey)
*/
@Contract(value = "_ -> this", mutates = "this")
@@ -1,35 +0,0 @@
package io.papermc.paper.registry.data;
import io.papermc.paper.dialog.Dialog;
import io.papermc.paper.registry.RegistryBuilderFactory;
import io.papermc.paper.registry.data.dialog.DialogRegistryEntry;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.function.Consumer;
import org.bukkit.MusicInstrument;
import org.bukkit.inventory.meta.trim.TrimMaterial;
import org.bukkit.inventory.meta.trim.TrimPattern;
import org.jetbrains.annotations.ApiStatus;
/**
* @hidden
*/
@ApiStatus.Internal
@ApiStatus.NonExtendable
public interface InlinedRegistryBuilderProvider {
static InlinedRegistryBuilderProvider instance() {
final class Holder {
static final Optional<InlinedRegistryBuilderProvider> INSTANCE = ServiceLoader.load(InlinedRegistryBuilderProvider.class, InlinedRegistryBuilderProvider.class.getClassLoader()).findFirst();
}
return Holder.INSTANCE.orElseThrow();
}
MusicInstrument createInstrument(Consumer<RegistryBuilderFactory<MusicInstrument, ? extends InstrumentRegistryEntry.Builder>> value);
Dialog createDialog(Consumer<RegistryBuilderFactory<Dialog, ? extends DialogRegistryEntry.Builder>> value);
TrimMaterial createTrimMaterial(Consumer<RegistryBuilderFactory<TrimMaterial, ? extends TrimMaterialRegistryEntry.Builder>> value);
TrimPattern createTrimPattern(Consumer<RegistryBuilderFactory<TrimPattern, ? extends TrimPatternRegistryEntry.Builder>> value);
}
@@ -0,0 +1,36 @@
package io.papermc.paper.registry.data;
import io.papermc.paper.registry.RegistryBuilder;
import io.papermc.paper.registry.RegistryBuilderFactory;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.TypedKey;
import io.papermc.paper.registry.holder.RegistryHolder;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.function.Consumer;
import org.bukkit.Keyed;
import org.jetbrains.annotations.ApiStatus;
/**
* @hidden
*/
@ApiStatus.Internal
@ApiStatus.NonExtendable
public interface RegistryBuilderProvider {
static RegistryBuilderProvider instance() {
final class Holder {
static final Optional<RegistryBuilderProvider> INSTANCE = ServiceLoader.load(RegistryBuilderProvider.class, RegistryBuilderProvider.class.getClassLoader()).findFirst();
}
return Holder.INSTANCE.orElseThrow();
}
static <T extends RegistryElement.Buildable<T, E, ?>, E> RegistryHolder<T, E> transientHolder(final TypedKey<T> key) {
return instance().createTransientReferenceHolder(key);
}
<T extends RegistryElement.Inlineable<T, ?, B> & Keyed, B extends RegistryBuilder<T>> T create(RegistryKey<T> key, Consumer<RegistryBuilderFactory<T, ? extends B>> value);
<T extends RegistryElement.Buildable<T, E, ?>, E> RegistryHolder.Reference<T, E> createTransientReferenceHolder(TypedKey<T> key);
}
@@ -2,6 +2,7 @@ package io.papermc.paper.registry.data;
import io.papermc.paper.registry.RegistryBuilder;
import io.papermc.paper.registry.TypedKey;
import io.papermc.paper.registry.holder.RegistryHolder;
import io.papermc.paper.registry.set.RegistryKeySet;
import java.util.List;
import org.bukkit.Sound;
@@ -16,6 +17,7 @@ import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jspecify.annotations.Nullable;
import static io.papermc.paper.registry.data.RegistryBuilderProvider.transientHolder;
import static io.papermc.paper.util.BoundChecker.requireNonNegative;
import static io.papermc.paper.util.BoundChecker.requirePositive;
@@ -180,18 +182,15 @@ public interface SulfurCubeArchetypeRegistryEntry {
@ApiStatus.NonExtendable
interface SoundSettings {
// todo The sounds should take a RegistryHolder but need more thoughts on the create method
/**
* {@return the sound played once the sulfur cube is knocked}
*/
@ApiStatus.Experimental
TypedKey<Sound> hitSound();
RegistryHolder<Sound, SoundEventRegistryEntry> hitSound();
/**
* {@return the sound played once the sulfur cube is pushed}
*/
@ApiStatus.Experimental
TypedKey<Sound> pushSound();
RegistryHolder<Sound, SoundEventRegistryEntry> pushSound();
/**
* {@return the smallest impulse required to play the push sound}
@@ -199,7 +198,7 @@ public interface SulfurCubeArchetypeRegistryEntry {
float pushSoundImpulseThreshold();
/**
* {@return the amount of seconds before the push sound can be played again}
* {@return the number of seconds before the push sound can be played again}
*/
float pushSoundCooldown();
@@ -209,13 +208,28 @@ public interface SulfurCubeArchetypeRegistryEntry {
* @param hitSound the sound played once the sulfur cube is knocked, as returned by {@link #hitSound()}
* @param pushSound the sound played once the sulfur cube is pushed, as returned by {@link #pushSound()}
* @param pushSoundImpulseThreshold the smallest impulse required to play the push sound, as returned by {@link #pushSoundImpulseThreshold()}
* @param pushSoundCooldown the amount of seconds before the push sound can be played again, as returned by {@link #pushSoundCooldown()}
* @param pushSoundCooldown the number of seconds before the push sound can be played again, as returned by {@link #pushSoundCooldown()}
* @return the created instance
*/
@Contract(value = "_, _, _, _ -> new", pure = true)
@ApiStatus.Experimental
static SoundSettings of(final TypedKey<Sound> hitSound, final TypedKey<Sound> pushSound, final float pushSoundImpulseThreshold, final float pushSoundCooldown) {
record Impl(TypedKey<Sound> hitSound, TypedKey<Sound> pushSound, float pushSoundImpulseThreshold, float pushSoundCooldown) implements SoundSettings {
return of(transientHolder(hitSound), transientHolder(pushSound), pushSoundImpulseThreshold, pushSoundCooldown);
}
/**
* Creates a new sound settings instance based on the passed values.
* <p>
* {@link RegistryHolder} instances can be created with {@link io.papermc.paper.registry.event.RegistryFactory}.
*
* @param hitSound the sound played once the sulfur cube is knocked, as returned by {@link #hitSound()}
* @param pushSound the sound played once the sulfur cube is pushed, as returned by {@link #pushSound()}
* @param pushSoundImpulseThreshold the smallest impulse required to play the push sound, as returned by {@link #pushSoundImpulseThreshold()}
* @param pushSoundCooldown the number of seconds before the push sound can be played again, as returned by {@link #pushSoundCooldown()}
* @return the created instance
*/
@Contract(value = "_, _, _, _ -> new", pure = true)
static SoundSettings of(final RegistryHolder<Sound, SoundEventRegistryEntry> hitSound, final RegistryHolder<Sound, SoundEventRegistryEntry> pushSound, final float pushSoundImpulseThreshold, final float pushSoundCooldown) {
record Impl(RegistryHolder<Sound, SoundEventRegistryEntry> hitSound, RegistryHolder<Sound, SoundEventRegistryEntry> pushSound, float pushSoundImpulseThreshold, float pushSoundCooldown) implements SoundSettings {
}
return new Impl(hitSound, pushSound, pushSoundImpulseThreshold, pushSoundCooldown);
@@ -48,8 +48,10 @@ public interface DialogRegistryEntry {
* <p>Not a part of the registry entry.</p>
*
* @return a new registry value set builder
* @deprecated use {@link io.papermc.paper.registry.event.RegistryFactory} on the registry event and {@link io.papermc.paper.registry.set.RegistryHolderSetBuilder}
*/
@Contract(value = "-> new", pure = true)
@Deprecated(since = "26.4", forRemoval = true)
RegistryValueSetBuilder<Dialog, DialogRegistryEntry.Builder> registryValueSet();
/**
@@ -114,7 +114,7 @@ public non-sealed interface TextDialogInput extends DialogInput {
* @return this builder
*/
@Contract(value = "_ -> this", mutates = "this")
Builder width(final @Range(from = 1, to = 1024) int width);
Builder width(@Range(from = 1, to = 1024) int width);
/**
* Sets whether the label should be visible.
@@ -123,7 +123,7 @@ public non-sealed interface TextDialogInput extends DialogInput {
* @return this builder
*/
@Contract(value = "_ -> this", mutates = "this")
Builder labelVisible(final boolean labelVisible);
Builder labelVisible(boolean labelVisible);
/**
* Sets the initial value of the input.
@@ -132,7 +132,7 @@ public non-sealed interface TextDialogInput extends DialogInput {
* @return this builder
*/
@Contract(value = "_ -> this", mutates = "this")
Builder initial(final String initial);
Builder initial(String initial);
/**
* Sets the maximum length of the input.
@@ -141,7 +141,7 @@ public non-sealed interface TextDialogInput extends DialogInput {
* @return this builder
*/
@Contract(value = "_ -> this", mutates = "this")
Builder maxLength(final @Positive int maxLength);
Builder maxLength(@Positive int maxLength);
/**
* Sets the multiline options for the input.
@@ -150,7 +150,7 @@ public non-sealed interface TextDialogInput extends DialogInput {
* @return this builder
*/
@Contract(value = "_ -> this", mutates = "this")
Builder multiline(final @Nullable MultilineOptions multiline);
Builder multiline(@Nullable MultilineOptions multiline);
/**
* Builds the text dialog input.
@@ -61,7 +61,7 @@ public non-sealed interface DialogListType extends DialogType {
* @return the builder
*/
@Contract(value = "_ -> this", mutates = "this")
Builder exitAction(final @Nullable ActionButton exitAction);
Builder exitAction(@Nullable ActionButton exitAction);
/**
* Sets the number of columns to display in the dialog list.
@@ -70,7 +70,7 @@ public non-sealed interface DialogListType extends DialogType {
* @return the builder
*/
@Contract(value = "_ -> this", mutates = "this")
Builder columns(final @Positive int columns);
Builder columns(@Positive int columns);
/**
* Sets the width of each button in the dialog list.
@@ -79,7 +79,7 @@ public non-sealed interface DialogListType extends DialogType {
* @return the builder
*/
@Contract(value = "_ -> this", mutates = "this")
Builder buttonWidth(final @Range(from = 1, to = 1024) int buttonWidth);
Builder buttonWidth(@Range(from = 1, to = 1024) int buttonWidth);
/**
* Builds the dialog list type.
@@ -53,7 +53,7 @@ public non-sealed interface MultiActionType extends DialogType {
* @return the builder
*/
@Contract(value = "_ -> this", mutates = "this")
Builder exitAction(final @Nullable ActionButton exitAction);
Builder exitAction(@Nullable ActionButton exitAction);
/**
* Sets the number of columns to display in the dialog.
@@ -62,7 +62,7 @@ public non-sealed interface MultiActionType extends DialogType {
* @return the builder
*/
@Contract(value = "_ -> this", mutates = "this")
Builder columns(final @Positive int columns);
Builder columns(@Positive int columns);
/**
* Builds the multi-action dialog.
@@ -7,7 +7,7 @@ import org.bukkit.Keyed;
import org.jetbrains.annotations.ApiStatus;
/**
* Event object for {@link RegistryEventProvider#compose()}. This
* Event object for {@link RegistryEvents#compose(io.papermc.paper.registry.RegistryKey)}. This
* event is fired after a registry is loaded with its normal values.
* It provides a way for plugins to add new objects to the registry.
*
@@ -34,4 +34,11 @@ public interface RegistryComposeEvent<T, B extends RegistryBuilder<T>> extends R
* @param <V> the tag value type
*/
<V extends Keyed> Tag<V> getOrCreateTag(TagKey<V> tagKey); // TODO remove Keyed
/**
* Gets the factory for creating tags, holders, and holder sets.
*
* @return the registry factory
*/
RegistryFactory factory();
}
@@ -8,8 +8,8 @@ import org.bukkit.Keyed;
import org.jetbrains.annotations.ApiStatus;
/**
* Event object for {@link RegistryEventProvider#entryAdd()}. This
* event is fired right before a specific entry is registered in/added to registry.
* Event object for {@link RegistryEvents#entryAdd(io.papermc.paper.registry.RegistryKey)}. This
* event is fired right before a specific entry is registered in/added to the registry.
* It provides a way for plugins to modify parts of this entry.
*
* @param <T> registry entry type
@@ -42,4 +42,11 @@ public interface RegistryEntryAddEvent<T, B extends RegistryBuilder<T>> extends
* @param <V> the tag value type
*/
<V extends Keyed> Tag<V> getOrCreateTag(TagKey<V> tagKey);
/**
* Gets the factory for creating tags, holders, and holder sets.
*
* @return the registry factory
*/
RegistryFactory factory();
}
@@ -4,6 +4,7 @@ import io.papermc.paper.plugin.bootstrap.BootstrapContext;
import io.papermc.paper.plugin.lifecycle.event.handler.LifecycleEventHandler;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEventType;
import io.papermc.paper.registry.RegistryBuilder;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.event.type.RegistryEntryAddEventType;
import org.jetbrains.annotations.ApiStatus;
@@ -19,9 +20,11 @@ import org.jetbrains.annotations.ApiStatus;
*
* @param <T> registry entry type
* @param <B> registry entry builder type
* @deprecated use {@link RegistryEvents#compose(RegistryKey)} and {@link RegistryEvents#entryAdd(RegistryKey)}
*/
@ApiStatus.NonExtendable
public interface RegistryEventProvider<T, B extends RegistryBuilder<T>> {
@Deprecated(forRemoval = true, since = "26.4")
public interface RegistryEventProvider<T extends RegistryElement.Buildable<T, ?, B>, B extends RegistryBuilder<T>> {
/**
* Gets the event type for {@link RegistryEntryAddEvent} which is fired just before
@@ -3,24 +3,25 @@ package io.papermc.paper.registry.event;
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEventType;
import io.papermc.paper.registry.RegistryBuilder;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.event.type.RegistryEntryAddEventType;
import org.jetbrains.annotations.ApiStatus;
@ApiStatus.Internal
record RegistryEventProviderImpl<T, B extends RegistryBuilder<T>>(RegistryKey<T> registryKey) implements RegistryEventProvider<T, B> {
record RegistryEventProviderImpl<T extends RegistryElement.Buildable<T, E, B>, E, B extends RegistryBuilder<T>>(RegistryKey<T> registryKey) implements RegistryEventProvider<T, B> {
static <T, B extends RegistryBuilder<T>> RegistryEventProvider<T, B> create(final RegistryKey<T> registryKey) {
static <T extends RegistryElement.Buildable<T, E, B>, E, B extends RegistryBuilder<T>> RegistryEventProvider<T, B> create(final RegistryKey<T> registryKey) {
return new RegistryEventProviderImpl<>(registryKey);
}
@Override
public RegistryEntryAddEventType<T, B> entryAdd() {
return RegistryEventTypeProvider.provider().registryEntryAdd(this);
return RegistryEvents.entryAdd(this.registryKey);
}
@Override
public LifecycleEventType.Prioritizable<BootstrapContext, RegistryComposeEvent<T, B>> compose() {
return RegistryEventTypeProvider.provider().registryCompose(this);
return RegistryEvents.compose(this.registryKey);
}
}
@@ -3,6 +3,8 @@ package io.papermc.paper.registry.event;
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEventType;
import io.papermc.paper.registry.RegistryBuilder;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.event.type.RegistryEntryAddEventType;
import java.util.Optional;
import java.util.ServiceLoader;
@@ -17,7 +19,7 @@ interface RegistryEventTypeProvider {
return PROVIDER.orElseThrow(() -> new IllegalStateException("Could not find a %s service implementation".formatted(RegistryEventTypeProvider.class.getSimpleName())));
}
<T, B extends RegistryBuilder<T>> RegistryEntryAddEventType<T, B> registryEntryAdd(RegistryEventProvider<T, B> type);
<API extends RegistryElement.Buildable<API, E, B>, E, B extends RegistryBuilder<API>> RegistryEntryAddEventType<API, B> registryEntryAdd(RegistryKey<API> key);
<T, B extends RegistryBuilder<T>> LifecycleEventType.Prioritizable<BootstrapContext, RegistryComposeEvent<T, B>> registryCompose(RegistryEventProvider<T, B> type);
<API extends RegistryElement.Buildable<API, E, B>, E, B extends RegistryBuilder<API>> LifecycleEventType.Prioritizable<BootstrapContext, RegistryComposeEvent<API, B>> registryCompose(RegistryKey<API> key);
}
@@ -2,6 +2,10 @@ package io.papermc.paper.registry.event;
import io.papermc.paper.block.pot.PotPatternType;
import io.papermc.paper.dialog.Dialog;
import io.papermc.paper.plugin.bootstrap.BootstrapContext;
import io.papermc.paper.plugin.lifecycle.event.types.LifecycleEventType;
import io.papermc.paper.registry.RegistryBuilder;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.BannerPatternRegistryEntry;
import io.papermc.paper.registry.data.CatTypeRegistryEntry;
@@ -22,6 +26,7 @@ import io.papermc.paper.registry.data.TrimPatternRegistryEntry;
import io.papermc.paper.registry.data.WolfVariantRegistryEntry;
import io.papermc.paper.registry.data.ZombieNautilusVariantRegistryEntry;
import io.papermc.paper.registry.data.dialog.DialogRegistryEntry;
import io.papermc.paper.registry.event.type.RegistryEntryAddEventType;
import org.bukkit.Art;
import org.bukkit.GameEvent;
import org.bukkit.JukeboxSong;
@@ -43,32 +48,141 @@ import org.bukkit.inventory.meta.trim.TrimPattern;
import static io.papermc.paper.registry.event.RegistryEventProviderImpl.create;
/**
* Holds providers for {@link RegistryEntryAddEvent} and {@link RegistryComposeEvent}
* handlers for each applicable registry.
* Holds methods to create registry event types for various registry-related events.
*/
public final class RegistryEvents {
// Start generate - RegistryEvents
/**
* @deprecated use {@link #entryAdd(RegistryKey)} and {@link #compose(RegistryKey)}
*/
@Deprecated(forRemoval = true, since = "26.4")
public static final RegistryEventProvider<GameEvent, GameEventRegistryEntry.Builder> GAME_EVENT = create(RegistryKey.GAME_EVENT);
/**
* @deprecated use {@link #entryAdd(RegistryKey)} and {@link #compose(RegistryKey)}
*/
@Deprecated(forRemoval = true, since = "26.4")
public static final RegistryEventProvider<TrimMaterial, TrimMaterialRegistryEntry.Builder> TRIM_MATERIAL = create(RegistryKey.TRIM_MATERIAL);
/**
* @deprecated use {@link #entryAdd(RegistryKey)} and {@link #compose(RegistryKey)}
*/
@Deprecated(forRemoval = true, since = "26.4")
public static final RegistryEventProvider<TrimPattern, TrimPatternRegistryEntry.Builder> TRIM_PATTERN = create(RegistryKey.TRIM_PATTERN);
/**
* @deprecated use {@link #entryAdd(RegistryKey)} and {@link #compose(RegistryKey)}
*/
@Deprecated(forRemoval = true, since = "26.4")
public static final RegistryEventProvider<DamageType, DamageTypeRegistryEntry.Builder> DAMAGE_TYPE = create(RegistryKey.DAMAGE_TYPE);
/**
* @deprecated use {@link #entryAdd(RegistryKey)} and {@link #compose(RegistryKey)}
*/
@Deprecated(forRemoval = true, since = "26.4")
public static final RegistryEventProvider<Wolf.Variant, WolfVariantRegistryEntry.Builder> WOLF_VARIANT = create(RegistryKey.WOLF_VARIANT);
/**
* @deprecated use {@link #entryAdd(RegistryKey)} and {@link #compose(RegistryKey)}
*/
@Deprecated(forRemoval = true, since = "26.4")
public static final RegistryEventProvider<Enchantment, EnchantmentRegistryEntry.Builder> ENCHANTMENT = create(RegistryKey.ENCHANTMENT);
/**
* @deprecated use {@link #entryAdd(RegistryKey)} and {@link #compose(RegistryKey)}
*/
@Deprecated(forRemoval = true, since = "26.4")
public static final RegistryEventProvider<JukeboxSong, JukeboxSongRegistryEntry.Builder> JUKEBOX_SONG = create(RegistryKey.JUKEBOX_SONG);
/**
* @deprecated use {@link #entryAdd(RegistryKey)} and {@link #compose(RegistryKey)}
*/
@Deprecated(forRemoval = true, since = "26.4")
public static final RegistryEventProvider<PatternType, BannerPatternRegistryEntry.Builder> BANNER_PATTERN = create(RegistryKey.BANNER_PATTERN);
/**
* @deprecated use {@link #entryAdd(RegistryKey)} and {@link #compose(RegistryKey)}
*/
@Deprecated(forRemoval = true, since = "26.4")
public static final RegistryEventProvider<PotPatternType, DecoratedPotPatternRegistryEntry.Builder> DECORATED_POT_PATTERN = create(RegistryKey.DECORATED_POT_PATTERN);
/**
* @deprecated use {@link #entryAdd(RegistryKey)} and {@link #compose(RegistryKey)}
*/
@Deprecated(forRemoval = true, since = "26.4")
public static final RegistryEventProvider<Art, PaintingVariantRegistryEntry.Builder> PAINTING_VARIANT = create(RegistryKey.PAINTING_VARIANT);
/**
* @deprecated use {@link #entryAdd(RegistryKey)} and {@link #compose(RegistryKey)}
*/
@Deprecated(forRemoval = true, since = "26.4")
public static final RegistryEventProvider<MusicInstrument, InstrumentRegistryEntry.Builder> INSTRUMENT = create(RegistryKey.INSTRUMENT);
/**
* @deprecated use {@link #entryAdd(RegistryKey)} and {@link #compose(RegistryKey)}
*/
@Deprecated(forRemoval = true, since = "26.4")
public static final RegistryEventProvider<Cat.Type, CatTypeRegistryEntry.Builder> CAT_VARIANT = create(RegistryKey.CAT_VARIANT);
/**
* @deprecated use {@link #entryAdd(RegistryKey)} and {@link #compose(RegistryKey)}
*/
@Deprecated(forRemoval = true, since = "26.4")
public static final RegistryEventProvider<Frog.Variant, FrogVariantRegistryEntry.Builder> FROG_VARIANT = create(RegistryKey.FROG_VARIANT);
/**
* @deprecated use {@link #entryAdd(RegistryKey)} and {@link #compose(RegistryKey)}
*/
@Deprecated(forRemoval = true, since = "26.4")
public static final RegistryEventProvider<Chicken.Variant, ChickenVariantRegistryEntry.Builder> CHICKEN_VARIANT = create(RegistryKey.CHICKEN_VARIANT);
/**
* @deprecated use {@link #entryAdd(RegistryKey)} and {@link #compose(RegistryKey)}
*/
@Deprecated(forRemoval = true, since = "26.4")
public static final RegistryEventProvider<Cow.Variant, CowVariantRegistryEntry.Builder> COW_VARIANT = create(RegistryKey.COW_VARIANT);
/**
* @deprecated use {@link #entryAdd(RegistryKey)} and {@link #compose(RegistryKey)}
*/
@Deprecated(forRemoval = true, since = "26.4")
public static final RegistryEventProvider<Pig.Variant, PigVariantRegistryEntry.Builder> PIG_VARIANT = create(RegistryKey.PIG_VARIANT);
/**
* @deprecated use {@link #entryAdd(RegistryKey)} and {@link #compose(RegistryKey)}
*/
@Deprecated(forRemoval = true, since = "26.4")
public static final RegistryEventProvider<ZombieNautilus.Variant, ZombieNautilusVariantRegistryEntry.Builder> ZOMBIE_NAUTILUS_VARIANT = create(RegistryKey.ZOMBIE_NAUTILUS_VARIANT);
/**
* @deprecated use {@link #entryAdd(RegistryKey)} and {@link #compose(RegistryKey)}
*/
@Deprecated(forRemoval = true, since = "26.4")
public static final RegistryEventProvider<SulfurCube.Archetype, SulfurCubeArchetypeRegistryEntry.Builder> SULFUR_CUBE_ARCHETYPE = create(RegistryKey.SULFUR_CUBE_ARCHETYPE);
/**
* @deprecated use {@link #entryAdd(RegistryKey)} and {@link #compose(RegistryKey)}
*/
@Deprecated(forRemoval = true, since = "26.4")
public static final RegistryEventProvider<Dialog, DialogRegistryEntry.Builder> DIALOG = create(RegistryKey.DIALOG);
// End generate - RegistryEvents
/**
* Gets the event type for {@link RegistryEntryAddEvent} which is fired just before
* an object is added to a registry.
* <p>
* Can be used in {@link io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager#registerEventHandler(LifecycleEventType, io.papermc.paper.plugin.lifecycle.event.handler.LifecycleEventHandler)}
* to register a handler for {@link RegistryEntryAddEvent}.
*
* @param registryKey the registry key
* @param <API> the api type
* @param <E> the registry entry type
* @param <B> the registry entry builder type
*
* @return the registry entry add event type
*/
public static <API extends RegistryElement.Buildable<API, E, B>, E, B extends RegistryBuilder<API>> RegistryEntryAddEventType<API, B> entryAdd(final RegistryKey<API> registryKey) {
return RegistryEventTypeProvider.provider().registryEntryAdd(registryKey);
}
/**
* Gets the event type for {@link RegistryComposeEvent} which is fired after
* a registry is loaded of expected elements. It allows for the registration of new objects.
* <p>
* Can be used in {@link io.papermc.paper.plugin.lifecycle.event.LifecycleEventManager#registerEventHandler(LifecycleEventType, io.papermc.paper.plugin.lifecycle.event.handler.LifecycleEventHandler)}
* to register a handler for {@link RegistryComposeEvent}.
*
* @param registryKey the registry key
* @param <API> the api type
* @param <E> the registry entry type
* @param <B> the registry entry builder type
*
* @return the registry compose event type
*/
public static <API extends RegistryElement.Buildable<API, E, B>, E, B extends RegistryBuilder<API>> LifecycleEventType.Prioritizable<BootstrapContext, RegistryComposeEvent<API, B>> compose(final RegistryKey<API> registryKey) {
return RegistryEventTypeProvider.provider().registryCompose(registryKey);
}
private RegistryEvents() {
}
@@ -0,0 +1,76 @@
package io.papermc.paper.registry.event;
import io.papermc.paper.registry.RegistryBuilder;
import io.papermc.paper.registry.RegistryBuilderFactory;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.TypedKey;
import io.papermc.paper.registry.holder.RegistryHolder;
import io.papermc.paper.registry.set.RegistryHolderSetBuilder;
import io.papermc.paper.registry.tag.Tag;
import io.papermc.paper.registry.tag.TagKey;
import java.util.function.Consumer;
import org.bukkit.Keyed;
import org.jetbrains.annotations.ApiStatus;
/**
* A factory for creating tags, holders, and holder sets while
* reacting to registry events.
*/
@ApiStatus.Experimental
public interface RegistryFactory {
/**
* Gets or creates a tag for the given tag key. This tag
* is then required to be filled either from the built-in or
* custom datapack.
*
* @param tagKey the tag key
* @return the tag
* @param <V> the tag value type
*/
<V extends Keyed> Tag<V> getOrCreateTag(TagKey<V> tagKey); // TODO remove Keyed
/**
* Gets or creates a reference holder for the given key. The referenced
* value does not need to be present in the registry yet.
* <p>
* You can only create new reference holders for registries in the same registry layer. For example,
* since {@link RegistryKey#SOUND_EVENT} is a built-in registry, you cannot create new
* reference holders while in an event for {@link RegistryKey#SULFUR_CUBE_ARCHETYPE} as that
* is in a later layer. Try a {@link #createInlinedHolder(RegistryKey, Consumer)}.
*
* @param key the key of the referenced value
* @return the reference holder
* @param <V> the API type
* @param <E> the registry entry type
* @param <B> the builder type
* @see #createInlinedHolder(RegistryKey, Consumer)
*/
<V extends Keyed & RegistryElement.Buildable<V, E, B>, E, B extends RegistryBuilder<V>> RegistryHolder.Reference<V, E> getOrCreateReferenceHolder(TypedKey<V> key); // TODO remove Keyed
/**
* Creates an inlined holder wrapping an anonymous value built from the
* given builder consumer.
*
* @param registryKey the registry key for the value's type
* @param value a consumer configuring the inlined value's builder
* @return the inlined holder
* @param <V> the API type
* @param <E> the registry entry type
* @param <B> the builder type
* @see #getOrCreateReferenceHolder(TypedKey)
*/
<V extends Keyed & RegistryElement.Inlineable<V, E, B>, E, B extends RegistryBuilder<V>> RegistryHolder.Inlined<V, E> createInlinedHolder(RegistryKey<V> registryKey, Consumer<RegistryBuilderFactory<V, ? extends B>> value); // TODO remove Keyed
/**
* Creates a new builder for a {@link RegistryHolderSetBuilder holder set} of the given registry.
*
* @param registryKey the registry key for the value's type
* @return a new holder set builder
* @param <V> the API type
* @param <E> the registry entry type
* @param <B> the builder type
*/
<V extends Keyed & RegistryElement.Inlineable<V, E, B>, E, B extends RegistryBuilder<V>> RegistryHolderSetBuilder<V, E, B> createSetBuilder(RegistryKey<V> registryKey); // TODO remove Keyed
}
@@ -1,5 +1,7 @@
package io.papermc.paper.registry.holder;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.TypedKey;
import org.jetbrains.annotations.ApiStatus;
@@ -12,7 +14,28 @@ import org.jetbrains.annotations.ApiStatus;
* @param <ENTRY> the type of the registry entry (for inlined values)
*/
@ApiStatus.Experimental
public sealed interface RegistryHolder<API, ENTRY> permits RegistryHolder.Reference, RegistryHolder.Inlined {
public sealed interface RegistryHolder<API extends RegistryElement.Buildable<API, ENTRY, ?>, ENTRY> permits RegistryHolder.Reference, RegistryHolder.Inlined {
/**
* Gets the registry key of the registry this holder's value belongs to.
*
* @return the registry key
*/
RegistryKey<API> registryKey();
/**
* Gets the value held by this holder.
*
* @return the value
*/
API value();
/**
* Gets the registry entry held by this holder.
*
* @return the entry
*/
ENTRY entry();
/**
* A holder that references a registry value by key, but does not have the entry itself.
@@ -22,7 +45,7 @@ public sealed interface RegistryHolder<API, ENTRY> permits RegistryHolder.Refere
* @param <ENTRY> the type of the registry entry
*/
@ApiStatus.NonExtendable
non-sealed interface Reference<API, ENTRY> extends RegistryHolder<API, ENTRY> {
non-sealed interface Reference<API extends RegistryElement.Buildable<API, ENTRY, ?>, ENTRY> extends RegistryHolder<API, ENTRY> {
/**
* The key of the referenced value.
@@ -39,13 +62,14 @@ public sealed interface RegistryHolder<API, ENTRY> permits RegistryHolder.Refere
* @param <ENTRY> the type of the registry entry
*/
@ApiStatus.NonExtendable
non-sealed interface Inlined<API, ENTRY> extends RegistryHolder<API, ENTRY> {
non-sealed interface Inlined<API extends RegistryElement.Buildable<API, ENTRY, ?>, ENTRY> extends RegistryHolder<API, ENTRY> {
/**
* The inlined entry.
*
* @return the inlined entry
*/
@Override
ENTRY entry();
}
}
@@ -0,0 +1,28 @@
package io.papermc.paper.registry.set;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.holder.RegistryHolder;
import java.util.Collection;
import org.jetbrains.annotations.Unmodifiable;
/**
* A {@link RegistrySet} backed by {@link RegistryHolder holders}, each of which is
* either a reference to a registry value or an inlined, anonymous value.
* <p>
* Create with {@link RegistrySet#holderSetBuilder(RegistryKey)}, or if in a registry event context,
* {@link io.papermc.paper.registry.event.RegistryFactory#createSetBuilder(RegistryKey)}.
* </p>
*
* @param <T> the API type
* @param <E> the registry entry type
*/
public non-sealed interface RegistryHolderSet<T extends RegistryElement.Buildable<T, E, ?>, E> extends RegistrySet<T> {
/**
* Gets the holders in this set.
*
* @return an unmodifiable collection of holders
*/
@Unmodifiable Collection<RegistryHolder<T, E>> holders();
}
@@ -0,0 +1,49 @@
package io.papermc.paper.registry.set;
import io.papermc.paper.registry.RegistryBuilder;
import io.papermc.paper.registry.RegistryBuilderFactory;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.TypedKey;
import java.util.function.Consumer;
/**
* A builder for a {@link RegistryHolderSet}.
*
* @param <T> the API type
* @param <E> the registry entry type
* @param <B> the builder type
*/
public interface RegistryHolderSetBuilder<T extends RegistryElement.Inlineable<T, E, B>, E, B extends RegistryBuilder<T>> {
/**
* Adds a value to the set.
*
* @param value the value to add
* @return this builder
*/
RegistryHolderSetBuilder<T, E, B> add(T value);
/**
* Adds a value by its key to the set. The referenced value does not need
* to be present in the registry yet.
*
* @param key the key of the value to add
* @return this builder
*/
RegistryHolderSetBuilder<T, E, B> add(TypedKey<T> key);
/**
* Adds an inlined, anonymous value built from the given builder consumer to the set.
*
* @param value a consumer configuring the inlined value's builder
* @return this builder
*/
RegistryHolderSetBuilder<T, E, B> add(Consumer<RegistryBuilderFactory<T, ? extends B>> value);
/**
* Builds the holder set.
*
* @return a new holder set
*/
RegistryHolderSet<T, E> build();
}
@@ -3,7 +3,6 @@ package io.papermc.paper.registry.set;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.TypedKey;
import io.papermc.paper.registry.tag.Tag;
import io.papermc.paper.registry.tag.TagKey;
import java.util.Collection;
import java.util.Iterator;
import org.bukkit.Keyed;
@@ -43,12 +42,24 @@ public non-sealed interface RegistryKeySet<T extends Keyed> extends Iterable<Typ
* Resolve this set into a collection of values. Prefer using
* {@link #values()}.
*
* @param registry the registry to resolve the values from (must match {@link #registryKey()})
* @param ignored the registry to resolve the values from (must match {@link #registryKey()})
* @return the resolved values
* @see RegistryKeySet#values()
* @see Registry#getTagValues(TagKey)
* @deprecated use {@link #resolve()}, the registry is not needed
*/
@Unmodifiable Collection<T> resolve(final Registry<T> registry);
@Deprecated(since = "26.4", forRemoval = true)
default @Unmodifiable Collection<T> resolve(final Registry<T> ignored) {
return this.resolve();
}
/**
* Resolve this set into a collection of values. Prefer using
* {@link #values()}.
*
* @return the resolved values
* @see RegistryKeySet#values()
*/
@Unmodifiable Collection<T> resolve();
/**
* Checks if this set contains the value with the given key.
@@ -37,7 +37,8 @@ record RegistryKeySetImpl<T extends Keyed>(RegistryKey<T> registryKey, List<Type
}
@Override
public Collection<T> resolve(final Registry<T> registry) {
public Collection<T> resolve() {
final Registry<T> registry = RegistryAccess.registryAccess().getRegistry(this.registryKey);
final List<T> values = new ArrayList<>(this.values.size());
for (final TypedKey<T> key : this.values) {
final T value = registry.get(key.key());
@@ -1,9 +1,12 @@
package io.papermc.paper.registry.set;
import com.google.common.collect.Lists;
import io.papermc.paper.registry.RegistryBuilder;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.TypedKey;
import io.papermc.paper.registry.tag.Tag;
import java.util.List;
import org.bukkit.Keyed;
import org.jetbrains.annotations.Contract;
@@ -16,13 +19,30 @@ import org.jetbrains.annotations.Contract;
* These are obtained via {@link org.bukkit.Registry#getTag(io.papermc.paper.registry.tag.TagKey)}.</li>
* <li>{@link RegistryKeySet} which is a set of keys linked to values that are present in the registry. These are
* created via {@link #keySet(RegistryKey, Iterable)} or {@link #keySetFromValues(RegistryKey, Iterable)}.</li>
* <li>{@link RegistryValueSet} which is a set of values which are anonymous (don't have keys in the registry). These are
* created via {@link #valueSet(RegistryKey, Iterable)}.</li>
* <li>{@link RegistryHolderSet} which is a mixed set of values, some of which are anonymous (don't have keys in the registry). These are
* created via {@link #holderSetBuilder(RegistryKey)}.</li>
* </ul>
*
* @param <T> registry value type
*/
public sealed interface RegistrySet<T> permits RegistryKeySet, RegistryValueSet {
public sealed interface RegistrySet<T> permits RegistryHolderSet, RegistryKeySet, RegistryValueSet {
/**
* Creates a new builder for a {@link RegistryHolderSet}, a mixed set of registry-backed
* references and inlined, anonymous values.
* <p>
* In a registry event context, use {@link io.papermc.paper.registry.event.RegistryFactory#createSetBuilder(RegistryKey)} instead.
*
* @param registryKey the registry key for the type of these values
* @return a new holder set builder
* @param <T> the API type
* @param <E> the registry entry type
* @param <B> the builder type
*/
@Contract(value = "_ -> new", pure = true)
static <T extends Keyed & RegistryElement.Inlineable<T, E, B>, E, B extends RegistryBuilder<T>> RegistryHolderSetBuilder<T, E, B> holderSetBuilder(final RegistryKey<T> registryKey) { // TODO remove Keyed
return RegistrySetProvider.instance().registryHolderSetBuilder(registryKey);
}
/**
* Creates a {@link RegistryValueSet} from anonymous values.
@@ -32,8 +52,10 @@ public sealed interface RegistrySet<T> permits RegistryKeySet, RegistryValueSet
* @param values the values
* @return a new registry set
* @param <T> the type of the values
* @deprecated Use {@link #holderSetBuilder(RegistryKey)}
*/
@Contract(value = "_, _ -> new", pure = true)
@Deprecated(since = "26.3", forRemoval = true)
static <T> RegistryValueSet<T> valueSet(final RegistryKey<T> registryKey, final Iterable<? extends T> values) {
return RegistryValueSetImpl.create(registryKey, values);
}
@@ -41,7 +63,7 @@ public sealed interface RegistrySet<T> permits RegistryKeySet, RegistryValueSet
/**
* Creates a {@link RegistryKeySet} from registry-backed values.
* <p>All values provided <b>must</b> have keys in the given registry.
* <!--For anonymous values, use {@link #valueSet(RegistryKey, Iterable)}--></p>
* For anonymous values, use {@link #valueSet(RegistryKey, Iterable)}.</p>
* <p>If references to actual objects are not available yet, use {@link #keySet(RegistryKey, Iterable)} to
* create an equivalent {@link RegistryKeySet} using just {@link TypedKey TypedKeys}.</p>
*
@@ -57,7 +79,7 @@ public sealed interface RegistrySet<T> permits RegistryKeySet, RegistryValueSet
}
/**
* Creates a direct {@link RegistrySet} from {@link TypedKey TypedKeys}.
* Creates a direct {@code RegistrySet} from {@link TypedKey TypedKeys}.
*
* @param registryKey the registry key for the owner of these keys
* @param keys the keys for the values
@@ -70,7 +92,22 @@ public sealed interface RegistrySet<T> permits RegistryKeySet, RegistryValueSet
}
/**
* Creates a direct {@link RegistrySet} from {@link TypedKey TypedKeys}.
* Creates a non empty direct {@code RegistrySet} from {@link TypedKey TypedKeys}.
*
* @param firstKey the first key for the values
* @param otherKeys the other keys for the values
* @return a new registry set
* @param <T> the type of the values
*/
@SafeVarargs
static <T extends Keyed> RegistryKeySet<T> keySet(final TypedKey<T> firstKey, final TypedKey<T>... otherKeys) { // TODO remove Keyed
final List<TypedKey<T>> keys = Lists.newArrayList(otherKeys);
keys.addFirst(firstKey);
return keySet(firstKey.registryKey(), keys);
}
/**
* Creates a direct {@code RegistrySet} from {@link TypedKey TypedKeys}.
*
* @param registryKey the registry key for the owner of these keys
* @param keys the keys for the values
@@ -0,0 +1,26 @@
package io.papermc.paper.registry.set;
import io.papermc.paper.registry.RegistryBuilder;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import java.util.Optional;
import java.util.ServiceLoader;
import org.bukkit.Keyed;
import org.jetbrains.annotations.ApiStatus;
/**
* @hidden
*/
@ApiStatus.Internal
@ApiStatus.NonExtendable
public interface RegistrySetProvider {
static RegistrySetProvider instance() {
final class Holder {
static final Optional<RegistrySetProvider> INSTANCE = ServiceLoader.load(RegistrySetProvider.class, RegistrySetProvider.class.getClassLoader()).findFirst();
}
return Holder.INSTANCE.orElseThrow();
}
<T extends Keyed & RegistryElement.Inlineable<T, E, B>, E, B extends RegistryBuilder<T>> RegistryHolderSetBuilder<T, E, B> registryHolderSetBuilder(RegistryKey<T> registryKey); // TODO remove Keyed
}
@@ -12,7 +12,9 @@ import org.jetbrains.annotations.Unmodifiable;
* in the context of a {@link io.papermc.paper.registry.RegistryBuilder},
* there are methods to create them like {@link DialogRegistryEntry.Builder#registryValueSet()}.
* @param <T> registry value type
* @deprecated use {@link RegistryHolderSet} and {@link RegistryHolderSetBuilder}
*/
@Deprecated(since = "26.4", forRemoval = true)
public sealed interface RegistryValueSet<T> extends Iterable<T>, RegistrySet<T> permits RegistryValueSetImpl {
@Override
@@ -10,8 +10,10 @@ import org.jetbrains.annotations.ApiStatus;
*
* @param <API> the API type
* @param <ENTRY_BUILDER> the type of the entry builder,
* @deprecated use {@link RegistryHolderSetBuilder}
*/
@ApiStatus.NonExtendable
@Deprecated(since = "26.4", forRemoval = true)
public interface RegistryValueSetBuilder<API, ENTRY_BUILDER extends RegistryBuilder<API>> {
/**
+3 -1
View File
@@ -2,7 +2,9 @@ package org.bukkit;
import com.google.common.base.Preconditions;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.PaintingVariantRegistryEntry;
import java.util.Locale;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
@@ -18,7 +20,7 @@ import org.jetbrains.annotations.Nullable;
* There may be additional arts present in the server, for example from a {@link io.papermc.paper.datapack.Datapack}
* which can be accessed via {@link RegistryAccess#registryAccess()} and {@link RegistryKey#PAINTING_VARIANT}.
*/
public interface Art extends OldEnum<Art>, Keyed {
public interface Art extends RegistryElement.Buildable<Art, PaintingVariantRegistryEntry, PaintingVariantRegistryEntry.Builder>, OldEnum<Art>, Keyed {
// Start generate - Art
Art ALBAN = getArt("alban");
@@ -1,6 +1,7 @@
package org.bukkit;
import com.google.common.base.Preconditions;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import java.util.Locale;
import net.kyori.adventure.key.Key;
@@ -11,7 +12,7 @@ import org.jetbrains.annotations.NotNull;
/**
* Represents a fluid type.
*/
public interface Fluid extends OldEnum<Fluid>, Keyed {
public interface Fluid extends RegistryElement<Fluid>, OldEnum<Fluid>, Keyed {
// Start generate - Fluid
Fluid EMPTY = getFluid("empty");
@@ -1,5 +1,7 @@
package org.bukkit;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.data.GameEventRegistryEntry;
import java.util.Collection;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
@@ -9,7 +11,7 @@ import org.jetbrains.annotations.Nullable;
/**
* Represents a generic Mojang game event.
*/
public abstract class GameEvent implements Keyed {
public abstract class GameEvent implements RegistryElement.Buildable<GameEvent, GameEventRegistryEntry, GameEventRegistryEntry.Builder>, Keyed {
// Start generate - GameEvent
public static final GameEvent BLOCK_ACTIVATE = getEvent("block_activate");
@@ -2,6 +2,7 @@ package org.bukkit;
import com.google.common.base.Preconditions;
import io.papermc.paper.InternalAPIBridge;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.world.flag.FeatureDependant;
import java.util.function.UnaryOperator;
import org.jetbrains.annotations.ApiStatus;
@@ -19,7 +20,7 @@ import org.jetbrains.annotations.Nullable;
* @see GameRules
*/
@ApiStatus.NonExtendable
public abstract class GameRule<T> implements net.kyori.adventure.translation.Translatable, FeatureDependant, Keyed {
public abstract class GameRule<T> implements RegistryElement<GameRule<T>>, net.kyori.adventure.translation.Translatable, FeatureDependant, Keyed {
// Boolean rules
/**
@@ -1,7 +1,9 @@
package org.bukkit;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.JukeboxSongRegistryEntry;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
import net.kyori.adventure.text.Component;
@@ -11,7 +13,7 @@ import org.jspecify.annotations.NullMarked;
* Represents a song which may play in a Jukebox.
*/
@NullMarked
public interface JukeboxSong extends Keyed, Translatable {
public interface JukeboxSong extends RegistryElement.Buildable<JukeboxSong, JukeboxSongRegistryEntry, JukeboxSongRegistryEntry.Builder>, Keyed, Translatable {
// Start generate - JukeboxSong
JukeboxSong ELEVEN = get("11");
@@ -2,9 +2,10 @@ package org.bukkit;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryBuilderFactory;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.InlinedRegistryBuilderProvider;
import io.papermc.paper.registry.data.InstrumentRegistryEntry;
import io.papermc.paper.registry.data.RegistryBuilderProvider;
import java.util.Collection;
import java.util.function.Consumer;
import net.kyori.adventure.key.Key;
@@ -14,7 +15,7 @@ import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
@NullMarked
public abstract class MusicInstrument implements Keyed, net.kyori.adventure.translation.Translatable {
public abstract class MusicInstrument implements RegistryElement.Inlineable<MusicInstrument, InstrumentRegistryEntry, InstrumentRegistryEntry.Builder>, Keyed, net.kyori.adventure.translation.Translatable {
/**
* Creates an inlined music instrument.
@@ -23,7 +24,7 @@ public abstract class MusicInstrument implements Keyed, net.kyori.adventure.tran
* @return the created music instrument
*/
public static MusicInstrument create(final Consumer<RegistryBuilderFactory<MusicInstrument, ? extends InstrumentRegistryEntry.Builder>> value) {
return InlinedRegistryBuilderProvider.instance().createInstrument(value);
return RegistryBuilderProvider.instance().create(RegistryKey.INSTRUMENT, value);
}
// Start generate - MusicInstrument
@@ -500,7 +500,6 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
* @throws NoSuchElementException if no tag with the given key is found
* @throws UnsupportedOperationException if this registry doesn't have or support tags
* @see #hasTag(TagKey)
* @see #getTagValues(TagKey)
*/
Tag<T> getTag(TagKey<T> key);
@@ -512,11 +511,13 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
* @throws NoSuchElementException if no tag with the given key is found
* @throws UnsupportedOperationException if this registry doesn't have or support tags
* @see #getTag(TagKey)
* @see Tag#resolve(Registry)
* @see Tag#resolve()
* @deprecated use {@link Tag#resolve()} on the fetched tag
*/
@Deprecated(since = "26.4", forRemoval = true)
default Collection<T> getTagValues(final TagKey<T> key) {
Tag<T> tag = this.getTag(key);
return tag.resolve(this);
final Tag<T> tag = this.getTag(key);
return tag.resolve();
}
/**
+42 -9
View File
@@ -1,12 +1,18 @@
package org.bukkit;
import com.google.common.base.Preconditions;
import io.papermc.paper.registry.RegistryBuilderFactory;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.RegistryBuilderProvider;
import io.papermc.paper.registry.data.SoundEventRegistryEntry;
import java.util.Locale;
import java.util.function.Consumer;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
import org.bukkit.util.OldEnum;
import org.jetbrains.annotations.NotNull;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
/**
* An interface of Sounds the server is able to send to players.
@@ -21,7 +27,29 @@ import org.jetbrains.annotations.NotNull;
* guarantee values will not be removed from this interface. As such, you should not
* depend on the ordinal values of this class.
*/
public interface Sound extends OldEnum<Sound>, Keyed, net.kyori.adventure.sound.Sound.Type { // Paper - implement Sound.Type
@NullMarked
public interface Sound extends RegistryElement.Inlineable<Sound, SoundEventRegistryEntry, SoundEventRegistryEntry.Builder>, OldEnum<Sound>, Keyed, net.kyori.adventure.sound.Sound.Type { // Paper - implement Sound.Type
/**
* Creates an inlined sound event.
*
* @param key the sound location
* @param range an optional fixed range
* @return the created sound
*/
static Sound create(final Key key, final @Nullable Float range) {
return create(builder -> builder.empty().location(key).fixedRange(range));
}
/**
* Creates an inlined sound event.
*
* @param value a consumer for the builder factory
* @return the created sound
*/
static Sound create(final Consumer<RegistryBuilderFactory<Sound, ? extends SoundEventRegistryEntry.Builder>> value) {
return RegistryBuilderProvider.instance().create(RegistryKey.SOUND_EVENT, value);
}
// Start generate - Sound
Sound AMBIENT_BASALT_DELTAS_ADDITIONS = getSound("ambient.basalt_deltas.additions");
@@ -4007,8 +4035,7 @@ public interface Sound extends OldEnum<Sound>, Keyed, net.kyori.adventure.sound.
Sound WEATHER_RAIN_ABOVE = getSound("weather.rain.above");
// End generate - Sound
@NotNull
private static Sound getSound(@NotNull @KeyPattern.Value String key) {
private static Sound getSound(@KeyPattern.Value String key) {
return Registry.SOUNDS.getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, key));
}
@@ -4017,9 +4044,8 @@ public interface Sound extends OldEnum<Sound>, Keyed, net.kyori.adventure.sound.
* @return the sound with the given name.
* @deprecated only for backwards compatibility, use {@link Registry#get(NamespacedKey)} instead.
*/
@NotNull
@Deprecated(since = "1.21.3", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils
static Sound valueOf(@NotNull String name) {
static Sound valueOf(String name) {
final NamespacedKey key = NamespacedKey.fromString(name.toLowerCase(Locale.ROOT));
Sound sound;
@@ -4049,14 +4075,21 @@ public interface Sound extends OldEnum<Sound>, Keyed, net.kyori.adventure.sound.
*/
@Deprecated(since = "1.20.5", forRemoval = true)
@Override
@NotNull NamespacedKey getKey();
NamespacedKey getKey();
// Paper end - deprecate getKey
/**
* Gets the fixed range, a radius in block which this sound is audible.
* The computed range will depends on the volume when this value is not defined.
*
* @return the fixed range
*/
@Nullable Float getFixedRange();
/**
* @return an array of all known sounds.
* @deprecated use {@link Registry#stream()}.
*/
@NotNull
@Deprecated(since = "1.21.3", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils
static Sound[] values() {
return Registry.SOUNDS.stream().toArray(Sound[]::new);
@@ -4069,7 +4102,7 @@ public interface Sound extends OldEnum<Sound>, Keyed, net.kyori.adventure.sound.
*/
@Deprecated(since = "1.20.5", forRemoval = true)
@Override
default net.kyori.adventure.key.@NotNull Key key() {
default net.kyori.adventure.key.Key key() {
return this.getKey();
}
// Paper end
@@ -1,6 +1,7 @@
package org.bukkit.attribute;
import com.google.common.base.Preconditions;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import java.util.Locale;
import net.kyori.adventure.key.Key;
@@ -17,7 +18,7 @@ import org.jetbrains.annotations.NotNull;
/**
* Types of attributes which may be present on an {@link Attributable}.
*/
public interface Attribute extends OldEnum<Attribute>, Keyed, Translatable, net.kyori.adventure.translation.Translatable { // Paper - Adventure translations
public interface Attribute extends RegistryElement<Attribute>, OldEnum<Attribute>, Keyed, Translatable, net.kyori.adventure.translation.Translatable { // Paper - Adventure translations
/**
* Maximum health of an Entity.
@@ -3,6 +3,7 @@ package org.bukkit.block;
import com.google.common.base.Preconditions;
import io.papermc.paper.InternalAPIBridge;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import java.util.Locale;
import net.kyori.adventure.key.Key;
@@ -23,7 +24,7 @@ import org.jetbrains.annotations.NotNull;
* There may be additional biomes present in the server, for example from a {@link io.papermc.paper.datapack.Datapack}
* which can be accessed via {@link io.papermc.paper.registry.RegistryAccess#getRegistry(RegistryKey)} and {@link RegistryKey#BIOME}.
*/
public interface Biome extends OldEnum<Biome>, Keyed, net.kyori.adventure.translation.Translatable { // Paper - Adventure translations
public interface Biome extends RegistryElement<Biome>, OldEnum<Biome>, Keyed, net.kyori.adventure.translation.Translatable { // Paper - Adventure translations
// Start generate - Biome
Biome BADLANDS = getBiome("badlands");
@@ -1,5 +1,6 @@
package org.bukkit.block;
import io.papermc.paper.registry.RegistryElement;
import java.util.Collection;
import java.util.function.Consumer;
import net.kyori.adventure.key.Key;
@@ -135,7 +136,7 @@ import org.jspecify.annotations.Nullable;
* Represents a block type.
*/
@NullMarked
public interface BlockType extends Keyed, Translatable, net.kyori.adventure.translation.Translatable, io.papermc.paper.world.flag.FeatureDependant { // Paper - add translatable & feature flag API
public interface BlockType extends RegistryElement<BlockType>, Keyed, Translatable, net.kyori.adventure.translation.Translatable, io.papermc.paper.world.flag.FeatureDependant { // Paper - add translatable & feature flag API
/**
* Typed represents a subtype of {@link BlockType}s that have a known block
@@ -2,7 +2,9 @@ package org.bukkit.block.banner;
import com.google.common.base.Preconditions;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.BannerPatternRegistryEntry;
import java.util.Locale;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
@@ -14,7 +16,7 @@ import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public interface PatternType extends OldEnum<PatternType>, Keyed {
public interface PatternType extends RegistryElement.Buildable<PatternType, BannerPatternRegistryEntry, BannerPatternRegistryEntry.Builder>, OldEnum<PatternType>, Keyed {
// Start generate - PatternType
PatternType BASE = getType("base");
@@ -1,7 +1,9 @@
package org.bukkit.damage;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.DamageTypeRegistryEntry;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
import org.bukkit.Keyed;
@@ -17,7 +19,7 @@ import org.jetbrains.annotations.NotNull;
*
* @see <a href="https://minecraft.wiki/w/Damage_type">Minecraft Wiki</a>
*/
public interface DamageType extends Keyed, Translatable {
public interface DamageType extends RegistryElement.Buildable<DamageType, DamageTypeRegistryEntry, DamageTypeRegistryEntry.Builder>, Keyed, Translatable {
// Start generate - DamageType
DamageType ARROW = getDamageType("arrow");
@@ -1,7 +1,9 @@
package org.bukkit.enchantments;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.EnchantmentRegistryEntry;
import java.util.Locale;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
@@ -18,7 +20,7 @@ import org.jetbrains.annotations.Nullable;
/**
* The various type of enchantments that may be added to armour or weapons
*/
public abstract class Enchantment implements Keyed, Translatable, net.kyori.adventure.translation.Translatable { // Paper - Adventure translations
public abstract class Enchantment implements RegistryElement.Buildable<Enchantment, EnchantmentRegistryEntry, EnchantmentRegistryEntry.Builder>, Keyed, Translatable, net.kyori.adventure.translation.Translatable { // Paper - Adventure translations
/**
* Provides protection against environmental damage
*/
@@ -2,7 +2,9 @@ package org.bukkit.entity;
import com.google.common.base.Preconditions;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.CatTypeRegistryEntry;
import java.util.Locale;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
@@ -68,7 +70,7 @@ public interface Cat extends Tameable, Sittable, io.papermc.paper.entity.CollarC
/**
* Represents the various different cat types there are.
*/
interface Type extends OldEnum<Type>, Keyed {
interface Type extends RegistryElement.Buildable<Type, CatTypeRegistryEntry, CatTypeRegistryEntry.Builder>, OldEnum<Type>, Keyed {
// Start generate - CatType
Type ALL_BLACK = getType("all_black");
@@ -127,7 +129,7 @@ public interface Cat extends Tameable, Sittable, io.papermc.paper.entity.CollarC
/**
* Represents the sound variant of a cat.
*/
interface SoundVariant extends Keyed {
interface SoundVariant extends RegistryElement<SoundVariant>, Keyed {
// Start generate - CatSoundVariant
SoundVariant CLASSIC = getSoundVariant("classic");
@@ -1,7 +1,9 @@
package org.bukkit.entity;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.ChickenVariantRegistryEntry;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
import org.bukkit.Keyed;
@@ -72,7 +74,7 @@ public interface Chicken extends Animals {
/**
* Represents the variant of a chicken.
*/
interface Variant extends Keyed {
interface Variant extends RegistryElement.Buildable<Variant, ChickenVariantRegistryEntry, ChickenVariantRegistryEntry.Builder>, Keyed {
// Start generate - ChickenVariant
Variant COLD = getVariant("cold");
@@ -90,7 +92,7 @@ public interface Chicken extends Animals {
/**
* Represents the sound variant of a chicken.
*/
interface SoundVariant extends Keyed {
interface SoundVariant extends RegistryElement<SoundVariant>, Keyed {
// Start generate - ChickenSoundVariant
SoundVariant CLASSIC = getSoundVariant("classic");
@@ -1,7 +1,9 @@
package org.bukkit.entity;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.CowVariantRegistryEntry;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
import org.bukkit.Keyed;
@@ -44,7 +46,7 @@ public interface Cow extends AbstractCow {
/**
* Represents the variant of a cow.
*/
interface Variant extends Keyed {
interface Variant extends RegistryElement.Buildable<Variant, CowVariantRegistryEntry, CowVariantRegistryEntry.Builder>, Keyed {
// Start generate - CowVariant
Variant COLD = getVariant("cold");
@@ -62,7 +64,7 @@ public interface Cow extends AbstractCow {
/**
* Represents the sound variant of a cow.
*/
interface SoundVariant extends Keyed {
interface SoundVariant extends RegistryElement<SoundVariant>, Keyed {
// Start generate - CowSoundVariant
SoundVariant CLASSIC = getSoundVariant("classic");
@@ -2,7 +2,9 @@ package org.bukkit.entity;
import com.google.common.base.Preconditions;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.FrogVariantRegistryEntry;
import java.util.Locale;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
@@ -51,7 +53,7 @@ public interface Frog extends Animals {
/**
* Represents the variant of a frog - ie its color.
*/
interface Variant extends OldEnum<Variant>, Keyed {
interface Variant extends RegistryElement.Buildable<Variant, FrogVariantRegistryEntry, FrogVariantRegistryEntry.Builder>, OldEnum<Variant>, Keyed {
// Start generate - FrogVariant
Variant COLD = getVariant("cold");
@@ -1,7 +1,9 @@
package org.bukkit.entity;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.PigVariantRegistryEntry;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
import org.bukkit.Keyed;
@@ -44,7 +46,7 @@ public interface Pig extends Steerable, Vehicle {
/**
* Represents the variant of a pig.
*/
interface Variant extends Keyed {
interface Variant extends RegistryElement.Buildable<Variant, PigVariantRegistryEntry, PigVariantRegistryEntry.Builder>, Keyed {
// Start generate - PigVariant
Variant COLD = getVariant("cold");
@@ -62,7 +64,7 @@ public interface Pig extends Steerable, Vehicle {
/**
* Represents the sound variant of a pig.
*/
interface SoundVariant extends Keyed {
interface SoundVariant extends RegistryElement<SoundVariant>, Keyed {
// Start generate - PigSoundVariant
SoundVariant BIG = getSoundVariant("big");
@@ -5,7 +5,9 @@ import io.papermc.paper.entity.Bucketable;
import io.papermc.paper.entity.Shearable;
import io.papermc.paper.event.entity.EntityEquipmentChangedEvent;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.SulfurCubeArchetypeRegistryEntry;
import io.papermc.paper.registry.keys.tags.ItemTypeTagKeys;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
@@ -135,7 +137,7 @@ public interface SulfurCube extends AbstractCubeMob, Shearable, Bucketable, Agea
* which define a lot of possible behavior and interaction
* throughout its lifetime.
*/
interface Archetype extends Keyed {
interface Archetype extends RegistryElement.Buildable<Archetype, SulfurCubeArchetypeRegistryEntry, SulfurCubeArchetypeRegistryEntry.Builder>, Keyed {
// Start generate - SulfurCubeArchetype
Archetype BOUNCY = getArchetype("bouncy");
@@ -1,9 +1,10 @@
package org.bukkit.entity;
import com.google.common.base.Preconditions;
import io.papermc.paper.registry.RegistryElement;
import java.util.Locale;
import java.util.Map; // Paper
import java.util.UUID; // Paper
import java.util.Map;
import java.util.UUID;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
import org.bukkit.Keyed;
@@ -166,7 +167,7 @@ public interface Villager extends AbstractVillager {
* Represents Villager type, usually corresponding to what biome they spawn
* in.
*/
interface Type extends OldEnum<Type>, Keyed {
interface Type extends RegistryElement<Type>, OldEnum<Type>, Keyed {
// Start generate - VillagerType
Type DESERT = getType("desert");
@@ -218,7 +219,7 @@ public interface Villager extends AbstractVillager {
* Represents the various different Villager professions there may be.
* Villagers have different trading options depending on their profession,
*/
interface Profession extends OldEnum<Profession>, Keyed, net.kyori.adventure.translation.Translatable {
interface Profession extends RegistryElement<Profession>, OldEnum<Profession>, Keyed, net.kyori.adventure.translation.Translatable {
// Start generate - VillagerProfession
/**
@@ -1,7 +1,9 @@
package org.bukkit.entity;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.WolfVariantRegistryEntry;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
import org.bukkit.DyeColor;
@@ -108,7 +110,7 @@ public interface Wolf extends Tameable, Sittable, io.papermc.paper.entity.Collar
/**
* Represents the variant of a wolf.
*/
interface Variant extends Keyed {
interface Variant extends RegistryElement.Buildable<Variant, WolfVariantRegistryEntry, WolfVariantRegistryEntry.Builder>, Keyed {
// Start generate - WolfVariant
// @GeneratedFrom 1.21.5
@@ -140,7 +142,7 @@ public interface Wolf extends Tameable, Sittable, io.papermc.paper.entity.Collar
/**
* Represents the sound variant of a wolf.
*/
interface SoundVariant extends Keyed {
interface SoundVariant extends RegistryElement<SoundVariant>, Keyed {
// Start generate - WolfSoundVariant
SoundVariant ANGRY = getSoundVariant("angry");
@@ -1,7 +1,9 @@
package org.bukkit.entity;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.ZombieNautilusVariantRegistryEntry;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
import org.bukkit.Keyed;
@@ -27,7 +29,7 @@ public interface ZombieNautilus extends AbstractNautilus {
/**
* Represents the variant of a Zombie Nautilus.
*/
interface Variant extends Keyed {
interface Variant extends RegistryElement.Buildable<Variant, ZombieNautilusVariantRegistryEntry, ZombieNautilusVariantRegistryEntry.Builder>, Keyed {
// Start generate - ZombieNautilusVariant
Variant TEMPERATE = getVariant("temperate");
@@ -1,6 +1,7 @@
package org.bukkit.generator.structure;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
@@ -16,7 +17,7 @@ import org.jetbrains.annotations.NotNull;
* there might be additional structures present (for example structures added by
* data packs), which can be received via {@link io.papermc.paper.registry.RegistryAccess#getRegistry(io.papermc.paper.registry.RegistryKey)} and {@link io.papermc.paper.registry.RegistryKey#STRUCTURE}.
*/
public abstract class Structure implements Keyed {
public abstract class Structure implements RegistryElement<Structure>, Keyed {
// Start generate - Structure
public static final Structure ABANDONED_CAMP_BAMBOO_JUNGLE = getStructure("abandoned_camp_bamboo_jungle");
@@ -1,5 +1,6 @@
package org.bukkit.generator.structure;
import io.papermc.paper.registry.RegistryElement;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
import org.bukkit.Keyed;
@@ -14,7 +15,7 @@ import org.jetbrains.annotations.NotNull;
* structure types added by data packs), which can be received via
* {@link Registry#STRUCTURE_TYPE}.
*/
public abstract class StructureType implements Keyed {
public abstract class StructureType implements RegistryElement<StructureType>, Keyed {
// Start generate - StructureType
public static final StructureType BURIED_TREASURE = getStructureType("buried_treasure");
@@ -1169,7 +1169,6 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat
}
// Paper end - expose itemstack tooltip lines
// Paper start - data component API
/**
* Gets the value for the data component type on this stack.
*
@@ -1358,7 +1357,31 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat
* @return {@code true} if the provided item is equal, ignoring the provided components
*/
public boolean matchesWithoutData(final @NotNull ItemStack item, final @NotNull java.util.Set<io.papermc.paper.datacomponent.@NotNull DataComponentType> excludeTypes, final boolean ignoreCount) {
return this.matchesWithoutData(item, excludeTypes::contains, ignoreCount);
}
/**
* Checks if this itemstack matches another given itemstack excluding the provided components.
* This is useful if you are wanting to ignore certain properties of itemstacks, such as durability.
*
* @param item the item to compare
* @param excludeTypes the data component types to ignore
* @return {@code true} if the provided item is equal, ignoring the provided components
*/
public boolean matchesWithoutData(final @NotNull ItemStack item, final @NotNull Predicate<io.papermc.paper.datacomponent.@NotNull DataComponentType> excludeTypes) {
return this.matchesWithoutData(item, excludeTypes, false);
}
/**
* Checks if this itemstack matches another given itemstack excluding the provided components.
* This is useful if you are wanting to ignore certain properties of itemstacks, such as durability.
*
* @param item the item to compare
* @param excludeTypes the data component types to ignore
* @param ignoreCount ignore the count of the item
* @return {@code true} if the provided item is equal, ignoring the provided components
*/
public boolean matchesWithoutData(final @NotNull ItemStack item, final @NotNull Predicate<io.papermc.paper.datacomponent.@NotNull DataComponentType> excludeTypes, final boolean ignoreCount) {
return this.craftDelegate.matchesWithoutData(item, excludeTypes, ignoreCount);
}
// Paper end - data component API
}
@@ -2,6 +2,7 @@ package org.bukkit.inventory;
import com.google.common.collect.Multimap;
import io.papermc.paper.datacomponent.DataComponentType;
import io.papermc.paper.registry.RegistryElement;
import java.util.Set;
import java.util.function.Consumer;
import net.kyori.adventure.key.Key;
@@ -47,7 +48,7 @@ import org.jspecify.annotations.Nullable;
* Represents an item type.
*/
@NullMarked
public interface ItemType extends Keyed, Translatable, net.kyori.adventure.translation.Translatable, io.papermc.paper.world.flag.FeatureDependant { // Paper - add Translatable & feature flag API
public interface ItemType extends RegistryElement<ItemType>, Keyed, Translatable, net.kyori.adventure.translation.Translatable, io.papermc.paper.world.flag.FeatureDependant { // Paper - add Translatable & feature flag API
/**
* Typed represents a subtype of {@link ItemType}s that have a known item meta type
@@ -70,7 +70,7 @@ final class ItemTypeRecipeChoiceImpl extends RecipeChoice.MaterialChoice impleme
if (this.legacyChoices == null) {
final List<Material> choices = new ArrayList<>();
for (final TypedKey<ItemType> itemTypeKey : this.itemTypes) {
choices.add(Registry.MATERIAL.getOrThrow(itemTypeKey));
choices.add(Registry.MATERIAL.getOrThrow(itemTypeKey.key()));
}
this.legacyChoices = Collections.unmodifiableList(choices);
}
@@ -1,5 +1,6 @@
package org.bukkit.inventory;
import io.papermc.paper.registry.RegistryElement;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
import net.kyori.adventure.text.Component;
@@ -27,7 +28,7 @@ import org.jspecify.annotations.Nullable;
* created and viewed by the player.
*/
@NullMarked
public interface MenuType extends Keyed, io.papermc.paper.world.flag.FeatureDependant { // Paper - make FeatureDependant
public interface MenuType extends RegistryElement<MenuType>, Keyed, io.papermc.paper.world.flag.FeatureDependant { // Paper - make FeatureDependant
/**
* A MenuType which represents a chest with 1 row.
@@ -59,7 +59,7 @@ public interface RecipeChoice extends Predicate<ItemStack>, Cloneable {
/**
* Creates a new recipe choice based on a {@link RegistryKeySet} of item types.
* Can either be created via {@link RegistryKeySet#keySet(RegistryKey, TypedKey[])}
* Can either be created via {@link RegistryKeySet#keySet(RegistryKey, TypedKey[])}/{@link RegistryKeySet#keySet(TypedKey, TypedKey[])}
* or obtained from {@link org.bukkit.Registry#getTag(TagKey)}.
*
* @param itemTypes the item types to match
@@ -2,8 +2,9 @@ package org.bukkit.inventory.meta.trim;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryBuilderFactory;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.InlinedRegistryBuilderProvider;
import io.papermc.paper.registry.data.RegistryBuilderProvider;
import io.papermc.paper.registry.data.TrimMaterialRegistryEntry;
import java.util.function.Consumer;
import net.kyori.adventure.key.Key;
@@ -19,7 +20,7 @@ import org.jspecify.annotations.NullMarked;
* Represents a material that may be used in an {@link ArmorTrim}.
*/
@NullMarked
public interface TrimMaterial extends Keyed, Translatable {
public interface TrimMaterial extends RegistryElement.Inlineable<TrimMaterial, TrimMaterialRegistryEntry, TrimMaterialRegistryEntry.Builder>, Keyed, Translatable {
/**
* Creates an inlined trim material.
@@ -28,7 +29,7 @@ public interface TrimMaterial extends Keyed, Translatable {
* @return the created trim material
*/
static TrimMaterial create(final Consumer<RegistryBuilderFactory<TrimMaterial, ? extends TrimMaterialRegistryEntry.Builder>> value) {
return InlinedRegistryBuilderProvider.instance().createTrimMaterial(value);
return RegistryBuilderProvider.instance().create(RegistryKey.TRIM_MATERIAL, value);
}
// Start generate - TrimMaterial
@@ -2,8 +2,9 @@ package org.bukkit.inventory.meta.trim;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryBuilderFactory;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.InlinedRegistryBuilderProvider;
import io.papermc.paper.registry.data.RegistryBuilderProvider;
import io.papermc.paper.registry.data.TrimPatternRegistryEntry;
import java.util.function.Consumer;
import net.kyori.adventure.key.Key;
@@ -19,7 +20,7 @@ import org.jspecify.annotations.NullMarked;
* Represents a pattern that may be used in an {@link ArmorTrim}.
*/
@NullMarked
public interface TrimPattern extends Keyed, Translatable {
public interface TrimPattern extends RegistryElement.Inlineable<TrimPattern, TrimPatternRegistryEntry, TrimPatternRegistryEntry.Builder>, Keyed, Translatable {
/**
* Creates an inlined trim pattern.
@@ -28,7 +29,7 @@ public interface TrimPattern extends Keyed, Translatable {
* @return the created trim pattern
*/
static TrimPattern create(final Consumer<RegistryBuilderFactory<TrimPattern, ? extends TrimPatternRegistryEntry.Builder>> value) {
return InlinedRegistryBuilderProvider.instance().createTrimPattern(value);
return RegistryBuilderProvider.instance().create(RegistryKey.TRIM_PATTERN, value);
}
// Start generate - TrimPattern
@@ -1,6 +1,7 @@
package org.bukkit.map;
import com.google.common.base.Preconditions;
import io.papermc.paper.registry.RegistryElement;
import java.util.Locale;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
@@ -287,7 +288,7 @@ public final class MapCursor {
* index in the file './assets/minecraft/textures/map/map_icons.png' from minecraft.jar or from a
* resource pack.
*/
public interface Type extends OldEnum<Type>, Keyed {
public interface Type extends RegistryElement<Type>, OldEnum<Type>, Keyed {
// Start generate - MapCursorType
Type ABANDONED_CAMP = getType("abandoned_camp");
@@ -3,6 +3,7 @@ package org.bukkit.potion;
import com.google.common.base.Preconditions;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import io.papermc.paper.registry.RegistryElement;
import java.util.Locale;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
@@ -20,7 +21,7 @@ import org.jetbrains.annotations.Nullable;
/**
* Represents a type of potion and its effect on an entity.
*/
public abstract class PotionEffectType implements Keyed, Translatable, net.kyori.adventure.translation.Translatable, io.papermc.paper.world.flag.FeatureDependant { // Paper - implement Translatable & feature flag API
public abstract class PotionEffectType implements RegistryElement<PotionEffectType>, Keyed, Translatable, net.kyori.adventure.translation.Translatable, io.papermc.paper.world.flag.FeatureDependant { // Paper - implement Translatable & feature flag API
private static final BiMap<Integer, PotionEffectType> ID_MAP = HashBiMap.create();
/**
@@ -17,14 +17,13 @@ import java.util.concurrent.CompletableFuture;
import java.util.function.Consumer;
import java.util.stream.Stream;
import net.minecraft.SharedConstants;
import net.minecraft.util.Util;
import net.minecraft.commands.Commands;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.LayeredRegistryAccess;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.RegistryDataLoader;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.RegistryDataLoader;
import net.minecraft.server.Bootstrap;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.RegistryLayer;
@@ -37,6 +36,7 @@ import net.minecraft.server.packs.resources.MultiPackResourceManager;
import net.minecraft.server.permissions.LevelBasedPermissionSet;
import net.minecraft.tags.TagKey;
import net.minecraft.tags.TagLoader;
import net.minecraft.util.Util;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.flag.FeatureFlags;
import net.minecraft.world.level.DataPackConfig;
@@ -197,12 +197,12 @@ public final class Rewriters {
.register("JukeboxSong", JukeboxSong.class, new RegistryFieldRewriter<>(Registries.JUKEBOX_SONG, "get") {
@Override
protected String rewriteFieldName(Holder.Reference<net.minecraft.world.item.JukeboxSong> reference) {
String keyedName = super.rewriteFieldName(reference);
if (!SourceVersion.isIdentifier(keyedName)) {
String constantName = super.rewriteFieldName(reference);
if (!SourceVersion.isIdentifier(constantName)) {
// fallback to field names for invalid identifier (happens for 5, 11, 13 etc.)
return RegistryEntries.byRegistryKey(Registries.JUKEBOX_SONG).getFieldNames().get(reference.key());
}
return keyedName;
return constantName;
}
})
.register("GameRules", GameRules.class, new RegistryFieldRewriter<>(Registries.GAME_RULE, "getRule") {
@@ -250,7 +250,6 @@ public final class Rewriters {
.register("FeatureFlag", FeatureFlag.class, new FeatureFlagRewriter())
.register("Tag", Tag.class, new TagRewriter())
.register("MapPalette#colors", MapPalette.class, new MapPaletteRewriter());
RegistryBootstrapper.bootstrapApi(sourceSet);
}
private static void bootstrapServer(PatternSourceSetRewriter sourceSet) {
@@ -3,11 +3,9 @@ package io.papermc.generator.registry;
import io.papermc.generator.rewriter.registration.PatternSourceSetRewriter;
import io.papermc.generator.rewriter.types.Types;
import io.papermc.generator.rewriter.types.registry.PaperRegistriesRewriter;
import io.papermc.generator.rewriter.types.registry.RegistryEventsRewriter;
import io.papermc.generator.types.SourceGenerator;
import io.papermc.generator.types.registry.GeneratedKeyType;
import io.papermc.generator.types.registry.GeneratedTagKeyType;
import io.papermc.paper.registry.event.RegistryEvents;
import java.util.List;
import net.minecraft.core.registries.Registries;
import org.jspecify.annotations.NullMarked;
@@ -22,24 +20,19 @@ public class RegistryBootstrapper {
RegistryEntries.forEach(entry -> {
generators.add(new GeneratedKeyType<>(PAPER_REGISTRY_PACKAGE + ".keys", entry));
if (entry.registry().listTags().findAny().isPresent()) {
generators.add(new GeneratedTagKeyType(entry, PAPER_REGISTRY_PACKAGE + ".keys.tags"));
generators.add(new GeneratedTagKeyType<>(entry, PAPER_REGISTRY_PACKAGE + ".keys.tags"));
}
});
// todo remove once entity type and potion are both a registry
generators.add(new GeneratedTagKeyType(RegistryEntries.byRegistryKey(Registries.ENTITY_TYPE), PAPER_REGISTRY_PACKAGE + ".keys.tags"));
generators.add(new GeneratedTagKeyType(RegistryEntries.byRegistryKey(Registries.POTION), PAPER_REGISTRY_PACKAGE + ".keys.tags"));
generators.add(new GeneratedTagKeyType<>(RegistryEntries.byRegistryKey(Registries.ENTITY_TYPE), PAPER_REGISTRY_PACKAGE + ".keys.tags"));
generators.add(new GeneratedTagKeyType<>(RegistryEntries.byRegistryKey(Registries.POTION), PAPER_REGISTRY_PACKAGE + ".keys.tags"));
}
public static void bootstrap(PatternSourceSetRewriter apiSourceSet, PatternSourceSetRewriter serverSourceSet) {
bootstrapApi(apiSourceSet);
bootstrapServer(serverSourceSet);
}
public static void bootstrapApi(PatternSourceSetRewriter sourceSet) {
sourceSet.register("RegistryEvents", RegistryEvents.class, new RegistryEventsRewriter());
}
public static void bootstrapServer(PatternSourceSetRewriter sourceSet) {
sourceSet.register("RegistryDefinitions", Types.PAPER_REGISTRIES, new PaperRegistriesRewriter());
}
@@ -18,9 +18,9 @@ public class PaperFeatureFlagMapping extends SearchReplaceRewriter {
while (flagIterator.hasNext()) {
Identifier name = flagIterator.next();
String keyedName = Formatting.formatKeyAsField(name.getPath());
String fieldName = Formatting.formatKeyAsField(name.getPath());
builder.append(metadata.indent());
builder.append("%s.%s, %s.%s".formatted(FeatureFlag.class.getSimpleName(), keyedName, FeatureFlags.class.getSimpleName(), keyedName));
builder.append("%s.%s, %s.%s".formatted(FeatureFlag.class.getSimpleName(), fieldName, FeatureFlags.class.getSimpleName(), fieldName));
if (flagIterator.hasNext()) {
builder.append(',');
}
@@ -4,6 +4,7 @@ import com.google.common.base.CaseFormat;
import io.papermc.generator.registry.RegistryEntries;
import io.papermc.generator.registry.RegistryEntry;
import io.papermc.generator.rewriter.types.Types;
import io.papermc.paper.registry.RegistryElement;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.typewriter.ClassNamed;
import io.papermc.typewriter.replace.SearchMetadata;
@@ -11,14 +12,12 @@ import io.papermc.typewriter.replace.SearchReplaceRewriter;
import java.lang.constant.ConstantDescs;
import java.util.stream.Stream;
import net.minecraft.core.registries.Registries;
import org.bukkit.Keyed;
import org.bukkit.Registry;
import org.jspecify.annotations.NullMarked;
@NullMarked
public class PaperRegistriesRewriter extends SearchReplaceRewriter {
private void appendEntry(String indent, StringBuilder builder, RegistryEntry<?> entry, boolean canBeDelayed, boolean apiOnly) {
builder.append(indent);
builder.append("start");
@@ -60,7 +59,11 @@ public class PaperRegistriesRewriter extends SearchReplaceRewriter {
case MODIFIABLE -> builder.append(".modifiable(");
case NONE -> builder.append(".create(");
}
builder.append(this.importCollector.getShortName(this.classNamedView.findFirst(entry.apiRegistryBuilderImpl()).resolve(this.classResolver))).append("::new");
// the builder impl is always nested in the base entry class; reference the base entry constructor first, then the builder constructor
ClassNamed builderImpl = this.classNamedView.findFirst(entry.apiRegistryBuilderImpl()).resolve(this.classResolver);
builder.append(this.importCollector.getShortName(builderImpl.topLevel())).append("::new");
builder.append(", ");
builder.append(builderImpl.dottedNestedName()).append("::new");
if (entry.modificationApiSupport() == RegistryEntry.RegistryModificationApiSupport.NONE) {
builder.append(", ");
builder.append(Types.REGISTRY_MODIFICATION_API_SUPPORT.dottedNestedName()).append(".NONE");
@@ -108,7 +111,7 @@ public class PaperRegistriesRewriter extends SearchReplaceRewriter {
private ClassNamed getImplClassName(RegistryEntry<?> entry) {
try (Stream<ClassNamed> stream = this.classNamedView.find(entry.implClass())) {
return stream.map(klass -> klass.resolve(this.classResolver))
.filter(klass -> Keyed.class.isAssignableFrom(klass.knownClass())) // todo check handleable/holderable once keyed is gone
.filter(klass -> RegistryElement.class.isAssignableFrom(klass.knownClass()))
.findFirst().orElseThrow();
}
}
@@ -1,34 +0,0 @@
package io.papermc.generator.rewriter.types.registry;
import io.papermc.generator.registry.RegistryEntries;
import io.papermc.generator.registry.RegistryEntry;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.event.RegistryEventProvider;
import io.papermc.typewriter.replace.SearchMetadata;
import io.papermc.typewriter.replace.SearchReplaceRewriter;
import org.jspecify.annotations.NullMarked;
import static javax.lang.model.element.Modifier.FINAL;
import static javax.lang.model.element.Modifier.PUBLIC;
import static javax.lang.model.element.Modifier.STATIC;
@NullMarked
public class RegistryEventsRewriter extends SearchReplaceRewriter {
@Override
public void insert(SearchMetadata metadata, StringBuilder builder) {
RegistryEntries.forEach(entry -> {
if (entry.apiRegistryBuilder() != null && entry.modificationApiSupport() != RegistryEntry.RegistryModificationApiSupport.NONE) {
builder.append(metadata.indent());
builder.append("%s %s %s ".formatted(PUBLIC, STATIC, FINAL));
builder.append(RegistryEventProvider.class.getSimpleName());
builder.append("<").append(this.importCollector.getShortName(entry.apiClass())).append(", ").append(this.importCollector.getShortName(entry.apiRegistryBuilder())).append('>');
builder.append(' ');
builder.append(entry.registryKeyField());
builder.append(" = ");
builder.append("create(").append(RegistryKey.class.getSimpleName()).append('.').append(entry.registryKeyField()).append(");");
builder.append('\n');
}
});
}
}
@@ -23,9 +23,9 @@ public class CraftPotionUtilRewriter extends SearchReplaceRewriter {
BuiltInRegistries.POTION.keySet().stream()
.filter(key -> BuiltInRegistries.POTION.containsKey(key.withPath(path -> this.statePrefix + "_" + path)))
.sorted(Formatting.alphabeticKeyOrder(Identifier::getPath)).forEach(key -> {
String keyedName = Formatting.formatKeyAsField(key.getPath());
String fieldName = Formatting.formatKeyAsField(key.getPath());
builder.append(metadata.indent());
builder.append(".put(%s.%s, %s.%s_%s)".formatted(PotionType.class.getSimpleName(), keyedName, PotionType.class.getSimpleName(), upperStatePrefix, keyedName));
builder.append(".put(%s.%s, %s.%s_%s)".formatted(PotionType.class.getSimpleName(), fieldName, PotionType.class.getSimpleName(), upperStatePrefix, fieldName));
builder.append('\n');
});
}
@@ -18,7 +18,7 @@ public class MapPaletteRewriter extends SearchReplaceRewriter {
int count = 0;
for (@Nullable MapColor mapColor : MapColor.MATERIAL_COLORS) {
if (mapColor == null) {
continue;
break;
}
for (MapColor.Brightness brightness : MapColor.Brightness.values()) {
@@ -102,8 +102,8 @@ public class MemoryKeyRewriter extends RegistryFieldRewriter<MemoryModuleType<?>
@Override
protected String rewriteFieldName(Holder.Reference<MemoryModuleType<?>> reference) {
String keyedName = super.rewriteFieldName(reference);
return FIELD_RENAMES.getOrDefault(keyedName, keyedName);
String constantName = super.rewriteFieldName(reference);
return FIELD_RENAMES.getOrDefault(constantName, constantName);
}
@Override
@@ -81,11 +81,11 @@ public class StatisticRewriter {
@Override
protected EnumValue.Builder rewriteEnumValue(Holder.Reference<Identifier> reference) {
String keyedName = Formatting.formatKeyAsField(reference.key().identifier().getPath());
String fieldName = Formatting.formatKeyAsField(reference.key().identifier().getPath());
return super.rewriteEnumValue(reference)
.rename(name -> FIELD_RENAMES.getOrDefault(name, name))
.argument("%s.%s".formatted(Stats.class.getSimpleName(), INTERNAL_FIELD_RENAMES.getOrDefault(keyedName, keyedName)));
.argument("%s.%s".formatted(Stats.class.getSimpleName(), INTERNAL_FIELD_RENAMES.getOrDefault(fieldName, fieldName)));
}
}
@@ -31,11 +31,11 @@ import static javax.lang.model.element.Modifier.PUBLIC;
import static javax.lang.model.element.Modifier.STATIC;
@NullMarked
public class GeneratedTagKeyType extends SimpleGenerator {
public class GeneratedTagKeyType<T> extends SimpleGenerator {
private final RegistryEntry<?> entry;
private final RegistryEntry<T> entry;
public GeneratedTagKeyType(RegistryEntry<?> entry, String packageName) {
public GeneratedTagKeyType(RegistryEntry<T> entry, String packageName) {
super(entry.keyClassName().concat("TagKeys"), packageName);
this.entry = entry;
}
+1 -1
View File
@@ -14,7 +14,7 @@ plugins {
val paperMavenPublicUrl = "https://repo.papermc.io/repository/maven-public/"
dependencies {
mache("io.papermc:mache:26.3+build.2")
mache("io.papermc:mache:26.3+build.1")
paperclip("io.papermc:paperclip:3.0.4")
}
@@ -522,10 +522,10 @@ index 0de6f540c5192dd152d2e0a55d6b26eee0f5107f..afb2c249078f85579f37a772c41c8138
delta = this.maybeBackOffFromEdge(delta, moverType);
Vec3 movement = this.collide(delta);
diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java
index db627b1d589e2c9d457b2f1b6429ea11849a1d3a..442bdb6b0bea65f4d2527eea43d2205cbaa4107a 100644
index 62ccee5c76303b679d591714e64ee93c1502f378..0ef6c4cefb457c87f4565701817d2f9034dfa0d8 100644
--- a/net/minecraft/world/entity/LivingEntity.java
+++ b/net/minecraft/world/entity/LivingEntity.java
@@ -3391,6 +3391,14 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
@@ -3380,6 +3380,14 @@ public abstract class LivingEntity extends Entity implements Attackable, Waypoin
protected void playAttackSound() {
}
@@ -1222,12 +1222,7 @@
this.player
.swingAndResetAttackStrength(hand, swingAnimation, success.swingSource() != InteractionResult.SwingSource.PREDICTED);
}
@@ -1458,24 +_,28 @@
} else if (direction == Direction.DOWN && pos.getY() <= minY) {
this.player.sendBuildLimitMessage(false, minY);
}
- } else if (interactionResult instanceof InteractionResult.Success success && success.shouldSwing()) {
+ } else if (interactionResult instanceof InteractionResult.Success success && success.shouldSwing() && !this.player.gameMode.interactResult) { // Paper - Call interact event
@@ -1462,20 +_,24 @@
this.player
.swingAndResetAttackStrength(hand, swingAnimation, success.swingSource() != InteractionResult.SwingSource.PREDICTED);
}
@@ -208,13 +208,12 @@
this.effectsDirty = true;
}
- this.setHealth(input.getFloatOr("Health", this.getMaxHealth()));
+ // CraftBukkit start
+ input.read("Bukkit.MaxHealth", com.mojang.serialization.Codec.DOUBLE).ifPresent(maxHealth -> {
+ this.getAttribute(Attributes.MAX_HEALTH).setBaseValue(maxHealth);
+ });
+ // CraftBukkit end
+ this.setHealth(input.getFloatOr("Health", this.getMaxHealth()), false); // Paper - Fix MC-17876
this.setHealth(input.getFloatOr("Health", this.getMaxHealth()));
this.hurtTime = input.getShortOr("HurtTime", (short)0);
this.deathTime = input.getShortOr("DeathTime", (short)0);
this.setSharedFlag(Entity.FLAG_FALL_FLYING, input.getBooleanOr("FallFlying", false));
@@ -424,7 +423,7 @@
if (effectInstance != null) {
this.onEffectsRemoved(List.of(effectInstance));
return true;
@@ -1152,18 +_,74 @@
@@ -1152,17 +_,62 @@
}
public void heal(final float heal) {
@@ -464,8 +463,9 @@
return this.entityData.get(DATA_HEALTH_ID);
}
- public void setHealth(final float health) {
+ // Paper start - Check for NaN
+ public void setHealth(float health, final boolean clamp) { // Paper - Fix MC-17876 - add clamp parameter
+ public void setHealth(float health) {
+ if (Float.isNaN(health)) { health = getMaxHealth(); if (this.valid) {
+ System.err.println("[NAN-HEALTH] " + getScoreboardName() + " had NaN health set");
+ } } // Paper end - Check for NaN
@@ -475,7 +475,7 @@
+ // Squeeze
+ if (health < 0.0F) {
+ player.setRealHealth(0.0);
+ } else if (clamp && health > player.getMaxHealth()) { // Paper - Fix MC-17876
+ } else if (health > player.getMaxHealth()) {
+ player.setRealHealth(player.getMaxHealth());
+ } else {
+ player.setRealHealth(health);
@@ -485,22 +485,9 @@
+ return;
+ }
+ // CraftBukkit end
+ // Paper start - Fix MC-17876
+ if (clamp) {
+ health = Math.clamp(health, 0.0F, this.getMaxHealth());
+ } else {
+ health = Math.max(health, 0.0F);
+ }
+
+ this.entityData.set(DATA_HEALTH_ID, health);
+ }
public void setHealth(final float health) {
- this.entityData.set(DATA_HEALTH_ID, Mth.clamp(health, 0.0F, this.getMaxHealth()));
+ this.setHealth(health, true);
+ // Paper end - Fix MC-17876
this.entityData.set(DATA_HEALTH_ID, Mth.clamp(health, 0.0F, this.getMaxHealth()));
}
public boolean isDeadOrDying() {
@@ -1180,7 +_,7 @@
return false;
}
@@ -161,17 +161,6 @@ public final class PaperAdventure {
return asVanilla(key);
}
public static Holder<SoundEvent> resolveSound(final Key key) {
Identifier id = asVanilla(key);
Optional<Holder.Reference<SoundEvent>> vanilla = BuiltInRegistries.SOUND_EVENT.get(id);
if (vanilla.isPresent()) {
return vanilla.get();
}
// sound is not known so not in the registry but might be used by the client with a resource pack
return Holder.direct(SoundEvent.createVariableRangeEvent(id));
}
// Component
public static @NotNull Component asAdventure(final net.minecraft.network.chat.@Nullable Component component) {
@@ -6,7 +6,7 @@ import net.minecraft.core.registries.Registries;
import net.minecraft.world.level.block.entity.DecoratedPotPattern;
import org.bukkit.craftbukkit.CraftRegistry;
public class PaperPotPatternType extends HolderableBase<net.minecraft.world.level.block.entity.DecoratedPotPattern> implements PotPatternType {
public class PaperPotPatternType extends HolderableBase<net.minecraft.world.level.block.entity.DecoratedPotPattern, PotPatternType> implements PotPatternType {
public PaperPotPatternType(final Holder<DecoratedPotPattern> holder) {
super(holder);
@@ -67,6 +67,7 @@ import net.minecraft.world.item.component.MapPostProcessing;
import org.bukkit.DyeColor;
import org.bukkit.craftbukkit.CraftArt;
import org.bukkit.craftbukkit.CraftMusicInstrument;
import org.bukkit.craftbukkit.CraftSound;
import org.bukkit.craftbukkit.damage.CraftDamageType;
import org.bukkit.craftbukkit.entity.CraftCat;
import org.bukkit.craftbukkit.entity.CraftChicken;
@@ -182,7 +183,7 @@ public final class DataComponentAdapters {
register(DataComponents.SULFUR_CUBE_CONTENT, PaperSulfurCubeContent::new);
// register(DataComponents.LOCK, PaperLockCode::new);
register(DataComponents.CONTAINER_LOOT, PaperSeededContainerLoot::new);
register(DataComponents.BREAK_SOUND, nms -> PaperAdventure.asAdventure(nms.value().location()), PaperAdventure::resolveSound);
register(DataComponents.BREAK_SOUND, CraftSound::minecraftHolderToBukkit, CraftSound::bukkitToMinecraftHolder);
register(DataComponents.BLOCKS_ATTACKS, PaperBlocksAttacks::new);
register(DataComponents.PIERCING_WEAPON, PaperPiercingWeapon::new);
register(DataComponents.KINETIC_WEAPON, PaperKineticWeapon::new);
@@ -6,12 +6,11 @@ import java.util.HashSet;
import java.util.Set;
import net.minecraft.core.Holder;
import net.minecraft.core.component.DataComponentGetter;
import net.minecraft.core.component.DataComponentMap;
import net.minecraft.core.registries.Registries;
import org.bukkit.craftbukkit.CraftRegistry;
import org.jspecify.annotations.Nullable;
public abstract class PaperDataComponentType<T, NMS> extends HolderableBase<net.minecraft.core.component.DataComponentType<NMS>> implements DataComponentType {
public abstract class PaperDataComponentType<T, NMS> extends HolderableBase<net.minecraft.core.component.DataComponentType<NMS>, DataComponentType> implements DataComponentType {
static {
DataComponentAdapters.bootstrap();
@@ -1,6 +1,5 @@
package io.papermc.paper.datacomponent.item;
import io.papermc.paper.adventure.PaperAdventure;
import io.papermc.paper.datacomponent.item.blocksattacks.DamageReduction;
import io.papermc.paper.datacomponent.item.blocksattacks.ItemDamageFunction;
import io.papermc.paper.datacomponent.item.blocksattacks.PaperDamageReduction;
@@ -12,8 +11,9 @@ import io.papermc.paper.registry.set.RegistryKeySet;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import java.util.List;
import java.util.Optional;
import net.kyori.adventure.key.Key;
import net.minecraft.core.registries.Registries;
import org.bukkit.Sound;
import org.bukkit.craftbukkit.CraftSound;
import org.bukkit.craftbukkit.util.Handleable;
import org.bukkit.damage.DamageType;
import org.checkerframework.checker.index.qual.NonNegative;
@@ -56,13 +56,13 @@ public record PaperBlocksAttacks(
}
@Override
public @Nullable Key blockSound() {
return this.impl.blockSound().map(holder -> PaperAdventure.asAdventure(holder.value().location())).orElse(null);
public @Nullable Sound blockSound() {
return this.impl.blockSound().map(CraftSound::minecraftHolderToBukkit).orElse(null);
}
@Override
public @Nullable Key disableSound() {
return this.impl.disableSound().map(holder -> PaperAdventure.asAdventure(holder.value().location())).orElse(null);
public @Nullable Sound disableSound() {
return this.impl.disableSound().map(CraftSound::minecraftHolderToBukkit).orElse(null);
}
static final class BuilderImpl implements Builder {
@@ -72,8 +72,8 @@ public record PaperBlocksAttacks(
private List<DamageReduction> damageReductions = new ObjectArrayList<>();
private ItemDamageFunction itemDamage = new PaperItemDamageFunction(net.minecraft.world.item.component.BlocksAttacks.ItemDamageFunction.DEFAULT);
private @Nullable RegistryKeySet<DamageType> bypassedBy;
private @Nullable Key blockSound;
private @Nullable Key disableSound;
private @Nullable Sound blockSound;
private @Nullable Sound disableSound;
@Override
public Builder blockDelaySeconds(final @NonNegative float delay) {
@@ -112,13 +112,13 @@ public record PaperBlocksAttacks(
}
@Override
public Builder blockSound(final @Nullable Key sound) {
public Builder blockSound(final @Nullable Sound sound) {
this.blockSound = sound;
return this;
}
@Override
public Builder disableSound(final @Nullable Key sound) {
public Builder disableSound(final @Nullable Sound sound) {
this.disableSound = sound;
return this;
}
@@ -131,8 +131,8 @@ public record PaperBlocksAttacks(
this.damageReductions.stream().map(damageReduction -> ((PaperDamageReduction) damageReduction).internal()).toList(),
((PaperItemDamageFunction) this.itemDamage).internal(),
Optional.ofNullable(this.bypassedBy).map(holders -> PaperRegistrySets.convertToNms(Registries.DAMAGE_TYPE, Conversions.global().lookup(), holders)),
Optional.ofNullable(this.blockSound).map(PaperAdventure::resolveSound),
Optional.ofNullable(this.disableSound).map(PaperAdventure::resolveSound)
Optional.ofNullable(this.blockSound).map(CraftSound::bukkitToMinecraftHolder),
Optional.ofNullable(this.disableSound).map(CraftSound::bukkitToMinecraftHolder)
));
}
}
@@ -1,16 +1,16 @@
package io.papermc.paper.datacomponent.item;
import io.papermc.paper.adventure.PaperAdventure;
import io.papermc.paper.datacomponent.item.consumable.ConsumeEffect;
import io.papermc.paper.datacomponent.item.consumable.ItemUseAnimation;
import io.papermc.paper.datacomponent.item.consumable.PaperConsumableEffect;
import io.papermc.paper.util.MCUtil;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import java.util.List;
import net.kyori.adventure.key.Key;
import net.minecraft.core.Holder;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import org.bukkit.Sound;
import org.bukkit.craftbukkit.CraftSound;
import org.bukkit.craftbukkit.util.Handleable;
import org.checkerframework.checker.index.qual.NonNegative;
import org.jetbrains.annotations.Unmodifiable;
@@ -39,8 +39,8 @@ public record PaperConsumable(
}
@Override
public Key sound() {
return PaperAdventure.asAdventure(this.impl.sound().value().location());
public Sound sound() {
return CraftSound.minecraftHolderToBukkit(this.impl.sound());
}
@Override
@@ -86,8 +86,8 @@ public record PaperConsumable(
}
@Override
public Builder sound(final Key sound) {
this.eatSound = PaperAdventure.resolveSound(sound);
public Builder sound(final Sound sound) {
this.eatSound = CraftSound.bukkitToMinecraftHolder(sound);
return this;
}
@@ -17,7 +17,9 @@ import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.item.equipment.EquipmentAsset;
import net.minecraft.world.item.equipment.EquipmentAssets;
import org.bukkit.Sound;
import org.bukkit.craftbukkit.CraftEquipmentSlot;
import org.bukkit.craftbukkit.CraftSound;
import org.bukkit.craftbukkit.util.Handleable;
import org.bukkit.entity.EntityType;
import org.bukkit.inventory.EquipmentSlot;
@@ -38,8 +40,8 @@ public record PaperEquippable(
}
@Override
public Key equipSound() {
return PaperAdventure.asAdventure(this.impl.equipSound().value().location());
public Sound equipSound() {
return CraftSound.minecraftHolderToBukkit(this.impl.equipSound());
}
@Override
@@ -89,8 +91,8 @@ public record PaperEquippable(
}
@Override
public Key shearSound() {
return PaperAdventure.asAdventure(this.impl.shearingSound().value().location());
public Sound shearSound() {
return CraftSound.minecraftHolderToBukkit(this.impl.shearingSound());
}
@Override
@@ -128,8 +130,8 @@ public record PaperEquippable(
}
@Override
public Builder equipSound(final Key sound) {
this.equipSound = PaperAdventure.resolveSound(sound);
public Builder equipSound(final Sound sound) {
this.equipSound = CraftSound.bukkitToMinecraftHolder(sound);
return this;
}
@@ -142,7 +144,7 @@ public record PaperEquippable(
}
@Override
public Builder cameraOverlay(@Nullable final Key cameraOverlay) {
public Builder cameraOverlay(final @Nullable Key cameraOverlay) {
this.cameraOverlay = Optional.ofNullable(cameraOverlay)
.map(PaperAdventure::asVanilla);
@@ -187,8 +189,8 @@ public record PaperEquippable(
}
@Override
public Builder shearSound(final Key shearSound) {
this.shearSound = PaperAdventure.resolveSound(shearSound);
public Builder shearSound(final Sound shearSound) {
this.shearSound = CraftSound.bukkitToMinecraftHolder(shearSound);
return this;
}
@@ -1,10 +1,8 @@
package io.papermc.paper.datacomponent.item;
import io.papermc.paper.adventure.PaperAdventure;
import java.util.Optional;
import net.kyori.adventure.key.Key;
import net.minecraft.core.Holder;
import net.minecraft.sounds.SoundEvent;
import org.bukkit.Sound;
import org.bukkit.craftbukkit.CraftSound;
import org.bukkit.craftbukkit.util.Handleable;
import org.checkerframework.checker.index.qual.NonNegative;
import org.jspecify.annotations.Nullable;
@@ -69,21 +67,13 @@ public record PaperKineticWeapon(
}
@Override
public @Nullable Key sound() {
return this.impl.sound()
.map(Holder::value)
.map(SoundEvent::location)
.map(PaperAdventure::asAdventure)
.orElse(null);
public @Nullable Sound sound() {
return this.impl.sound().map(CraftSound::minecraftHolderToBukkit).orElse(null);
}
@Override
public @Nullable Key hitSound() {
return this.impl.hitSound()
.map(Holder::value)
.map(SoundEvent::location)
.map(PaperAdventure::asAdventure)
.orElse(null);
public @Nullable Sound hitSound() {
return this.impl.hitSound().map(CraftSound::minecraftHolderToBukkit).orElse(null);
}
public record PaperKineticWeaponCondition(
@@ -120,8 +110,8 @@ public record PaperKineticWeapon(
private net.minecraft.world.item.component.KineticWeapon.@Nullable Condition knockbackConditions;
private net.minecraft.world.item.component.KineticWeapon.@Nullable Condition damageConditions;
private @Nullable Key sound = null;
private @Nullable Key hitSound = null;
private @Nullable Sound sound = null;
private @Nullable Sound hitSound = null;
private float damageMultiplier = 1;
private float forwardMovement = 0.0F;
@@ -169,13 +159,13 @@ public record PaperKineticWeapon(
}
@Override
public KineticWeapon.Builder sound(final @Nullable Key sound) {
public KineticWeapon.Builder sound(final @Nullable Sound sound) {
this.sound = sound;
return this;
}
@Override
public KineticWeapon.Builder hitSound(final @Nullable Key sound) {
public KineticWeapon.Builder hitSound(final @Nullable Sound sound) {
this.hitSound = sound;
return this;
}
@@ -191,8 +181,8 @@ public record PaperKineticWeapon(
Optional.ofNullable(this.damageConditions),
this.forwardMovement,
this.damageMultiplier,
Optional.ofNullable(this.sound).map(PaperAdventure::resolveSound),
Optional.ofNullable(this.hitSound).map(PaperAdventure::resolveSound)
Optional.ofNullable(this.sound).map(CraftSound::bukkitToMinecraftHolder),
Optional.ofNullable(this.hitSound).map(CraftSound::bukkitToMinecraftHolder)
)
);
}
@@ -1,10 +1,8 @@
package io.papermc.paper.datacomponent.item;
import io.papermc.paper.adventure.PaperAdventure;
import java.util.Optional;
import net.kyori.adventure.key.Key;
import net.minecraft.core.Holder;
import net.minecraft.sounds.SoundEvent;
import org.bukkit.Sound;
import org.bukkit.craftbukkit.CraftSound;
import org.bukkit.craftbukkit.util.Handleable;
import org.jspecify.annotations.Nullable;
@@ -28,21 +26,13 @@ public record PaperPiercingWeapon(
}
@Override
public @Nullable Key sound() {
return this.impl.sound()
.map(Holder::value)
.map(SoundEvent::location)
.map(PaperAdventure::asAdventure)
.orElse(null);
public @Nullable Sound sound() {
return this.impl.sound().map(CraftSound::minecraftHolderToBukkit).orElse(null);
}
@Override
public @Nullable Key hitSound() {
return this.impl.hitSound()
.map(Holder::value)
.map(SoundEvent::location)
.map(PaperAdventure::asAdventure)
.orElse(null);
public @Nullable Sound hitSound() {
return this.impl.hitSound().map(CraftSound::minecraftHolderToBukkit).orElse(null);
}
static final class BuilderImpl implements PiercingWeapon.Builder {
@@ -50,8 +40,8 @@ public record PaperPiercingWeapon(
private boolean dealsKnockback = true;
private boolean dismounts = false;
private @Nullable Key sound = null;
private @Nullable Key hitSound = null;
private @Nullable Sound sound = null;
private @Nullable Sound hitSound = null;
@Override
public PiercingWeapon.Builder dealsKnockback(final boolean dealsKnockback) {
@@ -66,13 +56,13 @@ public record PaperPiercingWeapon(
}
@Override
public PiercingWeapon.Builder sound(final @Nullable Key sound) {
public PiercingWeapon.Builder sound(final @Nullable Sound sound) {
this.sound = sound;
return this;
}
@Override
public PiercingWeapon.Builder hitSound(final @Nullable Key sound) {
public PiercingWeapon.Builder hitSound(final @Nullable Sound sound) {
this.hitSound = sound;
return this;
}
@@ -83,8 +73,8 @@ public record PaperPiercingWeapon(
new net.minecraft.world.item.component.PiercingWeapon(
this.dealsKnockback,
this.dismounts,
Optional.ofNullable(this.sound).map(PaperAdventure::resolveSound),
Optional.ofNullable(this.hitSound).map(PaperAdventure::resolveSound)
Optional.ofNullable(this.sound).map(CraftSound::bukkitToMinecraftHolder),
Optional.ofNullable(this.hitSound).map(CraftSound::bukkitToMinecraftHolder)
)
);
}
@@ -2,10 +2,12 @@ package io.papermc.paper.datacomponent.item;
import io.papermc.paper.datacomponent.DataComponentType;
import io.papermc.paper.datacomponent.PaperDataComponentType;
import io.papermc.paper.registry.set.RegistryKeySet;
import it.unimi.dsi.fastutil.objects.ReferenceLinkedOpenHashSet;
import java.util.Arrays;
import java.util.Set;
import java.util.stream.Collectors;
import org.bukkit.Registry;
import org.bukkit.craftbukkit.util.Handleable;
public record PaperTooltipDisplay(
@@ -52,6 +54,11 @@ public record PaperTooltipDisplay(
return this;
}
@Override
public Builder hiddenComponents(final RegistryKeySet<DataComponentType> components) {
return this.hiddenComponents(components.values().stream().map(Registry.DATA_COMPONENT_TYPE::getOrThrow).collect(Collectors.toSet()));
}
@Override
public TooltipDisplay build() {
return new PaperTooltipDisplay(new net.minecraft.world.item.component.TooltipDisplay(
@@ -1,14 +1,14 @@
package io.papermc.paper.datacomponent.item.consumable;
import com.google.common.collect.Lists;
import io.papermc.paper.adventure.PaperAdventure;
import io.papermc.paper.registry.data.util.Conversions;
import io.papermc.paper.registry.set.PaperRegistrySets;
import io.papermc.paper.registry.set.RegistryKeySet;
import java.util.ArrayList;
import java.util.List;
import net.kyori.adventure.key.Key;
import net.minecraft.core.registries.Registries;
import org.bukkit.Sound;
import org.bukkit.craftbukkit.CraftSound;
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
@@ -45,9 +45,9 @@ public class ConsumableTypesBridgeImpl implements ConsumableTypesBridge {
}
@Override
public ConsumeEffect.PlaySound playSoundEffect(final Key sound) {
public ConsumeEffect.PlaySound playSoundEffect(final Sound sound) {
return new PaperPlaySound(
new net.minecraft.world.item.consume_effects.PlaySoundConsumeEffect(PaperAdventure.resolveSound(sound))
new net.minecraft.world.item.consume_effects.PlaySoundConsumeEffect(CraftSound.bukkitToMinecraftHolder(sound))
);
}
Loaded 100 of 167 files, more files were not shown because too many files have changed in this diff. Show more