Search in sources :

Example 16 with AbstractArrowEntity

use of net.minecraft.entity.projectile.AbstractArrowEntity in project Vampirism by TeamLapen.

the class VampirismItemCrossbow method shoot.

/**
 * Shoots an arrow.
 *
 * @param player The shooting player
 * @param stack  The crossbow item stack
 * @return If successful
 */
protected boolean shoot(PlayerEntity player, float heightOffset, float centerOffset, World world, ItemStack stack, Hand hand) {
    boolean creative = player.abilities.instabuild;
    boolean bowInfinite = isCrossbowInfinite(stack, player);
    int bowFrugal = isCrossbowFrugal(stack);
    ItemStack itemstack = this.findAmmo(player, stack);
    if (!itemstack.isEmpty() || creative) {
        if (itemstack.isEmpty()) {
            itemstack = new ItemStack(ModItems.crossbow_arrow_normal);
        }
        float f = getArrowVelocity();
        if ((double) f >= 0.1D) {
            boolean consumeArrow = shouldConsumeArrow(player.getRandom(), itemstack, creative, bowInfinite, bowFrugal);
            if (!world.isClientSide) {
                boolean rightHand = player.getMainArm() == HandSide.RIGHT && hand == Hand.MAIN_HAND || player.getMainArm() == HandSide.LEFT && hand == Hand.OFF_HAND;
                IVampirismCrossbowArrow<?> itemarrow = itemstack.getItem() instanceof IVampirismCrossbowArrow ? (IVampirismCrossbowArrow<?>) itemstack.getItem() : ModItems.crossbow_arrow_normal;
                AbstractArrowEntity entityarrow = itemarrow.createEntity(itemstack, world, player, heightOffset, 0.3F + centerOffset, rightHand);
                Vector3d vector3d = player.getViewVector(1.0F);
                entityarrow.shoot(vector3d.x(), vector3d.y(), vector3d.z(), f * 3, 1f);
                if (isCritical(player.getRandom())) {
                    entityarrow.setCritArrow(true);
                }
                if (isIgnoreHurtTime(stack)) {
                    ((IEntityCrossbowArrow) entityarrow).setIgnoreHurtTimer();
                }
                int j = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.POWER_ARROWS, stack);
                if (j > 0) {
                    entityarrow.setBaseDamage(entityarrow.getBaseDamage() + (double) j * 0.5D + 0.5D);
                }
                int k = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.PUNCH_ARROWS, stack);
                if (k > 0) {
                    entityarrow.setKnockback(k);
                }
                if (EnchantmentHelper.getItemEnchantmentLevel(Enchantments.FLAMING_ARROWS, stack) > 0) {
                    entityarrow.setSecondsOnFire(100);
                }
                stack.hurtAndBreak(1, player, (consumer) -> consumer.broadcastBreakEvent(hand));
                if (!consumeArrow) {
                    entityarrow.pickup = AbstractArrowEntity.PickupStatus.CREATIVE_ONLY;
                }
                world.addFreshEntity(entityarrow);
                world.playSound(null, player.getX(), player.getY() + 0.5, player.getZ(), ModSounds.crossbow, SoundCategory.PLAYERS, 1F, world.random.nextFloat() * 0.1F + 0.9F);
            }
            if (consumeArrow) {
                itemstack.shrink(1);
                if (itemstack.isEmpty()) {
                    player.inventory.removeItem(itemstack);
                }
            }
            player.getCooldowns().addCooldown(stack.getItem(), getCooldown(player, stack));
            return true;
        }
    }
    return false;
}
Also used : Vector3d(net.minecraft.util.math.vector.Vector3d) IVampirismCrossbowArrow(de.teamlapen.vampirism.api.items.IVampirismCrossbowArrow) IEntityCrossbowArrow(de.teamlapen.vampirism.api.items.IEntityCrossbowArrow) ItemStack(net.minecraft.item.ItemStack) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity)

Example 17 with AbstractArrowEntity

use of net.minecraft.entity.projectile.AbstractArrowEntity 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 18 with AbstractArrowEntity

use of net.minecraft.entity.projectile.AbstractArrowEntity in project LoliServer by Loli-Server.

the class CraftWorld method spawnArrow.

