Add registry api for trim patterns and materials

This commit is contained in:
Jake Potrebic
2025-07-06 16:34:06 -07:00
parent b4466ec981
commit 6c29db47bb
13 changed files with 465 additions and 38 deletions

View File

@@ -32,7 +32,7 @@ public interface Dialog extends Keyed, DialogLike {
}
// Start generate - Dialog
// @GeneratedFrom 1.21.7-rc2
// @GeneratedFrom 1.21.7
Dialog CUSTOM_OPTIONS = getDialog("custom_options");
Dialog QUICK_ACTIONS = getDialog("quick_actions");

View File

@@ -59,7 +59,5 @@ public interface BannerPatternRegistryEntry {
*/
@Contract(value = "_ -> this", mutates = "this")
Builder translationKey(String translationKey);
}
}

View File

@@ -7,6 +7,8 @@ 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;
@ApiStatus.Internal
@@ -23,4 +25,8 @@ public interface InlinedRegistryBuilderProvider {
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);
}

View File

@@ -0,0 +1,91 @@
package io.papermc.paper.registry.data;
import io.papermc.paper.datacomponent.item.Equippable;
import io.papermc.paper.registry.RegistryBuilder;
import java.util.Map;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
import net.kyori.adventure.text.Component;
import org.bukkit.inventory.meta.trim.TrimMaterial;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.Unmodifiable;
/**
* A data-centric version-specific registry entry for the {@link org.bukkit.inventory.meta.trim.TrimMaterial} type.
*/
@ApiStatus.Experimental
@ApiStatus.NonExtendable
public interface TrimMaterialRegistryEntry {
/**
* The base asset path for the trim material.
*
* @return the base asset path
*/
@Contract(pure = true)
@KeyPattern.Value String baseAssetPath();
/**
* An immutable map of asset path overrides for the trim material.
* <p>
* The key is the identifier of the asset, and the value is the path to the asset.
*
* @return the asset path overrides
* @see Equippable#assetId()
*/
@Contract(pure = true)
@Unmodifiable Map<Key, String> assetPathOverrides();
/**
* The description of the trim material.
*
* @return the description
*/
@Contract(pure = true)
Component description();
/**
* A mutable builder for {@link TrimMaterialRegistryEntry} plugins may change in applicable registry events.
* <p>
* The following values are required for each builder:
* <ul>
* <li>{@link #baseAssetPath(String)}</li>
* <li>{@link #description(Component)}</li>
* </ul>
*/
@ApiStatus.Experimental
@ApiStatus.NonExtendable
interface Builder extends TrimMaterialRegistryEntry, RegistryBuilder<TrimMaterial> {
/**
* Sets the base asset path for the trim material.
*
* @param baseAssetPath the base asset path
* @return the builder
* @see #baseAssetPath()
*/
@Contract(value = "_ -> this", mutates = "this")
Builder baseAssetPath(@KeyPattern.Value String baseAssetPath);
/**
* Sets the asset path overrides for the trim material.
*
* @param assetPathOverrides the asset path overrides
* @return the builder
* @see #assetPathOverrides()
*/
@Contract(value = "_ -> this", mutates = "this")
Builder assetPathOverrides(Map<Key, String> assetPathOverrides);
/**
* Sets the description for the trim material.
*
* @param description the description
* @return the builder
* @see #description()
*/
@Contract(value = "_ -> this", mutates = "this")
Builder description(Component description);
}
}

View File

@@ -0,0 +1,84 @@
package io.papermc.paper.registry.data;
import io.papermc.paper.registry.RegistryBuilder;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import org.bukkit.inventory.meta.trim.TrimPattern;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Contract;
/**
* A data-centric version-specific registry entry for the {@link org.bukkit.inventory.meta.trim.TrimMaterial} type.
*/
@ApiStatus.Experimental
@ApiStatus.NonExtendable
public interface TrimPatternRegistryEntry {
/**
* The asset ID of the trim pattern.
*
* @return the asset ID
*/
@Contract(pure = true)
Key assetId();
/**
* The description of the trim pattern.
*
* @return the description
*/
@Contract(pure = true)
Component description();
/**
* Checks if the trim pattern is a decal.
*
* @return true if decal, false otherwise
*/
@Contract(pure = true)
boolean decal();
/**
* A mutable builder for {@link TrimPatternRegistryEntry} plugins may change in applicable registry events.
* <p>
* The following values are required for each builder:
* <ul>
* <li>{@link #assetId(Key)}</li>
* <li>{@link #description(Component)}</li>
* </ul>
*/
@ApiStatus.Experimental
@ApiStatus.NonExtendable
interface Builder extends TrimPatternRegistryEntry, RegistryBuilder<TrimPattern> {
/**
* Sets the asset ID for the trim pattern.
*
* @param key the asset ID
* @return the builder
* @see #assetId()
*/
@Contract(value = "_ -> this", mutates = "this")
Builder assetId(Key key);
/**
* Sets the description for the trim pattern.
*
* @param description the description
* @return the builder
* @see #description()
*/
@Contract(value = "_ -> this", mutates = "this")
Builder description(Component description);
/**
* Sets whether the trim pattern is a decal.
*
* @param decal true if decal, false otherwise
* @return the builder
* @see #decal()
*/
@Contract(value = "_ -> this", mutates = "this")
Builder decal(boolean decal);
}
}

