Search in sources :

Example 1 with ThrownExpBottle

use of org.bukkit.entity.ThrownExpBottle in project WindSpigot by Wind-Development.

the class CraftEventFactory method callExpBottleEvent.

public static ExpBottleEvent callExpBottleEvent(Entity entity, int exp) {
    ThrownExpBottle bottle = (ThrownExpBottle) entity.getBukkitEntity();
    ExpBottleEvent event = new ExpBottleEvent(bottle, exp);
    Bukkit.getPluginManager().callEvent(event);
    return event;
}
Also used : ExpBottleEvent(org.bukkit.event.entity.ExpBottleEvent) ThrownExpBottle(org.bukkit.entity.ThrownExpBottle)

Example 2 with ThrownExpBottle

use of org.bukkit.entity.ThrownExpBottle in project Mohist by MohistMC.

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 DispenserBlock.dispense()
    BlockSourceImpl isourceblock = new BlockSourceImpl((ServerLevel) dispenserBlock.getLevel(), dispenserBlock.getBlockPos());
    // Copied from DispenseBehaviorProjectile
    net.minecraft.core.Position iposition = DispenserBlock.getDispensePosition(isourceblock);
    Direction enumdirection = (Direction) isourceblock.getBlockState().getValue(DispenserBlock.FACING);
    net.minecraft.world.level.Level world = dispenserBlock.getLevel();
    net.minecraft.world.entity.Entity launch = null;
    if (Snowball.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.world.entity.projectile.Snowball(world, iposition.x(), iposition.y(), iposition.z());
    } else if (Egg.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.world.entity.projectile.ThrownEgg(world, iposition.x(), iposition.y(), iposition.z());
    } else if (EnderPearl.class.isAssignableFrom(projectile)) {
        launch = new ThrownEnderpearl(world, null);
        launch.setPos(iposition.x(), iposition.y(), iposition.z());
    } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
        launch = new net.minecraft.world.entity.projectile.ThrownExperienceBottle(world, iposition.x(), iposition.y(), iposition.z());
    } else if (ThrownPotion.class.isAssignableFrom(projectile)) {
        if (LingeringPotion.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.world.entity.projectile.ThrownPotion(world, iposition.x(), iposition.y(), iposition.z());
            ((net.minecraft.world.entity.projectile.ThrownPotion) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.LINGERING_POTION, 1)));
        } else {
            launch = new net.minecraft.world.entity.projectile.ThrownPotion(world, iposition.x(), iposition.y(), iposition.z());
            ((net.minecraft.world.entity.projectile.ThrownPotion) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.SPLASH_POTION, 1)));
        }
    } else if (AbstractArrow.class.isAssignableFrom(projectile)) {
        if (TippedArrow.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.world.entity.projectile.Arrow(world, iposition.x(), iposition.y(), iposition.z());
            ((net.minecraft.world.entity.projectile.Arrow) launch).setPotionType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false)));
        } else if (SpectralArrow.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.world.entity.projectile.SpectralArrow(world, iposition.x(), iposition.y(), iposition.z());
        } else {
            launch = new net.minecraft.world.entity.projectile.SpectralArrow(world, iposition.x(), iposition.y(), iposition.z());
        }
        ((net.minecraft.world.entity.projectile.AbstractArrow) launch).pickup = net.minecraft.world.entity.projectile.AbstractArrow.Pickup.ALLOWED;
        ((net.minecraft.world.entity.projectile.AbstractArrow) launch).projectileSource = this;
    } else if (Fireball.class.isAssignableFrom(projectile)) {
        double d0 = iposition.x() + (double) ((float) enumdirection.getStepX() * 0.3F);
        double d1 = iposition.y() + (double) ((float) enumdirection.getStepY() * 0.3F);
        double d2 = iposition.z() + (double) ((float) enumdirection.getStepZ() * 0.3F);
        Random random = world.random;
        double d3 = random.nextGaussian() * 0.05D + (double) enumdirection.getStepX();
        double d4 = random.nextGaussian() * 0.05D + (double) enumdirection.getStepY();
        double d5 = random.nextGaussian() * 0.05D + (double) enumdirection.getStepZ();
        if (SmallFireball.class.isAssignableFrom(projectile)) {
            launch = new net.minecraft.world.entity.projectile.SmallFireball(world, null, d0, d1, d2);
        } else if (WitherSkull.class.isAssignableFrom(projectile)) {
            launch = net.minecraft.world.entity.EntityType.WITHER_SKULL.create(world);
            launch.setPos(d0, d1, d2);
            double d6 = Math.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
            ((AbstractHurtingProjectile) launch).xPower = d3 / d6 * 0.1D;
            ((AbstractHurtingProjectile) launch).yPower = d4 / d6 * 0.1D;
            ((AbstractHurtingProjectile) launch).zPower = d5 / d6 * 0.1D;
        } else {
            launch = net.minecraft.world.entity.EntityType.FIREBALL.create(world);
            launch.setPos(d0, d1, d2);
            double d6 = Math.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
            ((AbstractHurtingProjectile) launch).xPower = d3 / d6 * 0.1D;
            ((AbstractHurtingProjectile) launch).yPower = d4 / d6 * 0.1D;
            ((AbstractHurtingProjectile) launch).zPower = d5 / d6 * 0.1D;
        }
        ((AbstractHurtingProjectile) launch).projectileSource = this;
    }
    Validate.notNull(launch, "Projectile not supported");
    if (launch instanceof net.minecraft.world.entity.projectile.Projectile) {
        if (launch instanceof net.minecraft.world.entity.projectile.ThrowableProjectile) {
            ((net.minecraft.world.entity.projectile.ThrowableProjectile) launch).projectileSource = this;
        }
        // Values from DispenseBehaviorProjectile
        float a = 6.0F;
        float b = 1.1F;
        if (launch instanceof ThrownPotion || launch instanceof ThrownExpBottle) {
            // Values from respective DispenseBehavior classes
            a *= 0.5F;
            b *= 1.25F;
        }
        // Copied from DispenseBehaviorProjectile
        ((net.minecraft.world.entity.projectile.Projectile) launch).shoot((double) enumdirection.getStepX(), (double) ((float) enumdirection.getStepY() + 0.1F), (double) enumdirection.getStepZ(), b, a);
    }
    if (velocity != null) {
        ((T) launch.getBukkitEntity()).setVelocity(velocity);
    }
    world.addFreshEntity(launch);
    return (T) launch.getBukkitEntity();
}
Also used : ThrownEnderpearl(net.minecraft.world.entity.projectile.ThrownEnderpearl) Direction(net.minecraft.core.Direction) PotionData(org.bukkit.potion.PotionData) TippedArrow(org.bukkit.entity.TippedArrow) Random(java.util.Random) AbstractHurtingProjectile(net.minecraft.world.entity.projectile.AbstractHurtingProjectile) ThrownPotion(org.bukkit.entity.ThrownPotion) AbstractArrow(org.bukkit.entity.AbstractArrow) SpectralArrow(org.bukkit.entity.SpectralArrow) TippedArrow(org.bukkit.entity.TippedArrow) BlockSourceImpl(net.minecraft.core.BlockSourceImpl) Egg(org.bukkit.entity.Egg) Projectile(org.bukkit.entity.Projectile) AbstractHurtingProjectile(net.minecraft.world.entity.projectile.AbstractHurtingProjectile) ThrownExpBottle(org.bukkit.entity.ThrownExpBottle) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack) WitherSkull(org.bukkit.entity.WitherSkull) AbstractArrow(org.bukkit.entity.AbstractArrow)

