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));
}
}
}
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;
}
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;
}
Aggregations