Search in sources :

Example 1 with AbstractArrow

use of net.minecraft.world.entity.projectile.AbstractArrow in project Tropicraft by Tropicraft.

the class BlowGunItem method fireProjectile.

public static void fireProjectile(Level world, LivingEntity shooter, InteractionHand hand, ItemStack heldItem, ItemStack projectile, float soundPitch, boolean isCreativeMode, float dmg, float pitch) {
    if (!world.isClientSide) {
        AbstractArrow arrowEntity = createArrow(world, shooter, projectile);
        if (isCreativeMode) {
            arrowEntity.pickup = AbstractArrow.Pickup.CREATIVE_ONLY;
        }
        Vec3 lookVec = shooter.getLookAngle();
        Quaternion quaternion = new Quaternion(new Vector3f(lookVec), 0, true);
        Vec3 look = shooter.getViewVector(1.0F);
        Vector3f look3f = new Vector3f(look);
        look3f.transform(quaternion);
        arrowEntity.shoot(look3f.x(), look3f.y(), look3f.z(), dmg, pitch);
        heldItem.hurtAndBreak(1, shooter, (i) -> {
            i.broadcastBreakEvent(hand);
        });
        projectile.split(1);
        if (projectile.isEmpty() && shooter instanceof Player) {
            ((Player) shooter).getInventory().removeItem(projectile);
        }
        world.addFreshEntity(arrowEntity);
        world.playSound(null, shooter.getX(), shooter.getY(), shooter.getZ(), SoundEvents.CROSSBOW_SHOOT, SoundSource.PLAYERS, 1.0F, soundPitch);
    }
}
Also used : Player(net.minecraft.world.entity.player.Player) Quaternion(com.mojang.math.Quaternion) Vec3(net.minecraft.world.phys.Vec3) Vector3f(com.mojang.math.Vector3f) AbstractArrow(net.minecraft.world.entity.projectile.AbstractArrow)

Aggregations

Quaternion (com.mojang.math.Quaternion)1 Vector3f (com.mojang.math.Vector3f)1 Player (net.minecraft.world.entity.player.Player)1 AbstractArrow (net.minecraft.world.entity.projectile.AbstractArrow)1 Vec3 (net.minecraft.world.phys.Vec3)1