Search in sources :

Example 1 with IPosition

use of net.minecraft.server.v1_12_R1.IPosition 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();
}
Also used : EntityWitherSkull(net.minecraft.server.v1_12_R1.EntityWitherSkull) EntityTippedArrow(net.minecraft.server.v1_12_R1.EntityTippedArrow) EntityLargeFireball(net.minecraft.server.v1_12_R1.EntityLargeFireball) EntityEnderPearl(net.minecraft.server.v1_12_R1.EntityEnderPearl) EntityEgg(net.minecraft.server.v1_12_R1.EntityEgg) IProjectile(net.minecraft.server.v1_12_R1.IProjectile) SourceBlock(net.minecraft.server.v1_12_R1.SourceBlock) PotionData(org.bukkit.potion.PotionData) EntityTippedArrow(net.minecraft.server.v1_12_R1.EntityTippedArrow) TippedArrow(org.bukkit.entity.TippedArrow) EntitySpectralArrow(net.minecraft.server.v1_12_R1.EntitySpectralArrow) Random(java.util.Random) EntitySmallFireball(net.minecraft.server.v1_12_R1.EntitySmallFireball) EntityPotion(net.minecraft.server.v1_12_R1.EntityPotion) EnumDirection(net.minecraft.server.v1_12_R1.EnumDirection) EntityFireball(net.minecraft.server.v1_12_R1.EntityFireball) EntityProjectile(net.minecraft.server.v1_12_R1.EntityProjectile) EntityTippedArrow(net.minecraft.server.v1_12_R1.EntityTippedArrow) Arrow(org.bukkit.entity.Arrow) EntityArrow(net.minecraft.server.v1_12_R1.EntityArrow) EntitySpectralArrow(net.minecraft.server.v1_12_R1.EntitySpectralArrow) SpectralArrow(org.bukkit.entity.SpectralArrow) TippedArrow(org.bukkit.entity.TippedArrow) EntityArrow(net.minecraft.server.v1_12_R1.EntityArrow) IPosition(net.minecraft.server.v1_12_R1.IPosition) EntityThrownExpBottle(net.minecraft.server.v1_12_R1.EntityThrownExpBottle) EntityEgg(net.minecraft.server.v1_12_R1.EntityEgg) Egg(org.bukkit.entity.Egg) EntitySnowball(net.minecraft.server.v1_12_R1.EntitySnowball) EntityThrownExpBottle(net.minecraft.server.v1_12_R1.EntityThrownExpBottle) ThrownExpBottle(org.bukkit.entity.ThrownExpBottle) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) EntityWitherSkull(net.minecraft.server.v1_12_R1.EntityWitherSkull) WitherSkull(org.bukkit.entity.WitherSkull)

Aggregations

Random (java.util.Random)1 EntityArrow (net.minecraft.server.v1_12_R1.EntityArrow)1 EntityEgg (net.minecraft.server.v1_12_R1.EntityEgg)1 EntityEnderPearl (net.minecraft.server.v1_12_R1.EntityEnderPearl)1 EntityFireball (net.minecraft.server.v1_12_R1.EntityFireball)1 EntityLargeFireball (net.minecraft.server.v1_12_R1.EntityLargeFireball)1 EntityPotion (net.minecraft.server.v1_12_R1.EntityPotion)1 EntityProjectile (net.minecraft.server.v1_12_R1.EntityProjectile)1 EntitySmallFireball (net.minecraft.server.v1_12_R1.EntitySmallFireball)1 EntitySnowball (net.minecraft.server.v1_12_R1.EntitySnowball)1 EntitySpectralArrow (net.minecraft.server.v1_12_R1.EntitySpectralArrow)1 EntityThrownExpBottle (net.minecraft.server.v1_12_R1.EntityThrownExpBottle)1 EntityTippedArrow (net.minecraft.server.v1_12_R1.EntityTippedArrow)1 EntityWitherSkull (net.minecraft.server.v1_12_R1.EntityWitherSkull)1 EnumDirection (net.minecraft.server.v1_12_R1.EnumDirection)1 IPosition (net.minecraft.server.v1_12_R1.IPosition)1 IProjectile (net.minecraft.server.v1_12_R1.IProjectile)1 SourceBlock (net.minecraft.server.v1_12_R1.SourceBlock)1 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)1 Arrow (org.bukkit.entity.Arrow)1