33Date: Thu, 13 Jun 2024 22:35:05 +0200
44Subject: [PATCH] Introduce registry entry and builders
55
6+ Co-authored-by: kokiriglade <
[email protected] >
67
78diff --git a/src/main/java/io/papermc/paper/registry/RegistryKey.java b/src/main/java/io/papermc/paper/registry/RegistryKey.java
89index 647f6a1ec1f9d3c203b41f90a99bfd415bf67366..9b39e33514b15a9d07104e2ad826d0da11f569d6 100644
@@ -414,6 +415,147 @@ index 0000000000000000000000000000000000000000..980fe12b75258b51cc2498590cadb9de
414415+ Builder range(@Range(from = 0, to = Integer.MAX_VALUE) int range);
415416+ }
416417+ }
418+ diff --git a/src/main/java/io/papermc/paper/registry/data/PaintingVariantRegistryEntry.java b/src/main/java/io/papermc/paper/registry/data/PaintingVariantRegistryEntry.java
419+ new file mode 100644
420+ index 0000000000000000000000000000000000000000..b8d133afa82da1b5b9e7a18e1c332ae3aefea50d
421+ --- /dev/null
422+ +++ b/src/main/java/io/papermc/paper/registry/data/PaintingVariantRegistryEntry.java
423+ @@ -0,0 +1,135 @@
424+ + package io.papermc.paper.registry.data;
425+ +
426+ + import io.papermc.paper.registry.RegistryBuilder;
427+ + import java.util.Optional;
428+ + import net.kyori.adventure.key.Key;
429+ + import net.kyori.adventure.text.Component;
430+ + import org.bukkit.Art;
431+ + import org.jetbrains.annotations.ApiStatus;
432+ + import org.jetbrains.annotations.Contract;
433+ + import org.jetbrains.annotations.Range;
434+ + import org.jspecify.annotations.NullMarked;
435+ + import org.jspecify.annotations.Nullable;
436+ +
437+ + /**
438+ + * A data-centric version-specific registry entry for the {@link Art} type.
439+ + */
440+ + @ApiStatus.Experimental
441+ + @NullMarked
442+ + @ApiStatus.NonExtendable
443+ + public interface PaintingVariantRegistryEntry {
444+ +
445+ + /**
446+ + * Provides the width of this variant in blocks.
447+ + *
448+ + * @return the width
449+ + * @see Art#getBlockWidth()
450+ + */
451+ + @Range(from = 1, to = 16)
452+ + int width();
453+ +
454+ + /**
455+ + * Provides the height of this variant in blocks.
456+ + *
457+ + * @return the height
458+ + * @see Art#getBlockHeight()
459+ + */
460+ + @Range(from = 1, to = 16)
461+ + int height();
462+ +
463+ + /**
464+ + * Provides the title of the painting visible in the creative inventory.
465+ + *
466+ + * @return the title
467+ + * @see Art#title()
468+ + */
469+ + @Nullable Component title();
470+ +
471+ + /**
472+ + * Provides the author of the painting visible in the creative inventory.
473+ + *
474+ + * @return the author
475+ + * @see Art#author()
476+ + */
477+ + @Nullable Component author();
478+ +
479+ + /**
480+ + * Provides the assetId of the variant, which is the location of the sprite to use.
481+ + *
482+ + * @return the asset id
483+ + * @see Art#assetId()
484+ + */
485+ + Key assetId();
486+ +
487+ + /**
488+ + * A mutable builder for the {@link PaintingVariantRegistryEntry} plugins may change in applicable registry events.
489+ + * <p>
490+ + * The following values are required for each builder:
491+ + * <ul>
492+ + * <li>{@link #width(int)}</li>
493+ + * <li>{@link #height(int)}</li>
494+ + * <li>{@link #assetId(Key)}</li>
495+ + * </ul>
496+ + */
497+ + @ApiStatus.Experimental
498+ + @ApiStatus.NonExtendable
499+ + interface Builder extends PaintingVariantRegistryEntry, RegistryBuilder<Art> {
500+ +
501+ + /**
502+ + * Sets the width of the painting in blocks.
503+ + *
504+ + * @param width the width in blocks
505+ + * @return this builder instance
506+ + * @see PaintingVariantRegistryEntry#width()
507+ + * @see Art#getBlockWidth()
508+ + */
509+ + @Contract(value = "_ -> this", mutates = "this")
510+ + Builder width(@Range(from = 0, to = 16) int width);
511+ +
512+ + /**
513+ + * Sets the height of the painting in blocks.
514+ + *
515+ + * @param height the height in blocks
516+ + * @return this builder instance
517+ + * @see PaintingVariantRegistryEntry#height()
518+ + * @see Art#getBlockHeight()
519+ + */
520+ + @Contract(value = "_ -> this", mutates = "this")
521+ + Builder height(@Range(from = 0, to = 16) int height);
522+ +
523+ + /**
524+ + * Sets the title of the painting.
525+ + *
526+ + * @param title the title
527+ + * @return this builder instance
528+ + * @see PaintingVariantRegistryEntry#title()
529+ + * @see Art#title()
530+ + */
531+ + @Contract(value = "_ -> this", mutates = "this")
532+ + Builder title(@Nullable Component title);
533+ +
534+ + /**
535+ + * Sets the author of the painting.
536+ + *
537+ + * @param author the author
538+ + * @return this builder instance
539+ + * @see PaintingVariantRegistryEntry#author()
540+ + * @see Art#author()
541+ + */
542+ + @Contract(value = "_ -> this", mutates = "this")
543+ + Builder author(@Nullable Component author);
544+ +
545+ + /**
546+ + * Sets the assetId of the variant, which is the location of the sprite to use.
547+ + *
548+ + * @param assetId the asset id
549+ + * @return this builder instance
550+ + * @see PaintingVariantRegistryEntry#assetId()
551+ + * @see Art#assetId()
552+ + */
553+ + @Contract(value = "_ -> this", mutates = "this")
554+ + Builder assetId(Key assetId);
555+ +
556+ + }
557+ +
558+ + }
417559diff --git a/src/main/java/io/papermc/paper/registry/data/package-info.java b/src/main/java/io/papermc/paper/registry/data/package-info.java
418560new file mode 100644
419561index 0000000000000000000000000000000000000000..4f8f536f437c5f483ac7bce393e664fd7bc38477
@@ -430,15 +572,17 @@ index 0000000000000000000000000000000000000000..4f8f536f437c5f483ac7bce393e664fd
430572+ */
431573+ package io.papermc.paper.registry.data;
432574diff --git a/src/main/java/io/papermc/paper/registry/event/RegistryEvents.java b/src/main/java/io/papermc/paper/registry/event/RegistryEvents.java
433- index 91ae9c0d3ec55ce417d4b447bf3d1b0d0c174b5e..1c8e77c7243cfedef6c4d1491cf98e6ec8f1690f 100644
575+ index 91ae9c0d3ec55ce417d4b447bf3d1b0d0c174b5e..40deffbd0930508bb04e9aedfd62ad2144855198 100644
434576--- a/src/main/java/io/papermc/paper/registry/event/RegistryEvents.java
435577+++ b/src/main/java/io/papermc/paper/registry/event/RegistryEvents.java
436- @@ -1,8 +1,15 @@
578+ @@ -1,8 +1,17 @@
437579 package io.papermc.paper.registry.event;
438580
439581+ import io.papermc.paper.registry.RegistryKey;
440582+ import io.papermc.paper.registry.data.EnchantmentRegistryEntry;
441583+ import io.papermc.paper.registry.data.GameEventRegistryEntry;
584+ + import io.papermc.paper.registry.data.PaintingVariantRegistryEntry;
585+ + import org.bukkit.Art;
442586+ import org.bukkit.GameEvent;
443587+ import org.bukkit.enchantments.Enchantment;
444588 import org.jetbrains.annotations.ApiStatus;
@@ -449,12 +593,13 @@ index 91ae9c0d3ec55ce417d4b447bf3d1b0d0c174b5e..1c8e77c7243cfedef6c4d1491cf98e6e
449593 /**
450594 * Holds providers for {@link RegistryEntryAddEvent} and {@link RegistryFreezeEvent}
451595 * handlers for each applicable registry.
452- @@ -11,6 +18,9 @@ import org.jspecify.annotations.NullMarked;
596+ @@ -11,6 +20,10 @@ import org.jspecify.annotations.NullMarked;
453597 @NullMarked
454598 public final class RegistryEvents {
455599
456600+ public static final RegistryEventProvider<GameEvent, GameEventRegistryEntry.Builder> GAME_EVENT = create(RegistryKey.GAME_EVENT);
457601+ public static final RegistryEventProvider<Enchantment, EnchantmentRegistryEntry.Builder> ENCHANTMENT = create(RegistryKey.ENCHANTMENT);
602+ + public static final RegistryEventProvider<Art, PaintingVariantRegistryEntry.Builder> PAINTING_VARIANT = create(RegistryKey.PAINTING_VARIANT);
458603+
459604 private RegistryEvents() {
460605 }
0 commit comments