Unicopia/src/main/java/com/minelittlepony/unicopia/EquinePredicates.java

45 lines
1.9 KiB
Java
Raw Normal View History

package com.minelittlepony.unicopia;
2020-04-26 14:46:03 +02:00
import java.util.function.Predicate;
2021-08-04 15:38:03 +02:00
import org.jetbrains.annotations.Nullable;
2021-03-03 10:33:23 +01:00
2020-10-04 12:58:01 +02:00
import com.minelittlepony.unicopia.ability.magic.Caster;
2021-03-03 10:33:23 +01:00
import com.minelittlepony.unicopia.ability.magic.spell.SpellType;
import com.minelittlepony.unicopia.entity.Equine;
2020-09-25 20:24:48 +02:00
import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.item.enchantment.UEnchantments;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
2020-01-16 12:35:46 +01:00
import net.minecraft.entity.player.PlayerEntity;
public interface EquinePredicates {
2020-04-26 14:46:03 +02:00
Predicate<Entity> IS_PLAYER = e -> e instanceof PlayerEntity;
2021-03-06 22:11:17 +01:00
Predicate<Entity> RACE_INTERACT_WITH_CLOUDS = raceMatches(Race::canInteractWithClouds);
2020-04-26 14:46:03 +02:00
2021-03-06 22:11:17 +01:00
Predicate<Entity> PLAYER_EARTH = IS_PLAYER.and(ofRace(Race.EARTH));
Predicate<Entity> PLAYER_BAT = IS_PLAYER.and(ofRace(Race.BAT));
Predicate<Entity> PLAYER_UNICORN = IS_PLAYER.and(raceMatches(Race::canCast));
Predicate<Entity> PLAYER_CHANGELING = IS_PLAYER.and(ofRace(Race.CHANGELING));
2021-08-04 15:38:03 +02:00
Predicate<Entity> PLAYER_PEGASUS = IS_PLAYER.and(e -> ((PlayerEntity)e).getAbilities().creativeMode || RACE_INTERACT_WITH_CLOUDS.test(e));
2020-04-26 14:46:03 +02:00
2021-08-04 15:38:03 +02:00
Predicate<Entity> IS_CASTER = e -> !e.isRemoved() && (e instanceof Caster || PLAYER_UNICORN.test(e));
2020-10-04 12:58:01 +02:00
Predicate<LivingEntity> HAS_WANT_IT_NEED_IT = e -> EnchantmentHelper.getEquipmentLevel(UEnchantments.WANT_IT_NEED_IT, e) > 0;
2021-03-03 10:33:23 +01:00
static Predicate<Entity> carryingSpell(@Nullable SpellType<?> type) {
2021-03-06 22:11:17 +01:00
return IS_PLAYER.and(e -> Pony.of((PlayerEntity)e).getSpellSlot().get(type, false).isPresent());
}
static Predicate<Entity> ofRace(Race race) {
return raceMatches(race::equals);
}
static Predicate<Entity> raceMatches(Predicate<Race> predicate) {
return e -> Equine.of(e).map(Equine::getSpecies).filter(predicate).isPresent();
2020-09-25 20:24:48 +02:00
}
}