aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/util/json/FirmCodecs.kt
blob: c0863bccdd62e4f025a843e45a3e5bcc191cfa91 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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))
}