Fix painting variant builder (#11660)

This commit is contained in:
Lulu13022002 2024-11-24 20:12:08 +01:00
parent bbe32f42f0
commit 8e2102c70b
6 changed files with 79 additions and 137 deletions

View File

@ -3589,7 +3589,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ +
+ ConsumeEffect.ApplyStatusEffects applyStatusEffects(List<PotionEffect> effectList, float probability); + ConsumeEffect.ApplyStatusEffects applyStatusEffects(List<PotionEffect> effectList, float probability);
+ +
+ ConsumeEffect.RemoveStatusEffects removeStatusEffects(RegistryKeySet<PotionEffectType> potionEffectTypeTagKey); + ConsumeEffect.RemoveStatusEffects removeStatusEffects(RegistryKeySet<PotionEffectType> effectTypes);
+ +
+ ConsumeEffect.ClearAllStatusEffects clearAllStatusEffects(); + ConsumeEffect.ClearAllStatusEffects clearAllStatusEffects();
+ +

View File

@ -177,7 +177,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * sharpness enchantment. + * sharpness enchantment.
+ * + *
+ * @param description the description component. + * @param description the description component.
+ * @return this builder. + * @return this builder instance.
+ */ + */
+ @Contract(value = "_ -> this", mutates = "this") + @Contract(value = "_ -> this", mutates = "this")
+ Builder description(Component description); + Builder description(Component description);
@ -191,7 +191,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * {@link io.papermc.paper.registry.keys.tags.ItemTypeTagKeys#ENCHANTABLE_SWORD}. + * {@link io.papermc.paper.registry.keys.tags.ItemTypeTagKeys#ENCHANTABLE_SWORD}.
+ * + *
+ * @param supportedItems the registry key set representing the supported items. + * @param supportedItems the registry key set representing the supported items.
+ * @return this builder. + * @return this builder instance.
+ * @see RegistrySet#keySet(RegistryKey, TypedKey[]) + * @see RegistrySet#keySet(RegistryKey, TypedKey[])
+ * @see io.papermc.paper.registry.event.RegistryFreezeEvent#getOrCreateTag(TagKey) + * @see io.papermc.paper.registry.event.RegistryFreezeEvent#getOrCreateTag(TagKey)
+ */ + */
@ -212,7 +212,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * which enchantments can even show up in an enchantment table. + * which enchantments can even show up in an enchantment table.
+ * + *
+ * @param primaryItems the registry key set representing the primary items. + * @param primaryItems the registry key set representing the primary items.
+ * @return this builder. + * @return this builder instance.
+ * @see RegistrySet#keySet(RegistryKey, TypedKey[]) + * @see RegistrySet#keySet(RegistryKey, TypedKey[])
+ * @see io.papermc.paper.registry.event.RegistryFreezeEvent#getOrCreateTag(TagKey) + * @see io.papermc.paper.registry.event.RegistryFreezeEvent#getOrCreateTag(TagKey)
+ */ + */
@ -223,7 +223,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * Configures the weight of this enchantment used by the weighted random when selecting enchantments. + * Configures the weight of this enchantment used by the weighted random when selecting enchantments.
+ * + *
+ * @param weight the weight value. + * @param weight the weight value.
+ * @return this builder. + * @return this builder instance.
+ * @see <a href="https://minecraft.wiki/w/Enchanting">https://minecraft.wiki/w/Enchanting</a> for examplary weights. + * @see <a href="https://minecraft.wiki/w/Enchanting">https://minecraft.wiki/w/Enchanting</a> for examplary weights.
+ */ + */
+ @Contract(value = "_ -> this", mutates = "this") + @Contract(value = "_ -> this", mutates = "this")
@ -233,7 +233,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * Configures the maximum level this enchantment can have when applied. + * Configures the maximum level this enchantment can have when applied.
+ * + *
+ * @param maxLevel the maximum level. + * @param maxLevel the maximum level.
+ * @return this builder. + * @return this builder instance.
+ */ + */
+ @Contract(value = "_ -> this", mutates = "this") + @Contract(value = "_ -> this", mutates = "this")
+ Builder maxLevel(@Range(from = 1, to = 255) int maxLevel); + Builder maxLevel(@Range(from = 1, to = 255) int maxLevel);
@ -244,7 +244,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * Note that a cost is not directly related to the consumed xp. + * Note that a cost is not directly related to the consumed xp.
+ * + *
+ * @param minimumCost the enchantment cost. + * @param minimumCost the enchantment cost.
+ * @return this builder. + * @return this builder instance.
+ * @see <a href="https://minecraft.wiki/w/Enchanting/Levels">https://minecraft.wiki/w/Enchanting/Levels</a> for + * @see <a href="https://minecraft.wiki/w/Enchanting/Levels">https://minecraft.wiki/w/Enchanting/Levels</a> for
+ * examplary costs. + * examplary costs.
+ */ + */
@ -257,7 +257,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * Note that a cost is not directly related to the consumed xp. + * Note that a cost is not directly related to the consumed xp.
+ * + *
+ * @param maximumCost the enchantment cost. + * @param maximumCost the enchantment cost.
+ * @return this builder. + * @return this builder instance.
+ * @see <a href="https://minecraft.wiki/w/Enchanting/Levels">https://minecraft.wiki/w/Enchanting/Levels</a> for + * @see <a href="https://minecraft.wiki/w/Enchanting/Levels">https://minecraft.wiki/w/Enchanting/Levels</a> for
+ * examplary costs. + * examplary costs.
+ */ + */
@ -272,7 +272,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * </p> + * </p>
+ * + *
+ * @param anvilCost the anvil cost of this enchantment + * @param anvilCost the anvil cost of this enchantment
+ * @return this builder. + * @return this builder instance.
+ * @see Enchantment#getAnvilCost() + * @see Enchantment#getAnvilCost()
+ */ + */
+ @Contract(value = "_ -> this", mutates = "this") + @Contract(value = "_ -> this", mutates = "this")
@ -285,7 +285,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * groups, the enchantment's effects, like attribute modifiers, will not activate. + * groups, the enchantment's effects, like attribute modifiers, will not activate.
+ * + *
+ * @param activeSlots a list of equipment slot groups. + * @param activeSlots a list of equipment slot groups.
+ * @return this builder. + * @return this builder instance.
+ * @see Enchantment#getActiveSlotGroups() + * @see Enchantment#getActiveSlotGroups()
+ */ + */
+ @Contract(value = "_ -> this", mutates = "this") + @Contract(value = "_ -> this", mutates = "this")
@ -300,7 +300,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * groups, the enchantment's effects, like attribute modifiers, will not activate. + * groups, the enchantment's effects, like attribute modifiers, will not activate.
+ * + *
+ * @param activeSlots a list of equipment slot groups. + * @param activeSlots a list of equipment slot groups.
+ * @return this builder. + * @return this builder instance.
+ * @see Enchantment#getActiveSlotGroups() + * @see Enchantment#getActiveSlotGroups()
+ */ + */
+ @Contract(value = "_ -> this", mutates = "this") + @Contract(value = "_ -> this", mutates = "this")
@ -315,7 +315,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ * Defaults to an empty set allowing this enchantment to be applied regardless of other enchantments. + * Defaults to an empty set allowing this enchantment to be applied regardless of other enchantments.
+ * + *
+ * @param exclusiveWith a registry set of enchantments exclusive to this one. + * @param exclusiveWith a registry set of enchantments exclusive to this one.
+ * @return this builder. + * @return this builder instance.
+ * @see RegistrySet#keySet(RegistryKey, TypedKey[]) + * @see RegistrySet#keySet(RegistryKey, TypedKey[])
+ * @see io.papermc.paper.registry.event.RegistryFreezeEvent#getOrCreateTag(TagKey) + * @see io.papermc.paper.registry.event.RegistryFreezeEvent#getOrCreateTag(TagKey)
+ */ + */
@ -358,7 +358,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ return new Impl(baseCost, additionalPerLevelCost); + return new Impl(baseCost, additionalPerLevelCost);
+ } + }
+ } + }
+
+} +}
diff --git a/src/main/java/io/papermc/paper/registry/data/GameEventRegistryEntry.java b/src/main/java/io/papermc/paper/registry/data/GameEventRegistryEntry.java diff --git a/src/main/java/io/papermc/paper/registry/data/GameEventRegistryEntry.java b/src/main/java/io/papermc/paper/registry/data/GameEventRegistryEntry.java
new file mode 100644 new file mode 100644
@ -443,27 +442,25 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+public interface PaintingVariantRegistryEntry { +public interface PaintingVariantRegistryEntry {
+ +
+ /** + /**
+ * Provides the width of this variant in blocks. + * Provides the width of this painting in blocks.
+ * + *
+ * @return the width + * @return the width.
+ * @see Art#getBlockWidth() + * @see Art#getBlockWidth()
+ */ + */
+ @Range(from = 1, to = 16) + @Range(from = 1, to = 16) int width();
+ int width();
+ +
+ /** + /**
+ * Provides the height of this variant in blocks. + * Provides the height of this painting in blocks.
+ * + *
+ * @return the height + * @return the height.
+ * @see Art#getBlockHeight() + * @see Art#getBlockHeight()
+ */ + */
+ @Range(from = 1, to = 16) + @Range(from = 1, to = 16) int height();
+ int height();
+ +
+ /** + /**
+ * Provides the title of the painting visible in the creative inventory. + * Provides the title of the painting visible in the creative inventory.
+ * + *
+ * @return the title + * @return the title.
+ * @see Art#title() + * @see Art#title()
+ */ + */
+ @Nullable Component title(); + @Nullable Component title();
@ -471,15 +468,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ /** + /**
+ * Provides the author of the painting visible in the creative inventory. + * Provides the author of the painting visible in the creative inventory.
+ * + *
+ * @return the author + * @return the author.
+ * @see Art#author() + * @see Art#author()
+ */ + */
+ @Nullable Component author(); + @Nullable Component author();
+ +
+ /** + /**
+ * Provides the assetId of the variant, which is the location of the sprite to use. + * Provides the asset id of the painting, which is the location of the sprite to use.
+ * + *
+ * @return the asset id + * @return the asset id.
+ * @see Art#assetId() + * @see Art#assetId()
+ */ + */
+ Key assetId(); + Key assetId();
@ -501,30 +498,30 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ /** + /**
+ * Sets the width of the painting in blocks. + * Sets the width of the painting in blocks.
+ * + *
+ * @param width the width in blocks + * @param width the width in blocks.
+ * @return this builder instance + * @return this builder instance.
+ * @see PaintingVariantRegistryEntry#width() + * @see PaintingVariantRegistryEntry#width()
+ * @see Art#getBlockWidth() + * @see Art#getBlockWidth()
+ */ + */
+ @Contract(value = "_ -> this", mutates = "this") + @Contract(value = "_ -> this", mutates = "this")
+ Builder width(@Range(from = 0, to = 16) int width); + Builder width(@Range(from = 1, to = 16) int width);
+ +
+ /** + /**
+ * Sets the height of the painting in blocks. + * Sets the height of the painting in blocks.
+ * + *
+ * @param height the height in blocks + * @param height the height in blocks.
+ * @return this builder instance + * @return this builder instance.
+ * @see PaintingVariantRegistryEntry#height() + * @see PaintingVariantRegistryEntry#height()
+ * @see Art#getBlockHeight() + * @see Art#getBlockHeight()
+ */ + */
+ @Contract(value = "_ -> this", mutates = "this") + @Contract(value = "_ -> this", mutates = "this")
+ Builder height(@Range(from = 0, to = 16) int height); + Builder height(@Range(from = 1, to = 16) int height);
+ +
+ /** + /**
+ * Sets the title of the painting. + * Sets the title of the painting.
+ * + *
+ * @param title the title + * @param title the title.
+ * @return this builder instance + * @return this builder instance.
+ * @see PaintingVariantRegistryEntry#title() + * @see PaintingVariantRegistryEntry#title()
+ * @see Art#title() + * @see Art#title()
+ */ + */
@ -534,8 +531,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ /** + /**
+ * Sets the author of the painting. + * Sets the author of the painting.
+ * + *
+ * @param author the author + * @param author the author.
+ * @return this builder instance + * @return this builder instance.
+ * @see PaintingVariantRegistryEntry#author() + * @see PaintingVariantRegistryEntry#author()
+ * @see Art#author() + * @see Art#author()
+ */ + */
@ -543,18 +540,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ Builder author(@Nullable Component author); + Builder author(@Nullable Component author);
+ +
+ /** + /**
+ * Sets the assetId of the variant, which is the location of the sprite to use. + * Sets the asset id of the painting, which is the location of the sprite to use.
+ * + *
+ * @param assetId the asset id + * @param assetId the asset id.
+ * @return this builder instance + * @return this builder instance.
+ * @see PaintingVariantRegistryEntry#assetId() + * @see PaintingVariantRegistryEntry#assetId()
+ * @see Art#assetId() + * @see Art#assetId()
+ */ + */
+ @Contract(value = "_ -> this", mutates = "this") + @Contract(value = "_ -> this", mutates = "this")
+ Builder assetId(Key assetId); + Builder assetId(Key assetId);
+
+ } + }
+
+} +}
diff --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 diff --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
new file mode 100644 new file mode 100644