View File

@@ -14,6 +14,8 @@ import io.papermc.paper.registry.data.InstrumentRegistryEntry;
import io.papermc.paper.registry.data.JukeboxSongRegistryEntry;
import io.papermc.paper.registry.data.PaintingVariantRegistryEntry;
import io.papermc.paper.registry.data.PigVariantRegistryEntry;
import io.papermc.paper.registry.data.TrimMaterialRegistryEntry;
import io.papermc.paper.registry.data.TrimPatternRegistryEntry;
import io.papermc.paper.registry.data.WolfVariantRegistryEntry;
import io.papermc.paper.registry.data.dialog.DialogRegistryEntry;
import org.bukkit.Art;
@@ -29,6 +31,8 @@ import org.bukkit.entity.Cow;
import org.bukkit.entity.Frog;
import org.bukkit.entity.Pig;
import org.bukkit.entity.Wolf;
import org.bukkit.inventory.meta.trim.TrimMaterial;
import org.bukkit.inventory.meta.trim.TrimPattern;
import static io.papermc.paper.registry.event.RegistryEventProviderImpl.create;
@@ -41,6 +45,8 @@ public final class RegistryEvents {
// Start generate - RegistryEvents
// @GeneratedFrom 1.21.7
public static final RegistryEventProvider<GameEvent, GameEventRegistryEntry.Builder> GAME_EVENT = create(RegistryKey.GAME_EVENT);
public static final RegistryEventProvider<TrimMaterial, TrimMaterialRegistryEntry.Builder> TRIM_MATERIAL = create(RegistryKey.TRIM_MATERIAL);
public static final RegistryEventProvider<TrimPattern, TrimPatternRegistryEntry.Builder> TRIM_PATTERN = create(RegistryKey.TRIM_PATTERN);
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);

View File

