From 8e2102c70b49f341663d8fa6c80a973998de1c6f Mon Sep 17 00:00:00 2001 From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> Date: Sun, 24 Nov 2024 20:12:08 +0100 Subject: [PATCH] Fix painting variant builder (#11660) --- patches/api/DataComponent-API.patch | 2 +- ...ntroduce-registry-entry-and-builders.patch | 73 +++++++++---------- .../Add-registry-entry-and-builders.patch | 73 ++++--------------- patches/server/DataComponent-API.patch | 6 +- patches/server/Expanded-Art-API.patch | 36 ++------- .../server/Registry-Modification-API.patch | 26 ++++--- 6 files changed, 79 insertions(+), 137 deletions(-) diff --git a/patches/api/DataComponent-API.patch b/patches/api/DataComponent-API.patch index c5c319ef51..0a838cc6f7 100644 --- a/patches/api/DataComponent-API.patch +++ b/patches/api/DataComponent-API.patch @@ -3589,7 +3589,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + ConsumeEffect.ApplyStatusEffects applyStatusEffects(List effectList, float probability); + -+ ConsumeEffect.RemoveStatusEffects removeStatusEffects(RegistryKeySet potionEffectTypeTagKey); ++ ConsumeEffect.RemoveStatusEffects removeStatusEffects(RegistryKeySet effectTypes); + + ConsumeEffect.ClearAllStatusEffects clearAllStatusEffects(); + diff --git a/patches/api/Introduce-registry-entry-and-builders.patch b/patches/api/Introduce-registry-entry-and-builders.patch index e345a913fc..6d708cc46d 100644 --- a/patches/api/Introduce-registry-entry-and-builders.patch +++ b/patches/api/Introduce-registry-entry-and-builders.patch @@ -177,7 +177,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * sharpness enchantment. + * + * @param description the description component. -+ * @return this builder. ++ * @return this builder instance. + */ + @Contract(value = "_ -> this", mutates = "this") + Builder description(Component description); @@ -191,7 +191,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * {@link io.papermc.paper.registry.keys.tags.ItemTypeTagKeys#ENCHANTABLE_SWORD}. + * + * @param supportedItems the registry key set representing the supported items. -+ * @return this builder. ++ * @return this builder instance. + * @see RegistrySet#keySet(RegistryKey, TypedKey[]) + * @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. + * + * @param primaryItems the registry key set representing the primary items. -+ * @return this builder. ++ * @return this builder instance. + * @see RegistrySet#keySet(RegistryKey, TypedKey[]) + * @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. + * + * @param weight the weight value. -+ * @return this builder. ++ * @return this builder instance. + * @see https://minecraft.wiki/w/Enchanting for examplary weights. + */ + @Contract(value = "_ -> this", mutates = "this") @@ -233,7 +233,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * Configures the maximum level this enchantment can have when applied. + * + * @param maxLevel the maximum level. -+ * @return this builder. ++ * @return this builder instance. + */ + @Contract(value = "_ -> this", mutates = "this") + 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. + * + * @param minimumCost the enchantment cost. -+ * @return this builder. ++ * @return this builder instance. + * @see https://minecraft.wiki/w/Enchanting/Levels for + * examplary costs. + */ @@ -257,7 +257,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * Note that a cost is not directly related to the consumed xp. + * + * @param maximumCost the enchantment cost. -+ * @return this builder. ++ * @return this builder instance. + * @see https://minecraft.wiki/w/Enchanting/Levels for + * examplary costs. + */ @@ -272,7 +272,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + *

+ * + * @param anvilCost the anvil cost of this enchantment -+ * @return this builder. ++ * @return this builder instance. + * @see Enchantment#getAnvilCost() + */ + @Contract(value = "_ -> this", mutates = "this") @@ -285,7 +285,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * groups, the enchantment's effects, like attribute modifiers, will not activate. + * + * @param activeSlots a list of equipment slot groups. -+ * @return this builder. ++ * @return this builder instance. + * @see Enchantment#getActiveSlotGroups() + */ + @Contract(value = "_ -> this", mutates = "this") @@ -300,7 +300,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + * groups, the enchantment's effects, like attribute modifiers, will not activate. + * + * @param activeSlots a list of equipment slot groups. -+ * @return this builder. ++ * @return this builder instance. + * @see Enchantment#getActiveSlotGroups() + */ + @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. + * + * @param exclusiveWith a registry set of enchantments exclusive to this one. -+ * @return this builder. ++ * @return this builder instance. + * @see RegistrySet#keySet(RegistryKey, TypedKey[]) + * @see io.papermc.paper.registry.event.RegistryFreezeEvent#getOrCreateTag(TagKey) + */ @@ -358,7 +358,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + 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 new file mode 100644 @@ -443,27 +442,25 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +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() + */ -+ @Range(from = 1, to = 16) -+ int width(); ++ @Range(from = 1, to = 16) 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() + */ -+ @Range(from = 1, to = 16) -+ int height(); ++ @Range(from = 1, to = 16) int height(); + + /** + * Provides the title of the painting visible in the creative inventory. + * -+ * @return the title ++ * @return the title. + * @see Art#title() + */ + @Nullable Component title(); @@ -471,15 +468,15 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + /** + * Provides the author of the painting visible in the creative inventory. + * -+ * @return the author ++ * @return the author. + * @see Art#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() + */ + Key assetId(); @@ -501,30 +498,30 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + /** + * Sets the width of the painting in blocks. + * -+ * @param width the width in blocks -+ * @return this builder instance ++ * @param width the width in blocks. ++ * @return this builder instance. + * @see PaintingVariantRegistryEntry#width() + * @see Art#getBlockWidth() + */ + @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. + * -+ * @param height the height in blocks -+ * @return this builder instance ++ * @param height the height in blocks. ++ * @return this builder instance. + * @see PaintingVariantRegistryEntry#height() + * @see Art#getBlockHeight() + */ + @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. + * -+ * @param title the title -+ * @return this builder instance ++ * @param title the title. ++ * @return this builder instance. + * @see PaintingVariantRegistryEntry#title() + * @see Art#title() + */ @@ -534,8 +531,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + /** + * Sets the author of the painting. + * -+ * @param author the author -+ * @return this builder instance ++ * @param author the author. ++ * @return this builder instance. + * @see PaintingVariantRegistryEntry#author() + * @see Art#author() + */ @@ -543,18 +540,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + 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 -+ * @return this builder instance ++ * @param assetId the asset id. ++ * @return this builder instance. + * @see PaintingVariantRegistryEntry#assetId() + * @see Art#assetId() + */ + @Contract(value = "_ -> this", mutates = "this") + 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 new file mode 100644 diff --git a/patches/server/Add-registry-entry-and-builders.patch b/patches/server/Add-registry-entry-and-builders.patch index f3bae1a3ed..5bb7305f7b 100644 --- a/patches/server/Add-registry-entry-and-builders.patch +++ b/patches/server/Add-registry-entry-and-builders.patch @@ -309,11 +309,11 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + public PaperGameEventRegistryEntry( + final Conversions ignoredConversions, + final io.papermc.paper.registry.TypedKey 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 @@ -327,9 +327,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + public PaperBuilder( + final Conversions conversions, + final io.papermc.paper.registry.TypedKey key, -+ final @Nullable GameEvent nms ++ final @Nullable GameEvent internal + ) { -+ super(conversions, key, nms); ++ super(conversions, key, internal); + } + + @Override @@ -385,16 +385,16 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + public PaperPaintingVariantRegistryEntry( + final Conversions conversions, + final TypedKey ignoredKey, -+ final @Nullable PaintingVariant nms ++ final @Nullable PaintingVariant internal + ) { + this.conversions = conversions; -+ if(nms == null) return; ++ if (internal == null) return; + -+ this.width = OptionalInt.of(nms.width()); -+ this.height = OptionalInt.of(nms.height()); -+ this.title = nms.title().orElse(null); -+ this.author = nms.title().orElse(null); -+ this.assetId = nms.assetId(); ++ this.width = OptionalInt.of(internal.width()); ++ this.height = OptionalInt.of(internal.height()); ++ this.title = internal.title().orElse(null); ++ this.author = internal.author().orElse(null); ++ this.assetId = internal.assetId(); + } + + @Override @@ -424,18 +424,18 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + + public static final class PaperBuilder extends PaperPaintingVariantRegistryEntry implements PaintingVariantRegistryEntry.Builder, PaperRegistryBuilder { + -+ public PaperBuilder(final Conversions conversions, final TypedKey key, final @Nullable PaintingVariant nms) { -+ super(conversions, key, nms); ++ public PaperBuilder(final Conversions conversions, final TypedKey key, final @Nullable PaintingVariant internal) { ++ super(conversions, key, internal); + } + + @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)); + return this; + } + + @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)); + return this; + } @@ -573,44 +573,3 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 @NotNull @Override 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 registries() { - return List.of( -+ arguments(Registries.ENCHANTMENT, (PaperRegistryBuilder.Filler) PaperEnchantmentRegistryEntry.PaperBuilder::new), -+ arguments(Registries.GAME_EVENT, (PaperRegistryBuilder.Filler) PaperGameEventRegistryEntry.PaperBuilder::new) - ); - } - -- @Disabled - @ParameterizedTest - @MethodSource("registries") - void testEquality(final ResourceKey> resourceKey, final PaperRegistryBuilder.Filler filler) { diff --git a/patches/server/DataComponent-API.patch b/patches/server/DataComponent-API.patch index 96a4927eab..bd553c86fb 100644 --- a/patches/server/DataComponent-API.patch +++ b/patches/server/DataComponent-API.patch @@ -1533,7 +1533,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + static final class BuilderImpl implements ItemAdventurePredicate.Builder { + + private final List predicates = new ObjectArrayList<>(); -+ private boolean showInTooltip = net.minecraft.world.item.component.ItemAttributeModifiers.EMPTY.showInTooltip(); ++ private boolean showInTooltip = true; + + @Override + public ItemAdventurePredicate.Builder addPredicate(final BlockPredicate predicate) { @@ -3349,10 +3349,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 + } + + @Override -+ public ConsumeEffect.RemoveStatusEffects removeStatusEffects(final RegistryKeySet potionEffectTypeTagKey) { ++ public ConsumeEffect.RemoveStatusEffects removeStatusEffects(final RegistryKeySet effectTypes) { + return new PaperRemoveStatusEffects( + 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) + ) + ); + } diff --git a/patches/server/Expanded-Art-API.patch b/patches/server/Expanded-Art-API.patch index 8ea7fe8921..e73e3f6606 100644 --- a/patches/server/Expanded-Art-API.patch +++ b/patches/server/Expanded-Art-API.patch @@ -8,45 +8,25 @@ diff --git a/src/main/java/org/bukkit/craftbukkit/CraftArt.java b/src/main/java/ index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644 --- a/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 { - - 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 { - 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 { return this.paintingVariant.height(); } -+ // Paper start - name and author components, assetId key ++ // Paper start - Expand Art API + @Override -+ public net.kyori.adventure.text.@org.jetbrains.annotations.Nullable Component title() { -+ return this.adventureTitle; ++ public net.kyori.adventure.text.Component title() { ++ return this.paintingVariant.title().map(io.papermc.paper.adventure.PaperAdventure::asAdventure).orElse(null); + } + + @Override -+ public net.kyori.adventure.text.@org.jetbrains.annotations.Nullable Component author() { -+ return this.adventureAuthor; ++ public net.kyori.adventure.text.Component author() { ++ return this.paintingVariant.author().map(io.papermc.paper.adventure.PaperAdventure::asAdventure).orElse(null); + } + -+ public net.kyori.adventure.key.@org.jspecify.annotations.NonNull Key assetId() { -+ return this.adventureAssetId; ++ public net.kyori.adventure.key.Key assetId() { ++ return io.papermc.paper.adventure.PaperAdventure.asAdventure(this.paintingVariant.assetId()); + } -+ // Paper end - name and author components, assetId key ++ // Paper end - Expand Art API + @Override public int getId() { diff --git a/patches/server/Registry-Modification-API.patch b/patches/server/Registry-Modification-API.patch index 986d20032e..38287678fe 100644 --- a/patches/server/Registry-Modification-API.patch +++ b/patches/server/Registry-Modification-API.patch @@ -1413,14 +1413,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +package io.papermc.paper.registry; + +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.stream.Stream; +import net.minecraft.core.Registry; +import net.minecraft.resources.RegistryOps; +import net.minecraft.resources.ResourceKey; ++import org.bukkit.Keyed; +import org.bukkit.support.RegistryHelper; +import org.bukkit.support.environment.AllFeatures; -+import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; @@ -1430,18 +1433,23 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000 +@AllFeatures +class RegistryBuilderTest { + -+ static List registries() { -+ return List.of( -+ ); ++ static Stream registries() { ++ return PaperRegistries.REGISTRY_ENTRIES.stream() ++ .map(RegistryBuilderTest::possiblyUnwrap) ++ .filter(RegistryEntry.BuilderHolder.class::isInstance) ++ .map(Arguments::arguments); ++ } ++ ++ private static RegistryEntryInfo possiblyUnwrap(final RegistryEntryInfo entry) { ++ return entry instanceof final DelayedRegistryEntry delayed ? delayed.delegate() : entry; + } + -+ @Disabled + @ParameterizedTest + @MethodSource("registries") -+ void testEquality(final ResourceKey> resourceKey, final PaperRegistryBuilder.Filler filler) { -+ final Registry registry = RegistryHelper.getRegistry().lookupOrThrow(resourceKey); ++ void testEquality(final RegistryEntry.BuilderHolder registryEntry) { ++ final Registry registry = RegistryHelper.getRegistry().lookupOrThrow(registryEntry.mcKey()); + for (final Map.Entry, 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); + } + }