Search in sources :

Example 1 with EnderPearlEntity

use of net.minecraft.entity.item.EnderPearlEntity in project Arclight by IzzelAliz.

the class EnderPearlItemMixin method onItemRightClick.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public ActionResult<ItemStack> onItemRightClick(World worldIn, PlayerEntity playerIn, Hand handIn) {
    ItemStack itemstack = playerIn.getHeldItem(handIn);
    if (!worldIn.isRemote) {
        EnderPearlEntity enderpearlentity = new EnderPearlEntity(worldIn, playerIn);
        enderpearlentity.setItem(itemstack);
        enderpearlentity.shoot(playerIn, playerIn.rotationPitch, playerIn.rotationYaw, 0.0F, 1.5F, 1.0F);
        if (!worldIn.addEntity(enderpearlentity)) {
            if (playerIn instanceof ServerPlayerEntityBridge) {
                ((ServerPlayerEntityBridge) playerIn).bridge$getBukkitEntity().updateInventory();
            }
            return new ActionResult<>(ActionResultType.FAIL, itemstack);
        }
    }
    worldIn.playSound((PlayerEntity) null, playerIn.posX, playerIn.posY, playerIn.posZ, SoundEvents.ENTITY_ENDER_PEARL_THROW, SoundCategory.NEUTRAL, 0.5F, 0.4F / (random.nextFloat() * 0.4F + 0.8F));
    playerIn.getCooldownTracker().setCooldown(this, 20);
    playerIn.addStat(Stats.ITEM_USED.get(this));
    if (!playerIn.abilities.isCreativeMode) {
        itemstack.shrink(1);
    }
    return new ActionResult<>(ActionResultType.SUCCESS, itemstack);
}
Also used : EnderPearlEntity(net.minecraft.entity.item.EnderPearlEntity) ActionResult(net.minecraft.util.ActionResult) ItemStack(net.minecraft.item.ItemStack) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with EnderPearlEntity

use of net.minecraft.entity.item.EnderPearlEntity in project Magma-1.16.x by magmafoundation.

the class CraftLivingEntity method launchProjectile.

