Skip to content

Commit 9bc1471

Browse files
authored
Fix painting variant builder (#11660)
1 parent bf8405f commit 9bc1471

6 files changed

+92
-150
lines changed

patches/api/0472-Introduce-registry-entry-and-builders.patch

Lines changed: 38 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ index 647f6a1ec1f9d3c203b41f90a99bfd415bf67366..9b39e33514b15a9d07104e2ad826d0da
2424
* Built-in registry for cat variants.
2525
diff --git a/src/main/java/io/papermc/paper/registry/data/EnchantmentRegistryEntry.java b/src/main/java/io/papermc/paper/registry/data/EnchantmentRegistryEntry.java
2626
new file mode 100644
27-
index 0000000000000000000000000000000000000000..d0d19a4bb2ba0e92710861b106777a428bdc5ad9
27+
index 0000000000000000000000000000000000000000..f092077453cb13dd8d849550896c2ef1cfa81b7a
2828
--- /dev/null
2929
+++ b/src/main/java/io/papermc/paper/registry/data/EnchantmentRegistryEntry.java
30-
@@ -0,0 +1,332 @@
30+
@@ -0,0 +1,331 @@
3131
+package io.papermc.paper.registry.data;
3232
+
3333
+import io.papermc.paper.registry.RegistryBuilder;
@@ -177,7 +177,7 @@ index 0000000000000000000000000000000000000000..d0d19a4bb2ba0e92710861b106777a42
177177
+ * sharpness enchantment.
178178
+ *
179179
+ * @param description the description component.
180-
+ * @return this builder.
180+
+ * @return this builder instance.
181181
+ */
182182
+ @Contract(value = "_ -> this", mutates = "this")
183183
+ Builder description(Component description);
@@ -191,7 +191,7 @@ index 0000000000000000000000000000000000000000..d0d19a4bb2ba0e92710861b106777a42
191191
+ * {@link io.papermc.paper.registry.keys.tags.ItemTypeTagKeys#ENCHANTABLE_SWORD}.
192192
+ *
193193
+ * @param supportedItems the registry key set representing the supported items.
194-
+ * @return this builder.
194+
+ * @return this builder instance.
195195
+ * @see RegistrySet#keySet(RegistryKey, TypedKey[])
196196
+ * @see io.papermc.paper.registry.event.RegistryFreezeEvent#getOrCreateTag(TagKey)
197197
+ */
@@ -212,7 +212,7 @@ index 0000000000000000000000000000000000000000..d0d19a4bb2ba0e92710861b106777a42
212212
+ * which enchantments can even show up in an enchantment table.
213213
+ *
214214
+ * @param primaryItems the registry key set representing the primary items.
215-
+ * @return this builder.
215+
+ * @return this builder instance.
216216
+ * @see RegistrySet#keySet(RegistryKey, TypedKey[])
217217
+ * @see io.papermc.paper.registry.event.RegistryFreezeEvent#getOrCreateTag(TagKey)
218218
+ */
@@ -223,7 +223,7 @@ index 0000000000000000000000000000000000000000..d0d19a4bb2ba0e92710861b106777a42
223223
+ * Configures the weight of this enchantment used by the weighted random when selecting enchantments.
224224
+ *
225225
+ * @param weight the weight value.
226-
+ * @return this builder.
226+
+ * @return this builder instance.
227227
+ * @see <a href="https://minecraft.wiki/w/Enchanting">https://minecraft.wiki/w/Enchanting</a> for examplary weights.
228228
+ */
229229
+ @Contract(value = "_ -> this", mutates = "this")
@@ -233,7 +233,7 @@ index 0000000000000000000000000000000000000000..d0d19a4bb2ba0e92710861b106777a42
233233
+ * Configures the maximum level this enchantment can have when applied.
234234
+ *
235235
+ * @param maxLevel the maximum level.
236-
+ * @return this builder.
236+
+ * @return this builder instance.
237237
+ */
238238
+ @Contract(value = "_ -> this", mutates = "this")
239239
+ Builder maxLevel(@Range(from = 1, to = 255) int maxLevel);
@@ -244,7 +244,7 @@ index 0000000000000000000000000000000000000000..d0d19a4bb2ba0e92710861b106777a42
244244
+ * Note that a cost is not directly related to the consumed xp.
245245
+ *
246246
+ * @param minimumCost the enchantment cost.
247-
+ * @return this builder.
247+
+ * @return this builder instance.
248248
+ * @see <a href="https://minecraft.wiki/w/Enchanting/Levels">https://minecraft.wiki/w/Enchanting/Levels</a> for
249249
+ * examplary costs.
250250
+ */
@@ -257,7 +257,7 @@ index 0000000000000000000000000000000000000000..d0d19a4bb2ba0e92710861b106777a42
257257
+ * Note that a cost is not directly related to the consumed xp.
258258
+ *
259259
+ * @param maximumCost the enchantment cost.
260-
+ * @return this builder.
260+
+ * @return this builder instance.
261261
+ * @see <a href="https://minecraft.wiki/w/Enchanting/Levels">https://minecraft.wiki/w/Enchanting/Levels</a> for
262262
+ * examplary costs.
263263
+ */
@@ -272,7 +272,7 @@ index 0000000000000000000000000000000000000000..d0d19a4bb2ba0e92710861b106777a42
272272
+ * </p>
273273
+ *
274274
+ * @param anvilCost the anvil cost of this enchantment
275-
+ * @return this builder.
275+
+ * @return this builder instance.
276276
+ * @see Enchantment#getAnvilCost()
277277
+ */
278278
+ @Contract(value = "_ -> this", mutates = "this")
@@ -285,7 +285,7 @@ index 0000000000000000000000000000000000000000..d0d19a4bb2ba0e92710861b106777a42
285285
+ * groups, the enchantment's effects, like attribute modifiers, will not activate.
286286
+ *
287287
+ * @param activeSlots a list of equipment slot groups.
288-
+ * @return this builder.
288+
+ * @return this builder instance.
289289
+ * @see Enchantment#getActiveSlotGroups()
290290
+ */
291291
+ @Contract(value = "_ -> this", mutates = "this")
@@ -300,7 +300,7 @@ index 0000000000000000000000000000000000000000..d0d19a4bb2ba0e92710861b106777a42
300300
+ * groups, the enchantment's effects, like attribute modifiers, will not activate.
301301
+ *
302302
+ * @param activeSlots a list of equipment slot groups.
303-
+ * @return this builder.
303+
+ * @return this builder instance.
304304
+ * @see Enchantment#getActiveSlotGroups()
305305
+ */
306306
+ @Contract(value = "_ -> this", mutates = "this")
@@ -315,7 +315,7 @@ index 0000000000000000000000000000000000000000..d0d19a4bb2ba0e92710861b106777a42
315315
+ * Defaults to an empty set allowing this enchantment to be applied regardless of other enchantments.
316316
+ *
317317
+ * @param exclusiveWith a registry set of enchantments exclusive to this one.
318-
+ * @return this builder.
318+
+ * @return this builder instance.
319319
+ * @see RegistrySet#keySet(RegistryKey, TypedKey[])
320320
+ * @see io.papermc.paper.registry.event.RegistryFreezeEvent#getOrCreateTag(TagKey)
321321
+ */
@@ -358,7 +358,6 @@ index 0000000000000000000000000000000000000000..d0d19a4bb2ba0e92710861b106777a42
358358
+ return new Impl(baseCost, additionalPerLevelCost);
359359
+ }
360360
+ }
361-
+
362361
+}
363362
diff --git a/src/main/java/io/papermc/paper/registry/data/GameEventRegistryEntry.java b/src/main/java/io/papermc/paper/registry/data/GameEventRegistryEntry.java
364363
new file mode 100644
@@ -417,10 +416,10 @@ index 0000000000000000000000000000000000000000..980fe12b75258b51cc2498590cadb9de
417416
+}
418417
diff --git a/src/main/java/io/papermc/paper/registry/data/PaintingVariantRegistryEntry.java b/src/main/java/io/papermc/paper/registry/data/PaintingVariantRegistryEntry.java
419418
new file mode 100644
420-
index 0000000000000000000000000000000000000000..b8d133afa82da1b5b9e7a18e1c332ae3aefea50d
419+
index 0000000000000000000000000000000000000000..4e2c99acd7dc307981ba8e33a62835f0f29fd73e
421420
--- /dev/null
422421
+++ b/src/main/java/io/papermc/paper/registry/data/PaintingVariantRegistryEntry.java
423-
@@ -0,0 +1,135 @@
422+
@@ -0,0 +1,131 @@
424423
+package io.papermc.paper.registry.data;
425424
+
426425
+import io.papermc.paper.registry.RegistryBuilder;
@@ -443,43 +442,41 @@ index 0000000000000000000000000000000000000000..b8d133afa82da1b5b9e7a18e1c332ae3
443442
+public interface PaintingVariantRegistryEntry {
444443
+
445444
+ /**
446-
+ * Provides the width of this variant in blocks.
445+
+ * Provides the width of this painting in blocks.
447446
+ *
448-
+ * @return the width
447+
+ * @return the width.
449448
+ * @see Art#getBlockWidth()
450449
+ */
451-
+ @Range(from = 1, to = 16)
452-
+ int width();
450+
+ @Range(from = 1, to = 16) int width();
453451
+
454452
+ /**
455-
+ * Provides the height of this variant in blocks.
453+
+ * Provides the height of this painting in blocks.
456454
+ *
457-
+ * @return the height
455+
+ * @return the height.
458456
+ * @see Art#getBlockHeight()
459457
+ */
460-
+ @Range(from = 1, to = 16)
461-
+ int height();
458+
+ @Range(from = 1, to = 16) int height();
462459
+
463460
+ /**
464461
+ * Provides the title of the painting visible in the creative inventory.
465462
+ *
466-
+ * @return the title
463+
+ * @return the title.
467464
+ * @see Art#title()
468465
+ */
469466
+ @Nullable Component title();
470467
+
471468
+ /**
472469
+ * Provides the author of the painting visible in the creative inventory.
473470
+ *
474-
+ * @return the author
471+
+ * @return the author.
475472
+ * @see Art#author()
476473
+ */
477474
+ @Nullable Component author();
478475
+
479476
+ /**
480-
+ * Provides the assetId of the variant, which is the location of the sprite to use.
477+
+ * Provides the asset id of the painting, which is the location of the sprite to use.
481478
+ *
482-
+ * @return the asset id
479+
+ * @return the asset id.
483480
+ * @see Art#assetId()
484481
+ */
485482
+ Key assetId();
@@ -501,30 +498,30 @@ index 0000000000000000000000000000000000000000..b8d133afa82da1b5b9e7a18e1c332ae3
501498
+ /**
502499
+ * Sets the width of the painting in blocks.
503500
+ *
504-
+ * @param width the width in blocks
505-
+ * @return this builder instance
501+
+ * @param width the width in blocks.
502+
+ * @return this builder instance.
506503
+ * @see PaintingVariantRegistryEntry#width()
507504
+ * @see Art#getBlockWidth()
508505
+ */
509506
+ @Contract(value = "_ -> this", mutates = "this")
510-
+ Builder width(@Range(from = 0, to = 16) int width);
507+
+ Builder width(@Range(from = 1, to = 16) int width);
511508
+
512509
+ /**
513510
+ * Sets the height of the painting in blocks.
514511
+ *
515-
+ * @param height the height in blocks
516-
+ * @return this builder instance
512+
+ * @param height the height in blocks.
513+
+ * @return this builder instance.
517514
+ * @see PaintingVariantRegistryEntry#height()
518515
+ * @see Art#getBlockHeight()
519516
+ */
520517
+ @Contract(value = "_ -> this", mutates = "this")
521-
+ Builder height(@Range(from = 0, to = 16) int height);
518+
+ Builder height(@Range(from = 1, to = 16) int height);
522519
+
523520
+ /**
524521
+ * Sets the title of the painting.
525522
+ *
526-
+ * @param title the title
527-
+ * @return this builder instance
523+
+ * @param title the title.
524+
+ * @return this builder instance.
528525
+ * @see PaintingVariantRegistryEntry#title()
529526
+ * @see Art#title()
530527
+ */
@@ -534,27 +531,25 @@ index 0000000000000000000000000000000000000000..b8d133afa82da1b5b9e7a18e1c332ae3
534531
+ /**
535532
+ * Sets the author of the painting.
536533
+ *
537-
+ * @param author the author
538-
+ * @return this builder instance
534+
+ * @param author the author.
535+
+ * @return this builder instance.
539536
+ * @see PaintingVariantRegistryEntry#author()
540537
+ * @see Art#author()
541538
+ */
542539
+ @Contract(value = "_ -> this", mutates = "this")
543540
+ Builder author(@Nullable Component author);
544541
+
545542
+ /**
546-
+ * Sets the assetId of the variant, which is the location of the sprite to use.
543+
+ * Sets the asset id of the painting, which is the location of the sprite to use.
547544
+ *
548-
+ * @param assetId the asset id
549-
+ * @return this builder instance
545+
+ * @param assetId the asset id.
546+
+ * @return this builder instance.
550547
+ * @see PaintingVariantRegistryEntry#assetId()
551548
+ * @see Art#assetId()
552549
+ */
553550
+ @Contract(value = "_ -> this", mutates = "this")
554551
+ Builder assetId(Key assetId);
555-
+
556552
+ }
557-
+
558553
+}
559554
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
560555
new file mode 100644

