Search in sources :

Example 1 with Horse

use of org.spongepowered.api.entity.living.animal.Horse in project Skree by Skelril.

the class BuildWorldWrapper method onEntitySpawn.

@Listener
public void onEntitySpawn(SpawnEntityEvent event) {
    List<Entity> entities = event.getEntities();
    Optional<BlockSpawnCause> optBlockCause = event.getCause().first(BlockSpawnCause.class);
    for (Entity entity : entities) {
        if (!isApplicable(entity))
            continue;
        if (entity instanceof Lightning) {
            ((Lightning) entity).setEffect(true);
            continue;
        }
        if (entity instanceof Egg && optBlockCause.isPresent()) {
            new ItemDropper(entity.getLocation()).dropStacks(Lists.newArrayList(newItemStack(ItemTypes.EGG)), SpawnTypes.DISPENSE);
            event.setCancelled(true);
            return;
        }
        if (entity instanceof Monster || (entity instanceof Horse && entity.get(Keys.HORSE_VARIANT).get().equals(HorseVariants.SKELETON_HORSE))) {
            event.setCancelled(true);
            return;
        }
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) Egg(org.spongepowered.api.entity.projectile.Egg) ItemDropper(com.skelril.nitro.item.ItemDropper) Lightning(org.spongepowered.api.entity.weather.Lightning) Monster(org.spongepowered.api.entity.living.monster.Monster) Horse(org.spongepowered.api.entity.living.animal.Horse) BlockSpawnCause(org.spongepowered.api.event.cause.entity.spawn.BlockSpawnCause) Listener(org.spongepowered.api.event.Listener)

Aggregations

ItemDropper (com.skelril.nitro.item.ItemDropper)1 Entity (org.spongepowered.api.entity.Entity)1 Horse (org.spongepowered.api.entity.living.animal.Horse)1 Monster (org.spongepowered.api.entity.living.monster.Monster)1 Egg (org.spongepowered.api.entity.projectile.Egg)1 Lightning (org.spongepowered.api.entity.weather.Lightning)1 Listener (org.spongepowered.api.event.Listener)1 BlockSpawnCause (org.spongepowered.api.event.cause.entity.spawn.BlockSpawnCause)1