Search in sources :

Example 1 with WaterMobEntity

use of net.minecraft.entity.passive.WaterMobEntity in project upgrade-aquatic by team-abnormals.

the class EntityEvents method onEntitySpawned.

@SubscribeEvent(priority = EventPriority.LOWEST)
public static void onEntitySpawned(EntityJoinWorldEvent event) {
    if (event.getWorld().isRemote)
        return;
    Entity entity = event.getEntity();
    if (entity instanceof DrownedEntity) {
        ((CreatureEntity) entity).goalSelector.addGoal(3, new AvoidEntityGoal<>((CreatureEntity) entity, TurtleEntity.class, 6.0F, 1.0D, 1.2D));
    }
    if (entity instanceof AbstractFishEntity) {
        ((AbstractFishEntity) entity).goalSelector.addGoal(2, new AvoidEntityGoal<>((CreatureEntity) entity, PikeEntity.class, 8.0F, 1.6D, 1.4D, UAEntityPredicates.IS_HIDING_IN_PICKERELWEED::test));
        if (entity instanceof TropicalFishEntity) {
            ((AbstractFishEntity) entity).goalSelector.addGoal(2, new AvoidEntityGoal<>((CreatureEntity) entity, LionfishEntity.class, 8.0F, 1.6D, 1.4D, EntityPredicates.IS_ALIVE::test));
        }
    }
    if (entity instanceof WaterMobEntity && !(entity instanceof IMob)) {
        if (!(entity instanceof DolphinEntity)) {
            ((MobEntity) entity).goalSelector.addGoal(1, new AvoidEntityGoal<>((CreatureEntity) entity, ThrasherEntity.class, 20.0F, 1.4D, 1.6D, EntityPredicates.IS_ALIVE::test));
        }
        if (entity instanceof DolphinEntity) {
            ((MobEntity) entity).targetSelector.addGoal(0, (new HurtByTargetGoal((DolphinEntity) entity, ThrasherEntity.class)).setCallsForHelp());
            ((MobEntity) entity).goalSelector.addGoal(1, new MeleeAttackGoal((DolphinEntity) entity, 1.2D, true));
        }
    }
}
Also used : PikeEntity(com.minecraftabnormals.upgrade_aquatic.common.entities.pike.PikeEntity) DolphinEntity(net.minecraft.entity.passive.DolphinEntity) PhantomEntity(net.minecraft.entity.monster.PhantomEntity) WaterMobEntity(net.minecraft.entity.passive.WaterMobEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) ThrasherEntity(com.minecraftabnormals.upgrade_aquatic.common.entities.thrasher.ThrasherEntity) SquidEntity(net.minecraft.entity.passive.SquidEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) AbstractFishEntity(net.minecraft.entity.passive.fish.AbstractFishEntity) LionfishEntity(com.minecraftabnormals.upgrade_aquatic.common.entities.LionfishEntity) DrownedEntity(net.minecraft.entity.monster.DrownedEntity) CreatureEntity(net.minecraft.entity.CreatureEntity) TurtleEntity(net.minecraft.entity.passive.TurtleEntity) TropicalFishEntity(net.minecraft.entity.passive.fish.TropicalFishEntity) MobEntity(net.minecraft.entity.MobEntity) Entity(net.minecraft.entity.Entity) TurtleEntity(net.minecraft.entity.passive.TurtleEntity) AbstractFishEntity(net.minecraft.entity.passive.fish.AbstractFishEntity) ThrasherEntity(com.minecraftabnormals.upgrade_aquatic.common.entities.thrasher.ThrasherEntity) HurtByTargetGoal(net.minecraft.entity.ai.goal.HurtByTargetGoal) DolphinEntity(net.minecraft.entity.passive.DolphinEntity) CreatureEntity(net.minecraft.entity.CreatureEntity) PikeEntity(com.minecraftabnormals.upgrade_aquatic.common.entities.pike.PikeEntity) LionfishEntity(com.minecraftabnormals.upgrade_aquatic.common.entities.LionfishEntity) UAEntityPredicates(com.minecraftabnormals.upgrade_aquatic.api.util.UAEntityPredicates) EntityPredicates(net.minecraft.util.EntityPredicates) UAEntityPredicates(com.minecraftabnormals.upgrade_aquatic.api.util.UAEntityPredicates) IMob(net.minecraft.entity.monster.IMob) MeleeAttackGoal(net.minecraft.entity.ai.goal.MeleeAttackGoal) TropicalFishEntity(net.minecraft.entity.passive.fish.TropicalFishEntity) DrownedEntity(net.minecraft.entity.monster.DrownedEntity) WaterMobEntity(net.minecraft.entity.passive.WaterMobEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with WaterMobEntity

use of net.minecraft.entity.passive.WaterMobEntity in project Magma-1.16.x by magmafoundation.

the class CraftEventFactory method doEntityAddEventCalling.

public static boolean doEntityAddEventCalling(World world, Entity entity, SpawnReason spawnReason) {
    if (entity == null)
        return false;
    org.bukkit.event.Cancellable event = null;
    if (entity instanceof net.minecraft.entity.LivingEntity && !(entity instanceof ServerPlayerEntity)) {
        boolean isAnimal = entity instanceof AnimalEntity || entity instanceof WaterMobEntity || entity instanceof GolemEntity;
        boolean isMonster = entity instanceof MonsterEntity || entity instanceof GhastEntity || entity instanceof SlimeEntity;
        boolean isNpc = entity instanceof INPC;
        if (spawnReason != CreatureSpawnEvent.SpawnReason.CUSTOM) {
            if (isAnimal && !world.getWorldCB().getAllowAnimals() || isMonster && !world.getWorldCB().getAllowMonsters() || isNpc && !world.getServer().getServer().isSpawningAnimals()) {
                entity.removed = true;
                return false;
            }
        }
        event = CraftEventFactory.callCreatureSpawnEvent((net.minecraft.entity.LivingEntity) entity, spawnReason);
    } else if (entity instanceof ItemEntity) {
        event = CraftEventFactory.callItemSpawnEvent((ItemEntity) entity);
    } else if (entity.getBukkitEntity() instanceof org.bukkit.entity.Projectile) {
        // Not all projectiles extend ThrowableEntity, so check for Bukkit interface instead
        event = CraftEventFactory.callProjectileLaunchEvent(entity);
    } else if (entity.getBukkitEntity() instanceof org.bukkit.entity.Vehicle) {
        event = CraftEventFactory.callVehicleCreateEvent(entity);
    // Spigot start
    } else if (entity instanceof ExperienceOrbEntity) {
        ExperienceOrbEntity xp = (ExperienceOrbEntity) entity;
        double radius = world.spigotConfig.expMerge;
        if (radius > 0) {
            List<Entity> entities = world.getEntities(entity, entity.getBoundingBox().inflate(radius, radius, radius));
            for (Entity e : entities) {
                if (e instanceof ExperienceOrbEntity) {
                    ExperienceOrbEntity loopItem = (ExperienceOrbEntity) e;
                    if (!loopItem.removed) {
                        xp.value += loopItem.value;
                        loopItem.remove();
                    }
                }
            }
        }
    // Spigot end
    } else if (!(entity instanceof ServerPlayerEntity)) {
        event = CraftEventFactory.callEntitySpawnEvent(entity);
    }
    if (event != null && (event.isCancelled() || entity.removed)) {
        Entity vehicle = entity.getVehicle();
        if (vehicle != null) {
            vehicle.removed = true;
        }
        for (Entity passenger : entity.getPassengers()) {
            passenger.removed = true;
        }
        entity.removed = true;
        return false;
    }
    return true;
}
Also used : SlimeEntity(net.minecraft.entity.monster.SlimeEntity) VillagerEntity(net.minecraft.entity.merchant.villager.VillagerEntity) WaterMobEntity(net.minecraft.entity.passive.WaterMobEntity) ProjectileEntity(net.minecraft.entity.projectile.ProjectileEntity) GolemEntity(net.minecraft.entity.passive.GolemEntity) AbstractRaiderEntity(net.minecraft.entity.monster.AbstractRaiderEntity) SlimeEntity(net.minecraft.entity.monster.SlimeEntity) LivingEntity(org.bukkit.entity.LivingEntity) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) AreaEffectCloudEntity(net.minecraft.entity.AreaEffectCloudEntity) StriderEntity(net.minecraft.entity.passive.StriderEntity) PotionEntity(net.minecraft.entity.projectile.PotionEntity) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) EnderDragonEntity(net.minecraft.entity.boss.dragon.EnderDragonEntity) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) SpellcastingIllagerEntity(net.minecraft.entity.monster.SpellcastingIllagerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) FireworkRocketEntity(net.minecraft.entity.projectile.FireworkRocketEntity) MobEntity(net.minecraft.entity.MobEntity) HumanEntity(org.bukkit.entity.HumanEntity) Entity(net.minecraft.entity.Entity) GhastEntity(net.minecraft.entity.monster.GhastEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity) Cancellable(org.bukkit.event.Cancellable) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) GolemEntity(net.minecraft.entity.passive.GolemEntity) GhastEntity(net.minecraft.entity.monster.GhastEntity) LivingEntity(org.bukkit.entity.LivingEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity) Vehicle(org.bukkit.entity.Vehicle) WaterMobEntity(net.minecraft.entity.passive.WaterMobEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) Projectile(org.bukkit.entity.Projectile) INPC(net.minecraft.entity.INPC)

