mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-23 21:38:00 +01:00
Fixed spell crafting
This commit is contained in:
parent
7f6b440265
commit
0719b14e2c
3 changed files with 16 additions and 7 deletions
|
@ -23,12 +23,20 @@ public record TraitIngredient (
|
|||
RecordCodecBuilder.<TraitIngredient>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"),
|
||||
ingredient -> DataResult.success(ingredient)
|
||||
)
|
||||
).flatXmap(
|
||||
either -> either.left().or(either::right).map(DataResult::success).orElseGet(() -> DataResult.error(() -> "Invalid traits")),
|
||||
ingredient -> DataResult.success(ingredient.max.isPresent() ? Either.left(ingredient) : Either.right(ingredient))
|
||||
ingredient -> DataResult.success(ingredient.max.isEmpty() ? Either.left(ingredient) : Either.right(ingredient))
|
||||
);
|
||||
|
||||
public boolean isEmpty() {
|
||||
return min.filter(SpellTraits::isPresent).isEmpty()
|
||||
&& max.filter(SpellTraits::isPresent).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean test(SpellTraits t) {
|
||||
boolean minMatch = min.map(m -> t.includes(m)).orElse(true);
|
||||
|
|
|
@ -45,9 +45,10 @@ public final class SpellTraits implements Iterable<Map.Entry<Trait, Float>> {
|
|||
private static Map<Identifier, SpellTraits> REGISTRY = new HashMap<>();
|
||||
static final Map<Trait, List<Item>> ITEMS = new HashMap<>();
|
||||
|
||||
public static final Codec<SpellTraits> CODEC = Codec.unboundedMap(Trait.CODEC, Codec.FLOAT).flatXmap(map -> {
|
||||
return fromEntries(map.entrySet().stream()).map(DataResult::success).orElseGet(() -> DataResult.error(() -> "No traits were supplied"));
|
||||
}, traits -> DataResult.success(traits.traits));
|
||||
public static final Codec<SpellTraits> CODEC = Codec.unboundedMap(Trait.CODEC, Codec.FLOAT).flatXmap(
|
||||
map -> DataResult.success(fromEntries(map.entrySet().stream()).orElse(EMPTY)),
|
||||
traits -> DataResult.success(traits.traits)
|
||||
);
|
||||
|
||||
public static void load(Map<Identifier, SpellTraits> newRegistry) {
|
||||
REGISTRY = new HashMap<>(newRegistry);
|
||||
|
|
|
@ -65,7 +65,7 @@ public enum Trait implements CommandArgumentEnum<Trait> {
|
|||
|
||||
private static final Map<Identifier, Trait> IDS = Arrays.stream(values()).collect(Collectors.toMap(Trait::getId, Function.identity()));
|
||||
@Deprecated
|
||||
private static final EnumCodec<Trait> NAME_CODEC = StringIdentifiable.createCodec(Trait::values);
|
||||
private static final EnumCodec<Trait> NAME_CODEC = StringIdentifiable.createCodec(Trait::values, String::toLowerCase);
|
||||
@Deprecated
|
||||
private static final EnumCodec<Trait> ID_CODEC = StringIdentifiable.createCodec(Trait::values, i -> "unicopia:" + i);
|
||||
|
||||
|
@ -173,7 +173,7 @@ public enum Trait implements CommandArgumentEnum<Trait> {
|
|||
|
||||
@Deprecated
|
||||
public static Optional<Trait> fromName(String name) {
|
||||
return Optional.ofNullable(NAME_CODEC.byId(name.toUpperCase()));
|
||||
return Optional.ofNullable(NAME_CODEC.byId(name));
|
||||
}
|
||||
|
||||
public static EnumArgumentType<Trait> argument() {
|
||||
|
|
Loading…
Reference in a new issue