Example 3 with ThrownExpBottle

use of org.bukkit.entity.ThrownExpBottle in project Mohist by MohistMC.

the class CraftEventFactory method callExpBottleEvent.

public static ExpBottleEvent callExpBottleEvent(Entity entity, int exp) {
    ThrownExpBottle bottle = (ThrownExpBottle) entity.getBukkitEntity();
    ExpBottleEvent event = new ExpBottleEvent(bottle, exp);
    Bukkit.getPluginManager().callEvent(event);
    return event;
}
Also used : ExpBottleEvent(org.bukkit.event.entity.ExpBottleEvent) ThrownExpBottle(org.bukkit.entity.ThrownExpBottle)

Example 4 with ThrownExpBottle

use of org.bukkit.entity.ThrownExpBottle in project Magma by magmafoundation.

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()
    IBlockSource isourceblock = new BlockSourceImpl(dispenserBlock.getWorld(), dispenserBlock.getPos());
    // Copied from DispenseBehaviorProjectile
    IPosition iposition = BlockDispenser.getDispensePosition(isourceblock);
    EnumFacing enumdirection = (EnumFacing) isourceblock.getBlockState().getValue(BlockDispenser.FACING);
    net.minecraft.world.World world = dispenserBlock.getWorld();
    net.minecraft.entity.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 EntityExpBottle(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(Material.LINGERING_POTION, 1)));
        } else {
            launch = new EntityPotion(world, iposition.getX(), iposition.getY(), iposition.getZ(), CraftItemStack.asNMSCopy(new ItemStack(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).pickupStatus = EntityArrow.PickupStatus.ALLOWED;
        ((EntityArrow) launch).projectileSource = this;
    } else if (Fireball.class.isAssignableFrom(projectile)) {
        double d0 = iposition.getX() + (double) ((float) enumdirection.getFrontOffsetX() * 0.3F);
        double d1 = iposition.getY() + (double) ((float) enumdirection.getFrontOffsetY() * 0.3F);
        double d2 = iposition.getZ() + (double) ((float) enumdirection.getFrontOffsetZ() * 0.3F);
        Random random = world.rand;
        double d3 = random.nextGaussian() * 0.05D + (double) enumdirection.getFrontOffsetX();
        double d4 = random.nextGaussian() * 0.05D + (double) enumdirection.getFrontOffsetY();
        double d5 = random.nextGaussian() * 0.05D + (double) enumdirection.getFrontOffsetZ();
        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).accelerationX = d3 / d6 * 0.1D;
            ((EntityFireball) launch).accelerationY = d4 / d6 * 0.1D;
            ((EntityFireball) launch).accelerationZ = 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).accelerationX = d3 / d6 * 0.1D;
            ((EntityFireball) launch).accelerationY = d4 / d6 * 0.1D;
            ((EntityFireball) launch).accelerationZ = d5 / d6 * 0.1D;
        }
        ((EntityFireball) launch).projectileSource = this;
    }
    Validate.notNull(launch, "Projectile not supported");
    if (launch instanceof IProjectile) {
        if (launch instanceof EntityThrowable) {
            ((EntityThrowable) 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.getFrontOffsetX(), (double) ((float) enumdirection.getFrontOffsetY() + 0.1F), (double) enumdirection.getFrontOffsetZ(), b, a);
    }
    if (velocity != null) {
        ((T) launch.getBukkitEntity()).setVelocity(velocity);
    }
    world.spawnEntity(launch);
    return (T) launch.getBukkitEntity();
}
Also used : EntityWitherSkull(net.minecraft.entity.projectile.EntityWitherSkull) EntityTippedArrow(net.minecraft.entity.projectile.EntityTippedArrow) EntityLargeFireball(net.minecraft.entity.projectile.EntityLargeFireball) EnumFacing(net.minecraft.util.EnumFacing) EntityEnderPearl(net.minecraft.entity.item.EntityEnderPearl) EntityEgg(net.minecraft.entity.projectile.EntityEgg) IProjectile(net.minecraft.entity.IProjectile) PotionData(org.bukkit.potion.PotionData) EntityTippedArrow(net.minecraft.entity.projectile.EntityTippedArrow) TippedArrow(org.bukkit.entity.TippedArrow) EntitySpectralArrow(net.minecraft.entity.projectile.EntitySpectralArrow) Random(java.util.Random) EntitySmallFireball(net.minecraft.entity.projectile.EntitySmallFireball) EntityPotion(net.minecraft.entity.projectile.EntityPotion) EntityFireball(net.minecraft.entity.projectile.EntityFireball) EntitySpectralArrow(net.minecraft.entity.projectile.EntitySpectralArrow) EntityTippedArrow(net.minecraft.entity.projectile.EntityTippedArrow) Arrow(org.bukkit.entity.Arrow) EntityArrow(net.minecraft.entity.projectile.EntityArrow) SpectralArrow(org.bukkit.entity.SpectralArrow) TippedArrow(org.bukkit.entity.TippedArrow) BlockSourceImpl(net.minecraft.block.BlockSourceImpl) EntityArrow(net.minecraft.entity.projectile.EntityArrow) EntityThrowable(net.minecraft.entity.projectile.EntityThrowable) IPosition(net.minecraft.dispenser.IPosition) EntityEgg(net.minecraft.entity.projectile.EntityEgg) Egg(org.bukkit.entity.Egg) EntityExpBottle(net.minecraft.entity.item.EntityExpBottle) IBlockSource(net.minecraft.dispenser.IBlockSource) EntitySnowball(net.minecraft.entity.projectile.EntitySnowball) ThrownExpBottle(org.bukkit.entity.ThrownExpBottle) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) EntityWitherSkull(net.minecraft.entity.projectile.EntityWitherSkull) WitherSkull(org.bukkit.entity.WitherSkull)

Example 5 with ThrownExpBottle

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

the class CraftEventFactory method callExpBottleEvent.

public static ExpBottleEvent callExpBottleEvent(Entity entity, int exp) {
    ThrownExpBottle bottle = (ThrownExpBottle) entity.getBukkitEntity();
    ExpBottleEvent event = new ExpBottleEvent(bottle, exp);
    Bukkit.getPluginManager().callEvent(event);
    return event;
}
Also used : ThrownExpBottle(org.bukkit.entity.ThrownExpBottle)

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