Search in sources :

Example 1 with ShulkerBulletEntity

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);
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) Entity(net.minecraft.entity.Entity) LivingEntity(net.minecraft.entity.LivingEntity) World(net.minecraft.world.World) Box(net.minecraft.util.math.Box) SnowballEntity(net.minecraft.entity.projectile.thrown.SnowballEntity) PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) Items(net.minecraft.item.Items) ArmorSets(chronosacaria.mcda.items.ArmorSets) ProjectileEntity(net.minecraft.entity.projectile.ProjectileEntity) Direction(net.minecraft.util.math.Direction) ItemStack(net.minecraft.item.ItemStack) List(java.util.List) Vec3d(net.minecraft.util.math.Vec3d) CleanlinessHelper.hasArmorSet(chronosacaria.mcda.api.CleanlinessHelper.hasArmorSet) MathHelper(net.minecraft.util.math.MathHelper) ShulkerBulletEntity(net.minecraft.entity.projectile.ShulkerBulletEntity) Optional(java.util.Optional) Mcda.random(chronosacaria.mcda.Mcda.random) Comparator(java.util.Comparator) ShulkerBulletEntity(net.minecraft.entity.projectile.ShulkerBulletEntity) Box(net.minecraft.util.math.Box) World(net.minecraft.world.World)

Aggregations

Mcda.random (chronosacaria.mcda.Mcda.random)1 CleanlinessHelper.hasArmorSet (chronosacaria.mcda.api.CleanlinessHelper.hasArmorSet)1 ArmorSets (chronosacaria.mcda.items.ArmorSets)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Optional (java.util.Optional)1 Entity (net.minecraft.entity.Entity)1 LivingEntity (net.minecraft.entity.LivingEntity)1 PersistentProjectileEntity (net.minecraft.entity.projectile.PersistentProjectileEntity)1 ProjectileEntity (net.minecraft.entity.projectile.ProjectileEntity)1 ShulkerBulletEntity (net.minecraft.entity.projectile.ShulkerBulletEntity)1 SnowballEntity (net.minecraft.entity.projectile.thrown.SnowballEntity)1 ItemStack (net.minecraft.item.ItemStack)1 Items (net.minecraft.item.Items)1 Box (net.minecraft.util.math.Box)1 Direction (net.minecraft.util.math.Direction)1 MathHelper (net.minecraft.util.math.MathHelper)1 Vec3d (net.minecraft.util.math.Vec3d)1 World (net.minecraft.world.World)1