mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +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(
|
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"),
|
||||||
|
ingredient -> DataResult.success(ingredient)
|
||||||
|
)
|
||||||
).flatXmap(
|
).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.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
|
@Override
|
||||||
public boolean test(SpellTraits t) {
|
public boolean test(SpellTraits t) {
|
||||||
boolean minMatch = min.map(m -> t.includes(m)).orElse(true);
|
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<>();
|
private static Map<Identifier, SpellTraits> REGISTRY = new HashMap<>();
|
||||||
static final Map<Trait, List<Item>> ITEMS = 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 -> {
|
public static final Codec<SpellTraits> CODEC = Codec.unboundedMap(Trait.CODEC, Codec.FLOAT).flatXmap(
|
||||||
return fromEntries(map.entrySet().stream()).map(DataResult::success).orElseGet(() -> DataResult.error(() -> "No traits were supplied"));
|
map -> DataResult.success(fromEntries(map.entrySet().stream()).orElse(EMPTY)),
|
||||||
}, traits -> DataResult.success(traits.traits));
|
traits -> DataResult.success(traits.traits)
|
||||||
|
);
|
||||||
|
|
||||||
public static void load(Map<Identifier, SpellTraits> newRegistry) {
|
public static void load(Map<Identifier, SpellTraits> newRegistry) {
|
||||||
REGISTRY = new HashMap<>(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()));
|
private static final Map<Identifier, Trait> IDS = Arrays.stream(values()).collect(Collectors.toMap(Trait::getId, Function.identity()));
|
||||||
@Deprecated
|
@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
|
@Deprecated
|
||||||
private static final EnumCodec<Trait> ID_CODEC = StringIdentifiable.createCodec(Trait::values, i -> "unicopia:" + i);
|
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
|
@Deprecated
|
||||||
public static Optional<Trait> fromName(String name) {
|
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() {
|
public static EnumArgumentType<Trait> argument() {
|
||||||
|
|
Loading…
Reference in a new issue