@Override
public <T extends AbstractArrow> T spawnArrow(Location loc, Vector velocity, float speed, float spread, Class<T> clazz) {
    Validate.notNull(loc, "Can not spawn arrow with a null location");
    Validate.notNull(velocity, "Can not spawn arrow with a null velocity");
    Validate.notNull(clazz, "Can not spawn an arrow with no class");
    AbstractArrowEntity arrow;
    if (TippedArrow.class.isAssignableFrom(clazz)) {
        arrow = net.minecraft.entity.EntityType.ARROW.create(world);
        ((ArrowEntity) arrow).setType(CraftPotionUtil.fromBukkit(new PotionData(PotionType.WATER, false, false)));
    } else if (SpectralArrow.class.isAssignableFrom(clazz)) {
        arrow = net.minecraft.entity.EntityType.SPECTRAL_ARROW.create(world);
    } else if (Trident.class.isAssignableFrom(clazz)) {
        arrow = net.minecraft.entity.EntityType.TRIDENT.create(world);
    } else {
        arrow = net.minecraft.entity.EntityType.ARROW.create(world);
    }
    arrow.moveTo(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
    arrow.shoot(velocity.getX(), velocity.getY(), velocity.getZ(), speed, spread);
    world.addFreshEntity(arrow);
    return (T) arrow.getBukkitEntity();
}
Also used : PotionData(org.bukkit.potion.PotionData) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) ArrowEntity(net.minecraft.entity.projectile.ArrowEntity) SpectralArrow(org.bukkit.entity.SpectralArrow) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity)

Example 19 with AbstractArrowEntity

use of net.minecraft.entity.projectile.AbstractArrowEntity in project ChaosAwakens by ChaosAwakens.

the class SkateBowItem method releaseUsing.

@Override
public void releaseUsing(ItemStack stack, World worldIn, LivingEntity entityLiving, int timeLeft) {
    if (entityLiving instanceof PlayerEntity) {
        PlayerEntity playerentity = (PlayerEntity) entityLiving;
        boolean flag = playerentity.abilities.instabuild || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.INFINITY_ARROWS, stack) > 0;
        ItemStack itemstack = findAmmo(stack, playerentity);
        int i = this.getUseDuration(stack) - timeLeft;
        i = net.minecraftforge.event.ForgeEventFactory.onArrowLoose(stack, worldIn, playerentity, i, !itemstack.isEmpty() || flag);
        if (i < 0)
            return;
        if (!itemstack.isEmpty() || flag) {
            if (itemstack.isEmpty()) {
                itemstack = new ItemStack(CAItems.IRUKANDJI_ARROW.get());
            }
            float f = getPowerForTime(i);
            if (!((double) f < 0.1D)) {
                boolean flag1 = playerentity.abilities.instabuild || (itemstack.getItem() instanceof ArrowItem && ((ArrowItem) itemstack.getItem()).isInfinite(itemstack, stack, playerentity));
                if (!worldIn.isClientSide) {
                    ArrowItem arrowitem = (ArrowItem) (itemstack.getItem() instanceof ArrowItem ? itemstack.getItem() : CAItems.IRUKANDJI_ARROW.get());
                    AbstractArrowEntity abstractarrowentity = arrowitem.createArrow(worldIn, itemstack, playerentity);
                    abstractarrowentity = customArrow(abstractarrowentity);
                    abstractarrowentity.shootFromRotation(playerentity, playerentity.xRot, playerentity.yRot, 0.0F, f * 3.0F, 1.0F);
                    if (f == 1.0F) {
                        abstractarrowentity.setCritArrow(true);
                    }
                    int j = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.POWER_ARROWS, stack);
                    if (j > 0) {
                        abstractarrowentity.setBaseDamage(abstractarrowentity.getBaseDamage() + (double) j * 0.5D + 0.5D);
                    }
                    int k = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.PUNCH_ARROWS, stack);
                    if (k > 0) {
                        abstractarrowentity.setKnockback(k);
                    }
                    if (EnchantmentHelper.getItemEnchantmentLevel(Enchantments.FLAMING_ARROWS, stack) > 0) {
                        abstractarrowentity.setSecondsOnFire(100);
                    }
                    stack.hurtAndBreak(1, playerentity, (player) -> player.broadcastBreakEvent(playerentity.getUsedItemHand()));
                    if (flag1 || playerentity.abilities.instabuild && (itemstack.getItem() == Items.SPECTRAL_ARROW || itemstack.getItem() == Items.TIPPED_ARROW || itemstack.getItem() == Items.ARROW)) {
                        abstractarrowentity.pickup = AbstractArrowEntity.PickupStatus.CREATIVE_ONLY;
                    }
                    worldIn.addFreshEntity(abstractarrowentity);
                }
                worldIn.playSound(null, playerentity.getX(), playerentity.getY(), playerentity.getZ(), SoundEvents.ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (random.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
                if (!flag1 && !playerentity.abilities.instabuild) {
                    itemstack.shrink(1);
                    if (itemstack.isEmpty()) {
                        playerentity.inventory.removeItem(itemstack);
                    }
                }
                playerentity.awardStat(Stats.ITEM_USED.get(this));
            }
        }
    }
}
Also used : PlayerEntity(net.minecraft.entity.player.PlayerEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity)