patches/api/0495-DataComponent-API.patch

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3561,7 +3561,7 @@ index 0000000000000000000000000000000000000000..979bc05009b84b6fcdb59938cceace35
35613561
+}
35623562
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
35633563
new file mode 100644
3564-
index 0000000000000000000000000000000000000000..a845ccfc21f101f0632249745bbd8b334f85e72c
3564+
index 0000000000000000000000000000000000000000..e632221f36d0f355b4750071c7d8ccdd84b040a9
35653565
--- /dev/null
35663566
+++ b/src/main/java/io/papermc/paper/datacomponent/item/consumable/ConsumableTypesBridge.java
35673567
@@ -0,0 +1,32 @@
@@ -3589,7 +3589,7 @@ index 0000000000000000000000000000000000000000..a845ccfc21f101f0632249745bbd8b33
35893589
+
35903590
+ ConsumeEffect.ApplyStatusEffects applyStatusEffects(List<PotionEffect> effectList, float probability);
35913591
+
3592-
+ ConsumeEffect.RemoveStatusEffects removeStatusEffects(RegistryKeySet<PotionEffectType> potionEffectTypeTagKey);
3592+
+ ConsumeEffect.RemoveStatusEffects removeStatusEffects(RegistryKeySet<PotionEffectType> effectTypes);
35933593
+
35943594
+ ConsumeEffect.ClearAllStatusEffects clearAllStatusEffects();
35953595
+

