Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix painting variant builder #11660

Merged
merged 1 commit into from
Nov 24, 2024
Merged
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
81 changes: 38 additions & 43 deletions patches/api/0472-Introduce-registry-entry-and-builders.patch
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ index 647f6a1ec1f9d3c203b41f90a99bfd415bf67366..9b39e33514b15a9d07104e2ad826d0da
* Built-in registry for cat variants.
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..d0d19a4bb2ba0e92710861b106777a428bdc5ad9
index 0000000000000000000000000000000000000000..f092077453cb13dd8d849550896c2ef1cfa81b7a
--- /dev/null
+++ b/src/main/java/io/papermc/paper/registry/data/EnchantmentRegistryEntry.java
@@ -0,0 +1,332 @@
@@ -0,0 +1,331 @@
+package io.papermc.paper.registry.data;
+
+import io.papermc.paper.registry.RegistryBuilder;
Expand Down Expand Up @@ -177,7 +177,7 @@ index 0000000000000000000000000000000000000000..d0d19a4bb2ba0e92710861b106777a42
+ * sharpness enchantment.
+ *
+ * @param description the description component.
+ * @return this builder.
+ * @return this builder instance.
+ */
+ @Contract(value = "_ -> this", mutates = "this")
+ Builder description(Component description);
Expand All @@ -191,7 +191,7 @@ index 0000000000000000000000000000000000000000..d0d19a4bb2ba0e92710861b106777a42
+ * {@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)
+ */
Expand All @@ -212,7 +212,7 @@ index 0000000000000000000000000000000000000000..d0d19a4bb2ba0e92710861b106777a42
+ * 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)
+ */
Expand All @@ -223,7 +223,7 @@ index 0000000000000000000000000000000000000000..d0d19a4bb2ba0e92710861b106777a42
+ * 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 <a href="https://minecraft.wiki/w/Enchanting">https://minecraft.wiki/w/Enchanting</a> for examplary weights.
+ */
+ @Contract(value = "_ -> this", mutates = "this")
Expand All @@ -233,7 +233,7 @@ index 0000000000000000000000000000000000000000..d0d19a4bb2ba0e92710861b106777a42
+ * 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);
Expand All @@ -244,7 +244,7 @@ index 0000000000000000000000000000000000000000..d0d19a4bb2ba0e92710861b106777a42
+ * 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 <a href="https://minecraft.wiki/w/Enchanting/Levels">https://minecraft.wiki/w/Enchanting/Levels</a> for
+ * examplary costs.
+ */
Expand All @@ -257,7 +257,7 @@ index 0000000000000000000000000000000000000000..d0d19a4bb2ba0e92710861b106777a42
+ * 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 <a href="https://minecraft.wiki/w/Enchanting/Levels">https://minecraft.wiki/w/Enchanting/Levels</a> for
+ * examplary costs.
+ */
Expand All @@ -272,7 +272,7 @@ index 0000000000000000000000000000000000000000..d0d19a4bb2ba0e92710861b106777a42
+ * </p>
+ *
+ * @param anvilCost the anvil cost of this enchantment
+ * @return this builder.
+ * @return this builder instance.
+ * @see Enchantment#getAnvilCost()
+ */
+ @Contract(value = "_ -> this", mutates = "this")
Expand All @@ -285,7 +285,7 @@ index 0000000000000000000000000000000000000000..d0d19a4bb2ba0e92710861b106777a42
+ * 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")
Expand All @@ -300,7 +300,7 @@ index 0000000000000000000000000000000000000000..d0d19a4bb2ba0e92710861b106777a42
+ * 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")
Expand All @@ -315,7 +315,7 @@ index 0000000000000000000000000000000000000000..d0d19a4bb2ba0e92710861b106777a42
+ * 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)
+ */
Expand Down Expand Up @@ -358,7 +358,6 @@ index 0000000000000000000000000000000000000000..d0d19a4bb2ba0e92710861b106777a42
+ 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
Expand Down Expand Up @@ -417,10 +416,10 @@ index 0000000000000000000000000000000000000000..980fe12b75258b51cc2498590cadb9de
+}
diff --git a/src/main/java/io/papermc/paper/registry/data/PaintingVariantRegistryEntry.java b/src/main/java/io/papermc/paper/registry/data/PaintingVariantRegistryEntry.java
new file mode 100644
index 0000000000000000000000000000000000000000..b8d133afa82da1b5b9e7a18e1c332ae3aefea50d
index 0000000000000000000000000000000000000000..4e2c99acd7dc307981ba8e33a62835f0f29fd73e
--- /dev/null
+++ b/src/main/java/io/papermc/paper/registry/data/PaintingVariantRegistryEntry.java
@@ -0,0 +1,135 @@
@@ -0,0 +1,131 @@
+package io.papermc.paper.registry.data;
+
+import io.papermc.paper.registry.RegistryBuilder;
Expand All @@ -443,43 +442,41 @@ index 0000000000000000000000000000000000000000..b8d133afa82da1b5b9e7a18e1c332ae3
+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();
+
+ /**
+ * 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();
Expand All @@ -501,30 +498,30 @@ index 0000000000000000000000000000000000000000..b8d133afa82da1b5b9e7a18e1c332ae3
+ /**
+ * 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()
+ */
Expand All @@ -534,27 +531,25 @@ index 0000000000000000000000000000000000000000..b8d133afa82da1b5b9e7a18e1c332ae3
+ /**
+ * 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()
+ */
+ @Contract(value = "_ -> this", mutates = "this")
+ 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
Expand Down
4 changes: 2 additions & 2 deletions patches/api/0495-DataComponent-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -3561,7 +3561,7 @@ index 0000000000000000000000000000000000000000..979bc05009b84b6fcdb59938cceace35
+}
diff --git a/src/main/java/io/papermc/paper/datacomponent/item/consumable/ConsumableTypesBridge.java b/src/main/java/io/papermc/paper/datacomponent/item/consumable/ConsumableTypesBridge.java
new file mode 100644
index 0000000000000000000000000000000000000000..a845ccfc21f101f0632249745bbd8b334f85e72c
index 0000000000000000000000000000000000000000..e632221f36d0f355b4750071c7d8ccdd84b040a9
--- /dev/null
+++ b/src/main/java/io/papermc/paper/datacomponent/item/consumable/ConsumableTypesBridge.java
@@ -0,0 +1,32 @@
Expand Down Expand Up @@ -3589,7 +3589,7 @@ index 0000000000000000000000000000000000000000..a845ccfc21f101f0632249745bbd8b33
+
+ ConsumeEffect.ApplyStatusEffects applyStatusEffects(List<PotionEffect> effectList, float probability);
+
+ ConsumeEffect.RemoveStatusEffects removeStatusEffects(RegistryKeySet<PotionEffectType> potionEffectTypeTagKey);
+ ConsumeEffect.RemoveStatusEffects removeStatusEffects(RegistryKeySet<PotionEffectType> effectTypes);
+
+ ConsumeEffect.ClearAllStatusEffects clearAllStatusEffects();
+
Expand Down
30 changes: 19 additions & 11 deletions patches/server/0992-Registry-Modification-API.patch
Original file line number Diff line number Diff line change
Expand Up @@ -1406,21 +1406,24 @@ index 0000000000000000000000000000000000000000..8bee1a5ed877a04e4d027593df1f42ce
+io.papermc.paper.registry.event.RegistryEventTypeProviderImpl
diff --git a/src/test/java/io/papermc/paper/registry/RegistryBuilderTest.java b/src/test/java/io/papermc/paper/registry/RegistryBuilderTest.java
new file mode 100644
index 0000000000000000000000000000000000000000..ceef7b5864deb1d7c6aa5630febe86ba9427bdc4
index 0000000000000000000000000000000000000000..f2f1dfe4277ce1e84a9494bee285badc958c8d3f
--- /dev/null
+++ b/src/test/java/io/papermc/paper/registry/RegistryBuilderTest.java
@@ -0,0 +1,36 @@
@@ -0,0 +1,44 @@
+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;
Expand All @@ -1430,18 +1433,23 @@ index 0000000000000000000000000000000000000000..ceef7b5864deb1d7c6aa5630febe86ba
+@AllFeatures
+class RegistryBuilderTest {
+
+ static List<Arguments> registries() {
+ return List.of(
+ );
+ static Stream<Arguments> registries() {
+ 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
+ @MethodSource("registries")
+ <M, T> void testEquality(final ResourceKey<? extends Registry<M>> resourceKey, final PaperRegistryBuilder.Filler<M, T, ?> filler) {
+ final Registry<M> registry = RegistryHelper.getRegistry().lookupOrThrow(resourceKey);
+ <M, T> void testEquality(final RegistryEntry.BuilderHolder<M, T, ?> registryEntry) {
+ final Registry<M> registry = RegistryHelper.getRegistry().lookupOrThrow(registryEntry.mcKey());
+ 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);
+ }
+ }
Expand Down
Loading
Loading