2020-04-15 14:22:03 +02:00
|
|
|
package com.minelittlepony.unicopia;
|
2018-09-16 00:45:44 +02:00
|
|
|
|
2020-04-26 14:46:03 +02:00
|
|
|
import java.util.function.Predicate;
|
2018-09-16 00:45:44 +02:00
|
|
|
|
2020-10-04 12:58:01 +02:00
|
|
|
import com.minelittlepony.unicopia.ability.magic.Caster;
|
2023-10-09 23:05:41 +02:00
|
|
|
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
|
2020-09-22 15:11:20 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.Equine;
|
2023-08-28 15:37:36 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.MagicImmune;
|
2023-09-13 15:33:01 +02:00
|
|
|
import com.minelittlepony.unicopia.item.enchantment.WantItNeedItEnchantment;
|
2020-04-26 19:51:30 +02:00
|
|
|
|
2022-10-01 18:20:53 +02:00
|
|
|
import net.minecraft.entity.*;
|
|
|
|
import net.minecraft.entity.decoration.AbstractDecorationEntity;
|
2020-01-16 12:35:46 +01:00
|
|
|
import net.minecraft.entity.player.PlayerEntity;
|
2024-02-27 22:20:33 +01:00
|
|
|
import net.minecraft.entity.projectile.ProjectileEntity;
|
2024-02-26 21:56:22 +01:00
|
|
|
import net.minecraft.entity.vehicle.BoatEntity;
|
2022-10-01 18:20:53 +02:00
|
|
|
import net.minecraft.predicate.entity.EntityPredicates;
|
2018-09-16 00:45:44 +02:00
|
|
|
|
2020-01-27 17:37:22 +01:00
|
|
|
public interface EquinePredicates {
|
2020-04-26 14:46:03 +02:00
|
|
|
Predicate<Entity> IS_PLAYER = e -> e instanceof PlayerEntity;
|
2023-09-01 20:09:13 +02:00
|
|
|
Predicate<Entity> BAT = physicalRaceMatches(Race.BAT::equals);
|
|
|
|
Predicate<Entity> CHANGELING = physicalRaceMatches(Race.CHANGELING::equals);
|
2020-04-26 14:46:03 +02:00
|
|
|
|
2021-03-06 22:11:17 +01:00
|
|
|
Predicate<Entity> RACE_INTERACT_WITH_CLOUDS = raceMatches(Race::canInteractWithClouds);
|
2023-10-09 23:05:41 +02:00
|
|
|
Predicate<Entity> RAGING = IS_PLAYER.and(SpellType.RAGE::isOn);
|
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));
|
2023-09-01 20:09:13 +02:00
|
|
|
Predicate<Entity> PLAYER_BAT = IS_PLAYER.and(BAT);
|
2021-03-06 22:11:17 +01:00
|
|
|
Predicate<Entity> PLAYER_UNICORN = IS_PLAYER.and(raceMatches(Race::canCast));
|
|
|
|
Predicate<Entity> PLAYER_CHANGELING = IS_PLAYER.and(ofRace(Race.CHANGELING));
|
2023-10-09 23:05:41 +02:00
|
|
|
Predicate<Entity> PLAYER_KIRIN = IS_PLAYER.and(ofRace(Race.KIRIN));
|
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));
|
2023-11-08 13:58:31 +01:00
|
|
|
Predicate<Entity> PLAYER_SEAPONY = IS_PLAYER.and(raceMatches(Race::isFish));
|
2020-04-26 14:46:03 +02:00
|
|
|
|
2021-09-02 19:11:51 +02:00
|
|
|
Predicate<Entity> PLAYER_CAN_USE_EARTH = IS_PLAYER.and(raceMatches(Race::canUseEarth));
|
2022-10-08 14:44:52 +02:00
|
|
|
Predicate<Entity> IS_CASTER = e -> !e.isRemoved() && (e instanceof Caster || IS_PLAYER.test(e));
|
2021-12-31 14:40:08 +01:00
|
|
|
Predicate<Entity> IS_PLACED_SPELL = e -> e instanceof Caster && !e.isRemoved();
|
2020-10-04 12:58:01 +02:00
|
|
|
|
2024-02-27 22:20:33 +01:00
|
|
|
Predicate<Entity> IS_MAGIC_IMMUNE = e -> (e instanceof MagicImmune || !(e instanceof LivingEntity))
|
|
|
|
&& !(e instanceof ItemEntity)
|
|
|
|
&& !(e instanceof ExperienceOrbEntity)
|
|
|
|
&& !(e instanceof BoatEntity)
|
|
|
|
&& !(e instanceof ProjectileEntity);
|
2023-08-28 15:37:36 +02:00
|
|
|
Predicate<Entity> EXCEPT_MAGIC_IMMUNE = IS_MAGIC_IMMUNE.negate();
|
2023-09-03 22:01:51 +02:00
|
|
|
Predicate<Entity> VALID_LIVING_AND_NOT_MAGIC_IMMUNE = EntityPredicates.VALID_LIVING_ENTITY.and(EXCEPT_MAGIC_IMMUNE);
|
2023-08-28 15:37:36 +02:00
|
|
|
|
2023-09-13 15:33:01 +02:00
|
|
|
Predicate<LivingEntity> LIVING_HAS_WANT_IT_NEED_IT = e -> WantItNeedItEnchantment.getLevel(e) > 0;
|
2022-10-01 18:20:53 +02:00
|
|
|
Predicate<Entity> VALID_FOR_DISGUISE = EntityPredicates.EXCEPT_SPECTATOR.and(e -> !(e instanceof LightningEntity || e instanceof AbstractDecorationEntity));
|
|
|
|
|
2021-03-06 22:11:17 +01:00
|
|
|
static Predicate<Entity> ofRace(Race race) {
|
|
|
|
return raceMatches(race::equals);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Predicate<Entity> raceMatches(Predicate<Race> predicate) {
|
2023-09-01 20:09:13 +02:00
|
|
|
return e -> Equine.of(e).filter(pony -> pony.getCompositeRace().any(predicate)).isPresent();
|
2020-09-25 20:24:48 +02:00
|
|
|
}
|
2022-12-09 23:34:50 +01:00
|
|
|
|
|
|
|
static Predicate<Entity> physicalRaceMatches(Predicate<Race> predicate) {
|
2023-09-01 20:09:13 +02:00
|
|
|
return e -> Equine.of(e).filter(pony -> predicate.test(pony.getCompositeRace().physical())).isPresent();
|
2022-12-09 23:34:50 +01:00
|
|
|
}
|
2018-09-16 00:45:44 +02:00
|
|
|
}
|