From 6c29db47bb1bbf29eac488f1ca7df1c1a191505d Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Sun, 6 Jul 2025 16:34:06 -0700 Subject: [PATCH] Add registry api for trim patterns and materials --- .../java/io/papermc/paper/dialog/Dialog.java | 2 +- .../data/BannerPatternRegistryEntry.java | 2 - .../data/InlinedRegistryBuilderProvider.java | 6 + .../data/TrimMaterialRegistryEntry.java | 91 ++++++++++++++ .../data/TrimPatternRegistryEntry.java | 84 +++++++++++++ .../paper/registry/event/RegistryEvents.java | 6 + .../inventory/meta/trim/TrimMaterial.java | 56 +++++---- .../inventory/meta/trim/TrimPattern.java | 38 ++++-- .../generator/registry/RegistryEntries.java | 6 +- .../paper/registry/PaperRegistries.java | 6 +- .../InlinedRegistryBuilderProviderImpl.java | 12 ++ .../data/PaperTrimMaterialRegistryEntry.java | 112 ++++++++++++++++++ .../data/PaperTrimPatternRegistryEntry.java | 82 +++++++++++++ 13 files changed, 465 insertions(+), 38 deletions(-) create mode 100644 paper-api/src/main/java/io/papermc/paper/registry/data/TrimMaterialRegistryEntry.java create mode 100644 paper-api/src/main/java/io/papermc/paper/registry/data/TrimPatternRegistryEntry.java create mode 100644 paper-server/src/main/java/io/papermc/paper/registry/data/PaperTrimMaterialRegistryEntry.java create mode 100644 paper-server/src/main/java/io/papermc/paper/registry/data/PaperTrimPatternRegistryEntry.java diff --git a/paper-api/src/main/java/io/papermc/paper/dialog/Dialog.java b/paper-api/src/main/java/io/papermc/paper/dialog/Dialog.java index a77c23ab0a..e7ab79fcfb 100644 --- a/paper-api/src/main/java/io/papermc/paper/dialog/Dialog.java +++ b/paper-api/src/main/java/io/papermc/paper/dialog/Dialog.java @@ -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"); diff --git a/paper-api/src/main/java/io/papermc/paper/registry/data/BannerPatternRegistryEntry.java b/paper-api/src/main/java/io/papermc/paper/registry/data/BannerPatternRegistryEntry.java index 8ca672a5bb..13e87c7fbb 100644 --- a/paper-api/src/main/java/io/papermc/paper/registry/data/BannerPatternRegistryEntry.java +++ b/paper-api/src/main/java/io/papermc/paper/registry/data/BannerPatternRegistryEntry.java @@ -59,7 +59,5 @@ public interface BannerPatternRegistryEntry { */ @Contract(value = "_ -> this", mutates = "this") Builder translationKey(String translationKey); - } - } diff --git a/paper-api/src/main/java/io/papermc/paper/registry/data/InlinedRegistryBuilderProvider.java b/paper-api/src/main/java/io/papermc/paper/registry/data/InlinedRegistryBuilderProvider.java index 33257a4147..3f218bf581 100644 --- a/paper-api/src/main/java/io/papermc/paper/registry/data/InlinedRegistryBuilderProvider.java +++ b/paper-api/src/main/java/io/papermc/paper/registry/data/InlinedRegistryBuilderProvider.java @@ -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> value); Dialog createDialog(Consumer> value); + + TrimMaterial createTrimMaterial(Consumer> value); + + TrimPattern createTrimPattern(Consumer> value); } diff --git a/paper-api/src/main/java/io/papermc/paper/registry/data/TrimMaterialRegistryEntry.java b/paper-api/src/main/java/io/papermc/paper/registry/data/TrimMaterialRegistryEntry.java new file mode 100644 index 0000000000..c257cede0c --- /dev/null +++ b/paper-api/src/main/java/io/papermc/paper/registry/data/TrimMaterialRegistryEntry.java @@ -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. + *

+ * 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 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. + *

