use of net.minecraft.entity.projectile.ShulkerBulletEntity in project MCDungeonsArmors by chronosacaria.
the class ProjectileEffectHelper method fireShulkerBulletAtNearbyEnemy.
public static void fireShulkerBulletAtNearbyEnemy(LivingEntity user) {
if (!hasArmorSet(user, ArmorSets.STURDY_SHULKER))
return;
World world = user.getEntityWorld();
int distance = 10;
List<LivingEntity> nearbyEntities = world.getEntitiesByClass(LivingEntity.class, new Box(user.getX() - distance, user.getY() - distance, user.getZ() - distance, user.getX() + distance, user.getY() + distance, user.getZ() + distance), (nearbyEntity) -> nearbyEntity != user && AbilityHelper.canFireAtEnemy(user, nearbyEntity));
if (nearbyEntities.size() < 2)
return;
Optional<LivingEntity> nearest = nearbyEntities.stream().min(Comparator.comparingDouble(e -> e.squaredDistanceTo(user)));
LivingEntity target = nearest.get();
ShulkerBulletEntity shulkerBulletEntity = new ShulkerBulletEntity(world, user, target, Direction.Axis.pickRandomAxis(random));
// borrowed from AbstractSkeletonEntity
double d = target.getX() - shulkerBulletEntity.getX();
double e = target.getBodyY(0.3333333333333333D) - shulkerBulletEntity.getY();
double f = target.getZ() - shulkerBulletEntity.getZ();
double g = Math.sqrt(d * d + f * f);
shulkerBulletEntity.setVelocity(user, user.getPitch(), user.getYaw(), 0.0F, 1.5F, 1.0F);
setProjectileTowards(shulkerBulletEntity, d, e, g, 0);
//
user.world.spawnEntity(shulkerBulletEntity);
}
Aggregations