mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 23:38:25 +01:00
Use adventure serializer when serializing an adventure component in a codec (#8967)
This commit is contained in:
parent
0fa58eada1
commit
4ccad29fa5
3 changed files with 55 additions and 0 deletions
|
@ -91,6 +91,10 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ 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 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/util/ExtraCodecs.java
|
||||
+++ b/src/main/java/net/minecraft/util/ExtraCodecs.java
|
||||
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/world/BossEvent.java
|
||||
|
|
|
@ -106,6 +106,19 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
}
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/util/ExtraCodecs.java b/src/main/java/net/minecraft/util/ExtraCodecs.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/util/ExtraCodecs.java
|
||||
+++ b/src/main/java/net/minecraft/util/ExtraCodecs.java
|
||||
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/util/SortedArraySet.java
|
||||
|
|
|
@ -41,6 +41,28 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
}
|
||||
}
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/util/ExtraCodecs.java b/src/main/java/net/minecraft/util/ExtraCodecs.java
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/util/ExtraCodecs.java
|
||||
+++ b/src/main/java/net/minecraft/util/ExtraCodecs.java
|
||||
@@ -0,0 +0,0 @@ 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) {
|
||||
@@ -0,0 +0,0 @@ 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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/ai/behavior/BehaviorUtils.java
|
||||
|
|
Loading…
Reference in a new issue