@@ -1,19 +1,38 @@
package org.bukkit.inventory.meta.trim;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryBuilderFactory;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.InlinedRegistryBuilderProvider;
import io.papermc.paper.registry.data.TrimMaterialRegistryEntry;
import java.util.function.Consumer;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
import net.kyori.adventure.text.Component;
import org.bukkit.Keyed;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.Translatable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
/**
* Represents a material that may be used in an {@link ArmorTrim}.
*/
@NullMarked
public interface TrimMaterial extends Keyed, Translatable {
/**
* Creates an inlined trim material.
*
* @param value a consumer for the builder factory
* @return the created trim material
*/
@ApiStatus.Experimental
static TrimMaterial create(final Consumer<RegistryBuilderFactory<TrimMaterial, ? extends TrimMaterialRegistryEntry.Builder>> value) {
return InlinedRegistryBuilderProvider.instance().createTrimMaterial(value);
}
// Start generate - TrimMaterial
// @GeneratedFrom 1.21.7
TrimMaterial AMETHYST = getTrimMaterial("amethyst");
@@ -39,18 +58,16 @@ public interface TrimMaterial extends Keyed, Translatable {
TrimMaterial RESIN = getTrimMaterial("resin");
// End generate - TrimMaterial
@NotNull
private static TrimMaterial getTrimMaterial(@NotNull String key) {
return RegistryAccess.registryAccess().getRegistry(RegistryKey.TRIM_MATERIAL).getOrThrow(NamespacedKey.minecraft(key));
private static TrimMaterial getTrimMaterial(@KeyPattern.Value final String key) {
return RegistryAccess.registryAccess().getRegistry(RegistryKey.TRIM_MATERIAL).getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, key));
}
// Paper start - adventure
/**
* Get the description of this {@link TrimMaterial}.
*
* @return the description
*/
net.kyori.adventure.text.@org.jetbrains.annotations.NotNull Component description();
Component description();
/**
* @deprecated this method assumes that {@link #description()} will
@@ -58,17 +75,7 @@ public interface TrimMaterial extends Keyed, Translatable {
*/
@Override
@Deprecated(forRemoval = true)
@org.jetbrains.annotations.NotNull String getTranslationKey();
// Paper end - adventure
// Paper start - Registry#getKey
/**
* @deprecated use {@link Registry#getKey(Keyed)}, {@link io.papermc.paper.registry.RegistryAccess#getRegistry(io.papermc.paper.registry.RegistryKey)},
* and {@link io.papermc.paper.registry.RegistryKey#TRIM_MATERIAL}. TrimMaterials can exist without a key.
*/
@Deprecated(forRemoval = true, since = "1.20.4")
@Override
org.bukkit.@org.jetbrains.annotations.NotNull NamespacedKey getKey();
String getTranslationKey();
/**
* @deprecated use {@link Registry#getKey(Keyed)}, {@link io.papermc.paper.registry.RegistryAccess#getRegistry(io.papermc.paper.registry.RegistryKey)},
@@ -76,8 +83,15 @@ public interface TrimMaterial extends Keyed, Translatable {
*/
@Deprecated(forRemoval = true, since = "1.20.4")
@Override
default net.kyori.adventure.key.@org.jetbrains.annotations.NotNull Key key() {
return org.bukkit.Keyed.super.key();
NamespacedKey getKey();
/**
* @deprecated use {@link Registry#getKey(Keyed)}, {@link io.papermc.paper.registry.RegistryAccess#getRegistry(io.papermc.paper.registry.RegistryKey)},
* and {@link io.papermc.paper.registry.RegistryKey#TRIM_MATERIAL}. TrimMaterials can exist without a key.
*/
@Deprecated(forRemoval = true, since = "1.20.4")
@Override
default Key key() {
return Keyed.super.key();
}
// Paper end - Registry#getKey
}

View File

@@ -1,19 +1,38 @@
package org.bukkit.inventory.meta.trim;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryBuilderFactory;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.InlinedRegistryBuilderProvider;
import io.papermc.paper.registry.data.TrimPatternRegistryEntry;
import java.util.function.Consumer;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.key.KeyPattern;
import net.kyori.adventure.text.Component;
import org.bukkit.Keyed;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.Translatable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
/**
* Represents a pattern that may be used in an {@link ArmorTrim}.
*/
@NullMarked
public interface TrimPattern extends Keyed, Translatable {
/**
* Creates an inlined trim pattern.
*
* @param value a consumer for the builder factory
* @return the created trim pattern
*/
@ApiStatus.Experimental
static TrimPattern create(final Consumer<RegistryBuilderFactory<TrimPattern, ? extends TrimPatternRegistryEntry.Builder>> value) {
return InlinedRegistryBuilderProvider.instance().createTrimPattern(value);
}
// Start generate - TrimPattern
// @GeneratedFrom 1.21.7
TrimPattern BOLT = getTrimPattern("bolt");
@@ -53,9 +72,8 @@ public interface TrimPattern extends Keyed, Translatable {
TrimPattern WILD = getTrimPattern("wild");
// End generate - TrimPattern
@NotNull
private static TrimPattern getTrimPattern(@NotNull String key) {
return RegistryAccess.registryAccess().getRegistry(RegistryKey.TRIM_PATTERN).getOrThrow(NamespacedKey.minecraft(key));
private static TrimPattern getTrimPattern(@KeyPattern.Value final String key) {
return RegistryAccess.registryAccess().getRegistry(RegistryKey.TRIM_PATTERN).getOrThrow(Key.key(Key.MINECRAFT_NAMESPACE, key));
}
// Paper start - adventure
@@ -64,7 +82,7 @@ public interface TrimPattern extends Keyed, Translatable {
*
* @return the description
*/
net.kyori.adventure.text.@org.jetbrains.annotations.NotNull Component description();
Component description();
/**
* @deprecated this method assumes that {@link #description()} will
@@ -72,7 +90,7 @@ public interface TrimPattern extends Keyed, Translatable {
*/
@Override
@Deprecated(forRemoval = true)
@org.jetbrains.annotations.NotNull String getTranslationKey();
String getTranslationKey();
// Paper end - adventure
// Paper start - Registry#getKey
@@ -82,7 +100,7 @@ public interface TrimPattern extends Keyed, Translatable {
*/
@Deprecated(forRemoval = true, since = "1.20.4")
@Override
org.bukkit.@org.jetbrains.annotations.NotNull NamespacedKey getKey();
NamespacedKey getKey();
/**
* @deprecated use {@link Registry#getKey(Keyed)}, {@link io.papermc.paper.registry.RegistryAccess#getRegistry(io.papermc.paper.registry.RegistryKey)},
@@ -90,8 +108,8 @@ public interface TrimPattern extends Keyed, Translatable {
*/
@Deprecated(forRemoval = true, since = "1.20.4")
@Override
default net.kyori.adventure.key.@org.jetbrains.annotations.NotNull Key key() {
return org.bukkit.Keyed.super.key();
default Key key() {
return Keyed.super.key();
}
// Paper end - Registry#getKey
}