Search in sources :

Example 11 with ThrownExpBottle

use of org.bukkit.entity.ThrownExpBottle in project NachoSpigot by CobbleSword.

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 = BlockDispenser.b(isourceblock.f());
    net.minecraft.server.World world = dispenserBlock.getWorld();
    net.minecraft.server.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)) {
        launch = new EntityPotion(world, iposition.getX(), iposition.getY(), iposition.getZ(), CraftItemStack.asNMSCopy(new ItemStack(Material.POTION, 1)));
    } else if (Arrow.class.isAssignableFrom(projectile)) {
        launch = new EntityArrow(world, iposition.getX(), iposition.getY(), iposition.getZ());
        ((EntityArrow) launch).fromPlayer = 1;
        ((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, d0, d1, d2, d3, d4, d5);
        } 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();
}
Also used : EntityWitherSkull(net.minecraft.server.EntityWitherSkull) EntityLargeFireball(net.minecraft.server.EntityLargeFireball) EntityEnderPearl(net.minecraft.server.EntityEnderPearl) EntityEgg(net.minecraft.server.EntityEgg) IProjectile(net.minecraft.server.IProjectile) SourceBlock(net.minecraft.server.SourceBlock) Random(java.util.Random) EntitySmallFireball(net.minecraft.server.EntitySmallFireball) EntityPotion(net.minecraft.server.EntityPotion) EnumDirection(net.minecraft.server.EnumDirection) EntityFireball(net.minecraft.server.EntityFireball) EntityProjectile(net.minecraft.server.EntityProjectile) EntityArrow(net.minecraft.server.EntityArrow) Arrow(org.bukkit.entity.Arrow) EntityArrow(net.minecraft.server.EntityArrow) IPosition(net.minecraft.server.IPosition) EntityThrownExpBottle(net.minecraft.server.EntityThrownExpBottle) EntityEgg(net.minecraft.server.EntityEgg) Egg(org.bukkit.entity.Egg) EntitySnowball(net.minecraft.server.EntitySnowball) EntityThrownExpBottle(net.minecraft.server.EntityThrownExpBottle) ThrownExpBottle(org.bukkit.entity.ThrownExpBottle) CraftItemStack(org.bukkit.craftbukkit.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) EntityWitherSkull(net.minecraft.server.EntityWitherSkull) WitherSkull(org.bukkit.entity.WitherSkull)

Aggregations

ThrownExpBottle (org.bukkit.entity.ThrownExpBottle)11 Random (java.util.Random)6 Egg (org.bukkit.entity.Egg)6 WitherSkull (org.bukkit.entity.WitherSkull)6 ItemStack (org.bukkit.inventory.ItemStack)6 IPosition (net.minecraft.dispenser.IPosition)3 TippedArrow (org.bukkit.entity.TippedArrow)3 ExpBottleEvent (org.bukkit.event.entity.ExpBottleEvent)3 PotionData (org.bukkit.potion.PotionData)3 ProxyBlockSource (net.minecraft.dispenser.ProxyBlockSource)2 EnderPearlEntity (net.minecraft.entity.item.EnderPearlEntity)2 ExperienceBottleEntity (net.minecraft.entity.item.ExperienceBottleEntity)2 AbstractArrowEntity (net.minecraft.entity.projectile.AbstractArrowEntity)2 ArrowEntity (net.minecraft.entity.projectile.ArrowEntity)2 DamagingProjectileEntity (net.minecraft.entity.projectile.DamagingProjectileEntity)2 EggEntity (net.minecraft.entity.projectile.EggEntity)2 PotionEntity (net.minecraft.entity.projectile.PotionEntity)2 ProjectileEntity (net.minecraft.entity.projectile.ProjectileEntity)2 SmallFireballEntity (net.minecraft.entity.projectile.SmallFireballEntity)2 SnowballEntity (net.minecraft.entity.projectile.SnowballEntity)2