Example 3 with WaterMobEntity

use of net.minecraft.entity.passive.WaterMobEntity in project LoliServer by Loli-Server.

the class CraftEventFactory method doEntityAddEventCalling.

public static boolean doEntityAddEventCalling(World world, Entity entity, CreatureSpawnEvent.SpawnReason spawnReason) {
    if (entity == null)
        return false;
    Cancellable event = null;
    if (entity instanceof LivingEntity && !(entity instanceof ServerPlayerEntity)) {
        boolean isAnimal = entity instanceof AnimalEntity || entity instanceof WaterMobEntity || entity instanceof GolemEntity;
        boolean isMonster = entity instanceof MonsterEntity || entity instanceof GhastEntity || entity instanceof SlimeEntity;
        boolean isNpc = entity instanceof NPC;
        if (spawnReason != CreatureSpawnEvent.SpawnReason.CUSTOM) {
            if (isAnimal && !world.getWorld().getAllowAnimals() || isMonster && !world.getWorld().getAllowMonsters() || isNpc && !world.getServer().getServer().areNpcsEnabled()) {
                entity.removed = true;
                return false;
            }
        }
        event = CraftEventFactory.callCreatureSpawnEvent((LivingEntity) entity, spawnReason);
    } else if (entity instanceof ItemEntity) {
        event = CraftEventFactory.callItemSpawnEvent((ItemEntity) entity);
    } else if (entity.getBukkitEntity() instanceof Projectile) {
        // Not all projectiles extend EntityProjectile, so check for Bukkit interface instead
        event = CraftEventFactory.callProjectileLaunchEvent(entity);
    } else if (entity.getBukkitEntity() instanceof Vehicle) {
        event = CraftEventFactory.callVehicleCreateEvent(entity);
    } else if (entity.getBukkitEntity() instanceof LightningStrike) {
        LightningStrikeEvent.Cause cause = (spawnReason == CreatureSpawnEvent.SpawnReason.COMMAND ? LightningStrikeEvent.Cause.COMMAND : LightningStrikeEvent.Cause.UNKNOWN);
        event = CraftEventFactory.callLightningStrikeEvent((LightningStrike) entity.getBukkitEntity(), cause);
    } else // Spigot start
    if (entity instanceof ExperienceOrbEntity) {
        ExperienceOrbEntity xp = (ExperienceOrbEntity) entity;
        double radius = world.spigotConfig.expMerge;
        if (radius > 0) {
            List<Entity> entities = world.getEntities(entity, entity.getBoundingBox().inflate(radius, radius, radius));
            for (Entity e : entities) {
                if (e instanceof ExperienceOrbEntity) {
                    ExperienceOrbEntity loopItem = (ExperienceOrbEntity) e;
                    if (!loopItem.removed) {
                        xp.value += loopItem.value;
                        loopItem.remove();
                    }
                }
            }
        }
    // Spigot end
    } else if (!(entity instanceof ServerPlayerEntity)) {
        event = CraftEventFactory.callEntitySpawnEvent(entity);
    }
    if (event != null && (event.isCancelled() || entity.removed)) {
        Entity vehicle = entity.getVehicle();
        if (vehicle != null) {
            vehicle.removed = true;
        }
        for (Entity passenger : entity.getIndirectPassengers()) {
            passenger.removed = true;
        }
        entity.removed = true;
        return false;
    }
    return true;
}
Also used : SlimeEntity(net.minecraft.entity.monster.SlimeEntity) StriderEntity(net.minecraft.entity.passive.StriderEntity) VillagerEntity(net.minecraft.entity.merchant.villager.VillagerEntity) WaterMobEntity(net.minecraft.entity.passive.WaterMobEntity) PotionEntity(net.minecraft.entity.projectile.PotionEntity) LivingEntity(net.minecraft.entity.LivingEntity) ProjectileEntity(net.minecraft.entity.projectile.ProjectileEntity) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) EnderDragonEntity(net.minecraft.entity.boss.dragon.EnderDragonEntity) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) GolemEntity(net.minecraft.entity.passive.GolemEntity) CraftEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftEntity) AbstractRaiderEntity(net.minecraft.entity.monster.AbstractRaiderEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) SlimeEntity(net.minecraft.entity.monster.SlimeEntity) SpellcastingIllagerEntity(net.minecraft.entity.monster.SpellcastingIllagerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) FireworkRocketEntity(net.minecraft.entity.projectile.FireworkRocketEntity) AbstractFishEntity(net.minecraft.entity.passive.fish.AbstractFishEntity) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) PiglinEntity(net.minecraft.entity.monster.piglin.PiglinEntity) MobEntity(net.minecraft.entity.MobEntity) AreaEffectCloudEntity(net.minecraft.entity.AreaEffectCloudEntity) Entity(net.minecraft.entity.Entity) GhastEntity(net.minecraft.entity.monster.GhastEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity) ItemEntity(net.minecraft.entity.item.ItemEntity) Cancellable(org.bukkit.event.Cancellable) AnimalEntity(net.minecraft.entity.passive.AnimalEntity) LightningStrikeEvent(org.bukkit.event.weather.LightningStrikeEvent) MonsterEntity(net.minecraft.entity.monster.MonsterEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) GolemEntity(net.minecraft.entity.passive.GolemEntity) GhastEntity(net.minecraft.entity.monster.GhastEntity) ExperienceOrbEntity(net.minecraft.entity.item.ExperienceOrbEntity) LivingEntity(net.minecraft.entity.LivingEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity) ArrayList(java.util.ArrayList) List(java.util.List) WaterMobEntity(net.minecraft.entity.passive.WaterMobEntity)

