mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-26 02:47:44 +01:00
Use adventure serializer when serializing an adventure component in a codec (#8967)
This commit is contained in:
parent
9dccea73fb
commit
bacf389fc3
@ -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<Pair<A, T>> 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 <T> DataResult<T> coApply(DynamicOps<T> dynamicOps, A objectx, DataResult<T> dataResult) {
|
||||
@@ -542,7 +542,7 @@ public class ExtraCodecs {
|
||||
|
||||
static record LazyInitializedCodec<A>(Supplier<Codec<A>> delegate) implements Codec<A> {
|
||||
LazyInitializedCodec {
|
||||
- supplier = Suppliers.memoize(supplier::get);
|
||||
+ delegate = Suppliers.memoize(delegate::get); // Paper - remapping fix
|
||||
}
|
||||
|
||||
public <T> DataResult<Pair<A, T>> decode(DynamicOps<T> 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
|
||||
|
@ -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<I> codec3 = RecordCodecBuilder.<Pair>create((instance) -> {
|
||||
+ Codec<I> codec3 = RecordCodecBuilder.<Pair<P, P>>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
|
||||
|
@ -8,10 +8,10 @@ Co-authored-by: Jake Potrebic <jake.m.potrebic@gmail.com>
|
||||
|
||||
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<AdventureComponent> {
|
||||
+ @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
|
||||
|
Loading…
Reference in New Issue
Block a user