From 4ebf803df15f10818208475e911aa2cbc18de5cb Mon Sep 17 00:00:00 2001
From: kokiriglade <60290002+celerry@users.noreply.github.com>
Date: Tue, 24 Dec 2024 02:24:32 +0000
Subject: [PATCH] Banner pattern registry modification API
---
.../data/BannerPatternRegistryEntry.java | 67 +++++++++++++++++++
.../paper/registry/PaperRegistries.java | 3 +-
.../data/PaperBannerPatternRegistryEntry.java | 65 ++++++++++++++++++
3 files changed, 134 insertions(+), 1 deletion(-)
create mode 100644 paper-api/src/main/java/io/papermc/paper/registry/data/BannerPatternRegistryEntry.java
create mode 100644 paper-server/src/main/java/io/papermc/paper/registry/data/PaperBannerPatternRegistryEntry.java
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
new file mode 100644
index 0000000000..efdbe890c6
--- /dev/null
+++ b/paper-api/src/main/java/io/papermc/paper/registry/data/BannerPatternRegistryEntry.java
@@ -0,0 +1,67 @@
+package io.papermc.paper.registry.data;
+
+import io.papermc.paper.registry.RegistryBuilder;
+import net.kyori.adventure.key.Key;
+import org.bukkit.block.banner.PatternType;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.Contract;
+import org.jspecify.annotations.NullMarked;
+
+/**
+ * A data-centric version-specific registry entry for the {@link PatternType} type.
+ */
+@ApiStatus.Experimental
+@NullMarked
+@ApiStatus.NonExtendable
+public interface BannerPatternRegistryEntry {
+
+ /**
+ * Provides the asset id of the pattern type, which is the location of the sprite to use.
+ *
+ * @return the asset id.
+ */
+ Key assetId();
+
+ /**
+ * Provides the translation key for displaying the pattern inside the banner's tooltip.
+ *
+ * @return the translation key.
+ */
+ String translationKey();
+
+ /**
+ * A mutable builder for the {@link BannerPatternRegistryEntry} plugins may change in applicable registry events.
+ *
+ * The following values are required for each builder:
+ *
+ * - {@link #assetId(Key)}
+ * - {@link #translationKey(String)}
+ *
+ */
+ @ApiStatus.Experimental
+ @ApiStatus.NonExtendable
+ interface Builder extends BannerPatternRegistryEntry, RegistryBuilder {
+
+ /**
+ * Sets the asset id of the pattern type, which is the location of the sprite to use.
+ *
+ * @param assetId the asset id.
+ * @return this builder instance.
+ * @see BannerPatternRegistryEntry#assetId()
+ */
+ @Contract(value = "_ -> this", mutates = "this")
+ Builder assetId(Key assetId);
+
+ /**
+ * Sets the translation key for displaying the pattern inside the banner's tooltip.
+ *
+ * @param translationKey the translation key.
+ * @return this builder instance.
+ * @see BannerPatternRegistryEntry#translationKey()
+ */
+ @Contract(value = "_ -> this", mutates = "this")
+ Builder translationKey(String translationKey);
+
+ }
+
+}
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 a41356e136..c79981e50e 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
@@ -4,6 +4,7 @@ import com.google.common.base.Preconditions;
import io.papermc.paper.adventure.PaperAdventure;
import io.papermc.paper.datacomponent.DataComponentTypes;
import io.papermc.paper.datacomponent.PaperDataComponentType;
+import io.papermc.paper.registry.data.PaperBannerPatternRegistryEntry;
import io.papermc.paper.registry.data.PaperEnchantmentRegistryEntry;
import io.papermc.paper.registry.data.PaperGameEventRegistryEntry;
import io.papermc.paper.registry.data.PaperPaintingVariantRegistryEntry;
@@ -106,7 +107,7 @@ public final class PaperRegistries {
start(Registries.WOLF_VARIANT, RegistryKey.WOLF_VARIANT).craft(Wolf.Variant.class, CraftWolf.CraftVariant::new).build().delayed(),
start(Registries.ENCHANTMENT, RegistryKey.ENCHANTMENT).craft(Enchantment.class, CraftEnchantment::new).serializationUpdater(FieldRename.ENCHANTMENT_RENAME).writable(PaperEnchantmentRegistryEntry.PaperBuilder::new).delayed(),
start(Registries.JUKEBOX_SONG, RegistryKey.JUKEBOX_SONG).craft(JukeboxSong.class, CraftJukeboxSong::new).build().delayed(),
- start(Registries.BANNER_PATTERN, RegistryKey.BANNER_PATTERN).craft(PatternType.class, CraftPatternType::new).build().delayed(),
+ start(Registries.BANNER_PATTERN, RegistryKey.BANNER_PATTERN).craft(PatternType.class, CraftPatternType::new).writable(PaperBannerPatternRegistryEntry.PaperBuilder::new).delayed(),
start(Registries.PAINTING_VARIANT, RegistryKey.PAINTING_VARIANT).craft(Art.class, CraftArt::new).writable(PaperPaintingVariantRegistryEntry.PaperBuilder::new).delayed(),
start(Registries.INSTRUMENT, RegistryKey.INSTRUMENT).craft(MusicInstrument.class, CraftMusicInstrument::new).build().delayed(),
diff --git a/paper-server/src/main/java/io/papermc/paper/registry/data/PaperBannerPatternRegistryEntry.java b/paper-server/src/main/java/io/papermc/paper/registry/data/PaperBannerPatternRegistryEntry.java
new file mode 100644
index 0000000000..70d226a14a
--- /dev/null
+++ b/paper-server/src/main/java/io/papermc/paper/registry/data/PaperBannerPatternRegistryEntry.java
@@ -0,0 +1,65 @@
+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.minecraft.resources.ResourceLocation;
+import net.minecraft.world.level.block.entity.BannerPattern;
+import org.bukkit.block.banner.PatternType;
+import org.jspecify.annotations.Nullable;
+
+import static io.papermc.paper.registry.data.util.Checks.*;
+
+public class PaperBannerPatternRegistryEntry implements BannerPatternRegistryEntry {
+
+ protected @Nullable ResourceLocation assetId;
+ protected @Nullable String translationKey;
+
+ public PaperBannerPatternRegistryEntry(
+ final Conversions ignoredConversions,
+ final @Nullable BannerPattern internal
+ ) {
+ if (internal == null) return;
+
+ this.assetId = internal.assetId();
+ this.translationKey = internal.translationKey();
+ }
+
+ @Override
+ public Key assetId() {
+ return PaperAdventure.asAdventure(asConfigured(this.assetId, "assetId"));
+ }
+
+ @Override
+ public String translationKey() {
+ return asConfigured(this.translationKey, "translationKey");
+ }
+
+ public static final class PaperBuilder extends PaperBannerPatternRegistryEntry implements Builder, PaperRegistryBuilder {
+
+ public PaperBuilder(final Conversions conversions, final @Nullable BannerPattern internal) {
+ super(conversions, internal);
+ }
+
+ @Override
+ public Builder assetId(final Key assetId) {
+ this.assetId = PaperAdventure.asVanilla(asArgument(assetId, "assetId"));
+ return this;
+ }
+
+ @Override
+ public Builder translationKey(final String translationKey) {
+ this.translationKey = asArgument(translationKey, "translationKey");
+ return this;
+ }
+
+ @Override
+ public BannerPattern build() {
+ return new BannerPattern(
+ asConfigured(this.assetId, "assetId"),
+ this.translationKey()
+ );
+ }
+ }
+}