package com.minelittlepony.unicopia; import java.util.function.Predicate; import org.jetbrains.annotations.Nullable; import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.spell.SpellType; import com.minelittlepony.unicopia.entity.Equine; 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; import net.minecraft.entity.player.PlayerEntity; public interface EquinePredicates { Predicate IS_PLAYER = e -> e instanceof PlayerEntity; Predicate RACE_INTERACT_WITH_CLOUDS = raceMatches(Race::canInteractWithClouds); Predicate PLAYER_EARTH = IS_PLAYER.and(ofRace(Race.EARTH)); Predicate PLAYER_BAT = IS_PLAYER.and(ofRace(Race.BAT)); Predicate PLAYER_UNICORN = IS_PLAYER.and(raceMatches(Race::canCast)); Predicate PLAYER_CHANGELING = IS_PLAYER.and(ofRace(Race.CHANGELING)); Predicate PLAYER_PEGASUS = IS_PLAYER.and(e -> ((PlayerEntity)e).getAbilities().creativeMode || RACE_INTERACT_WITH_CLOUDS.test(e)); Predicate IS_CASTER = e -> !e.isRemoved() && (e instanceof Caster || PLAYER_UNICORN.test(e)); Predicate HAS_WANT_IT_NEED_IT = e -> EnchantmentHelper.getEquipmentLevel(UEnchantments.WANT_IT_NEED_IT, e) > 0; static Predicate carryingSpell(@Nullable SpellType type) { return IS_PLAYER.and(e -> Pony.of((PlayerEntity)e).getSpellSlot().get(type, false).isPresent()); } static Predicate ofRace(Race race) { return raceMatches(race::equals); } static Predicate raceMatches(Predicate predicate) { return e -> Equine.of(e).map(Equine::getSpecies).filter(predicate).isPresent(); } }