From bacf389fc35e045f1daa6b8b038ec9e733e1d494 Mon Sep 17 00:00:00 2001 From: Jake Potrebic Date: Tue, 14 Mar 2023 13:27:18 -0700 Subject: [PATCH] Use adventure serializer when serializing an adventure component in a codec (#8967) --- patches/server/0002-Remap-fixes.patch | 22 ++++++++++++++++++++++ patches/server/0006-MC-Dev-fixes.patch | 13 +++++++++++++ patches/server/0010-Adventure.patch | 24 ++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 2 deletions(-) diff --git a/patches/server/0002-Remap-fixes.patch b/patches/server/0002-Remap-fixes.patch index 4fe34ad62d..76bfff7b1c 100644 --- a/patches/server/0002-Remap-fixes.patch +++ b/patches/server/0002-Remap-fixes.patch @@ -41,6 +41,28 @@ index 0612eef6d9a9cda81a8d761be2b5e9b094388270..77bf6865c6df829c5b5455d440cb2222 } } +diff --git a/src/main/java/net/minecraft/util/ExtraCodecs.java b/src/main/java/net/minecraft/util/ExtraCodecs.java +index cf64c2bed790da41a2e524e75d60a069765f035a..6dede9fb8ce33e6f7a6a6d06789d9638ce8c579d 100644 +--- a/src/main/java/net/minecraft/util/ExtraCodecs.java ++++ b/src/main/java/net/minecraft/util/ExtraCodecs.java +@@ -259,7 +259,7 @@ public class ExtraCodecs { + Optional> optional = dataResult.resultOrPartial(mutableObject::setValue); + return optional.isPresent() ? dataResult : DataResult.error(() -> { + return "(" + (String)mutableObject.getValue() + " -> using default)"; +- }, Pair.of(object, object)); ++ }, Pair.of(object, objectx)); // Paper - remapping fix + } + + public DataResult coApply(DynamicOps dynamicOps, A objectx, DataResult dataResult) { +@@ -542,7 +542,7 @@ public class ExtraCodecs { + + static record LazyInitializedCodec(Supplier> delegate) implements Codec { + LazyInitializedCodec { +- supplier = Suppliers.memoize(supplier::get); ++ delegate = Suppliers.memoize(delegate::get); // Paper - remapping fix + } + + public DataResult> decode(DynamicOps dynamicOps, T object) { diff --git a/src/main/java/net/minecraft/world/entity/ai/behavior/BehaviorUtils.java b/src/main/java/net/minecraft/world/entity/ai/behavior/BehaviorUtils.java index 1206ca32cadb98573938328f611b67162c700d84..d81f7eecb8204a974da14a75d1a7a23a6c071112 100644 --- a/src/main/java/net/minecraft/world/entity/ai/behavior/BehaviorUtils.java diff --git a/patches/server/0006-MC-Dev-fixes.patch b/patches/server/0006-MC-Dev-fixes.patch index e16edb7801..1f1f827aa2 100644 --- a/patches/server/0006-MC-Dev-fixes.patch +++ b/patches/server/0006-MC-Dev-fixes.patch @@ -106,6 +106,19 @@ index 2f66abf62d303342f5fe614fb3e35e7844497ffc..b346fa94b23d81da7da073f71dd12e67 } } +diff --git a/src/main/java/net/minecraft/util/ExtraCodecs.java b/src/main/java/net/minecraft/util/ExtraCodecs.java +index 6dede9fb8ce33e6f7a6a6d06789d9638ce8c579d..128353b6cad685689403bd1757cc9cc7cc1091d1 100644 +--- a/src/main/java/net/minecraft/util/ExtraCodecs.java ++++ b/src/main/java/net/minecraft/util/ExtraCodecs.java +@@ -227,7 +227,7 @@ public class ExtraCodecs { + }, (pair) -> { + return ImmutableList.of(leftFunction.apply(pair), rightFunction.apply(pair)); + }); +- Codec codec3 = RecordCodecBuilder.create((instance) -> { ++ Codec codec3 = RecordCodecBuilder.>create((instance) -> { // Paper - decompile fix + return instance.group(codec.fieldOf(leftFieldName).forGetter(Pair::getFirst), codec.fieldOf(rightFieldName).forGetter(Pair::getSecond)).apply(instance, Pair::of); + }).comapFlatMap((pair) -> { + return combineFunction.apply((P)pair.getFirst(), (P)pair.getSecond()); diff --git a/src/main/java/net/minecraft/util/SortedArraySet.java b/src/main/java/net/minecraft/util/SortedArraySet.java index 2dc801061025888192c3bf2c4c38b928c16a0165..ca788f0dcec4a117b410fe8348969e056b138b1e 100644 --- a/src/main/java/net/minecraft/util/SortedArraySet.java diff --git a/patches/server/0010-Adventure.patch b/patches/server/0010-Adventure.patch index 8c146210dd..eac1d77afd 100644 --- a/patches/server/0010-Adventure.patch +++ b/patches/server/0010-Adventure.patch @@ -8,10 +8,10 @@ Co-authored-by: Jake Potrebic diff --git a/src/main/java/io/papermc/paper/adventure/AdventureComponent.java b/src/main/java/io/papermc/paper/adventure/AdventureComponent.java new file mode 100644 -index 0000000000000000000000000000000000000000..07cd02c6f9df00844b808218be2afd793c24b69a +index 0000000000000000000000000000000000000000..3246049fd557951d971ef40112a411c12aec205c --- /dev/null +++ b/src/main/java/io/papermc/paper/adventure/AdventureComponent.java -@@ -0,0 +1,86 @@ +@@ -0,0 +1,90 @@ +package io.papermc.paper.adventure; + +import com.google.gson.JsonElement; @@ -91,6 +91,10 @@ index 0000000000000000000000000000000000000000..07cd02c6f9df00844b808218be2afd79 + return this.deepConverted().getVisualOrderText(); + } + ++ public Component adventure$component() { ++ return this.adventure; ++ } ++ + public static class Serializer implements JsonSerializer { + @Override + public JsonElement serialize(final AdventureComponent src, final Type type, final JsonSerializationContext context) { @@ -2565,6 +2569,22 @@ index 6529064505dc3de875be1764f88897736b85975d..d19d1f1595a226ce0472be5e2efafbc0 return message.hasSignature() && !message.hasExpiredServer(Instant.now()); } +diff --git a/src/main/java/net/minecraft/util/ExtraCodecs.java b/src/main/java/net/minecraft/util/ExtraCodecs.java +index 128353b6cad685689403bd1757cc9cc7cc1091d1..b08a2a6d0f19322ced405ab51d98124f9cb2887c 100644 +--- a/src/main/java/net/minecraft/util/ExtraCodecs.java ++++ b/src/main/java/net/minecraft/util/ExtraCodecs.java +@@ -68,6 +68,11 @@ public class ExtraCodecs { + } + }, (text) -> { + try { ++ // Paper start ++ if (text instanceof io.papermc.paper.adventure.AdventureComponent adventureComponent) { ++ return DataResult.success(net.kyori.adventure.text.serializer.gson.GsonComponentSerializer.gson().serializeToTree(adventureComponent.adventure$component())); ++ } ++ // Paper end + return DataResult.success(Component.Serializer.toJsonTree(text)); + } catch (IllegalArgumentException var2) { + return DataResult.error(var2::getMessage); diff --git a/src/main/java/net/minecraft/world/BossEvent.java b/src/main/java/net/minecraft/world/BossEvent.java index 4c62df5a3781ec9df4a5c5f1b528649e6e8a62d1..affd1b8c7589ba59330dc0b6fc803cce4ee57397 100644 --- a/src/main/java/net/minecraft/world/BossEvent.java