patches/server/0992-Registry-Modification-API.patch

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1406,21 +1406,24 @@ index 0000000000000000000000000000000000000000..8bee1a5ed877a04e4d027593df1f42ce
14061406
+io.papermc.paper.registry.event.RegistryEventTypeProviderImpl
14071407
diff --git a/src/test/java/io/papermc/paper/registry/RegistryBuilderTest.java b/src/test/java/io/papermc/paper/registry/RegistryBuilderTest.java
14081408
new file mode 100644
1409-
index 0000000000000000000000000000000000000000..ceef7b5864deb1d7c6aa5630febe86ba9427bdc4
1409+
index 0000000000000000000000000000000000000000..f2f1dfe4277ce1e84a9494bee285badc958c8d3f
14101410
--- /dev/null
14111411
+++ b/src/test/java/io/papermc/paper/registry/RegistryBuilderTest.java
1412-
@@ -0,0 +1,36 @@
1412+
@@ -0,0 +1,44 @@
14131413
+package io.papermc.paper.registry;
14141414
+
14151415
+import io.papermc.paper.registry.data.util.Conversions;
1416-
+import java.util.List;
1416+
+import io.papermc.paper.registry.entry.RegistryEntry;
1417+
+import io.papermc.paper.registry.entry.RegistryEntryInfo;
1418+
+import io.papermc.paper.registry.legacy.DelayedRegistryEntry;
14171419
+import java.util.Map;
1420+
+import java.util.stream.Stream;
14181421
+import net.minecraft.core.Registry;
14191422
+import net.minecraft.resources.RegistryOps;
14201423
+import net.minecraft.resources.ResourceKey;
1424+
+import org.bukkit.Keyed;
14211425
+import org.bukkit.support.RegistryHelper;
14221426
+import org.bukkit.support.environment.AllFeatures;
1423-
+import org.junit.jupiter.api.Disabled;
14241427
+import org.junit.jupiter.params.ParameterizedTest;
14251428
+import org.junit.jupiter.params.provider.Arguments;
14261429
+import org.junit.jupiter.params.provider.MethodSource;
@@ -1430,18 +1433,23 @@ index 0000000000000000000000000000000000000000..ceef7b5864deb1d7c6aa5630febe86ba
14301433
+@AllFeatures
14311434
+class RegistryBuilderTest {
14321435
+
1433-
+ static List<Arguments> registries() {
1434-
+ return List.of(
1435-
+ );
1436+
+ static Stream<Arguments> registries() {
1437+
+ return PaperRegistries.REGISTRY_ENTRIES.stream()
1438+
+ .map(RegistryBuilderTest::possiblyUnwrap)
1439+
+ .filter(RegistryEntry.BuilderHolder.class::isInstance)
1440+
+ .map(Arguments::arguments);
1441+
+ }
1442+
+
1443+
+ private static <M, B extends Keyed> RegistryEntryInfo<M, B> possiblyUnwrap(final RegistryEntryInfo<M, B> entry) {
1444+
+ return entry instanceof final DelayedRegistryEntry<M, B> delayed ? delayed.delegate() : entry;
14361445
+ }
14371446
+
1438-
+ @Disabled
14391447
+ @ParameterizedTest
14401448
+ @MethodSource("registries")
1441-
+ <M, T> void testEquality(final ResourceKey<? extends Registry<M>> resourceKey, final PaperRegistryBuilder.Filler<M, T, ?> filler) {
1442-
+ final Registry<M> registry = RegistryHelper.getRegistry().lookupOrThrow(resourceKey);
1449+
+ <M, T> void testEquality(final RegistryEntry.BuilderHolder<M, T, ?> registryEntry) {
1450+
+ final Registry<M> registry = RegistryHelper.getRegistry().lookupOrThrow(registryEntry.mcKey());
14431451
+ for (final Map.Entry<ResourceKey<M>, M> entry : registry.entrySet()) {
1444-
+ final M built = filler.fill(new Conversions(new RegistryOps.HolderLookupAdapter(RegistryHelper.getRegistry())), PaperRegistries.fromNms(entry.getKey()), entry.getValue()).build();
1452+
+ final M built = registryEntry.fillBuilder(new Conversions(new RegistryOps.HolderLookupAdapter(RegistryHelper.getRegistry())), PaperRegistries.fromNms(entry.getKey()), entry.getValue()).build();
14451453
+ assertEquals(entry.getValue(), built);
14461454
+ }
14471455
+ }

0 commit comments

Comments
 (0)