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

53 lines
2 KiB
Java
Raw Normal View History

package com.minelittlepony.unicopia;
import com.google.common.base.Predicate;
import net.minecraft.entity.Entity;
2020-01-16 12:35:46 +01:00
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
2020-01-17 14:27:26 +01:00
public final class EquinePredicates {
2020-01-16 12:35:46 +01:00
public static final Predicate<PlayerEntity> INTERACT_WITH_CLOUDS = player -> {
return player != null && SpeciesList.instance().getPlayer(player).getSpecies().canInteractWithClouds();
};
2018-09-24 21:37:16 +02:00
public static final Predicate<Entity> MAGI = entity -> {
2020-01-16 12:35:46 +01:00
return entity instanceof PlayerEntity && SpeciesList.instance().getPlayer((PlayerEntity)entity).getSpecies().canCast();
};
public static final Predicate<Entity> ITEMS = entity -> {
2020-01-16 12:35:46 +01:00
return entity instanceof ItemEntity && entity.isAlive() && entity.age > 1;
};
2020-01-16 12:35:46 +01:00
public static final Predicate<ItemEntity> ITEM_INTERACT_WITH_CLOUDS = item -> {
return ITEMS.test(item) && SpeciesList.instance().getEntity(item).getSpecies().canInteractWithClouds();
};
public static final Predicate<Entity> ENTITY_INTERACT_WITH_CLOUDS = entity -> {
return entity != null && (
2020-01-16 12:35:46 +01:00
(entity instanceof PlayerEntity && INTERACT_WITH_CLOUDS.test((PlayerEntity)entity))
|| (entity instanceof ItemEntity && ITEM_INTERACT_WITH_CLOUDS.test((ItemEntity)entity))
);
};
public static final Predicate<Entity> BUGGY = entity -> {
2020-01-16 12:35:46 +01:00
return entity instanceof PlayerEntity
&& SpeciesList.instance().getPlayer((PlayerEntity)entity).getSpecies() == Race.CHANGELING;
};
2020-01-16 12:35:46 +01:00
public static PlayerEntity getPlayerFromEntity(Entity entity) {
if (entity instanceof PlayerEntity) {
return (PlayerEntity) entity;
}
2020-01-16 12:35:46 +01:00
if (entity instanceof ItemEntity) {
ItemEntity item = (ItemEntity)entity;
if (item.getOwner() != null) {
2020-01-16 12:35:46 +01:00
return item.getEntityWorld().getPlayerByUuid(item.getOwner());
}
}
return null;
}
}