@Override
@SuppressWarnings("unchecked")
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
    net.minecraft.world.World world = ((CraftWorld) getWorld()).getHandle();
    net.minecraft.entity.Entity launch = null;
    if (Snowball.class.isAssignableFrom(projectile)) {
        launch = new SnowballEntity(world, getHandle());
        // ItemSnowball
        ((ThrowableEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, 0.0F, 1.5F, 1.0F);
    } else if (Egg.class.isAssignableFrom(projectile)) {
        launch = new EggEntity(world, getHandle());
        // ItemEgg
        ((ThrowableEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, 0.0F, 1.5F, 1.0F);
    } else if (EnderPearl.class.isAssignableFrom(projectile)) {
        launch = new EnderPearlEntity(world, getHandle());
        // EnderPearlItem
        ((ThrowableEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, 0.0F, 1.5F, 1.0F);
    } else if (AbstractArrow.class.isAssignableFrom(projectile)) {
        if (TippedArrow.class.isAssignableFrom(projectile)) {
            launch = new ArrowEntity(world, getHandle());
            ((ArrowEntity) launch).setType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false)));
        } else if (SpectralArrow.class.isAssignableFrom(projectile)) {
            launch = new SpectralArrowEntity(world, getHandle());
        } else if (Trident.class.isAssignableFrom(projectile)) {
            launch = new TridentEntity(world, getHandle(), new net.minecraft.item.ItemStack(net.minecraft.item.Items.TRIDENT));
        } else {
            launch = new ArrowEntity(world, getHandle());
        }
        // ItemBow
        ((AbstractArrowEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, 0.0F, 3.0F, 1.0F);
    } else if (ThrownPotion.class.isAssignableFrom(projectile)) {
        if (LingeringPotion.class.isAssignableFrom(projectile)) {
            launch = new PotionEntity(world, getHandle());
            ((PotionEntity) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.LINGERING_POTION, 1)));
        } else {
            launch = new PotionEntity(world, getHandle());
            ((PotionEntity) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.SPLASH_POTION, 1)));
        }
        // SplashPotionItem
        ((ThrowableEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, -20.0F, 0.5F, 1.0F);
    } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
        launch = new ExperienceBottleEntity(world, getHandle());
        // ExperienceBottleItem
        ((ThrowableEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, -20.0F, 0.7F, 1.0F);
    } else if (FishHook.class.isAssignableFrom(projectile) && getHandle() instanceof PlayerEntity) {
        launch = new FishingBobberEntity((PlayerEntity) getHandle(), world, 0, 0);
    } else if (Fireball.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        Vector direction = location.getDirection().multiply(10);
        if (SmallFireball.class.isAssignableFrom(projectile)) {
            launch = new SmallFireballEntity(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else if (WitherSkull.class.isAssignableFrom(projectile)) {
            launch = new WitherSkullEntity(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else if (DragonFireball.class.isAssignableFrom(projectile)) {
            launch = new DragonFireballEntity(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else {
            launch = new FireballEntity(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        }
        ((DamagingProjectileEntity) launch).projectileSource = this;
        launch.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    } else if (LlamaSpit.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        Vector direction = location.getDirection();
        launch = net.minecraft.entity.EntityType.LLAMA_SPIT.create(world);
        ((LlamaSpitEntity) launch).setOwner(getHandle());
        // LlamaEntity
        ((LlamaSpitEntity) launch).shoot(direction.getX(), direction.getY(), direction.getZ(), 1.5F, 10.0F);
        launch.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    } else if (ShulkerBullet.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        launch = new ShulkerBulletEntity(world, getHandle(), null, null);
        launch.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    } else if (Firework.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        launch = new FireworkRocketEntity(world, net.minecraft.item.ItemStack.EMPTY, getHandle());
        launch.moveTo(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.addFreshEntity(launch);
    return (T) launch.getBukkitEntity();
}
Also used : ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) SpectralArrowEntity(net.minecraft.entity.projectile.SpectralArrowEntity) SmallFireballEntity(net.minecraft.entity.projectile.SmallFireballEntity) ThrowableEntity(net.minecraft.entity.projectile.ThrowableEntity) EggEntity(net.minecraft.entity.projectile.EggEntity) SpectralArrowEntity(net.minecraft.entity.projectile.SpectralArrowEntity) FireworkRocketEntity(net.minecraft.entity.projectile.FireworkRocketEntity) ShulkerBullet(org.bukkit.entity.ShulkerBullet) PlayerEntity(net.minecraft.entity.player.PlayerEntity) EnderPearlEntity(net.minecraft.entity.item.EnderPearlEntity) PotionData(org.bukkit.potion.PotionData) DragonFireball(org.bukkit.entity.DragonFireball) Fireball(org.bukkit.entity.Fireball) SmallFireball(org.bukkit.entity.SmallFireball) TippedArrow(org.bukkit.entity.TippedArrow) DragonFireball(org.bukkit.entity.DragonFireball) DamagingProjectileEntity(net.minecraft.entity.projectile.DamagingProjectileEntity) LlamaSpitEntity(net.minecraft.entity.projectile.LlamaSpitEntity) Trident(org.bukkit.entity.Trident) SmallFireball(org.bukkit.entity.SmallFireball) SnowballEntity(net.minecraft.entity.projectile.SnowballEntity) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) Vector(org.bukkit.util.Vector) FishingBobberEntity(net.minecraft.entity.projectile.FishingBobberEntity) FishHook(org.bukkit.entity.FishHook) DragonFireballEntity(net.minecraft.entity.projectile.DragonFireballEntity) Egg(org.bukkit.entity.Egg) ShulkerBulletEntity(net.minecraft.entity.projectile.ShulkerBulletEntity) PotionEntity(net.minecraft.entity.projectile.PotionEntity) WitherSkullEntity(net.minecraft.entity.projectile.WitherSkullEntity) ThrownExpBottle(org.bukkit.entity.ThrownExpBottle) ExperienceBottleEntity(net.minecraft.entity.item.ExperienceBottleEntity) TridentEntity(net.minecraft.entity.projectile.TridentEntity) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) AbstractArrow(org.bukkit.entity.AbstractArrow) Location(org.bukkit.Location) FireballEntity(net.minecraft.entity.projectile.FireballEntity) SmallFireballEntity(net.minecraft.entity.projectile.SmallFireballEntity) DragonFireballEntity(net.minecraft.entity.projectile.DragonFireballEntity)

Example 3 with EnderPearlEntity

use of net.minecraft.entity.item.EnderPearlEntity in project LoliServer by Loli-Server.

the class CraftLivingEntity method launchProjectile.

@Override
@SuppressWarnings("unchecked")
public <T extends Projectile> T launchProjectile(Class<? extends T> projectile, Vector velocity) {
    net.minecraft.world.World world = ((CraftWorld) getWorld()).getHandle();
    net.minecraft.entity.Entity launch = null;
    if (Snowball.class.isAssignableFrom(projectile)) {
        launch = new SnowballEntity(world, getHandle());
        // ItemSnowball
        ((ThrowableEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, 0.0F, 1.5F, 1.0F);
    } else if (Egg.class.isAssignableFrom(projectile)) {
        launch = new EggEntity(world, getHandle());
        // ItemEgg
        ((ThrowableEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, 0.0F, 1.5F, 1.0F);
    } else if (EnderPearl.class.isAssignableFrom(projectile)) {
        launch = new EnderPearlEntity(world, getHandle());
        // EnderPearlItem
        ((ThrowableEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, 0.0F, 1.5F, 1.0F);
    } else if (AbstractArrow.class.isAssignableFrom(projectile)) {
        if (TippedArrow.class.isAssignableFrom(projectile)) {
            launch = new ArrowEntity(world, getHandle());
            ((ArrowEntity) launch).setType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false)));
        } else if (SpectralArrow.class.isAssignableFrom(projectile)) {
            launch = new SpectralArrowEntity(world, getHandle());
        } else if (Trident.class.isAssignableFrom(projectile)) {
            launch = new TridentEntity(world, getHandle(), new net.minecraft.item.ItemStack(net.minecraft.item.Items.TRIDENT));
        } else {
            launch = new ArrowEntity(world, getHandle());
        }
        // ItemBow
        ((AbstractArrowEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, 0.0F, 3.0F, 1.0F);
    } else if (ThrownPotion.class.isAssignableFrom(projectile)) {
        if (LingeringPotion.class.isAssignableFrom(projectile)) {
            launch = new PotionEntity(world, getHandle());
            ((PotionEntity) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.LINGERING_POTION, 1)));
        } else {
            launch = new PotionEntity(world, getHandle());
            ((PotionEntity) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.SPLASH_POTION, 1)));
        }
        // SplashPotionItem
        ((ThrowableEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, -20.0F, 0.5F, 1.0F);
    } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
        launch = new ExperienceBottleEntity(world, getHandle());
        // ExperienceBottleItem
        ((ThrowableEntity) launch).shootFromRotation(getHandle(), getHandle().xRot, getHandle().yRot, -20.0F, 0.7F, 1.0F);
    } else if (FishHook.class.isAssignableFrom(projectile) && getHandle() instanceof PlayerEntity) {
        launch = new FishingBobberEntity((PlayerEntity) getHandle(), world, 0, 0);
    } else if (Fireball.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        Vector direction = location.getDirection().multiply(10);
        if (SmallFireball.class.isAssignableFrom(projectile)) {
            launch = new SmallFireballEntity(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else if (WitherSkull.class.isAssignableFrom(projectile)) {
            launch = new WitherSkullEntity(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else if (DragonFireball.class.isAssignableFrom(projectile)) {
            launch = new DragonFireballEntity(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        } else {
            launch = new FireballEntity(world, getHandle(), direction.getX(), direction.getY(), direction.getZ());
        }
        ((DamagingProjectileEntity) launch).projectileSource = this;
        launch.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    } else if (LlamaSpit.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        Vector direction = location.getDirection();
        launch = net.minecraft.entity.EntityType.LLAMA_SPIT.create(world);
        ((LlamaSpitEntity) launch).setOwner(getHandle());
        // LlamaEntity
        ((LlamaSpitEntity) launch).shoot(direction.getX(), direction.getY(), direction.getZ(), 1.5F, 10.0F);
        launch.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    } else if (ShulkerBullet.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        launch = new ShulkerBulletEntity(world, getHandle(), null, null);
        launch.moveTo(location.getX(), location.getY(), location.getZ(), location.getYaw(), location.getPitch());
    } else if (Firework.class.isAssignableFrom(projectile)) {
        Location location = getEyeLocation();
        launch = new FireworkRocketEntity(world, net.minecraft.item.ItemStack.EMPTY, getHandle());
        launch.moveTo(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.addFreshEntity(launch);
    return (T) launch.getBukkitEntity();
}
Also used : ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) SpectralArrowEntity(net.minecraft.entity.projectile.SpectralArrowEntity) SmallFireballEntity(net.minecraft.entity.projectile.SmallFireballEntity) ThrowableEntity(net.minecraft.entity.projectile.ThrowableEntity) EggEntity(net.minecraft.entity.projectile.EggEntity) SpectralArrowEntity(net.minecraft.entity.projectile.SpectralArrowEntity) FireworkRocketEntity(net.minecraft.entity.projectile.FireworkRocketEntity) ShulkerBullet(org.bukkit.entity.ShulkerBullet) PlayerEntity(net.minecraft.entity.player.PlayerEntity) EnderPearlEntity(net.minecraft.entity.item.EnderPearlEntity) PotionData(org.bukkit.potion.PotionData) DragonFireball(org.bukkit.entity.DragonFireball) Fireball(org.bukkit.entity.Fireball) SmallFireball(org.bukkit.entity.SmallFireball) TippedArrow(org.bukkit.entity.TippedArrow) DragonFireball(org.bukkit.entity.DragonFireball) DamagingProjectileEntity(net.minecraft.entity.projectile.DamagingProjectileEntity) LlamaSpitEntity(net.minecraft.entity.projectile.LlamaSpitEntity) Trident(org.bukkit.entity.Trident) SmallFireball(org.bukkit.entity.SmallFireball) SnowballEntity(net.minecraft.entity.projectile.SnowballEntity) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) Vector(org.bukkit.util.Vector) FishingBobberEntity(net.minecraft.entity.projectile.FishingBobberEntity) FishHook(org.bukkit.entity.FishHook) DragonFireballEntity(net.minecraft.entity.projectile.DragonFireballEntity) Egg(org.bukkit.entity.Egg) ShulkerBulletEntity(net.minecraft.entity.projectile.ShulkerBulletEntity) PotionEntity(net.minecraft.entity.projectile.PotionEntity) WitherSkullEntity(net.minecraft.entity.projectile.WitherSkullEntity) ThrownExpBottle(org.bukkit.entity.ThrownExpBottle) ExperienceBottleEntity(net.minecraft.entity.item.ExperienceBottleEntity) TridentEntity(net.minecraft.entity.projectile.TridentEntity) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) AbstractArrow(org.bukkit.entity.AbstractArrow) Location(org.bukkit.Location) FireballEntity(net.minecraft.entity.projectile.FireballEntity) SmallFireballEntity(net.minecraft.entity.projectile.SmallFireballEntity) DragonFireballEntity(net.minecraft.entity.projectile.DragonFireballEntity)

Example 4 with EnderPearlEntity

use of net.minecraft.entity.item.EnderPearlEntity in project Magma-1.16.x 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 DispenserBlock.dispense()
    ProxyBlockSource isourceblock = new ProxyBlockSource(dispenserBlock.getLevel().getMinecraftWorld(), dispenserBlock.getBlockPos());
    // Copied from DispenseTaskProjectile
    IPosition iposition = DispenserBlock.getDispensePosition(isourceblock);
    Direction enumdirection = (Direction) isourceblock.getBlockState().getValue(DispenserBlock.FACING);
    net.minecraft.world.World world = dispenserBlock.getLevel();
    net.minecraft.entity.Entity launch = null;
    if (Snowball.class.isAssignableFrom(projectile)) {
        launch = new SnowballEntity(world, iposition.x(), iposition.y(), iposition.z());
    } else if (Egg.class.isAssignableFrom(projectile)) {
        launch = new EggEntity(world, iposition.x(), iposition.y(), iposition.z());
    } else if (EnderPearl.class.isAssignableFrom(projectile)) {
        launch = new EnderPearlEntity(world, null);
        launch.setPos(iposition.x(), iposition.y(), iposition.z());
    } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
        launch = new ExperienceBottleEntity(world, iposition.x(), iposition.y(), iposition.z());
    } else if (ThrownPotion.class.isAssignableFrom(projectile)) {
        if (LingeringPotion.class.isAssignableFrom(projectile)) {
            launch = new PotionEntity(world, iposition.x(), iposition.y(), iposition.z());
            ((PotionEntity) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.LINGERING_POTION, 1)));
        } else {
            launch = new PotionEntity(world, iposition.x(), iposition.y(), iposition.z());
            ((PotionEntity) 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 ArrowEntity(world, iposition.x(), iposition.y(), iposition.z());
            ((ArrowEntity) launch).setType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false)));
        } else if (SpectralArrow.class.isAssignableFrom(projectile)) {
            launch = new SpectralArrowEntity(world, iposition.x(), iposition.y(), iposition.z());
        } else {
            launch = new ArrowEntity(world, iposition.x(), iposition.y(), iposition.z());
        }
        ((AbstractArrowEntity) launch).pickup = AbstractArrowEntity.PickupStatus.ALLOWED;
        ((AbstractArrowEntity) 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 SmallFireballEntity(world, null, d0, d1, d2);
        } else if (WitherSkull.class.isAssignableFrom(projectile)) {
            launch = EntityType.WITHER_SKULL.create(world);
            launch.setPos(d0, d1, d2);
            double d6 = (double) MathHelper.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
            ((DamagingProjectileEntity) launch).xPower = d3 / d6 * 0.1D;
            ((DamagingProjectileEntity) launch).yPower = d4 / d6 * 0.1D;
            ((DamagingProjectileEntity) launch).zPower = d5 / d6 * 0.1D;
        } else {
            launch = EntityType.FIREBALL.create(world);
            launch.setPos(d0, d1, d2);
            double d6 = (double) MathHelper.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
            ((DamagingProjectileEntity) launch).xPower = d3 / d6 * 0.1D;
            ((DamagingProjectileEntity) launch).yPower = d4 / d6 * 0.1D;
            ((DamagingProjectileEntity) launch).zPower = d5 / d6 * 0.1D;
        }
        ((DamagingProjectileEntity) launch).projectileSource = this;
    }
    Validate.notNull(launch, "Projectile not supported");
    if (launch instanceof ProjectileEntity) {
        if (launch instanceof ThrowableEntity) {
            ((ThrowableEntity) launch).projectileSource = this;
        }
        // Values from DispenseTaskProjectile
        float a = 6.0F;
        float b = 1.1F;
        if (launch instanceof PotionEntity || launch instanceof ThrownExpBottle) {
            // Values from respective DispenseTask classes
            a *= 0.5F;
            b *= 1.25F;
        }
        // Copied from DispenseTaskProjectile
        ((ProjectileEntity) 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 : SpectralArrowEntity(net.minecraft.entity.projectile.SpectralArrowEntity) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) SmallFireballEntity(net.minecraft.entity.projectile.SmallFireballEntity) EggEntity(net.minecraft.entity.projectile.EggEntity) SpectralArrowEntity(net.minecraft.entity.projectile.SpectralArrowEntity) ThrowableEntity(net.minecraft.entity.projectile.ThrowableEntity) Direction(net.minecraft.util.Direction) EnderPearlEntity(net.minecraft.entity.item.EnderPearlEntity) PotionData(org.bukkit.potion.PotionData) TippedArrow(org.bukkit.entity.TippedArrow) Random(java.util.Random) DamagingProjectileEntity(net.minecraft.entity.projectile.DamagingProjectileEntity) SnowballEntity(net.minecraft.entity.projectile.SnowballEntity) DamagingProjectileEntity(net.minecraft.entity.projectile.DamagingProjectileEntity) ProjectileEntity(net.minecraft.entity.projectile.ProjectileEntity) IPosition(net.minecraft.dispenser.IPosition) ProxyBlockSource(net.minecraft.dispenser.ProxyBlockSource) Egg(org.bukkit.entity.Egg) PotionEntity(net.minecraft.entity.projectile.PotionEntity) ThrownExpBottle(org.bukkit.entity.ThrownExpBottle) ExperienceBottleEntity(net.minecraft.entity.item.ExperienceBottleEntity) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) WitherSkull(org.bukkit.entity.WitherSkull) AbstractArrow(org.bukkit.entity.AbstractArrow) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity)

