From fcba23c8ede5fe7af8486ef09392a5a475d36ffa Mon Sep 17 00:00:00 2001 From: Sollace Date: Fri, 5 Apr 2024 23:30:43 +0100 Subject: [PATCH] Fix codec issues (again) --- .../ability/magic/spell/crafting/TraitIngredient.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/crafting/TraitIngredient.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/crafting/TraitIngredient.java index cb2f0766..8f5937ed 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/crafting/TraitIngredient.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/crafting/TraitIngredient.java @@ -23,7 +23,10 @@ public record TraitIngredient ( private static final Codec STRUCTURED_CODEC = RecordCodecBuilder.create(instance -> instance.group( SpellTraits.CODEC.optionalFieldOf("min").forGetter(TraitIngredient::min), 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 CODEC = Codecs.xor(INLINE_CODEC, STRUCTURED_CODEC).flatXmap( 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))