use of net.minecraft.server.v1_12_R1.EntityArrow in project PaperDev by Kamillaova.
the class CraftBlockProjectileSource method launchProjectile.
@Override
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
Validate.isTrue(getBlock().getType() == Material.DISPENSER, "Block is no longer dispenser");
// Copied from BlockDispenser.dispense()
SourceBlock isourceblock = new SourceBlock(dispenserBlock.getWorld(), dispenserBlock.getPosition());
// Copied from DispenseBehaviorProjectile
IPosition iposition = BlockDispenser.a(isourceblock);
EnumDirection enumdirection = (EnumDirection) isourceblock.e().get(BlockDispenser.FACING);
net.minecraft.server.v1_12_R1.World world = dispenserBlock.getWorld();
net.minecraft.server.v1_12_R1.Entity launch = null;
if (Snowball.class.isAssignableFrom(projectile)) {
launch = new EntitySnowball(world, iposition.getX(), iposition.getY(), iposition.getZ());
} else if (Egg.class.isAssignableFrom(projectile)) {
launch = new EntityEgg(world, iposition.getX(), iposition.getY(), iposition.getZ());
} else if (EnderPearl.class.isAssignableFrom(projectile)) {
launch = new EntityEnderPearl(world, null);
launch.setPosition(iposition.getX(), iposition.getY(), iposition.getZ());
} else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
launch = new EntityThrownExpBottle(world, iposition.getX(), iposition.getY(), iposition.getZ());
} else if (ThrownPotion.class.isAssignableFrom(projectile)) {
if (LingeringPotion.class.isAssignableFrom(projectile)) {
launch = new EntityPotion(world, iposition.getX(), iposition.getY(), iposition.getZ(), CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.LINGERING_POTION, 1)));
} else {
launch = new EntityPotion(world, iposition.getX(), iposition.getY(), iposition.getZ(), CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.SPLASH_POTION, 1)));
}
} else if (Arrow.class.isAssignableFrom(projectile)) {
if (TippedArrow.class.isAssignableFrom(projectile)) {
launch = new EntityTippedArrow(world, iposition.getX(), iposition.getY(), iposition.getZ());
((EntityTippedArrow) launch).setType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false)));
} else if (SpectralArrow.class.isAssignableFrom(projectile)) {
launch = new EntitySpectralArrow(world, iposition.getX(), iposition.getY(), iposition.getZ());
} else {
launch = new EntityTippedArrow(world, iposition.getX(), iposition.getY(), iposition.getZ());
}
((EntityArrow) launch).fromPlayer = EntityArrow.PickupStatus.ALLOWED;
((EntityArrow) launch).projectileSource = this;
} else if (Fireball.class.isAssignableFrom(projectile)) {
double d0 = iposition.getX() + (double) ((float) enumdirection.getAdjacentX() * 0.3F);
double d1 = iposition.getY() + (double) ((float) enumdirection.getAdjacentY() * 0.3F);
double d2 = iposition.getZ() + (double) ((float) enumdirection.getAdjacentZ() * 0.3F);
Random random = world.random;
double d3 = random.nextGaussian() * 0.05D + (double) enumdirection.getAdjacentX();
double d4 = random.nextGaussian() * 0.05D + (double) enumdirection.getAdjacentY();
double d5 = random.nextGaussian() * 0.05D + (double) enumdirection.getAdjacentZ();
if (SmallFireball.class.isAssignableFrom(projectile)) {
launch = new EntitySmallFireball(world, null, d0, d1, d2);
} else if (WitherSkull.class.isAssignableFrom(projectile)) {
launch = new EntityWitherSkull(world);
launch.setPosition(d0, d1, d2);
double d6 = (double) MathHelper.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
((EntityFireball) launch).dirX = d3 / d6 * 0.1D;
((EntityFireball) launch).dirY = d4 / d6 * 0.1D;
((EntityFireball) launch).dirZ = d5 / d6 * 0.1D;
} else {
launch = new EntityLargeFireball(world);
launch.setPosition(d0, d1, d2);
double d6 = (double) MathHelper.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
((EntityFireball) launch).dirX = d3 / d6 * 0.1D;
((EntityFireball) launch).dirY = d4 / d6 * 0.1D;
((EntityFireball) launch).dirZ = d5 / d6 * 0.1D;
}
((EntityFireball) launch).projectileSource = this;
}
Validate.notNull(launch, "Projectile not supported");
if (launch instanceof IProjectile) {
if (launch instanceof EntityProjectile) {
((EntityProjectile) launch).projectileSource = this;
}
// Values from DispenseBehaviorProjectile
float a = 6.0F;
float b = 1.1F;
if (launch instanceof EntityPotion || launch instanceof ThrownExpBottle) {
// Values from respective DispenseBehavior classes
a *= 0.5F;
b *= 1.25F;
}
// Copied from DispenseBehaviorProjectile
((IProjectile) launch).shoot((double) enumdirection.getAdjacentX(), (double) ((float) enumdirection.getAdjacentY() + 0.1F), (double) enumdirection.getAdjacentZ(), b, a);
}
if (velocity != null) {
((T) launch.getBukkitEntity()).setVelocity(velocity);
}
world.addEntity(launch);
return (T) launch.getBukkitEntity();
}
use of net.minecraft.server.v1_12_R1.EntityArrow in project MyPet by xXKeyleXx.
the class RangedAttack method shootProjectile.
public void shootProjectile(EntityLiving target, float damage, Projectiles projectile) {
World world = target.world;
if (projectile == Projectiles.Arrow) {
EntityArrow arrow = new MyPetArrow(world, entityMyPet, target, 1.6F, 1);
arrow.b(damage);
arrow.setCritical(false);
double distanceX = target.locX - entityMyPet.locX;
double distanceY = target.locY + target.getHeadHeight() - 1.100000023841858D - arrow.locY;
double distanceZ = target.locZ - entityMyPet.locZ;
float distance20percent = MathHelper.sqrt(distanceX * distanceX + distanceZ * distanceZ) * 0.2F;
arrow.shoot(distanceX, distanceY + distance20percent, distanceZ, 1.6F, 1);
entityMyPet.makeSound("random.bow", 1.0F, 1.0F / (entityMyPet.getRandom().nextFloat() * 0.4F + 0.8F));
world.addEntity(arrow);
} else if (projectile == Projectiles.Snowball) {
MyPetSnowball snowball = new MyPetSnowball(world, entityMyPet);
double distanceX = target.locX - entityMyPet.locX;
double distanceY = target.locY + target.getHeadHeight() - 1.100000023841858D - snowball.locY;
double distanceZ = target.locZ - entityMyPet.locZ;
float distance20percent = MathHelper.sqrt(distanceX * distanceX + distanceZ * distanceZ) * 0.2F;
snowball.setDamage(damage);
snowball.shoot(distanceX, distanceY + distance20percent, distanceZ, 1.6F, 1);
entityMyPet.makeSound("random.bow", 0.5F, 0.4F / (entityMyPet.getRandom().nextFloat() * 0.4F + 0.8F));
world.addEntity(snowball);
} else if (projectile == Projectiles.Egg) {
MyPetEgg egg = new MyPetEgg(world, entityMyPet);
double distanceX = target.locX - entityMyPet.locX;
double distanceY = target.locY + target.getHeadHeight() - 1.100000023841858D - egg.locY;
double distanceZ = target.locZ - entityMyPet.locZ;
float distance20percent = MathHelper.sqrt(distanceX * distanceX + distanceZ * distanceZ) * 0.2F;
egg.setDamage(damage);
egg.shoot(distanceX, distanceY + distance20percent, distanceZ, 1.6F, 1);
entityMyPet.makeSound("random.bow", 0.5F, 0.4F / (entityMyPet.getRandom().nextFloat() * 0.4F + 0.8F));
world.addEntity(egg);
} else if (projectile == Projectiles.LargeFireball) {
double distanceX = this.target.locX - entityMyPet.locX;
double distanceY = this.target.boundingBox.b + (double) (this.target.length / 2.0F) - (0.5D + entityMyPet.locY + (double) (entityMyPet.length / 2.0F));
double distanceZ = this.target.locZ - entityMyPet.locZ;
MyPetLargeFireball largeFireball = new MyPetLargeFireball(world, entityMyPet, distanceX, distanceY, distanceZ);
largeFireball.locY = (entityMyPet.locY + entityMyPet.length / 2.0F + 0.5D);
largeFireball.setDamage(damage);
world.addEntity(largeFireball);
world.makeSound(entityMyPet.locX + 0.5D, entityMyPet.locY + 0.5D, entityMyPet.locZ + 0.5D, "mob.ghast.fireball", 1.0F + entityMyPet.getRandom().nextFloat(), entityMyPet.getRandom().nextFloat() * 0.7F + 0.3F);
} else if (projectile == Projectiles.SmallFireball) {
double distanceX = this.target.locX - entityMyPet.locX;
double distanceY = this.target.boundingBox.b + (this.target.length / 2.0F) - (0.5D + entityMyPet.locY + (entityMyPet.length / 2.0F));
double distanceZ = this.target.locZ - entityMyPet.locZ;
MyPetSmallFireball smallFireball = new MyPetSmallFireball(world, entityMyPet, distanceX, distanceY, distanceZ);
smallFireball.locY = (entityMyPet.locY + entityMyPet.length / 2.0F + 0.5D);
smallFireball.setDamage(damage);
world.addEntity(smallFireball);
world.makeSound(entityMyPet.locX + 0.5D, entityMyPet.locY + 0.5D, entityMyPet.locZ + 0.5D, "mob.ghast.fireball", 1.0F + entityMyPet.getRandom().nextFloat(), entityMyPet.getRandom().nextFloat() * 0.7F + 0.3F);
} else if (projectile == Projectiles.WitherSkull) {
double distanceX = this.target.locX - entityMyPet.locX;
double distanceY = this.target.boundingBox.b + (double) (this.target.length / 2.0F) - (0.5D + entityMyPet.locY + (double) (entityMyPet.length / 2.0F));
double distanceZ = this.target.locZ - entityMyPet.locZ;
MyPetWitherSkull witherSkull = new MyPetWitherSkull(world, entityMyPet, distanceX, distanceY, distanceZ);
witherSkull.locY = (entityMyPet.locY + entityMyPet.length / 2.0F + 0.5D);
witherSkull.setDamage(damage);
world.addEntity(witherSkull);
world.makeSound(entityMyPet.locX + 0.5D, entityMyPet.locY + 0.5D, entityMyPet.locZ + 0.5D, "mob.wither.shoot", 1.0F + entityMyPet.getRandom().nextFloat(), entityMyPet.getRandom().nextFloat() * 0.7F + 0.3F);
}
}
use of net.minecraft.server.v1_12_R1.EntityArrow in project PaperDev by Kamillaova.
the class CraftLivingEntity method launchProjectile.
@SuppressWarnings("unchecked")
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
net.minecraft.server.v1_12_R1.World world = ((CraftWorld) getWorld()).getHandle();
net.minecraft.server.v1_12_R1.Entity launch = null;
if (Snowball.class.isAssignableFrom(projectile)) {
launch = new EntitySnowball(world, getHandle());
// ItemSnowball
((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());
// ItemEgg
((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());
// ItemEnderPearl
((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());
}
// ItemBow
((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(org.bukkit.Material.LINGERING_POTION, 1)));
} else {
launch = new EntityPotion(world, getHandle(), CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.SPLASH_POTION, 1)));
}
// ItemSplashPotion
((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());
// ItemExpBottle
((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());
} else if (LlamaSpit.class.isAssignableFrom(projectile)) {
Location location = getEyeLocation();
Vector direction = location.getDirection();
launch = new EntityLlamaSpit(world);
((EntityLlamaSpit) launch).shooter = getHandle();
// EntityLlama
((EntityLlamaSpit) launch).shoot(direction.getX(), direction.getY(), direction.getZ(), 1.5F, 10.0F);
launch.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
} else if (ShulkerBullet.class.isAssignableFrom(projectile)) {
Location location = getEyeLocation();
launch = new EntityShulkerBullet(world, getHandle(), null, null);
launch.setPositionRotation(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
}
Validate.notNull(launch, "Projectile not supported");
if (velocity != null) {
((T) launch.getBukkitEntity()).setVelocity(velocity);
}
world.addEntity(launch);
return (T) launch.getBukkitEntity();
}
Aggregations