View File

@ -309,11 +309,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ public PaperGameEventRegistryEntry( + public PaperGameEventRegistryEntry(
+ final Conversions ignoredConversions, + final Conversions ignoredConversions,
+ final io.papermc.paper.registry.TypedKey<org.bukkit.GameEvent> ignoredKey, + final io.papermc.paper.registry.TypedKey<org.bukkit.GameEvent> ignoredKey,
+ final @Nullable GameEvent nms + final @Nullable GameEvent internal
+ ) { + ) {
+ if (nms == null) return; + if (internal == null) return;
+ +
+ this.range = OptionalInt.of(nms.notificationRadius()); + this.range = OptionalInt.of(internal.notificationRadius());
+ } + }
+ +
+ @Override + @Override
@ -327,9 +327,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ public PaperBuilder( + public PaperBuilder(
+ final Conversions conversions, + final Conversions conversions,
+ final io.papermc.paper.registry.TypedKey<org.bukkit.GameEvent> key, + final io.papermc.paper.registry.TypedKey<org.bukkit.GameEvent> key,
+ final @Nullable GameEvent nms + final @Nullable GameEvent internal
+ ) { + ) {
+ super(conversions, key, nms); + super(conversions, key, internal);
+ } + }
+ +
+ @Override + @Override
@ -385,16 +385,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ public PaperPaintingVariantRegistryEntry( + public PaperPaintingVariantRegistryEntry(
+ final Conversions conversions, + final Conversions conversions,
+ final TypedKey<Art> ignoredKey, + final TypedKey<Art> ignoredKey,
+ final @Nullable PaintingVariant nms + final @Nullable PaintingVariant internal
+ ) { + ) {
+ this.conversions = conversions; + this.conversions = conversions;
+ if(nms == null) return; + if (internal == null) return;
+ +
+ this.width = OptionalInt.of(nms.width()); + this.width = OptionalInt.of(internal.width());
+ this.height = OptionalInt.of(nms.height()); + this.height = OptionalInt.of(internal.height());
+ this.title = nms.title().orElse(null); + this.title = internal.title().orElse(null);
+ this.author = nms.title().orElse(null); + this.author = internal.author().orElse(null);
+ this.assetId = nms.assetId(); + this.assetId = internal.assetId();
+ } + }
+ +
+ @Override + @Override
@ -424,18 +424,18 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ +
+ public static final class PaperBuilder extends PaperPaintingVariantRegistryEntry implements PaintingVariantRegistryEntry.Builder, PaperRegistryBuilder<PaintingVariant, Art> { + public static final class PaperBuilder extends PaperPaintingVariantRegistryEntry implements PaintingVariantRegistryEntry.Builder, PaperRegistryBuilder<PaintingVariant, Art> {
+ +
+ public PaperBuilder(final Conversions conversions, final TypedKey<Art> key, final @Nullable PaintingVariant nms) { + public PaperBuilder(final Conversions conversions, final TypedKey<Art> key, final @Nullable PaintingVariant internal) {
+ super(conversions, key, nms); + super(conversions, key, internal);
+ } + }
+ +
+ @Override + @Override
+ public Builder width(@Range(from = 0, to = 16) final int width) { + public Builder width(final @Range(from = 1, to = 16) int width) {
+ this.width = OptionalInt.of(asArgumentRange(width, "width", 1, 16)); + this.width = OptionalInt.of(asArgumentRange(width, "width", 1, 16));
+ return this; + return this;
+ } + }
+ +
+ @Override + @Override
+ public Builder height(@Range(from = 0, to = 16) final int height) { + public Builder height(final @Range(from = 1, to = 16) int height) {
+ this.height = OptionalInt.of(asArgumentRange(height, "height", 1, 16)); + this.height = OptionalInt.of(asArgumentRange(height, "height", 1, 16));
+ return this; + return this;
+ } + }
@ -573,44 +573,3 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
@NotNull @NotNull
@Override @Override
public NamespacedKey getKey() { public NamespacedKey getKey() {
diff --git a/src/test/java/io/papermc/paper/registry/RegistryBuilderTest.java b/src/test/java/io/papermc/paper/registry/RegistryBuilderTest.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/test/java/io/papermc/paper/registry/RegistryBuilderTest.java
+++ b/src/test/java/io/papermc/paper/registry/RegistryBuilderTest.java
@@ -0,0 +0,0 @@
package io.papermc.paper.registry;
+import io.papermc.paper.registry.data.PaperEnchantmentRegistryEntry;
+import io.papermc.paper.registry.data.PaperGameEventRegistryEntry;
import io.papermc.paper.registry.data.util.Conversions;
import java.util.List;
import java.util.Map;
import net.minecraft.core.Registry;
+import net.minecraft.core.registries.Registries;
import net.minecraft.resources.RegistryOps;
import net.minecraft.resources.ResourceKey;
+import net.minecraft.world.item.enchantment.Enchantment;
+import net.minecraft.world.level.gameevent.GameEvent;
import org.bukkit.support.RegistryHelper;
import org.bukkit.support.environment.AllFeatures;
import org.junit.jupiter.api.Disabled;
@@ -0,0 +0,0 @@ import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.params.provider.Arguments.arguments;
@AllFeatures
class RegistryBuilderTest {
static List<Arguments> registries() {
return List.of(
+ arguments(Registries.ENCHANTMENT, (PaperRegistryBuilder.Filler<Enchantment, org.bukkit.enchantments.Enchantment, PaperEnchantmentRegistryEntry.PaperBuilder>) PaperEnchantmentRegistryEntry.PaperBuilder::new),
+ arguments(Registries.GAME_EVENT, (PaperRegistryBuilder.Filler<GameEvent, org.bukkit.GameEvent, PaperGameEventRegistryEntry.PaperBuilder>) PaperGameEventRegistryEntry.PaperBuilder::new)
);
}
- @Disabled
@ParameterizedTest
@MethodSource("registries")
<M, T> void testEquality(final ResourceKey<? extends Registry<M>> resourceKey, final PaperRegistryBuilder.Filler<M, T, ?> filler) {

View File

@ -1533,7 +1533,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ static final class BuilderImpl implements ItemAdventurePredicate.Builder { + static final class BuilderImpl implements ItemAdventurePredicate.Builder {
+ +
+ private final List<net.minecraft.advancements.critereon.BlockPredicate> predicates = new ObjectArrayList<>(); + private final List<net.minecraft.advancements.critereon.BlockPredicate> predicates = new ObjectArrayList<>();
+ private boolean showInTooltip = net.minecraft.world.item.component.ItemAttributeModifiers.EMPTY.showInTooltip(); + private boolean showInTooltip = true;
+ +
+ @Override + @Override
+ public ItemAdventurePredicate.Builder addPredicate(final BlockPredicate predicate) { + public ItemAdventurePredicate.Builder addPredicate(final BlockPredicate predicate) {
@ -3349,10 +3349,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ } + }
+ +
+ @Override + @Override
+ public ConsumeEffect.RemoveStatusEffects removeStatusEffects(final RegistryKeySet<PotionEffectType> potionEffectTypeTagKey) { + public ConsumeEffect.RemoveStatusEffects removeStatusEffects(final RegistryKeySet<PotionEffectType> effectTypes) {
+ return new PaperRemoveStatusEffects( + return new PaperRemoveStatusEffects(
+ new net.minecraft.world.item.consume_effects.RemoveStatusEffectsConsumeEffect( + new net.minecraft.world.item.consume_effects.RemoveStatusEffectsConsumeEffect(
+ PaperRegistrySets.convertToNms(Registries.MOB_EFFECT, BuiltInRegistries.BUILT_IN_CONVERSIONS.lookup(), potionEffectTypeTagKey) + PaperRegistrySets.convertToNms(Registries.MOB_EFFECT, BuiltInRegistries.BUILT_IN_CONVERSIONS.lookup(), effectTypes)
+ ) + )
+ ); + );
+ } + }

View File

@ -8,45 +8,25 @@ diff --git a/src/main/java/org/bukkit/craftbukkit/CraftArt.java b/src/main/java/
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftArt.java --- a/src/main/java/org/bukkit/craftbukkit/CraftArt.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftArt.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftArt.java
@@ -0,0 +0,0 @@ public class CraftArt implements Art, Handleable<PaintingVariant> {
private final NamespacedKey key;
private final PaintingVariant paintingVariant;
+ private final net.kyori.adventure.text.@org.jspecify.annotations.Nullable Component adventureTitle; // Paper - name and author components, assetId key
+ private final net.kyori.adventure.text.@org.jspecify.annotations.Nullable Component adventureAuthor; // Paper - name and author components, assetId key
+ private final net.kyori.adventure.key.@org.jspecify.annotations.NonNull Key adventureAssetId; // Paper - name and author components, assetId key
private final String name;
private final int ordinal;
@@ -0,0 +0,0 @@ public class CraftArt implements Art, Handleable<PaintingVariant> {
this.name = key.toString();
}
this.ordinal = CraftArt.count++;
+ this.adventureTitle = paintingVariant.title().map(io.papermc.paper.adventure.PaperAdventure::asAdventure).orElse(null); // Paper - name and author components, assetId key
+ this.adventureAuthor = paintingVariant.author().map(io.papermc.paper.adventure.PaperAdventure::asAdventure).orElse(null); // Paper - name and author components, assetId key
+ this.adventureAssetId = io.papermc.paper.adventure.PaperAdventure.asAdventure(paintingVariant.assetId()); // Paper - name and author components, assetId key
}
@Override
@@ -0,0 +0,0 @@ public class CraftArt implements Art, Handleable<PaintingVariant> { @@ -0,0 +0,0 @@ public class CraftArt implements Art, Handleable<PaintingVariant> {
return this.paintingVariant.height(); return this.paintingVariant.height();
} }
+ // Paper start - name and author components, assetId key + // Paper start - Expand Art API
+ @Override + @Override
+ public net.kyori.adventure.text.@org.jetbrains.annotations.Nullable Component title() { + public net.kyori.adventure.text.Component title() {
+ return this.adventureTitle; + return this.paintingVariant.title().map(io.papermc.paper.adventure.PaperAdventure::asAdventure).orElse(null);
+ } + }
+ +
+ @Override + @Override
+ public net.kyori.adventure.text.@org.jetbrains.annotations.Nullable Component author() { + public net.kyori.adventure.text.Component author() {
+ return this.adventureAuthor; + return this.paintingVariant.author().map(io.papermc.paper.adventure.PaperAdventure::asAdventure).orElse(null);
+ } + }
+ +
+ public net.kyori.adventure.key.@org.jspecify.annotations.NonNull Key assetId() { + public net.kyori.adventure.key.Key assetId() {
+ return this.adventureAssetId; + return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.paintingVariant.assetId());
+ } + }
+ // Paper end - name and author components, assetId key + // Paper end - Expand Art API
+ +
@Override @Override
public int getId() { public int getId() {

View File

@ -1413,14 +1413,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+package io.papermc.paper.registry; +package io.papermc.paper.registry;
+ +
+import io.papermc.paper.registry.data.util.Conversions; +import io.papermc.paper.registry.data.util.Conversions;
+import java.util.List; +import io.papermc.paper.registry.entry.RegistryEntry;
+import io.papermc.paper.registry.entry.RegistryEntryInfo;
+import io.papermc.paper.registry.legacy.DelayedRegistryEntry;
+import java.util.Map; +import java.util.Map;
+import java.util.stream.Stream;
+import net.minecraft.core.Registry; +import net.minecraft.core.Registry;
+import net.minecraft.resources.RegistryOps; +import net.minecraft.resources.RegistryOps;
+import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceKey;
+import org.bukkit.Keyed;
+import org.bukkit.support.RegistryHelper; +import org.bukkit.support.RegistryHelper;
+import org.bukkit.support.environment.AllFeatures; +import org.bukkit.support.environment.AllFeatures;
+import org.junit.jupiter.api.Disabled;
+import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.Arguments;
+import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.MethodSource;
@ -1430,18 +1433,23 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+@AllFeatures +@AllFeatures
+class RegistryBuilderTest { +class RegistryBuilderTest {
+ +
+ static List<Arguments> registries() { + static Stream<Arguments> registries() {
+ return List.of( + return PaperRegistries.REGISTRY_ENTRIES.stream()
+ ); + .map(RegistryBuilderTest::possiblyUnwrap)
+ .filter(RegistryEntry.BuilderHolder.class::isInstance)
+ .map(Arguments::arguments);
+ }
+
+ private static <M, B extends Keyed> RegistryEntryInfo<M, B> possiblyUnwrap(final RegistryEntryInfo<M, B> entry) {
+ return entry instanceof final DelayedRegistryEntry<M, B> delayed ? delayed.delegate() : entry;
+ } + }
+ +
+ @Disabled
+ @ParameterizedTest + @ParameterizedTest
+ @MethodSource("registries") + @MethodSource("registries")
+ <M, T> void testEquality(final ResourceKey<? extends Registry<M>> resourceKey, final PaperRegistryBuilder.Filler<M, T, ?> filler) { + <M, T> void testEquality(final RegistryEntry.BuilderHolder<M, T, ?> registryEntry) {
+ final Registry<M> registry = RegistryHelper.getRegistry().lookupOrThrow(resourceKey); + final Registry<M> registry = RegistryHelper.getRegistry().lookupOrThrow(registryEntry.mcKey());
+ for (final Map.Entry<ResourceKey<M>, M> entry : registry.entrySet()) { + for (final Map.Entry<ResourceKey<M>, M> entry : registry.entrySet()) {
+ final M built = filler.fill(new Conversions(new RegistryOps.HolderLookupAdapter(RegistryHelper.getRegistry())), PaperRegistries.fromNms(entry.getKey()), entry.getValue()).build(); + final M built = registryEntry.fillBuilder(new Conversions(new RegistryOps.HolderLookupAdapter(RegistryHelper.getRegistry())), PaperRegistries.fromNms(entry.getKey()), entry.getValue()).build();
+ assertEquals(entry.getValue(), built); + assertEquals(entry.getValue(), built);
+ } + }
+ } + }