Fix painting variant builder (#11660)
This commit is contained in:
parent
bf8405fcdd
commit
9bc147178d
6 changed files with 92 additions and 150 deletions
|
@ -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;
|
||||
|
@ -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);
|
||||
+ }
|
||||
+ }
|
||||
|
|
|
@ -283,7 +283,7 @@ index 0000000000000000000000000000000000000000..481f5f0cfae1fada3bc3f873fb7e04c3
|
|||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/registry/data/PaperGameEventRegistryEntry.java b/src/main/java/io/papermc/paper/registry/data/PaperGameEventRegistryEntry.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..18f9463ae23ba2d9c65ffb7531a87c925a5a8d6f
|
||||
index 0000000000000000000000000000000000000000..a96609223ed1e0500f8a4b868e309c0fc82bbc31
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/registry/data/PaperGameEventRegistryEntry.java
|
||||
@@ -0,0 +1,57 @@
|
||||
|
@ -309,11 +309,11 @@ index 0000000000000000000000000000000000000000..18f9463ae23ba2d9c65ffb7531a87c92
|
|||
+ public PaperGameEventRegistryEntry(
|
||||
+ final Conversions ignoredConversions,
|
||||
+ 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
|
||||
|
@ -327,9 +327,9 @@ index 0000000000000000000000000000000000000000..18f9463ae23ba2d9c65ffb7531a87c92
|
|||
+ public PaperBuilder(
|
||||
+ final Conversions conversions,
|
||||
+ 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
|
||||
|
@ -346,7 +346,7 @@ index 0000000000000000000000000000000000000000..18f9463ae23ba2d9c65ffb7531a87c92
|
|||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/registry/data/PaperPaintingVariantRegistryEntry.java b/src/main/java/io/papermc/paper/registry/data/PaperPaintingVariantRegistryEntry.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..21cb8c28c0027b4b2446279f6cf9dbedfc8945d5
|
||||
index 0000000000000000000000000000000000000000..68b3d747f759f615a3c942de3f4d7a0fe856cd84
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/registry/data/PaperPaintingVariantRegistryEntry.java
|
||||
@@ -0,0 +1,120 @@
|
||||
|
@ -385,16 +385,16 @@ index 0000000000000000000000000000000000000000..21cb8c28c0027b4b2446279f6cf9dbed
|
|||
+ public PaperPaintingVariantRegistryEntry(
|
||||
+ final Conversions conversions,
|
||||
+ final TypedKey<Art> 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..21cb8c28c0027b4b2446279f6cf9dbed
|
|||
+
|
||||
+ 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) {
|
||||
+ super(conversions, key, nms);
|
||||
+ public PaperBuilder(final Conversions conversions, final TypedKey<Art> 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 ac9b4328cd55a68664a3f71186bc9a7be7cd9658..ea9fe1f8b1a1685ea975eba0ca418a83
|
|||
@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 ceef7b5864deb1d7c6aa5630febe86ba9427bdc4..4d4632da6bf1bde85115dde2e2f7e353bd392176 100644
|
||||
--- a/src/test/java/io/papermc/paper/registry/RegistryBuilderTest.java
|
||||
+++ b/src/test/java/io/papermc/paper/registry/RegistryBuilderTest.java
|
||||
@@ -1,11 +1,16 @@
|
||||
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;
|
||||
@@ -14,16 +19,18 @@ 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) {
|
||||
|
|
|
@ -1484,7 +1484,7 @@ index 0000000000000000000000000000000000000000..2a043bb9001048f66d3a6aa8cb896b35
|
|||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/datacomponent/item/PaperItemAdventurePredicate.java b/src/main/java/io/papermc/paper/datacomponent/item/PaperItemAdventurePredicate.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..c7e40bd15b7063f155b2065927e8201f80fb6d0e
|
||||
index 0000000000000000000000000000000000000000..e6315cd0ebd46f874284c32da9cc03eb77f0677f
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/datacomponent/item/PaperItemAdventurePredicate.java
|
||||
@@ -0,0 +1,75 @@
|
||||
|
@ -1533,7 +1533,7 @@ index 0000000000000000000000000000000000000000..c7e40bd15b7063f155b2065927e8201f
|
|||
+ static final class BuilderImpl implements ItemAdventurePredicate.Builder {
|
||||
+
|
||||
+ 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
|
||||
+ public ItemAdventurePredicate.Builder addPredicate(final BlockPredicate predicate) {
|
||||
|
@ -3311,7 +3311,7 @@ index 0000000000000000000000000000000000000000..037a6695bdb8ee6e3c119fa79000c4ea
|
|||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/datacomponent/item/consumable/ConsumableTypesBridgeImpl.java b/src/main/java/io/papermc/paper/datacomponent/item/consumable/ConsumableTypesBridgeImpl.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..e11e7b36c0b0b499a6149c44ca2ad9f331d1b863
|
||||
index 0000000000000000000000000000000000000000..eab1883d691e0d0034b7959c8130a6240c3f529c
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/datacomponent/item/consumable/ConsumableTypesBridgeImpl.java
|
||||
@@ -0,0 +1,64 @@
|
||||
|
@ -3349,10 +3349,10 @@ index 0000000000000000000000000000000000000000..e11e7b36c0b0b499a6149c44ca2ad9f3
|
|||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public ConsumeEffect.RemoveStatusEffects removeStatusEffects(final RegistryKeySet<PotionEffectType> potionEffectTypeTagKey) {
|
||||
+ public ConsumeEffect.RemoveStatusEffects removeStatusEffects(final RegistryKeySet<PotionEffectType> 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)
|
||||
+ )
|
||||
+ );
|
||||
+ }
|
||||
|
|
|
@ -5,48 +5,28 @@ Subject: [PATCH] Expanded Art API
|
|||
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftArt.java b/src/main/java/org/bukkit/craftbukkit/CraftArt.java
|
||||
index 40af940193d0df66bbcdcf5f46132e304016a4d7..932118f5e5bfc765c852acaf21f9721d8fa5fb6a 100644
|
||||
index 40af940193d0df66bbcdcf5f46132e304016a4d7..9d73954282104a6e315c1840feb7d6034d27cfbe 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftArt.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftArt.java
|
||||
@@ -42,6 +42,9 @@ 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;
|
||||
|
||||
@@ -58,6 +61,9 @@ 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
|
||||
@@ -75,6 +81,22 @@ public class CraftArt implements Art, Handleable<PaintingVariant> {
|
||||
@@ -75,6 +75,22 @@ public class CraftArt implements Art, Handleable<PaintingVariant> {
|
||||
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() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue