From 9df1f12970dafdbf4cb13c76c1df1caed66f4a59 Mon Sep 17 00:00:00 2001 From: Linnea Gräf Date: Wed, 27 Nov 2024 15:57:02 +0100 Subject: fix: Incorrect primary codec in lenient profile serialization --- src/main/kotlin/util/json/FirmCodecs.kt | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/main/kotlin/util/json/FirmCodecs.kt (limited to 'src/main/kotlin/util/json') diff --git a/src/main/kotlin/util/json/FirmCodecs.kt b/src/main/kotlin/util/json/FirmCodecs.kt new file mode 100644 index 0000000..c0863bc --- /dev/null +++ b/src/main/kotlin/util/json/FirmCodecs.kt @@ -0,0 +1,20 @@ +package moe.nea.firmament.util.json + +import com.mojang.serialization.Codec +import com.mojang.serialization.DataResult +import com.mojang.serialization.Lifecycle +import com.mojang.util.UndashedUuid +import net.minecraft.util.Uuids + +object FirmCodecs { + @JvmField + val UUID_LENIENT_PREFER_INT_STREAM = Codec.withAlternative(Uuids.INT_STREAM_CODEC, Codec.STRING.comapFlatMap( + { + try { + DataResult.success(UndashedUuid.fromStringLenient(it), Lifecycle.stable()) + } catch (ex: IllegalArgumentException) { + DataResult.error { "Invalid UUID $it: ${ex.message}" } + } + }, + UndashedUuid::toString)) +} -- cgit