Example 20 with AbstractArrowEntity

use of net.minecraft.entity.projectile.AbstractArrowEntity in project ChaosAwakens by ChaosAwakens.

the class UltimateBowItem method releaseUsing.

@Override
public void releaseUsing(ItemStack stack, World worldIn, LivingEntity entityLiving, int timeLeft) {
    if (entityLiving instanceof PlayerEntity) {
        PlayerEntity playerentity = (PlayerEntity) entityLiving;
        if (ForgeEventFactory.onArrowLoose(stack, worldIn, playerentity, this.getUseDuration(stack) - timeLeft, true) < 0)
            return;
        if (!worldIn.isClientSide) {
            AbstractArrowEntity arrowEntity = new UltimateArrowEntity(worldIn, entityLiving);
            arrowEntity.shootFromRotation(playerentity, playerentity.xRot, playerentity.yRot, 0.0F, 3.0F, 0F);
            arrowEntity.setCritArrow(true);
            arrowEntity.setSecondsOnFire(EnchantmentHelper.getItemEnchantmentLevel(Enchantments.FLAMING_ARROWS, stack) > 0 ? 250 : 75);
            int powerLevel = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.POWER_ARROWS, stack);
            if (!CAConfig.COMMON.enableAutoEnchanting.get()) {
                arrowEntity.setBaseDamage(CAConfig.COMMON.ultimateBowArrowBaseDamage.get() + (double) powerLevel * CAConfig.COMMON.ultimateBowArrowDamageMultiplier.get() + 2D);
            } else {
                arrowEntity.setBaseDamage(CAConfig.COMMON.ultimateBowArrowBaseDamage.get() + 3D);
            }
            int k = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.PUNCH_ARROWS, stack);
            arrowEntity.setKnockback(!CAConfig.COMMON.enableAutoEnchanting.get() ? k + 1 : 1);
            if (!playerentity.isCreative()) {
                stack.hurtAndBreak(1, entityLiving, (entity) -> entity.broadcastBreakEvent(EquipmentSlotType.MAINHAND));
            }
            worldIn.addFreshEntity(arrowEntity);
            worldIn.playSound(null, playerentity.getX(), playerentity.getY(), playerentity.getZ(), SoundEvents.ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (random.nextFloat() * 0.4F + 1.2F) + 0.5F);
            playerentity.awardStat(Stats.ITEM_USED.get(this));
        }
    }
}
Also used : UltimateArrowEntity(io.github.chaosawakens.common.entity.projectile.UltimateArrowEntity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity)

Aggregations

AbstractArrowEntity (net.minecraft.entity.projectile.AbstractArrowEntity)40 ItemStack (net.minecraft.item.ItemStack)19 PlayerEntity (net.minecraft.entity.player.PlayerEntity)16 ArrowItem (net.minecraft.item.ArrowItem)7 LivingEntity (net.minecraft.entity.LivingEntity)6 DamagingProjectileEntity (net.minecraft.entity.projectile.DamagingProjectileEntity)6 Entity (net.minecraft.entity.Entity)5 ArrowEntity (net.minecraft.entity.projectile.ArrowEntity)5 Vector3d (net.minecraft.util.math.vector.Vector3d)5 PotionData (org.bukkit.potion.PotionData)5 PotionEntity (net.minecraft.entity.projectile.PotionEntity)4 SpectralArrowEntity (net.minecraft.entity.projectile.SpectralArrowEntity)4 ThrowableEntity (net.minecraft.entity.projectile.ThrowableEntity)4 Overwrite (org.spongepowered.asm.mixin.Overwrite)4 ServerPlayerEntityBridge (io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge)3 EnderPearlEntity (net.minecraft.entity.item.EnderPearlEntity)3 ExperienceBottleEntity (net.minecraft.entity.item.ExperienceBottleEntity)3 CreeperEntity (net.minecraft.entity.monster.CreeperEntity)3 GhastEntity (net.minecraft.entity.monster.GhastEntity)3 AnimalEntity (net.minecraft.entity.passive.AnimalEntity)3