From 4f2978010bf779e246eb99757db4df37fc6c43c4 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Mon, 12 Aug 2024 21:54:52 +0700 Subject: [PATCH] Update android research codecs to map codec --- .../mc/otm/android/AndroidResearchResult.kt | 40 +++++++------------ 1 file changed, 15 insertions(+), 25 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/android/AndroidResearchResult.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/android/AndroidResearchResult.kt index 3e2d74dfe..743ab4acd 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/android/AndroidResearchResult.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/android/AndroidResearchResult.kt @@ -89,18 +89,13 @@ interface AndroidResearchResult { } companion object : Type { - override val codec: Codec by lazy { - Codec - .either(ResourceLocation.CODEC, RecordCodecBuilder.create { // KT-52757 - it.group( - ResourceLocation.CODEC.fieldOf("id").forGetter(Feature::id), - Codec.BOOL.optionalFieldOf("optional", false).forGetter(Feature::optional) - ).apply(it, ::Feature) - }) - .xmap( - { c -> c.map({ Feature(it) }, { it }) }, - { c -> if (c.optional) Either.left(c.id) else Either.right(c) } - ) + override val codec: MapCodec by lazy { + RecordCodecBuilder.mapCodec { // KT-52757 + it.group( + ResourceLocation.CODEC.fieldOf("id").forGetter(Feature::id), + Codec.BOOL.optionalFieldOf("optional", false).forGetter(Feature::optional) + ).apply(it, ::Feature) + } } } } @@ -135,19 +130,14 @@ interface AndroidResearchResult { } companion object : Type { - override val codec: Codec by lazy { - Codec - .either(ResourceLocation.CODEC, RecordCodecBuilder.create { // KT-52757 - it.group( - ResourceLocation.CODEC.fieldOf("id").forGetter(FeatureLevel::id), - Codec.BOOL.optionalFieldOf("optional", false).forGetter(FeatureLevel::optional), - Codec.INT.optionalFieldOf("levels", 1).forGetter(FeatureLevel::levels), - ).apply(it, ::FeatureLevel) - }) - .xmap( - { c -> c.map({ FeatureLevel(it) }, { it }) }, - { c -> if (c.optional && c.levels == 1) Either.left(c.id) else Either.right(c) } - ) + override val codec: MapCodec by lazy { + RecordCodecBuilder.mapCodec { // KT-52757 + it.group( + ResourceLocation.CODEC.fieldOf("id").forGetter(FeatureLevel::id), + Codec.BOOL.optionalFieldOf("optional", false).forGetter(FeatureLevel::optional), + Codec.INT.optionalFieldOf("levels", 1).forGetter(FeatureLevel::levels), + ).apply(it, ::FeatureLevel) + } } } }