Registry API for supported Mob Variants (#12417)

---------

Co-authored-by: Bjarne Koll <git@lynxplay.dev>
This commit is contained in:
Bert Towne
2025-05-06 16:13:00 -05:00
committed by GitHub
parent 753cff7c8a
commit e2da5d2f0a
20 changed files with 1027 additions and 14 deletions

View File

@ -0,0 +1,45 @@
package io.papermc.paper.registry.data;
import io.papermc.paper.registry.RegistryBuilder;
import io.papermc.paper.registry.data.client.ClientTextureAsset;
import org.bukkit.entity.Cat;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
/**
* A data-centric version-specific registry entry for the {@link Cat.Type} type.
*/
@ApiStatus.Experimental
@ApiStatus.NonExtendable
public interface CatTypeRegistryEntry {
/**
* Provides the client texture asset of the cat type, which represents the texture to use.
*
* @return the client texture asset.
*/
ClientTextureAsset clientTextureAsset();
/**
* A mutable builder for the {@link CatTypeRegistryEntry} plugins may change in applicable registry events.
* <p>
* The following values are required for each builder:
* <ul>
* <li>{@link #clientTextureAsset(ClientTextureAsset)}</li>
* </ul>
*/
@ApiStatus.Experimental
@ApiStatus.NonExtendable
interface Builder extends CatTypeRegistryEntry, RegistryBuilder<Cat.Type> {
/**
* Sets the client texture asset of the cat type, which is the location of the texture to use.
*
* @param clientTextureAsset the client texture asset.
* @return this builder instance.
* @see CatTypeRegistryEntry#clientTextureAsset()
*/
@Contract(value = "_ -> this", mutates = "this")
Builder clientTextureAsset(ClientTextureAsset clientTextureAsset);
}
}

View File

@ -0,0 +1,78 @@
package io.papermc.paper.registry.data;
import io.papermc.paper.registry.RegistryBuilder;
import io.papermc.paper.registry.data.client.ClientTextureAsset;
import org.bukkit.entity.Chicken;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
/**
* A data-centric version-specific registry entry for the {@link Chicken.Variant} type.
*/
@ApiStatus.Experimental
@ApiStatus.NonExtendable
public interface ChickenVariantRegistryEntry {
/**
* The model of the chicken variant to render the configured texture on.
*/
enum Model {
/**
* The normal chicken model.
*/
NORMAL,
/**
* The cold chicken model.
*/
COLD,
}
/**
* Provides the client texture asset of the chicken variant, which represents the texture to use.
*
* @return the client texture asset.
*/
ClientTextureAsset clientTextureAsset();
/**
* Provides the model of the chicken variant.
*
* @return the model.
*/
Model model();
/**
* A mutable builder for the {@link ChickenVariantRegistryEntry} plugins may change in applicable registry events.
* <p>
* The following values are required for each builder:
* <ul>
* <li>{@link #clientTextureAsset(ClientTextureAsset)}</li>
* <li>{@link #model(Model)}</li>
* </ul>
*/
@ApiStatus.Experimental
@ApiStatus.NonExtendable
interface Builder extends ChickenVariantRegistryEntry, RegistryBuilder<Chicken.Variant> {
/**
* Sets the client texture asset of the chicken variant, which is the location of the texture to use.
*
* @param clientTextureAsset the client texture asset.
* @return this builder instance.
* @see ChickenVariantRegistryEntry#clientTextureAsset()
*/
@Contract(value = "_ -> this", mutates = "this")
Builder clientTextureAsset(ClientTextureAsset clientTextureAsset);
/**
* Sets the model to use for this chicken variant.
*
* @param model the model.
* @return this builder instance.
* @see ChickenVariantRegistryEntry#model()
*/
@Contract(value = "_ -> this", mutates = "this")
Builder model(Model model);
}
}

View File

@ -0,0 +1,83 @@
package io.papermc.paper.registry.data;
import io.papermc.paper.registry.RegistryBuilder;
import io.papermc.paper.registry.data.client.ClientTextureAsset;
import org.bukkit.entity.Cow;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
/**
* A data-centric version-specific registry entry for the {@link Cow.Variant} type.
*/
@ApiStatus.Experimental
@ApiStatus.NonExtendable
public interface CowVariantRegistryEntry {
/**
* The model of the cow variant to render the configured texture on.
*/
enum Model {
/**
* The normal cow model.
*/
NORMAL,
/**
* The cold cow model.
*/
COLD,
/**
* The warm cow model.
*/
WARM,
}
/**
* Provides the client texture asset of the cow variant, which represents the texture to use.
*
* @return the client texture asset.
*/
ClientTextureAsset clientTextureAsset();
/**
* Provides the model of the cow variant.
*
* @return the model.
*/
Model model();
/**
* A mutable builder for the {@link CowVariantRegistryEntry} plugins may change in applicable registry events.
* <p>
* The following values are required for each builder:
* <ul>
* <li>{@link #clientTextureAsset(ClientTextureAsset)}</li>
* <li>{@link #model(Model)}</li>
* </ul>
*/
@ApiStatus.Experimental
@ApiStatus.NonExtendable
interface Builder extends CowVariantRegistryEntry, RegistryBuilder<Cow.Variant> {
/**
* Sets the client texture asset of the cow variant, which is the location of the texture to use.
*
* @param clientTextureAsset the client texture asset.
* @return this builder instance.
* @see CowVariantRegistryEntry#clientTextureAsset()
*/
@Contract(value = "_ -> this", mutates = "this")
Builder clientTextureAsset(ClientTextureAsset clientTextureAsset);
/**
* Sets the model to use for this cow variant.
*
* @param model the model.
* @return this builder instance.
* @see CowVariantRegistryEntry#model()
*/
@Contract(value = "_ -> this", mutates = "this")
Builder model(Model model);
}
}

View File

@ -0,0 +1,45 @@
package io.papermc.paper.registry.data;
import io.papermc.paper.registry.RegistryBuilder;
import io.papermc.paper.registry.data.client.ClientTextureAsset;
import org.bukkit.entity.Frog;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
/**
* A data-centric version-specific registry entry for the {@link Frog.Variant} type.
*/
@ApiStatus.Experimental
@ApiStatus.NonExtendable
public interface FrogVariantRegistryEntry {
/**
* Provides the client texture asset of the frog variant, which represents the texture to use.
*
* @return the client texture asset.
*/
ClientTextureAsset clientTextureAsset();
/**
* A mutable builder for the {@link FrogVariantRegistryEntry} plugins may change in applicable registry events.
* <p>
* The following values are required for each builder:
* <ul>
* <li>{@link #clientTextureAsset(ClientTextureAsset)}</li>
* </ul>
*/
@ApiStatus.Experimental
@ApiStatus.NonExtendable
interface Builder extends FrogVariantRegistryEntry, RegistryBuilder<Frog.Variant> {
/**
* Sets the client texture asset of the frog variant, which is the location of the texture to use.
*
* @param clientTextureAsset the client texture asset.
* @return this builder instance.
* @see FrogVariantRegistryEntry#clientTextureAsset()
*/
@Contract(value = "_ -> this", mutates = "this")
Builder clientTextureAsset(ClientTextureAsset clientTextureAsset);
}
}

View File

@ -0,0 +1,78 @@
package io.papermc.paper.registry.data;
import io.papermc.paper.registry.RegistryBuilder;
import io.papermc.paper.registry.data.client.ClientTextureAsset;
import org.bukkit.entity.Pig;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
/**
* A data-centric version-specific registry entry for the {@link Pig.Variant} type.
*/
@ApiStatus.Experimental
@ApiStatus.NonExtendable
public interface PigVariantRegistryEntry {
/**
* The model of the pig variant to render the configured texture on.
*/
enum Model {
/**
* The normal pig model.
*/
NORMAL,
/**
* The cold pig model.
*/
COLD,
}
/**
* Provides the client texture asset of the pig variant, which represents the texture to use.
*
* @return the client texture asset.
*/
ClientTextureAsset clientTextureAsset();
/**
* Provides the model of the pig variant.
*
* @return the model.
*/
Model model();
/**
* A mutable builder for the {@link PigVariantRegistryEntry} plugins may change in applicable registry events.
* <p>
* The following values are required for each builder:
* <ul>
* <li>{@link #clientTextureAsset(ClientTextureAsset)}</li>
* <li>{@link #model(Model)}</li>
* </ul>
*/
@ApiStatus.Experimental
@ApiStatus.NonExtendable
interface Builder extends PigVariantRegistryEntry, RegistryBuilder<Pig.Variant> {
/**
* Sets the client texture asset of the pig variant, which is the location of the texture to use.
*
* @param clientTextureAsset the client texture asset.
* @return this builder instance.
* @see PigVariantRegistryEntry#clientTextureAsset()
*/
@Contract(value = "_ -> this", mutates = "this")
Builder clientTextureAsset(ClientTextureAsset clientTextureAsset);
/**
* Sets the model to use for this pig variant.
*
* @param model the model.
* @return this builder instance.
* @see PigVariantRegistryEntry#model()
*/
@Contract(value = "_ -> this", mutates = "this")
Builder model(Model model);
}
}

View File

@ -0,0 +1,81 @@
package io.papermc.paper.registry.data;
import io.papermc.paper.registry.RegistryBuilder;
import io.papermc.paper.registry.data.client.ClientTextureAsset;
import org.bukkit.entity.Wolf;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
/**
* A data-centric version-specific registry entry for the {@link Wolf.Variant} type.
*/
@ApiStatus.Experimental
@ApiStatus.NonExtendable
public interface WolfVariantRegistryEntry {
/**
* Provides the client texture asset of the wolf variant for when it is angry, which is the location of the texture to use.
*
* @return the client texture asset.
*/
ClientTextureAsset angryClientTextureAsset();
/**
* Provides the client texture asset of the wolf variant for when it is wild, which is the location of the texture to use.
*
* @return the client texture asset.
*/
ClientTextureAsset wildClientTextureAsset();
/**
* Provides the client texture asset of the wolf variant for when it is tame, which is the location of the texture to use.
*
* @return the client texture asset.
*/
ClientTextureAsset tameClientTextureAsset();
/**
* A mutable builder for the {@link WolfVariantRegistryEntry} plugins may change in applicable registry events.
* <p>
* The following values are required for each builder:
* <ul>
* <li>{@link #angryClientTextureAsset(ClientTextureAsset)}</li>
* <li>{@link #wildClientTextureAsset(ClientTextureAsset)}</li>
* <li>{@link #tameClientTextureAsset(ClientTextureAsset)}</li>
* </ul>
*/
@ApiStatus.Experimental
@ApiStatus.NonExtendable
interface Builder extends WolfVariantRegistryEntry, RegistryBuilder<Wolf.Variant> {
/**
* Sets the client texture asset of the wolf variant for when it is angry, which is the location of the texture to use.
*
* @param angryClientTextureAsset the client texture asset.
* @return this builder instance.
* @see WolfVariantRegistryEntry#angryClientTextureAsset()
*/
@Contract(value = "_ -> this", mutates = "this")
Builder angryClientTextureAsset(ClientTextureAsset angryClientTextureAsset);
/**
* Sets the client texture asset of the wolf variant for when it is wild, which is the location of the texture to use.
*
* @param wildClientTextureAsset the client texture asset.
* @return this builder instance.
* @see WolfVariantRegistryEntry#wildClientTextureAsset()
*/
@Contract(value = "_ -> this", mutates = "this")
Builder wildClientTextureAsset(ClientTextureAsset wildClientTextureAsset);
/**
* Sets the client texture asset of the wolf variant for when it is tame, which is the location of the texture to use.
*
* @param tameClientTextureAsset the client texture asset.
* @return this builder instance.
* @see WolfVariantRegistryEntry#tameClientTextureAsset()
*/
@Contract(value = "_ -> this", mutates = "this")
Builder tameClientTextureAsset(ClientTextureAsset tameClientTextureAsset);
}
}

View File

@ -0,0 +1,66 @@
package io.papermc.paper.registry.data.client;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
/**
* A data-centric version-specific representation of a client texture asset, composed of an identifier and a path.
* Follows the same, version-specific, compatibility guarantees as the RegistryEntry types it is used in.
*/
@ApiStatus.Experimental
@ApiStatus.NonExtendable
public interface ClientTextureAsset {
/**
* The identifier of the client texture asset, uniquely identifying the asset on the client.
*
* @return the identifier.
*/
Key identifier();
/**
* The path of the texture on the client, split into a namespace and a path/key.
*
* @return the texture path.
*/
Key texturePath();
/**
* Creates a new {@link ClientTextureAsset} with the specified identifier and texture path.
*
* @param identifier the unique identifier for the client texture asset.
* @param texturePath the path where the asset is located on the client.
* @return a new {@code ClientAsset} instance.
*/
@Contract("_,_ -> new")
static ClientTextureAsset clientTextureAsset(final Key identifier, final Key texturePath) {
return new ClientTextureAssetImpl(identifier, texturePath);
}
/**
* Creates a new {@link ClientTextureAsset} using the provided identifier and infers the texture path from it.
*
* @param identifier the unique identifier for the client texture asset.
* @return a new {@code ClientAsset} instance.
*/
@Contract("_ -> new")
static ClientTextureAsset clientTextureAsset(final Key identifier) {
return new ClientTextureAssetImpl(identifier, ClientTextureAssetImpl.pathFromIdentifier(identifier));
}
/**
* Creates a new {@link ClientTextureAsset} from the provided string-formatted {@link Key}
* and infers the texture path from it.
* <p>
* The identifier string must conform to the {@link KeyPattern} format.
*
* @param identifier the string representation of the asset's identifier.
* @return a new {@code ClientAsset} instance.
*/
@Contract("_ -> new")
static ClientTextureAsset clientTextureAsset(final @KeyPattern String identifier) {
return clientTextureAsset(Key.key(identifier));
}
}

View File

@ -0,0 +1,31 @@
package io.papermc.paper.registry.data.client;
import net.kyori.adventure.key.Key;
import org.intellij.lang.annotations.Subst;
import org.jspecify.annotations.NullMarked;
/**
* Package local implementation of the {@link ClientTextureAsset} type.
* Chosen over bridging into server internals as no internal types are required for this.
*/
@NullMarked
record ClientTextureAssetImpl(
Key identifier,
Key texturePath
) implements ClientTextureAsset {
/**
* Constructs the default asset path from the identifier of the asset.
* Mirrors internal logic in net.minecraft.core.ClientAsset
*
* @param identifier the identifier of the asset.
* @return the key/path of the asset.
*/
static Key pathFromIdentifier(@Subst("") final Key identifier) {
return Key.key(
identifier.namespace(),
"textures/" + identifier.value() + ".png"
);
}
}

View File

@ -2,15 +2,27 @@ package io.papermc.paper.registry.event;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.BannerPatternRegistryEntry;
import io.papermc.paper.registry.data.CatTypeRegistryEntry;
import io.papermc.paper.registry.data.ChickenVariantRegistryEntry;
import io.papermc.paper.registry.data.CowVariantRegistryEntry;
import io.papermc.paper.registry.data.DamageTypeRegistryEntry;
import io.papermc.paper.registry.data.EnchantmentRegistryEntry;
import io.papermc.paper.registry.data.FrogVariantRegistryEntry;
import io.papermc.paper.registry.data.GameEventRegistryEntry;
import io.papermc.paper.registry.data.PaintingVariantRegistryEntry;
import io.papermc.paper.registry.data.PigVariantRegistryEntry;
import io.papermc.paper.registry.data.WolfVariantRegistryEntry;
import org.bukkit.Art;
import org.bukkit.GameEvent;
import org.bukkit.block.banner.PatternType;
import org.bukkit.damage.DamageType;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Cat;
import org.bukkit.entity.Chicken;
import org.bukkit.entity.Cow;
import org.bukkit.entity.Frog;
import org.bukkit.entity.Pig;
import org.bukkit.entity.Wolf;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
@ -28,9 +40,15 @@ public final class RegistryEvents {
// @GeneratedFrom 1.21.5
public static final RegistryEventProvider<GameEvent, GameEventRegistryEntry.Builder> GAME_EVENT = create(RegistryKey.GAME_EVENT);
public static final RegistryEventProvider<DamageType, DamageTypeRegistryEntry.Builder> DAMAGE_TYPE = create(RegistryKey.DAMAGE_TYPE);
public static final RegistryEventProvider<Wolf.Variant, WolfVariantRegistryEntry.Builder> WOLF_VARIANT = create(RegistryKey.WOLF_VARIANT);
public static final RegistryEventProvider<Enchantment, EnchantmentRegistryEntry.Builder> ENCHANTMENT = create(RegistryKey.ENCHANTMENT);
public static final RegistryEventProvider<PatternType, BannerPatternRegistryEntry.Builder> BANNER_PATTERN = create(RegistryKey.BANNER_PATTERN);
public static final RegistryEventProvider<Art, PaintingVariantRegistryEntry.Builder> PAINTING_VARIANT = create(RegistryKey.PAINTING_VARIANT);
public static final RegistryEventProvider<Cat.Type, CatTypeRegistryEntry.Builder> CAT_VARIANT = create(RegistryKey.CAT_VARIANT);
public static final RegistryEventProvider<Frog.Variant, FrogVariantRegistryEntry.Builder> FROG_VARIANT = create(RegistryKey.FROG_VARIANT);
public static final RegistryEventProvider<Chicken.Variant, ChickenVariantRegistryEntry.Builder> CHICKEN_VARIANT = create(RegistryKey.CHICKEN_VARIANT);
public static final RegistryEventProvider<Cow.Variant, CowVariantRegistryEntry.Builder> COW_VARIANT = create(RegistryKey.COW_VARIANT);
public static final RegistryEventProvider<Pig.Variant, PigVariantRegistryEntry.Builder> PIG_VARIANT = create(RegistryKey.PIG_VARIANT);
// End generate - RegistryEvents
private RegistryEvents() {

View File

@ -5,7 +5,6 @@ import io.papermc.paper.registry.RegistryKey;
import org.bukkit.DyeColor;
import org.bukkit.Keyed;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.jetbrains.annotations.NotNull;
/**