Painting variant registry modification API (#11648)
This commit is contained in:
parent
edabff8a35
commit
6051dac82b
16 changed files with 391 additions and 22 deletions
|
@ -11,7 +11,7 @@ public net.minecraft.resources.RegistryOps lookupProvider
|
|||
public net.minecraft.resources.RegistryOps$HolderLookupAdapter
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/registry/PaperRegistries.java b/src/main/java/io/papermc/paper/registry/PaperRegistries.java
|
||||
index c6969f968b45eff2aeb44e647712abda10c7c113..d34ffad8a36abbb215491d74ae8d9b490a0bc64f 100644
|
||||
index 2f22f46f80b80be43a2cc1cd8afb51f4d1fd0e91..3ec2aa5da045b62809afd2c13fc9ae74189dbdad 100644
|
||||
--- a/src/main/java/io/papermc/paper/registry/PaperRegistries.java
|
||||
+++ b/src/main/java/io/papermc/paper/registry/PaperRegistries.java
|
||||
@@ -3,6 +3,7 @@ package io.papermc.paper.registry;
|
||||
|
|
|
@ -6,19 +6,20 @@ Subject: [PATCH] Add registry entry and builders
|
|||
Feature patch
|
||||
|
||||
diff --git a/src/main/java/io/papermc/paper/registry/PaperRegistries.java b/src/main/java/io/papermc/paper/registry/PaperRegistries.java
|
||||
index 3ec2aa5da045b62809afd2c13fc9ae74189dbdad..82fc79fb78be6e5d77060717e28d75cb9e8c388b 100644
|
||||
index 3ec2aa5da045b62809afd2c13fc9ae74189dbdad..31d660bbbe62cd2c26715e8d90fef58b8e024e34 100644
|
||||
--- a/src/main/java/io/papermc/paper/registry/PaperRegistries.java
|
||||
+++ b/src/main/java/io/papermc/paper/registry/PaperRegistries.java
|
||||
@@ -2,6 +2,8 @@ package io.papermc.paper.registry;
|
||||
@@ -2,6 +2,9 @@ package io.papermc.paper.registry;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import io.papermc.paper.adventure.PaperAdventure;
|
||||
+import io.papermc.paper.registry.data.PaperEnchantmentRegistryEntry;
|
||||
+import io.papermc.paper.registry.data.PaperGameEventRegistryEntry;
|
||||
+import io.papermc.paper.registry.data.PaperPaintingVariantRegistryEntry;
|
||||
import io.papermc.paper.registry.entry.RegistryEntry;
|
||||
import io.papermc.paper.registry.tag.TagKey;
|
||||
import java.util.Collections;
|
||||
@@ -81,7 +83,7 @@ public final class PaperRegistries {
|
||||
@@ -81,7 +84,7 @@ public final class PaperRegistries {
|
||||
static {
|
||||
REGISTRY_ENTRIES = List.of(
|
||||
// built-ins
|
||||
|
@ -27,7 +28,7 @@ index 3ec2aa5da045b62809afd2c13fc9ae74189dbdad..82fc79fb78be6e5d77060717e28d75cb
|
|||
entry(Registries.STRUCTURE_TYPE, RegistryKey.STRUCTURE_TYPE, StructureType.class, CraftStructureType::new),
|
||||
entry(Registries.MOB_EFFECT, RegistryKey.MOB_EFFECT, PotionEffectType.class, CraftPotionEffectType::new),
|
||||
entry(Registries.BLOCK, RegistryKey.BLOCK, BlockType.class, CraftBlockType::new),
|
||||
@@ -103,7 +105,7 @@ public final class PaperRegistries {
|
||||
@@ -103,10 +106,10 @@ public final class PaperRegistries {
|
||||
entry(Registries.TRIM_PATTERN, RegistryKey.TRIM_PATTERN, TrimPattern.class, CraftTrimPattern::new).delayed(),
|
||||
entry(Registries.DAMAGE_TYPE, RegistryKey.DAMAGE_TYPE, DamageType.class, CraftDamageType::new).delayed(),
|
||||
entry(Registries.WOLF_VARIANT, RegistryKey.WOLF_VARIANT, Wolf.Variant.class, CraftWolf.CraftVariant::new).delayed(),
|
||||
|
@ -35,7 +36,11 @@ index 3ec2aa5da045b62809afd2c13fc9ae74189dbdad..82fc79fb78be6e5d77060717e28d75cb
|
|||
+ writable(Registries.ENCHANTMENT, RegistryKey.ENCHANTMENT, Enchantment.class, CraftEnchantment::new, PaperEnchantmentRegistryEntry.PaperBuilder::new).withSerializationUpdater(FieldRename.ENCHANTMENT_RENAME).delayed(),
|
||||
entry(Registries.JUKEBOX_SONG, RegistryKey.JUKEBOX_SONG, JukeboxSong.class, CraftJukeboxSong::new).delayed(),
|
||||
entry(Registries.BANNER_PATTERN, RegistryKey.BANNER_PATTERN, PatternType.class, CraftPatternType::new).delayed(),
|
||||
entry(Registries.PAINTING_VARIANT, RegistryKey.PAINTING_VARIANT, Art.class, CraftArt::new).delayed(),
|
||||
- entry(Registries.PAINTING_VARIANT, RegistryKey.PAINTING_VARIANT, Art.class, CraftArt::new).delayed(),
|
||||
+ writable(Registries.PAINTING_VARIANT, RegistryKey.PAINTING_VARIANT, Art.class, CraftArt::new, PaperPaintingVariantRegistryEntry.PaperBuilder::new).delayed(),
|
||||
entry(Registries.INSTRUMENT, RegistryKey.INSTRUMENT, MusicInstrument.class, CraftMusicInstrument::new).delayed(),
|
||||
|
||||
// api-only
|
||||
diff --git a/src/main/java/io/papermc/paper/registry/data/PaperEnchantmentRegistryEntry.java b/src/main/java/io/papermc/paper/registry/data/PaperEnchantmentRegistryEntry.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..481f5f0cfae1fada3bc3f873fb7e04c3086ea9bf
|
||||
|
@ -339,6 +344,132 @@ 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
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/registry/data/PaperPaintingVariantRegistryEntry.java
|
||||
@@ -0,0 +1,120 @@
|
||||
+package io.papermc.paper.registry.data;
|
||||
+
|
||||
+import io.papermc.paper.adventure.PaperAdventure;
|
||||
+import io.papermc.paper.registry.PaperRegistryBuilder;
|
||||
+import io.papermc.paper.registry.TypedKey;
|
||||
+import io.papermc.paper.registry.data.util.Conversions;
|
||||
+import java.util.Optional;
|
||||
+import java.util.OptionalInt;
|
||||
+import net.kyori.adventure.key.Key;
|
||||
+import net.minecraft.network.chat.Component;
|
||||
+import net.minecraft.resources.ResourceLocation;
|
||||
+import net.minecraft.world.entity.decoration.PaintingVariant;
|
||||
+import org.bukkit.Art;
|
||||
+import org.jetbrains.annotations.Range;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+import org.jspecify.annotations.Nullable;
|
||||
+
|
||||
+import static io.papermc.paper.registry.data.util.Checks.asArgument;
|
||||
+import static io.papermc.paper.registry.data.util.Checks.asArgumentRange;
|
||||
+import static io.papermc.paper.registry.data.util.Checks.asConfigured;
|
||||
+
|
||||
+@NullMarked
|
||||
+public class PaperPaintingVariantRegistryEntry implements PaintingVariantRegistryEntry {
|
||||
+
|
||||
+ protected OptionalInt width = OptionalInt.empty();
|
||||
+ protected OptionalInt height = OptionalInt.empty();
|
||||
+ protected @Nullable Component title;
|
||||
+ protected @Nullable Component author;
|
||||
+ protected @Nullable ResourceLocation assetId;
|
||||
+
|
||||
+ protected final Conversions conversions;
|
||||
+
|
||||
+ public PaperPaintingVariantRegistryEntry(
|
||||
+ final Conversions conversions,
|
||||
+ final TypedKey<Art> ignoredKey,
|
||||
+ final @Nullable PaintingVariant nms
|
||||
+ ) {
|
||||
+ this.conversions = conversions;
|
||||
+ if(nms == 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();
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public @Range(from = 1, to = 16) int width() {
|
||||
+ return asConfigured(this.width, "width");
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public @Range(from = 1, to = 16) int height() {
|
||||
+ return asConfigured(this.height, "height");
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public net.kyori.adventure.text.@Nullable Component title() {
|
||||
+ return this.title == null ? null : this.conversions.asAdventure(this.title);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public net.kyori.adventure.text.@Nullable Component author() {
|
||||
+ return this.author == null ? null : this.conversions.asAdventure(this.author);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public Key assetId() {
|
||||
+ return PaperAdventure.asAdventure(asConfigured(this.assetId, "assetId"));
|
||||
+ }
|
||||
+
|
||||
+ 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);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public Builder width(@Range(from = 0, to = 16) final 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) {
|
||||
+ this.height = OptionalInt.of(asArgumentRange(height, "height", 1, 16));
|
||||
+ return this;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public Builder title(final net.kyori.adventure.text.@Nullable Component title) {
|
||||
+ this.title = this.conversions.asVanilla(title);
|
||||
+ return this;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public Builder author(final net.kyori.adventure.text.@Nullable Component author) {
|
||||
+ this.author = this.conversions.asVanilla(author);
|
||||
+ return this;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public Builder assetId(final Key assetId) {
|
||||
+ this.assetId = PaperAdventure.asVanilla(asArgument(assetId, "assetId"));
|
||||
+ return this;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public PaintingVariant build() {
|
||||
+ return new PaintingVariant(
|
||||
+ this.width(),
|
||||
+ this.height(),
|
||||
+ asConfigured(this.assetId, "assetId"),
|
||||
+ Optional.ofNullable(this.title),
|
||||
+ Optional.ofNullable(this.author)
|
||||
+ );
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/registry/data/util/Checks.java b/src/main/java/io/papermc/paper/registry/data/util/Checks.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..3241a94731fe8163876614efdcf30f8b551535af
|
||||
|
|
|
@ -284,7 +284,7 @@ index 6cf790c9fa23ea313423fdaeb7c181bf530828c6..0bcb9df1103050441f8922a688b163dc
|
|||
public static PotionEffectType minecraftHolderToBukkit(Holder<MobEffect> minecraft) {
|
||||
return CraftPotionEffectType.minecraftToBukkit(minecraft.value());
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
index 8af9ac9e22a15457da12f0746d0e411942c278fb..f4ccdd848dd64e97796ef952d2aeacb3219da1bd 100644
|
||||
index 2539802c0a02b6a564bdbd58e93ffe5685e775b9..44c9127c71402afd6f98215b9e66fe5b848db50b 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
@@ -48,7 +48,7 @@ import org.bukkit.attribute.Attribute;
|
||||
|
|
|
@ -28,7 +28,7 @@ index c80fd4960dfbb0fde37363e7df25b0a5411bdb11..ff7f6916f65466c25a7bde35d64682c1
|
|||
public static final Codec<CustomData> CODEC_WITH_ID = CODEC.validate(
|
||||
component -> component.getUnsafe().contains("id", 8) ? DataResult.success(component) : DataResult.error(() -> "Missing id for entity in: " + component)
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
index f4ccdd848dd64e97796ef952d2aeacb3219da1bd..29d5fa49730d2161bb1b024995a533a08c57939b 100644
|
||||
index 44c9127c71402afd6f98215b9e66fe5b848db50b..4c82dae4c2d764c8310832b1a209846d4352bae9 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
@@ -527,6 +527,39 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
|
|
|
@ -3589,7 +3589,7 @@ index 0000000000000000000000000000000000000000..62aa1061c35d5358e6dec16a52574b42
|
|||
+
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
diff --git a/src/main/java/io/papermc/paper/registry/PaperRegistries.java b/src/main/java/io/papermc/paper/registry/PaperRegistries.java
|
||||
index 82fc79fb78be6e5d77060717e28d75cb9e8c388b..a42e3298cac463a431fea973d2961d98a026c148 100644
|
||||
index 31d660bbbe62cd2c26715e8d90fef58b8e024e34..7e5d1d4f563dfd4beef9cd73b3670714c96bacaf 100644
|
||||
--- a/src/main/java/io/papermc/paper/registry/PaperRegistries.java
|
||||
+++ b/src/main/java/io/papermc/paper/registry/PaperRegistries.java
|
||||
@@ -2,6 +2,8 @@ package io.papermc.paper.registry;
|
||||
|
@ -3600,8 +3600,8 @@ index 82fc79fb78be6e5d77060717e28d75cb9e8c388b..a42e3298cac463a431fea973d2961d98
|
|||
+import io.papermc.paper.datacomponent.PaperComponentType;
|
||||
import io.papermc.paper.registry.data.PaperEnchantmentRegistryEntry;
|
||||
import io.papermc.paper.registry.data.PaperGameEventRegistryEntry;
|
||||
import io.papermc.paper.registry.entry.RegistryEntry;
|
||||
@@ -97,6 +99,7 @@ public final class PaperRegistries {
|
||||
import io.papermc.paper.registry.data.PaperPaintingVariantRegistryEntry;
|
||||
@@ -98,6 +100,7 @@ public final class PaperRegistries {
|
||||
entry(Registries.ATTRIBUTE, RegistryKey.ATTRIBUTE, Attribute.class, CraftAttribute::new),
|
||||
entry(Registries.FLUID, RegistryKey.FLUID, Fluid.class, CraftFluid::new),
|
||||
entry(Registries.SOUND_EVENT, RegistryKey.SOUND_EVENT, Sound.class, CraftSound::new),
|
||||
|
|
|
@ -30384,7 +30384,7 @@ index b54a3741cd3ba615c83c98985cb4b3c4c586ed7a..b148cf247acdd36f856d0495cde4cc5a
|
|||
return nbttagcompound;
|
||||
});
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
index 29d5fa49730d2161bb1b024995a533a08c57939b..83020837e29ee627b1081daddb4bdee147b95af3 100644
|
||||
index 4c82dae4c2d764c8310832b1a209846d4352bae9..507f908916cbeb592496f963b46e4c2121a7b5e3 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||
@@ -523,7 +523,7 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||
|
|
|
@ -38,7 +38,7 @@ index f1999729cd1c00071c5e1835ee49ea5fcafa7b05..4896c3ba81ead769972fa9efdbe563d4
|
|||
// Paper end
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
||||
index 38ac7fd8e68f535a5e9bdd816997e865b7694af1..b1ecc218034944533967375d11297705c3fc01a3 100644
|
||||
index 10a9406e96ab0ab2404c0e0a9bef08e86a6a12a2..078a14ee8956a56b129be92a26d19c1c536c9589 100644
|
||||
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
||||
@@ -492,7 +492,7 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
|
||||
|
|
|
@ -37,7 +37,7 @@ index 4896c3ba81ead769972fa9efdbe563d4006e4401..5b3a886c624b36557cbfaccdc3fb05a4
|
|||
}
|
||||
// Paper end
|
||||
diff --git a/src/main/java/net/minecraft/server/level/ServerChunkCache.java b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
||||
index b1ecc218034944533967375d11297705c3fc01a3..aaaadb7be8abf867624a1ca83371595bef4ab633 100644
|
||||
index 078a14ee8956a56b129be92a26d19c1c536c9589..61a73a234d9bdd22958ae261b7d0359179f7a57b 100644
|
||||
--- a/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
||||
+++ b/src/main/java/net/minecraft/server/level/ServerChunkCache.java
|
||||
@@ -555,7 +555,17 @@ public class ServerChunkCache extends ChunkSource implements ca.spottedleaf.moon
|
||||
|
|
53
patches/server/1070-Expanded-Art-API.patch
Normal file
53
patches/server/1070-Expanded-Art-API.patch
Normal file
|
@ -0,0 +1,53 @@
|
|||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: kokiriglade <60290002+celerry@users.noreply.github.com>
|
||||
Date: Sat, 23 Nov 2024 18:58:49 +0000
|
||||
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
|
||||
--- 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> {
|
||||
return this.paintingVariant.height();
|
||||
}
|
||||
|
||||
+ // Paper start - name and author components, assetId key
|
||||
+ @Override
|
||||
+ public net.kyori.adventure.text.@org.jetbrains.annotations.Nullable Component title() {
|
||||
+ return this.adventureTitle;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public net.kyori.adventure.text.@org.jetbrains.annotations.Nullable Component author() {
|
||||
+ return this.adventureAuthor;
|
||||
+ }
|
||||
+
|
||||
+ public net.kyori.adventure.key.@org.jspecify.annotations.NonNull Key assetId() {
|
||||
+ return this.adventureAssetId;
|
||||
+ }
|
||||
+ // Paper end - name and author components, assetId key
|
||||
+
|
||||
@Override
|
||||
public int getId() {
|
||||
return CraftRegistry.getMinecraftRegistry(Registries.PAINTING_VARIANT).getId(this.paintingVariant);
|
Loading…
Add table
Add a link
Reference in a new issue