Aggregations

Entity (net.minecraft.entity.Entity)3 MobEntity (net.minecraft.entity.MobEntity)3 WaterMobEntity (net.minecraft.entity.passive.WaterMobEntity)3 PlayerEntity (net.minecraft.entity.player.PlayerEntity)3 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)3 AreaEffectCloudEntity (net.minecraft.entity.AreaEffectCloudEntity)2 LivingEntity (net.minecraft.entity.LivingEntity)2 EnderDragonEntity (net.minecraft.entity.boss.dragon.EnderDragonEntity)2 ExperienceOrbEntity (net.minecraft.entity.item.ExperienceOrbEntity)2 ItemEntity (net.minecraft.entity.item.ItemEntity)2 VillagerEntity (net.minecraft.entity.merchant.villager.VillagerEntity)2 AbstractRaiderEntity (net.minecraft.entity.monster.AbstractRaiderEntity)2 GhastEntity (net.minecraft.entity.monster.GhastEntity)2 MonsterEntity (net.minecraft.entity.monster.MonsterEntity)2 SlimeEntity (net.minecraft.entity.monster.SlimeEntity)2 SpellcastingIllagerEntity (net.minecraft.entity.monster.SpellcastingIllagerEntity)2 AnimalEntity (net.minecraft.entity.passive.AnimalEntity)2 GolemEntity (net.minecraft.entity.passive.GolemEntity)2 StriderEntity (net.minecraft.entity.passive.StriderEntity)2 AbstractFishEntity (net.minecraft.entity.passive.fish.AbstractFishEntity)2