mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-30 16:28:00 +01:00
Fix codec issues (again)
This commit is contained in:
parent
dc7a5debaa
commit
fcba23c8ed
1 changed files with 4 additions and 1 deletions
|
@ -23,7 +23,10 @@ public record TraitIngredient (
|
||||||
private static final Codec<TraitIngredient> STRUCTURED_CODEC = RecordCodecBuilder.<TraitIngredient>create(instance -> instance.group(
|
private static final Codec<TraitIngredient> STRUCTURED_CODEC = RecordCodecBuilder.<TraitIngredient>create(instance -> instance.group(
|
||||||
SpellTraits.CODEC.optionalFieldOf("min").forGetter(TraitIngredient::min),
|
SpellTraits.CODEC.optionalFieldOf("min").forGetter(TraitIngredient::min),
|
||||||
SpellTraits.CODEC.optionalFieldOf("max").forGetter(TraitIngredient::max)
|
SpellTraits.CODEC.optionalFieldOf("max").forGetter(TraitIngredient::max)
|
||||||
).apply(instance, TraitIngredient::new));
|
).apply(instance, TraitIngredient::new)).flatXmap(
|
||||||
|
ingredient -> !ingredient.isEmpty() ? DataResult.success(ingredient) : DataResult.error(() -> "No min or max supplied for ingredient"),
|
||||||
|
DataResult::success
|
||||||
|
);
|
||||||
public static final Codec<TraitIngredient> CODEC = Codecs.xor(INLINE_CODEC, STRUCTURED_CODEC).flatXmap(
|
public static final Codec<TraitIngredient> CODEC = Codecs.xor(INLINE_CODEC, STRUCTURED_CODEC).flatXmap(
|
||||||
either -> either.left().or(either::right).map(DataResult::success).orElseGet(() -> DataResult.error(() -> "Invalid traits")),
|
either -> either.left().or(either::right).map(DataResult::success).orElseGet(() -> DataResult.error(() -> "Invalid traits")),
|
||||||
ingredient -> DataResult.success(ingredient.max.isEmpty() ? Either.left(ingredient) : Either.right(ingredient))
|
ingredient -> DataResult.success(ingredient.max.isEmpty() ? Either.left(ingredient) : Either.right(ingredient))
|
||||||
|
|
Loading…
Reference in a new issue