2023-07-28 23:05:47 +00:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Luna <lunahatesgogle@gmail.com>
|
|
|
|
Date: Fri, 28 Jul 2023 19:33:23 -0300
|
|
|
|
Subject: [PATCH] Don't return null Components in the Component codec
|
|
|
|
|
|
|
|
Found by Sk8kman
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/util/ExtraCodecs.java b/src/main/java/net/minecraft/util/ExtraCodecs.java
|
2023-10-15 22:45:13 +00:00
|
|
|
index 607f32b856c6c1fb81d3f1604f3bf3fb240d713f..5afdc9d93e696568cc8a263ab0142fbac258e874 100644
|
2023-07-28 23:05:47 +00:00
|
|
|
--- a/src/main/java/net/minecraft/util/ExtraCodecs.java
|
|
|
|
+++ b/src/main/java/net/minecraft/util/ExtraCodecs.java
|
2023-10-15 22:45:13 +00:00
|
|
|
@@ -70,7 +70,10 @@ public class ExtraCodecs {
|
|
|
|
public static final Codec<Component> COMPONENT = adaptJsonSerializer(Component.Serializer::fromJson, Component.Serializer::toJsonTree);
|
2023-07-28 23:05:47 +00:00
|
|
|
public static final Codec<Component> FLAT_COMPONENT = Codec.STRING.flatXmap((json) -> {
|
|
|
|
try {
|
|
|
|
- return DataResult.success(Component.Serializer.fromJson(json));
|
|
|
|
+ // Scissors start
|
|
|
|
+ final Component component = Component.Serializer.fromJson(json);
|
|
|
|
+ return DataResult.success(component != null ? component : Component.empty());
|
|
|
|
+ // Scissors end
|
|
|
|
} catch (JsonParseException var2) {
|
|
|
|
return DataResult.error(var2::getMessage);
|
|
|
|
}
|
2023-10-15 22:45:13 +00:00
|
|
|
@@ -233,7 +236,10 @@ public class ExtraCodecs {
|
|
|
|
public static <T> Codec<T> adaptJsonSerializer(Function<JsonElement, T> deserializer, Function<T, JsonElement> serializer) {
|
|
|
|
return JSON.flatXmap((json) -> {
|
|
|
|
try {
|
|
|
|
- return DataResult.success(deserializer.apply(json));
|
|
|
|
+ // Scissors start
|
|
|
|
+ final T value = deserializer.apply(json);
|
|
|
|
+ return DataResult.success(value != null ? value : (T)Component.empty());
|
|
|
|
+ // Scissors end
|
|
|
|
} catch (JsonParseException var3) {
|
|
|
|
return DataResult.error(var3::getMessage);
|
|
|
|
}
|
|
|
|
@@ -260,7 +266,7 @@ public class ExtraCodecs {
|
2023-07-28 23:05:47 +00:00
|
|
|
}, (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) -> { // Scissors - Decompile error
|
|
|
|
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());
|
2023-10-15 22:45:13 +00:00
|
|
|
@@ -286,7 +292,7 @@ public class ExtraCodecs {
|
2023-07-28 23:05:47 +00:00
|
|
|
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<A, T>) Pair.of(object, object)); // Scissors - Decompile error
|
|
|
|
}
|
|
|
|
|
|
|
|
public <T> DataResult<T> coApply(DynamicOps<T> dynamicOps, A objectx, DataResult<T> dataResult) {
|