public <T extends Projectile> T launchProjectile(
Class<? extends T> projectile, Vector velocity) {
World world = ((CraftWorld) getWorld()).getHandle();
net.minecraft.server.v1_10_R1.Entity launch = null;
if (Snowball.class.isAssignableFrom(projectile)) {
launch = new EntitySnowball(world, getHandle());
((EntityProjectile) launch).a(getHandle(), getHandle().pitch,
getHandle().yaw, 0.0F, 1.5F, 1.0F);
} else if (Egg.class.isAssignableFrom(projectile)) {
launch = new EntityEgg(world, getHandle());
((EntityProjectile) launch).a(getHandle(), getHandle().pitch,
getHandle().yaw, 0.0F, 1.5F, 1.0F);
} else if (EnderPearl.class.isAssignableFrom(projectile)) {
launch = new EntityEnderPearl(world, getHandle());
((EntityProjectile) launch).a(getHandle(), getHandle().pitch,
getHandle().yaw, 0.0F, 1.5F, 1.0F);
} else if (Arrow.class.isAssignableFrom(projectile)) {
if (TippedArrow.class.isAssignableFrom(projectile)) {
launch = new EntityTippedArrow(world, getHandle());
((EntityTippedArrow) launch).setType(CraftPotionUtil
.fromBukkit(new PotionData(PotionType.WATER, false,
false)));
} else if (SpectralArrow.class.isAssignableFrom(projectile)) {
launch = new EntitySpectralArrow(world, getHandle());
} else {
launch = new EntityTippedArrow(world, getHandle());
}
((EntityArrow) launch).a(getHandle(), getHandle().pitch,
getHandle().yaw, 0.0F, 3.0F, 1.0F);
} else if (ThrownPotion.class.isAssignableFrom(projectile)) {
if (LingeringPotion.class.isAssignableFrom(projectile))
launch = new EntityPotion(world, getHandle(),
CraftItemStack.asNMSCopy(new ItemStack(
Material.LINGERING_POTION, 1)));
else {
launch = new EntityPotion(world, getHandle(),
CraftItemStack.asNMSCopy(new ItemStack(
Material.SPLASH_POTION, 1)));
}
((EntityProjectile) launch).a(getHandle(), getHandle().pitch,
getHandle().yaw, -20.0F, 0.5F, 1.0F);
} else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
launch = new EntityThrownExpBottle(world, getHandle());
((EntityProjectile) launch).a(getHandle(), getHandle().pitch,
getHandle().yaw, -20.0F, 0.7F, 1.0F);
} else if ((Fish.class.isAssignableFrom(projectile))
&& (getHandle() instanceof EntityHuman)) {
launch = new EntityFishingHook(world, (EntityHuman) getHandle());
} else if (Fireball.class.isAssignableFrom(projectile)) {
Location location = getEyeLocation();
Vector direction = location.getDirection().multiply(10);
if (SmallFireball.class.isAssignableFrom(projectile))
launch = new EntitySmallFireball(world, getHandle(),
direction.getX(), direction.getY(), direction.getZ());
else if (WitherSkull.class.isAssignableFrom(projectile))
launch = new EntityWitherSkull(world, getHandle(),
direction.getX(), direction.getY(), direction.getZ());
else if (DragonFireball.class.isAssignableFrom(projectile))
launch = new EntityDragonFireball(world, getHandle(),
direction.getX(), direction.getY(), direction.getZ());
else {
launch = new EntityLargeFireball(world, getHandle(),
direction.getX(), direction.getY(), direction.getZ());
}
((EntityFireball) launch).projectileSource = this;
launch.setPositionRotation(location.getX(), location.getY(),
location.getZ(), location.getYaw(), location.getPitch());
}
Validate.notNull(launch, "Projectile not supported");
if (velocity != null) {
((Projectile) launch.getBukkitEntity()).setVelocity(velocity);
}
world.addEntity(launch);
return ((Projectile) launch.getBukkitEntity());
}
public EntityProjectile(World world, EntityLiving entityliving) {
this(world, entityliving.locX, entityliving.locY
+ entityliving.getHeadHeight() - 0.1000000014901161D,
entityliving.locZ);
this.shooter = entityliving;
this.projectileSource = ((LivingEntity) entityliving.getBukkitEntity());
}
public void a(Entity entity, float f, float f1, float f2, float f3, float f4) {
float f5 = -MathHelper.sin(f1 * 0.01745329F)
* MathHelper.cos(f * 0.01745329F);
float f6 = -MathHelper.sin((f + f2) * 0.01745329F);
float f7 = MathHelper.cos(f1 * 0.01745329F)
* MathHelper.cos(f * 0.01745329F);
shoot(f5, f6, f7, f3, f4);
this.motX += entity.motX;
this.motZ += entity.motZ;
if (!(entity.onGround))
this.motY += entity.motY;
}
public void shoot(double d0, double d1, double d2, float f, float f1) {
float f2 = MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
d0 /= f2;
d1 /= f2;
d2 /= f2;
d0 += this.random.nextGaussian() * 0.007499999832361937D * f1;
d1 += this.random.nextGaussian() * 0.007499999832361937D * f1;
d2 += this.random.nextGaussian() * 0.007499999832361937D * f1;
d0 *= f;
d1 *= f;
d2 *= f;
this.motX = d0;
this.motY = d1;
this.motZ = d2;
float f3 = MathHelper.sqrt(d0 * d0 + d2 * d2);
this.yaw = (float) (MathHelper.b(d0, d2) * 57.2957763671875D);
this.pitch = (float) (MathHelper.b(d1, f3) * 57.2957763671875D);
this.lastYaw = this.yaw;
this.lastPitch = this.pitch;
this.av = 0;
}