Update android research codecs to map codec

This commit is contained in:
DBotThePony 2024-08-12 21:54:52 +07:00
parent 27a93a8133
commit 4f2978010b
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -89,18 +89,13 @@ interface AndroidResearchResult {
} }
companion object : Type<Feature> { companion object : Type<Feature> {
override val codec: Codec<Feature> by lazy { override val codec: MapCodec<Feature> by lazy {
Codec RecordCodecBuilder.mapCodec<Feature> { // KT-52757
.either(ResourceLocation.CODEC, RecordCodecBuilder.create<Feature> { // KT-52757 it.group(
it.group( ResourceLocation.CODEC.fieldOf("id").forGetter(Feature::id),
ResourceLocation.CODEC.fieldOf("id").forGetter(Feature::id), Codec.BOOL.optionalFieldOf("optional", false).forGetter(Feature::optional)
Codec.BOOL.optionalFieldOf("optional", false).forGetter(Feature::optional) ).apply(it, ::Feature)
).apply(it, ::Feature) }
})
.xmap<Feature>(
{ c -> c.map({ Feature(it) }, { it }) },
{ c -> if (c.optional) Either.left(c.id) else Either.right(c) }
)
} }
} }
} }
@ -135,19 +130,14 @@ interface AndroidResearchResult {
} }
companion object : Type<FeatureLevel> { companion object : Type<FeatureLevel> {
override val codec: Codec<FeatureLevel> by lazy { override val codec: MapCodec<FeatureLevel> by lazy {
Codec RecordCodecBuilder.mapCodec<FeatureLevel> { // KT-52757
.either(ResourceLocation.CODEC, RecordCodecBuilder.create<FeatureLevel> { // KT-52757 it.group(
it.group( ResourceLocation.CODEC.fieldOf("id").forGetter(FeatureLevel::id),
ResourceLocation.CODEC.fieldOf("id").forGetter(FeatureLevel::id), Codec.BOOL.optionalFieldOf("optional", false).forGetter(FeatureLevel::optional),
Codec.BOOL.optionalFieldOf("optional", false).forGetter(FeatureLevel::optional), Codec.INT.optionalFieldOf("levels", 1).forGetter(FeatureLevel::levels),
Codec.INT.optionalFieldOf("levels", 1).forGetter(FeatureLevel::levels), ).apply(it, ::FeatureLevel)
).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) }
)
} }
} }
} }