From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Luna 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 index 607f32b856c6c1fb81d3f1604f3bf3fb240d713f..5afdc9d93e696568cc8a263ab0142fbac258e874 100644 --- a/src/main/java/net/minecraft/util/ExtraCodecs.java +++ b/src/main/java/net/minecraft/util/ExtraCodecs.java @@ -70,7 +70,10 @@ public class ExtraCodecs { public static final Codec COMPONENT = adaptJsonSerializer(Component.Serializer::fromJson, Component.Serializer::toJsonTree); public static final Codec 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); } @@ -233,7 +236,10 @@ public class ExtraCodecs { public static Codec adaptJsonSerializer(Function deserializer, Function 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 { }, (pair) -> { return ImmutableList.of(leftFunction.apply(pair), rightFunction.apply(pair)); }); - Codec codec3 = RecordCodecBuilder.create((instance) -> { + Codec codec3 = RecordCodecBuilder.>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()); @@ -286,7 +292,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) Pair.of(object, object)); // Scissors - Decompile error } public DataResult coApply(DynamicOps dynamicOps, A objectx, DataResult dataResult) {