+ * The following values are required for each builder: + *

    + *
  • {@link #baseAssetPath(String)}
  • + *
  • {@link #description(Component)}
  • + *
+ */ + @ApiStatus.Experimental + @ApiStatus.NonExtendable + interface Builder extends TrimMaterialRegistryEntry, RegistryBuilder { + + /** + * 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 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); + } +} diff --git a/paper-api/src/main/java/io/papermc/paper/registry/data/TrimPatternRegistryEntry.java b/paper-api/src/main/java/io/papermc/paper/registry/data/TrimPatternRegistryEntry.java new file mode 100644 index 0000000000..19c379713a --- /dev/null +++ b/paper-api/src/main/java/io/papermc/paper/registry/data/TrimPatternRegistryEntry.java @@ -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. + *

+ * The following values are required for each builder: + *

    + *
  • {@link #assetId(Key)}
  • + *
  • {@link #description(Component)}
  • + *
+ */ + @ApiStatus.Experimental + @ApiStatus.NonExtendable + interface Builder extends TrimPatternRegistryEntry, RegistryBuilder { + + /** + * 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); + } +} diff --git a/paper-api/src/main/java/io/papermc/paper/registry/event/RegistryEvents.java b/paper-api/src/main/java/io/papermc/paper/registry/event/RegistryEvents.java index 2c652f3f13..95d2098075 100644 --- a/paper-api/src/main/java/io/papermc/paper/registry/event/RegistryEvents.java +++ b/paper-api/src/main/java/io/papermc/paper/registry/event/RegistryEvents.java @@ -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 GAME_EVENT = create(RegistryKey.GAME_EVENT); + public static final RegistryEventProvider TRIM_MATERIAL = create(RegistryKey.TRIM_MATERIAL); + public static final RegistryEventProvider TRIM_PATTERN = create(RegistryKey.TRIM_PATTERN); public static final RegistryEventProvider DAMAGE_TYPE = create(RegistryKey.DAMAGE_TYPE); public static final RegistryEventProvider WOLF_VARIANT = create(RegistryKey.WOLF_VARIANT); public static final RegistryEventProvider ENCHANTMENT = create(RegistryKey.ENCHANTMENT); diff --git a/paper-api/src/main/java/org/bukkit/inventory/meta/trim/TrimMaterial.java b/paper-api/src/main/java/org/bukkit/inventory/meta/trim/TrimMaterial.java index cfe91bd251..51aff89e3a 100644 --- a/paper-api/src/main/java/org/bukkit/inventory/meta/trim/TrimMaterial.java +++ b/paper-api/src/main/java/org/bukkit/inventory/meta/trim/TrimMaterial.java @@ -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> 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 } diff --git a/paper-api/src/main/java/org/bukkit/inventory/meta/trim/TrimPattern.java b/paper-api/src/main/java/org/bukkit/inventory/meta/trim/TrimPattern.java index 883d124192..427d1f8a8f 100644 --- a/paper-api/src/main/java/org/bukkit/inventory/meta/trim/TrimPattern.java +++ b/paper-api/src/main/java/org/bukkit/inventory/meta/trim/TrimPattern.java @@ -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> 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 } diff --git a/paper-generator/src/main/java/io/papermc/generator/registry/RegistryEntries.java b/paper-generator/src/main/java/io/papermc/generator/registry/RegistryEntries.java index a4e46283c7..20e8464397 100644 --- a/paper-generator/src/main/java/io/papermc/generator/registry/RegistryEntries.java +++ b/paper-generator/src/main/java/io/papermc/generator/registry/RegistryEntries.java @@ -17,6 +17,8 @@ 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.SoundEventRegistryEntry; +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 java.lang.reflect.Field; @@ -170,8 +172,8 @@ public final class RegistryEntries { public static final List> DATA_DRIVEN = List.of( entry(Registries.BIOME, Biomes.class, Biome.class).delayed(), entry(Registries.STRUCTURE, BuiltinStructures.class, Structure.class).delayed(), - entry(Registries.TRIM_MATERIAL, TrimMaterials.class, TrimMaterial.class).allowDirect().delayed(), - entry(Registries.TRIM_PATTERN, TrimPatterns.class, TrimPattern.class).allowDirect().delayed(), + entry(Registries.TRIM_MATERIAL, TrimMaterials.class, TrimMaterial.class).writableApiRegistryBuilder(TrimMaterialRegistryEntry.Builder.class, "PaperTrimMaterialRegistryEntry.PaperBuilder").allowDirect().delayed(), + entry(Registries.TRIM_PATTERN, TrimPatterns.class, TrimPattern.class).writableApiRegistryBuilder(TrimPatternRegistryEntry.Builder.class, "PaperTrimPatternRegistryEntry.PaperBuilder").allowDirect().delayed(), entry(Registries.DAMAGE_TYPE, DamageTypes.class, DamageType.class).writableApiRegistryBuilder(DamageTypeRegistryEntry.Builder.class, "PaperDamageTypeRegistryEntry.PaperBuilder").delayed(), entry(Registries.WOLF_VARIANT, WolfVariants.class, Wolf.Variant.class).writableApiRegistryBuilder(WolfVariantRegistryEntry.Builder.class, "PaperWolfVariantRegistryEntry.PaperBuilder").delayed(), entry(Registries.WOLF_SOUND_VARIANT, WolfSoundVariants.class, Wolf.SoundVariant.class), diff --git a/paper-server/src/main/java/io/papermc/paper/registry/PaperRegistries.java b/paper-server/src/main/java/io/papermc/paper/registry/PaperRegistries.java index 804d6408eb..ac0486e56d 100644 --- a/paper-server/src/main/java/io/papermc/paper/registry/PaperRegistries.java +++ b/paper-server/src/main/java/io/papermc/paper/registry/PaperRegistries.java @@ -19,6 +19,8 @@ import io.papermc.paper.registry.data.PaperJukeboxSongRegistryEntry; import io.papermc.paper.registry.data.PaperPaintingVariantRegistryEntry; import io.papermc.paper.registry.data.PaperPigVariantRegistryEntry; import io.papermc.paper.registry.data.PaperSoundEventRegistryEntry; +import io.papermc.paper.registry.data.PaperTrimMaterialRegistryEntry; +import io.papermc.paper.registry.data.PaperTrimPatternRegistryEntry; import io.papermc.paper.registry.data.PaperWolfVariantRegistryEntry; import io.papermc.paper.registry.data.dialog.PaperDialogRegistryEntry; import io.papermc.paper.registry.entry.RegistryEntry; @@ -120,8 +122,8 @@ public final class PaperRegistries { // data-driven start(Registries.BIOME, RegistryKey.BIOME).craft(Biome.class, CraftBiome::new).build().delayed(), start(Registries.STRUCTURE, RegistryKey.STRUCTURE).craft(Structure.class, CraftStructure::new).build().delayed(), - start(Registries.TRIM_MATERIAL, RegistryKey.TRIM_MATERIAL).craft(TrimMaterial.class, CraftTrimMaterial::new, true).build().delayed(), - start(Registries.TRIM_PATTERN, RegistryKey.TRIM_PATTERN).craft(TrimPattern.class, CraftTrimPattern::new, true).build().delayed(), + start(Registries.TRIM_MATERIAL, RegistryKey.TRIM_MATERIAL).craft(TrimMaterial.class, CraftTrimMaterial::new, true).writable(PaperTrimMaterialRegistryEntry.PaperBuilder::new).delayed(), + start(Registries.TRIM_PATTERN, RegistryKey.TRIM_PATTERN).craft(TrimPattern.class, CraftTrimPattern::new, true).writable(PaperTrimPatternRegistryEntry.PaperBuilder::new).delayed(), start(Registries.DAMAGE_TYPE, RegistryKey.DAMAGE_TYPE).craft(DamageType.class, CraftDamageType::new).writable(PaperDamageTypeRegistryEntry.PaperBuilder::new).delayed(), start(Registries.WOLF_VARIANT, RegistryKey.WOLF_VARIANT).craft(Wolf.Variant.class, CraftWolf.CraftVariant::new).writable(PaperWolfVariantRegistryEntry.PaperBuilder::new).delayed(), start(Registries.WOLF_SOUND_VARIANT, RegistryKey.WOLF_SOUND_VARIANT).craft(Wolf.SoundVariant.class, CraftWolf.CraftSoundVariant::new).build(), diff --git a/paper-server/src/main/java/io/papermc/paper/registry/data/InlinedRegistryBuilderProviderImpl.java b/paper-server/src/main/java/io/papermc/paper/registry/data/InlinedRegistryBuilderProviderImpl.java index 8927a5fc4f..417baceb96 100644 --- a/paper-server/src/main/java/io/papermc/paper/registry/data/InlinedRegistryBuilderProviderImpl.java +++ b/paper-server/src/main/java/io/papermc/paper/registry/data/InlinedRegistryBuilderProviderImpl.java @@ -7,6 +7,8 @@ import io.papermc.paper.registry.data.dialog.DialogRegistryEntry; import io.papermc.paper.registry.data.util.Conversions; import java.util.function.Consumer; import org.bukkit.MusicInstrument; +import org.bukkit.inventory.meta.trim.TrimMaterial; +import org.bukkit.inventory.meta.trim.TrimPattern; public final class InlinedRegistryBuilderProviderImpl implements InlinedRegistryBuilderProvider { @@ -19,4 +21,14 @@ public final class InlinedRegistryBuilderProviderImpl implements InlinedRegistry public Dialog createDialog(final Consumer> value) { return Conversions.global().createApiInstanceFromBuilder(RegistryKey.DIALOG, value); } + + @Override + public TrimMaterial createTrimMaterial(final Consumer> value) { + return Conversions.global().createApiInstanceFromBuilder(RegistryKey.TRIM_MATERIAL, value); + } + + @Override + public TrimPattern createTrimPattern(final Consumer> value) { + return Conversions.global().createApiInstanceFromBuilder(RegistryKey.TRIM_PATTERN, value); + } } diff --git a/paper-server/src/main/java/io/papermc/paper/registry/data/PaperTrimMaterialRegistryEntry.java b/paper-server/src/main/java/io/papermc/paper/registry/data/PaperTrimMaterialRegistryEntry.java new file mode 100644 index 0000000000..b75900f94b --- /dev/null +++ b/paper-server/src/main/java/io/papermc/paper/registry/data/PaperTrimMaterialRegistryEntry.java @@ -0,0 +1,112 @@ +package io.papermc.paper.registry.data; + +import com.google.common.collect.ImmutableMap; +import io.papermc.paper.adventure.PaperAdventure; +import io.papermc.paper.registry.PaperRegistryBuilder; +import io.papermc.paper.registry.data.util.Conversions; +import java.util.Collections; +import java.util.Map; +import net.kyori.adventure.key.Key; +import net.kyori.adventure.key.KeyPattern; +import net.kyori.adventure.text.Component; +import net.minecraft.resources.ResourceKey; +import net.minecraft.world.item.equipment.EquipmentAsset; +import net.minecraft.world.item.equipment.EquipmentAssets; +import net.minecraft.world.item.equipment.trim.MaterialAssetGroup; +import net.minecraft.world.item.equipment.trim.TrimMaterial; +import org.intellij.lang.annotations.Subst; +import org.jetbrains.annotations.Unmodifiable; +import org.jspecify.annotations.Nullable; + +import static io.papermc.paper.registry.data.util.Checks.asArgument; +import static io.papermc.paper.registry.data.util.Checks.asConfigured; + +public class PaperTrimMaterialRegistryEntry implements TrimMaterialRegistryEntry { + + protected MaterialAssetGroup.@Nullable AssetInfo baseAssetPath; + protected Map, MaterialAssetGroup.AssetInfo> assetPathOverrides = Collections.emptyMap(); + protected net.minecraft.network.chat.@Nullable Component description; + + protected final Conversions conversions; + + public PaperTrimMaterialRegistryEntry(final Conversions conversions, final @Nullable TrimMaterial internal) { + this.conversions = conversions; + if (internal == null) { + return; + } + + this.baseAssetPath = internal.assets().base(); + this.assetPathOverrides = internal.assets().overrides(); + this.description = internal.description(); + } + + + @Override + @KeyPattern.Value + public String baseAssetPath() { + @Subst("suffix") final String path = asConfigured(this.baseAssetPath, "baseAssetPath").suffix(); + return path; + } + + @Override + public @Unmodifiable Map assetPathOverrides() { + if (this.assetPathOverrides.isEmpty()) { + return Collections.emptyMap(); + } + final ImmutableMap.Builder builder = ImmutableMap.builder(); + this.assetPathOverrides.forEach((key, value) -> { + builder.put(PaperAdventure.asAdventureKey(key), value.suffix()); + }); + return builder.buildOrThrow(); + } + + @Override + public Component description() { + return this.conversions.asAdventure(asConfigured(this.description, "description")); + } + + public static final class PaperBuilder extends PaperTrimMaterialRegistryEntry implements Builder, PaperRegistryBuilder { + + public PaperBuilder(final Conversions conversions, final @Nullable TrimMaterial internal) { + super(conversions, internal); + } + + @Override + public Builder baseAssetPath(final String baseAssetPath) { + this.baseAssetPath = new MaterialAssetGroup.AssetInfo(asArgument(baseAssetPath, "baseAssetPath")); + return this; + } + + @Override + public Builder assetPathOverrides(final Map assetPathOverrides) { + final Map input = asArgument(assetPathOverrides, "assetPathOverrides"); + if (input.isEmpty()) { + this.assetPathOverrides = Collections.emptyMap(); + } else { + final ImmutableMap.Builder, MaterialAssetGroup.AssetInfo> builder = ImmutableMap.builder(); + input.forEach((key, value) -> { + builder.put(PaperAdventure.asVanilla(EquipmentAssets.ROOT_ID, key), new MaterialAssetGroup.AssetInfo(value)); + }); + this.assetPathOverrides = builder.buildOrThrow(); + } + return this; + } + + @Override + public Builder description(final Component description) { + this.description = this.conversions.asVanilla(asArgument(description, "description")); + return this; + } + + @Override + public TrimMaterial build() { + return new TrimMaterial( + new MaterialAssetGroup( + asConfigured(this.baseAssetPath, "baseAssetPath"), + asConfigured(this.assetPathOverrides, "assetPathOverrides") + ), + asConfigured(this.description, "description") + ); + } + } +} diff --git a/paper-server/src/main/java/io/papermc/paper/registry/data/PaperTrimPatternRegistryEntry.java b/paper-server/src/main/java/io/papermc/paper/registry/data/PaperTrimPatternRegistryEntry.java new file mode 100644 index 0000000000..4391eda9de --- /dev/null +++ b/paper-server/src/main/java/io/papermc/paper/registry/data/PaperTrimPatternRegistryEntry.java @@ -0,0 +1,82 @@ +package io.papermc.paper.registry.data; + +import io.papermc.paper.adventure.PaperAdventure; +import io.papermc.paper.registry.PaperRegistryBuilder; +import io.papermc.paper.registry.data.util.Conversions; +import net.kyori.adventure.key.Key; +import net.kyori.adventure.text.Component; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.equipment.trim.TrimPattern; +import org.jspecify.annotations.Nullable; + +import static io.papermc.paper.registry.data.util.Checks.asArgument; +import static io.papermc.paper.registry.data.util.Checks.asConfigured; + +public class PaperTrimPatternRegistryEntry implements TrimPatternRegistryEntry { + + protected @Nullable ResourceLocation assetId; + protected net.minecraft.network.chat.@Nullable Component description; + protected boolean decal = false; + + protected final Conversions conversions; + + public PaperTrimPatternRegistryEntry(final Conversions conversions, final @Nullable TrimPattern internal) { + this.conversions = conversions; + if (internal == null) { + return; + } + + this.assetId = internal.assetId(); + this.description = internal.description(); + this.decal = internal.decal(); + } + + @Override + public Key assetId() { + return PaperAdventure.asAdventure(asConfigured(this.assetId, "assetId")); + } + + @Override + public Component description() { + return this.conversions.asAdventure(asConfigured(this.description, "description")); + } + + @Override + public boolean decal() { + return this.decal; + } + + public static final class PaperBuilder extends PaperTrimPatternRegistryEntry implements Builder, PaperRegistryBuilder { + + public PaperBuilder(final Conversions conversions, final @Nullable TrimPattern internal) { + super(conversions, internal); + } + + @Override + public Builder assetId(final Key key) { + this.assetId = PaperAdventure.asVanilla(asArgument(key, "assetId")); + return this; + } + + @Override + public Builder description(final Component description) { + this.description = this.conversions.asVanilla(asArgument(description, "description")); + return this; + } + + @Override + public Builder decal(final boolean decal) { + this.decal = decal; + return this; + } + + @Override + public TrimPattern build() { + return new TrimPattern( + asConfigured(this.assetId, "assetId"), + asConfigured(this.description, "description"), + this.decal + ); + } + } +}