Example 5 with EnderPearlEntity

use of net.minecraft.entity.item.EnderPearlEntity in project LoliServer by Loli-Server.

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()
    ProxyBlockSource isourceblock = new ProxyBlockSource((ServerWorld) dispenserBlock.getLevel(), dispenserBlock.getBlockPos());
    // Copied from DispenseTaskProjectile
    IPosition iposition = DispenserBlock.getDispensePosition(isourceblock);
    Direction enumdirection = (Direction) isourceblock.getBlockState().getValue(DispenserBlock.FACING);
    net.minecraft.world.World world = dispenserBlock.getLevel();
    net.minecraft.entity.Entity launch = null;
    if (Snowball.class.isAssignableFrom(projectile)) {
        launch = new SnowballEntity(world, iposition.x(), iposition.y(), iposition.z());
    } else if (Egg.class.isAssignableFrom(projectile)) {
        launch = new EggEntity(world, iposition.x(), iposition.y(), iposition.z());
    } else if (EnderPearl.class.isAssignableFrom(projectile)) {
        launch = new EnderPearlEntity(world, null);
        launch.setPos(iposition.x(), iposition.y(), iposition.z());
    } else if (ThrownExpBottle.class.isAssignableFrom(projectile)) {
        launch = new ExperienceBottleEntity(world, iposition.x(), iposition.y(), iposition.z());
    } else if (ThrownPotion.class.isAssignableFrom(projectile)) {
        if (LingeringPotion.class.isAssignableFrom(projectile)) {
            launch = new PotionEntity(world, iposition.x(), iposition.y(), iposition.z());
            ((PotionEntity) launch).setItem(CraftItemStack.asNMSCopy(new ItemStack(org.bukkit.Material.LINGERING_POTION, 1)));
        } else {
            launch = new PotionEntity(world, iposition.x(), iposition.y(), iposition.z());
            ((PotionEntity) 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 ArrowEntity(world, iposition.x(), iposition.y(), iposition.z());
            ((ArrowEntity) launch).setType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false)));
        } else if (SpectralArrow.class.isAssignableFrom(projectile)) {
            launch = new SpectralArrowEntity(world, iposition.x(), iposition.y(), iposition.z());
        } else {
            launch = new ArrowEntity(world, iposition.x(), iposition.y(), iposition.z());
        }
        ((AbstractArrowEntity) launch).pickup = AbstractArrowEntity.PickupStatus.ALLOWED;
        ((AbstractArrowEntity) 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 SmallFireballEntity(world, null, d0, d1, d2);
        } else if (WitherSkull.class.isAssignableFrom(projectile)) {
            launch = EntityType.WITHER_SKULL.create(world);
            launch.setPos(d0, d1, d2);
            double d6 = (double) MathHelper.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
            ((DamagingProjectileEntity) launch).xPower = d3 / d6 * 0.1D;
            ((DamagingProjectileEntity) launch).yPower = d4 / d6 * 0.1D;
            ((DamagingProjectileEntity) launch).zPower = d5 / d6 * 0.1D;
        } else {
            launch = EntityType.FIREBALL.create(world);
            launch.setPos(d0, d1, d2);
            double d6 = (double) MathHelper.sqrt(d3 * d3 + d4 * d4 + d5 * d5);
            ((DamagingProjectileEntity) launch).xPower = d3 / d6 * 0.1D;
            ((DamagingProjectileEntity) launch).yPower = d4 / d6 * 0.1D;
            ((DamagingProjectileEntity) launch).zPower = d5 / d6 * 0.1D;
        }
        ((DamagingProjectileEntity) launch).projectileSource = this;
    }
    Validate.notNull(launch, "Projectile not supported");
    if (launch instanceof ProjectileEntity) {
        if (launch instanceof ThrowableEntity) {
            ((ThrowableEntity) launch).projectileSource = this;
        }
        // Values from DispenseTaskProjectile
        float a = 6.0F;
        float b = 1.1F;
        if (launch instanceof PotionEntity || launch instanceof ThrownExpBottle) {
            // Values from respective DispenseTask classes
            a *= 0.5F;
            b *= 1.25F;
        }
        // Copied from DispenseTaskProjectile
        ((ProjectileEntity) 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 : SpectralArrowEntity(net.minecraft.entity.projectile.SpectralArrowEntity) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) SmallFireballEntity(net.minecraft.entity.projectile.SmallFireballEntity) EggEntity(net.minecraft.entity.projectile.EggEntity) SpectralArrowEntity(net.minecraft.entity.projectile.SpectralArrowEntity) ThrowableEntity(net.minecraft.entity.projectile.ThrowableEntity) Direction(net.minecraft.util.Direction) EnderPearlEntity(net.minecraft.entity.item.EnderPearlEntity) PotionData(org.bukkit.potion.PotionData) TippedArrow(org.bukkit.entity.TippedArrow) Random(java.util.Random) DamagingProjectileEntity(net.minecraft.entity.projectile.DamagingProjectileEntity) SnowballEntity(net.minecraft.entity.projectile.SnowballEntity) DamagingProjectileEntity(net.minecraft.entity.projectile.DamagingProjectileEntity) ProjectileEntity(net.minecraft.entity.projectile.ProjectileEntity) IPosition(net.minecraft.dispenser.IPosition) ProxyBlockSource(net.minecraft.dispenser.ProxyBlockSource) Egg(org.bukkit.entity.Egg) PotionEntity(net.minecraft.entity.projectile.PotionEntity) ThrownExpBottle(org.bukkit.entity.ThrownExpBottle) ExperienceBottleEntity(net.minecraft.entity.item.ExperienceBottleEntity) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) WitherSkull(org.bukkit.entity.WitherSkull) AbstractArrow(org.bukkit.entity.AbstractArrow) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity)

