Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 79 additions & 3 deletions patches/api/0472-Introduce-registry-entry-and-builders.patch
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,79 @@ index 647f6a1ec1f9d3c203b41f90a99bfd415bf67366..9b39e33514b15a9d07104e2ad826d0da
RegistryKey<ItemType> ITEM = create("item");
/**
* Built-in registry for cat variants.
diff --git a/src/main/java/io/papermc/paper/registry/data/BannerPatternRegistryEntry.java b/src/main/java/io/papermc/paper/registry/data/BannerPatternRegistryEntry.java
new file mode 100644
index 0000000000000000000000000000000000000000..efdbe890c6f4a9ef8ef3c0d9985c3fce5a7ef692
--- /dev/null
+++ b/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.
+ */
[email protected]
+@NullMarked
[email protected]
+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.
+ * <p>
+ * The following values are required for each builder:
+ * <ul>
+ * <li>{@link #assetId(Key)}</li>
+ * <li>{@link #translationKey(String)}</li>
+ * </ul>
+ */
+ @ApiStatus.Experimental
+ @ApiStatus.NonExtendable
+ interface Builder extends BannerPatternRegistryEntry, RegistryBuilder<PatternType> {
+
+ /**
+ * 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/src/main/java/io/papermc/paper/registry/data/EnchantmentRegistryEntry.java b/src/main/java/io/papermc/paper/registry/data/EnchantmentRegistryEntry.java
new file mode 100644
index 0000000000000000000000000000000000000000..f092077453cb13dd8d849550896c2ef1cfa81b7a
Expand Down Expand Up @@ -567,18 +640,20 @@ index 0000000000000000000000000000000000000000..4f8f536f437c5f483ac7bce393e664fd
+ */
+package io.papermc.paper.registry.data;
diff --git a/src/main/java/io/papermc/paper/registry/event/RegistryEvents.java b/src/main/java/io/papermc/paper/registry/event/RegistryEvents.java
index 91ae9c0d3ec55ce417d4b447bf3d1b0d0c174b5e..40deffbd0930508bb04e9aedfd62ad2144855198 100644
index 91ae9c0d3ec55ce417d4b447bf3d1b0d0c174b5e..cfda2a7e2ecd826238c28b3267146d9b06ac13b9 100644
--- a/src/main/java/io/papermc/paper/registry/event/RegistryEvents.java
+++ b/src/main/java/io/papermc/paper/registry/event/RegistryEvents.java
@@ -1,8 +1,17 @@
@@ -1,8 +1,19 @@
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.EnchantmentRegistryEntry;
+import io.papermc.paper.registry.data.GameEventRegistryEntry;
+import io.papermc.paper.registry.data.PaintingVariantRegistryEntry;
+import org.bukkit.Art;
+import org.bukkit.GameEvent;
+import org.bukkit.block.banner.PatternType;
+import org.bukkit.enchantments.Enchantment;
import org.jetbrains.annotations.ApiStatus;
import org.jspecify.annotations.NullMarked;
Expand All @@ -588,13 +663,14 @@ index 91ae9c0d3ec55ce417d4b447bf3d1b0d0c174b5e..40deffbd0930508bb04e9aedfd62ad21
/**
* Holds providers for {@link RegistryEntryAddEvent} and {@link RegistryFreezeEvent}
* handlers for each applicable registry.
@@ -11,6 +20,10 @@ import org.jspecify.annotations.NullMarked;
@@ -11,6 +22,11 @@ import org.jspecify.annotations.NullMarked;
@NullMarked
public final class RegistryEvents {

+ public static final RegistryEventProvider<GameEvent, GameEventRegistryEntry.Builder> GAME_EVENT = create(RegistryKey.GAME_EVENT);
+ public static final RegistryEventProvider<Enchantment, EnchantmentRegistryEntry.Builder> ENCHANTMENT = create(RegistryKey.ENCHANTMENT);
+ public static final RegistryEventProvider<Art, PaintingVariantRegistryEntry.Builder> PAINTING_VARIANT = create(RegistryKey.PAINTING_VARIANT);
+ public static final RegistryEventProvider<PatternType, BannerPatternRegistryEntry.Builder> BANNER_PATTERN = create(RegistryKey.BANNER_PATTERN);
+
private RegistryEvents() {
}
Expand Down
87 changes: 82 additions & 5 deletions patches/server/0991-Add-registry-entry-and-builders.patch
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@ Subject: [PATCH] Add registry entry and builders

Feature patch

Co-authored-by: kokiriglade <[email protected]>

diff --git a/src/main/java/io/papermc/paper/registry/PaperRegistries.java b/src/main/java/io/papermc/paper/registry/PaperRegistries.java
index 86c9f87cdb41c0d1ccc2a61b501f969cfaae47bc..fd024576e70e0c121c1477a0b7777af18159b7c4 100644
index 86c9f87cdb41c0d1ccc2a61b501f969cfaae47bc..3c47207d9781ac5005d5ac15bdb885add7e66240 100644
--- a/src/main/java/io/papermc/paper/registry/PaperRegistries.java
+++ b/src/main/java/io/papermc/paper/registry/PaperRegistries.java
@@ -2,6 +2,9 @@ package io.papermc.paper.registry;
@@ -2,6 +2,10 @@ package io.papermc.paper.registry;

import com.google.common.base.Preconditions;
import io.papermc.paper.adventure.PaperAdventure;
+import io.papermc.paper.registry.data.PaperEnchantmentRegistryEntry;
+import io.papermc.paper.registry.data.PaperGameEventRegistryEntry;
+import io.papermc.paper.registry.data.PaperPaintingVariantRegistryEntry;
+import io.papermc.paper.registry.data.PaperBannerPatternRegistryEntry;
import io.papermc.paper.registry.entry.RegistryEntry;
import io.papermc.paper.registry.tag.TagKey;
import java.util.Collections;
@@ -78,7 +81,7 @@ public final class PaperRegistries {
@@ -78,7 +82,7 @@ public final class PaperRegistries {
static {
REGISTRY_ENTRIES = List.of(
// built-ins
Expand All @@ -28,19 +31,93 @@ index 86c9f87cdb41c0d1ccc2a61b501f969cfaae47bc..fd024576e70e0c121c1477a0b7777af1
entry(Registries.STRUCTURE_TYPE, RegistryKey.STRUCTURE_TYPE, StructureType.class, CraftStructureType::new),
entry(Registries.MOB_EFFECT, RegistryKey.MOB_EFFECT, PotionEffectType.class, CraftPotionEffectType::new),
entry(Registries.BLOCK, RegistryKey.BLOCK, BlockType.class, CraftBlockType::new),
@@ -100,10 +103,10 @@ public final class PaperRegistries {
@@ -100,10 +104,10 @@ public final class PaperRegistries {
entry(Registries.TRIM_PATTERN, RegistryKey.TRIM_PATTERN, TrimPattern.class, CraftTrimPattern::new).delayed(),
entry(Registries.DAMAGE_TYPE, RegistryKey.DAMAGE_TYPE, DamageType.class, CraftDamageType::new).delayed(),
entry(Registries.WOLF_VARIANT, RegistryKey.WOLF_VARIANT, Wolf.Variant.class, CraftWolf.CraftVariant::new).delayed(),
- entry(Registries.ENCHANTMENT, RegistryKey.ENCHANTMENT, Enchantment.class, CraftEnchantment::new).withSerializationUpdater(FieldRename.ENCHANTMENT_RENAME).delayed(),
+ writable(Registries.ENCHANTMENT, RegistryKey.ENCHANTMENT, Enchantment.class, CraftEnchantment::new, PaperEnchantmentRegistryEntry.PaperBuilder::new).withSerializationUpdater(FieldRename.ENCHANTMENT_RENAME).delayed(),
entry(Registries.JUKEBOX_SONG, RegistryKey.JUKEBOX_SONG, JukeboxSong.class, CraftJukeboxSong::new).delayed(),
entry(Registries.BANNER_PATTERN, RegistryKey.BANNER_PATTERN, PatternType.class, CraftPatternType::new).delayed(),
- entry(Registries.BANNER_PATTERN, RegistryKey.BANNER_PATTERN, PatternType.class, CraftPatternType::new).delayed(),
- entry(Registries.PAINTING_VARIANT, RegistryKey.PAINTING_VARIANT, Art.class, CraftArt::new).delayed(),
+ writable(Registries.BANNER_PATTERN, RegistryKey.BANNER_PATTERN, PatternType.class, CraftPatternType::new, PaperBannerPatternRegistryEntry.PaperBuilder::new).delayed(),
+ writable(Registries.PAINTING_VARIANT, RegistryKey.PAINTING_VARIANT, Art.class, CraftArt::new, PaperPaintingVariantRegistryEntry.PaperBuilder::new).delayed(),
entry(Registries.INSTRUMENT, RegistryKey.INSTRUMENT, MusicInstrument.class, CraftMusicInstrument::new).delayed(),

// api-only
diff --git a/src/main/java/io/papermc/paper/registry/data/PaperBannerPatternRegistryEntry.java b/src/main/java/io/papermc/paper/registry/data/PaperBannerPatternRegistryEntry.java
new file mode 100644
index 0000000000000000000000000000000000000000..6271aa3bc5961a824a6c0f4f5bb0a76b13e137e8
--- /dev/null
+++ b/src/main/java/io/papermc/paper/registry/data/PaperBannerPatternRegistryEntry.java
@@ -0,0 +1,67 @@
+package io.papermc.paper.registry.data;
+
+import io.papermc.paper.adventure.PaperAdventure;
+import io.papermc.paper.registry.PaperRegistryBuilder;
+import io.papermc.paper.registry.TypedKey;
+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 TypedKey<PatternType> ignoredKey,
+ 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<BannerPattern, PatternType> {
+
+ public PaperBuilder(final Conversions conversions, final TypedKey<PatternType> key, final @Nullable BannerPattern nms) {
+ super(conversions, key, nms);
+ }
+
+ @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()
+ );
+ }
+ }
+}
diff --git a/src/main/java/io/papermc/paper/registry/data/PaperEnchantmentRegistryEntry.java b/src/main/java/io/papermc/paper/registry/data/PaperEnchantmentRegistryEntry.java
new file mode 100644
index 0000000000000000000000000000000000000000..1b1c6838452d3001070a5d43cc49e3a09de7153d
Expand Down
2 changes: 1 addition & 1 deletion patches/server/1033-DataComponent-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -3600,7 +3600,7 @@ index fd024576e70e0c121c1477a0b7777af18159b7c4..132afec6bceb6c866de0aeb83db9613d
import io.papermc.paper.registry.data.PaperEnchantmentRegistryEntry;
import io.papermc.paper.registry.data.PaperGameEventRegistryEntry;
import io.papermc.paper.registry.data.PaperPaintingVariantRegistryEntry;
@@ -95,6 +97,7 @@ public final class PaperRegistries {
@@ -96,6 +98,7 @@ public final class PaperRegistries {
entry(Registries.ATTRIBUTE, RegistryKey.ATTRIBUTE, Attribute.class, CraftAttribute::new),
entry(Registries.FLUID, RegistryKey.FLUID, Fluid.class, CraftFluid::new),
entry(Registries.SOUND_EVENT, RegistryKey.SOUND_EVENT, Sound.class, CraftSound::new),
Expand Down
Loading