Aggregations

EnderPearlEntity (net.minecraft.entity.item.EnderPearlEntity)5 ExperienceBottleEntity (net.minecraft.entity.item.ExperienceBottleEntity)4 AbstractArrowEntity (net.minecraft.entity.projectile.AbstractArrowEntity)4 ArrowEntity (net.minecraft.entity.projectile.ArrowEntity)4 DamagingProjectileEntity (net.minecraft.entity.projectile.DamagingProjectileEntity)4 EggEntity (net.minecraft.entity.projectile.EggEntity)4 PotionEntity (net.minecraft.entity.projectile.PotionEntity)4 SmallFireballEntity (net.minecraft.entity.projectile.SmallFireballEntity)4 SnowballEntity (net.minecraft.entity.projectile.SnowballEntity)4 SpectralArrowEntity (net.minecraft.entity.projectile.SpectralArrowEntity)4 ThrowableEntity (net.minecraft.entity.projectile.ThrowableEntity)4 CraftItemStack (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)4 AbstractArrow (org.bukkit.entity.AbstractArrow)4 Egg (org.bukkit.entity.Egg)4 ThrownExpBottle (org.bukkit.entity.ThrownExpBottle)4 TippedArrow (org.bukkit.entity.TippedArrow)4 ItemStack (org.bukkit.inventory.ItemStack)4 PotionData (org.bukkit.potion.PotionData)4 Random (java.util.Random)2 IPosition (net.minecraft.dispenser.IPosition)2