Search in sources :

Example 11 with PersistentProjectileEntity

use of net.minecraft.entity.projectile.PersistentProjectileEntity in project HWG by cybercat-mods.

the class GrenadeLauncherItem method shoot.

private static void shoot(World world, LivingEntity shooter, Hand hand, ItemStack stack, ItemStack projectile, float soundPitch, boolean creative, float speed, float divergence, float simulated) {
    if (!world.isClient) {
        boolean bl = projectile.getItem() == HWGItems.G_EMP;
        boolean b2 = projectile.getItem() == HWGItems.G_FRAG;
        boolean b3 = projectile.getItem() == HWGItems.G_NAPALM;
        boolean b4 = projectile.getItem() == HWGItems.G_STUN;
        GrenadeEntity projectileEntity2 = new GrenadeEntity(world, projectile, shooter, shooter.getX(), shooter.getEyeY() - 0.15000000596046448D, shooter.getZ(), true);
        projectileEntity2.setState(0);
        if (bl) {
            projectileEntity2.setVariant(1);
        } else if (b2) {
            projectileEntity2.setVariant(2);
        } else if (b3) {
            projectileEntity2.setVariant(3);
        } else if (b4) {
            projectileEntity2.setVariant(5);
        } else {
            projectileEntity2.setVariant(4);
        }
        Vec3d vec3d = shooter.getOppositeRotationVector(1.0F);
        Quaternion quaternion = new Quaternion(new Vec3f(vec3d), simulated, true);
        Vec3d vec3d2 = shooter.getRotationVec(1.0F);
        Vec3f vector3f = new Vec3f(vec3d2);
        vector3f.rotate(quaternion);
        ((PersistentProjectileEntity) projectileEntity2).setVelocity((double) vector3f.getX(), (double) vector3f.getY(), (double) vector3f.getZ(), speed, divergence);
        stack.damage(1, shooter, p -> p.sendToolBreakStatus(shooter.getActiveHand()));
        world.spawnEntity((Entity) projectileEntity2);
        world.playSound((PlayerEntity) null, shooter.getX(), shooter.getY(), shooter.getZ(), HWGSounds.GLAUNCHERFIRE, SoundCategory.PLAYERS, 1.0F, 0.9F);
    }
}
Also used : Quaternion(net.minecraft.util.math.Quaternion) GrenadeEntity(mod.azure.hwg.entity.projectiles.GrenadeEntity) PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) Vec3f(net.minecraft.util.math.Vec3f) Vec3d(net.minecraft.util.math.Vec3d)

Example 12 with PersistentProjectileEntity

use of net.minecraft.entity.projectile.PersistentProjectileEntity in project gobber_fabric-1.17 by kwpugh.

the class SwordEndSniper method use.

@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
    ItemStack stack = player.getStackInHand(hand);
    ItemStack stack2 = player.getMainHandStack();
    boolean hasQuickUse = stack2.getEnchantments().toString().contains("quickuse");
    if (!hasQuickUse) {
        player.getItemCooldownManager().set(this, cooldown);
    }
    if (!world.isClient) {
        ArrowItem itemarrow = (ArrowItem) Items.ARROW;
        PersistentProjectileEntity persistentProjectileEntity = itemarrow.createArrow(world, new ItemStack(Items.ARROW), player);
        float arrowVelocity = 60.0F;
        persistentProjectileEntity.setVelocity(player, player.getPitch(), player.getYaw(), 0.0F, arrowVelocity, 0.0F);
        persistentProjectileEntity.setDamage(1);
        if (EnchantmentHelper.getLevel(Enchantments.FIRE_ASPECT, stack) > 0) {
            persistentProjectileEntity.setOnFireFor(100);
        }
        world.spawnEntity(persistentProjectileEntity);
        persistentProjectileEntity.pickupType = PickupPermission.DISALLOWED;
    }
    return TypedActionResult.success(stack);
}
Also used : PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) ArrowItem(net.minecraft.item.ArrowItem) ItemStack(net.minecraft.item.ItemStack)

Example 13 with PersistentProjectileEntity

use of net.minecraft.entity.projectile.PersistentProjectileEntity in project gobber_fabric-1.17 by kwpugh.

the class BowEnd method onStoppedUsing.

@Override
public void onStoppedUsing(ItemStack stack, World world, LivingEntity user, int remainingUseTicks) {
    if (user instanceof PlayerEntity) {
        PlayerEntity playerEntity = (PlayerEntity) user;
        boolean bl = playerEntity.getAbilities().creativeMode || EnchantmentHelper.getLevel(Enchantments.INFINITY, stack) > 0;
        ItemStack itemStack = playerEntity.getArrowType(stack);
        if (!itemStack.isEmpty() || bl) {
            if (itemStack.isEmpty()) {
                itemStack = new ItemStack(Items.ARROW);
            }
            int i = getMaxUseTime(stack) - remainingUseTicks;
            float f = getPullProgress(i);
            if (f >= 0.1D) {
                boolean bl2 = bl && itemStack.getItem() == Items.ARROW;
                if (!world.isClient) {
                    ArrowItem arrowItem = (ArrowItem) (itemStack.getItem() instanceof ArrowItem ? itemStack.getItem() : Items.ARROW);
                    PersistentProjectileEntity persistentProjectileEntity = arrowItem.createArrow(world, itemStack, playerEntity);
                    persistentProjectileEntity.setVelocity(playerEntity, playerEntity.getPitch(), playerEntity.getYaw(), 0.0F, f * 6.0F, 0.0F);
                    if (f == 1.0F) {
                        persistentProjectileEntity.setCritical(true);
                    }
                    int j = EnchantmentHelper.getLevel(Enchantments.POWER, stack);
                    if (j > 0) {
                        persistentProjectileEntity.setDamage(persistentProjectileEntity.getDamage() + j * 0.5D + 0.5D);
                    }
                    persistentProjectileEntity.setDamage(persistentProjectileEntity.getDamage() + j * 0.5D + 0.5D);
                    int k = EnchantmentHelper.getLevel(Enchantments.PUNCH, stack);
                    if (k > 0) {
                        persistentProjectileEntity.setPunch(k);
                    }
                    if (EnchantmentHelper.getLevel(Enchantments.FLAME, stack) > 0) {
                        persistentProjectileEntity.setOnFireFor(100);
                    }
                    stack.damage(1, (LivingEntity) playerEntity, (Consumer<LivingEntity>) (p) -> {
                        p.sendToolBreakStatus(playerEntity.getActiveHand());
                    });
                    if (bl2 || playerEntity.getAbilities().creativeMode && (itemStack.getItem() == Items.SPECTRAL_ARROW || itemStack.getItem() == Items.TIPPED_ARROW)) {
                        persistentProjectileEntity.pickupType = PersistentProjectileEntity.PickupPermission.CREATIVE_ONLY;
                    }
                    world.spawnEntity(persistentProjectileEntity);
                }
                world.playSound((PlayerEntity) null, playerEntity.getX(), playerEntity.getY(), playerEntity.getZ(), SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (world.random.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
                if (!bl2 && !playerEntity.getAbilities().creativeMode) {
                    itemStack.decrement(1);
                    if (itemStack.isEmpty()) {
                        playerEntity.getInventory().removeOne(itemStack);
                    }
                }
                playerEntity.incrementStat(Stats.USED.getOrCreateStat(this));
            }
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) TypedActionResult(net.minecraft.util.TypedActionResult) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Predicate(java.util.function.Predicate) Gobber2(com.kwpugh.gobber2.Gobber2) LivingEntity(net.minecraft.entity.LivingEntity) UseAction(net.minecraft.util.UseAction) World(net.minecraft.world.World) PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) ArrowItem(net.minecraft.item.ArrowItem) Items(net.minecraft.item.Items) EnchantmentHelper(net.minecraft.enchantment.EnchantmentHelper) Consumer(java.util.function.Consumer) ItemStack(net.minecraft.item.ItemStack) SoundEvents(net.minecraft.sound.SoundEvents) Enchantments(net.minecraft.enchantment.Enchantments) Stats(net.minecraft.stat.Stats) Hand(net.minecraft.util.Hand) BowItem(net.minecraft.item.BowItem) SoundCategory(net.minecraft.sound.SoundCategory) PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) ArrowItem(net.minecraft.item.ArrowItem) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 14 with PersistentProjectileEntity

use of net.minecraft.entity.projectile.PersistentProjectileEntity in project gobber_fabric-1.17 by kwpugh.

the class StaffSniper method use.

@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, Hand hand) {
    ItemStack stack = player.getStackInHand(hand);
    ItemStack stack2 = player.getMainHandStack();
    boolean hasQuickUse = stack2.getEnchantments().toString().contains("quickuse");
    if (!hasQuickUse) {
        player.getItemCooldownManager().set(this, cooldown);
    }
    if (!world.isClient) {
        ArrowItem itemarrow = (ArrowItem) Items.ARROW;
        PersistentProjectileEntity persistentProjectileEntity = itemarrow.createArrow(world, new ItemStack(Items.ARROW), player);
        float arrowVelocity = 60.0F;
        persistentProjectileEntity.setVelocity(player, player.getPitch(), player.getYaw(), 0.0F, arrowVelocity, 0.0F);
        persistentProjectileEntity.setDamage(1);
        world.spawnEntity(persistentProjectileEntity);
        persistentProjectileEntity.pickupType = PickupPermission.DISALLOWED;
    }
    return TypedActionResult.success(stack);
}
Also used : PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) ArrowItem(net.minecraft.item.ArrowItem) ItemStack(net.minecraft.item.ItemStack)

Example 15 with PersistentProjectileEntity

use of net.minecraft.entity.projectile.PersistentProjectileEntity in project gobber_fabric-1.17 by kwpugh.

the class ModBow method onStoppedUsing.

@Override
public void onStoppedUsing(ItemStack stack, World world, LivingEntity user, int remainingUseTicks) {
    if (user instanceof PlayerEntity) {
        PlayerEntity playerEntity = (PlayerEntity) user;
        boolean bl = playerEntity.getAbilities().creativeMode || EnchantmentHelper.getLevel(Enchantments.INFINITY, stack) > 0;
        ItemStack itemStack = playerEntity.getArrowType(stack);
        if (!itemStack.isEmpty() || bl) {
            if (itemStack.isEmpty()) {
                itemStack = new ItemStack(Items.ARROW);
            }
            int i = getMaxUseTime(stack) - remainingUseTicks;
            float f = getPullProgress(i);
            if (f >= 0.1D) {
                boolean bl2 = bl && itemStack.getItem() == Items.ARROW;
                if (!world.isClient) {
                    ArrowItem arrowItem = (ArrowItem) (itemStack.getItem() instanceof ArrowItem ? itemStack.getItem() : Items.ARROW);
                    PersistentProjectileEntity persistentProjectileEntity = arrowItem.createArrow(world, itemStack, playerEntity);
                    persistentProjectileEntity.setVelocity(playerEntity, playerEntity.getPitch(), playerEntity.getYaw(), 0.0F, f * 6.0F, 0.0F);
                    if (f == 1.0F) {
                        persistentProjectileEntity.setCritical(true);
                    }
                    int j = EnchantmentHelper.getLevel(Enchantments.POWER, stack);
                    if (j > 0) {
                        persistentProjectileEntity.setDamage(persistentProjectileEntity.getDamage() + j * 0.5D + 0.5D);
                    }
                    persistentProjectileEntity.setDamage(persistentProjectileEntity.getDamage() + j * 0.5D + 0.5D);
                    int k = EnchantmentHelper.getLevel(Enchantments.PUNCH, stack);
                    if (k > 0) {
                        persistentProjectileEntity.setPunch(k);
                    }
                    if (EnchantmentHelper.getLevel(Enchantments.FLAME, stack) > 0) {
                        persistentProjectileEntity.setOnFireFor(100);
                    }
                    stack.damage(1, (LivingEntity) playerEntity, (Consumer<LivingEntity>) (p) -> {
                        p.sendToolBreakStatus(playerEntity.getActiveHand());
                    });
                    if (bl2 || playerEntity.getAbilities().creativeMode && (itemStack.getItem() == Items.SPECTRAL_ARROW || itemStack.getItem() == Items.TIPPED_ARROW)) {
                        persistentProjectileEntity.pickupType = PersistentProjectileEntity.PickupPermission.CREATIVE_ONLY;
                    }
                    world.spawnEntity(persistentProjectileEntity);
                }
                world.playSound((PlayerEntity) null, playerEntity.getX(), playerEntity.getY(), playerEntity.getZ(), SoundEvents.ENTITY_ARROW_SHOOT, SoundCategory.PLAYERS, 1.0F, 1.0F / (world.random.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
                if (!bl2 && !playerEntity.getAbilities().creativeMode) {
                    itemStack.decrement(1);
                    if (itemStack.isEmpty()) {
                        playerEntity.getInventory().removeOne(itemStack);
                    }
                }
                playerEntity.incrementStat(Stats.USED.getOrCreateStat(this));
            }
        }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) TypedActionResult(net.minecraft.util.TypedActionResult) PlayerEntity(net.minecraft.entity.player.PlayerEntity) Predicate(java.util.function.Predicate) LivingEntity(net.minecraft.entity.LivingEntity) UseAction(net.minecraft.util.UseAction) World(net.minecraft.world.World) PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) ArrowItem(net.minecraft.item.ArrowItem) Items(net.minecraft.item.Items) EnchantmentHelper(net.minecraft.enchantment.EnchantmentHelper) Consumer(java.util.function.Consumer) ItemStack(net.minecraft.item.ItemStack) SoundEvents(net.minecraft.sound.SoundEvents) Enchantments(net.minecraft.enchantment.Enchantments) Stats(net.minecraft.stat.Stats) Hand(net.minecraft.util.Hand) BowItem(net.minecraft.item.BowItem) SoundCategory(net.minecraft.sound.SoundCategory) PersistentProjectileEntity(net.minecraft.entity.projectile.PersistentProjectileEntity) ArrowItem(net.minecraft.item.ArrowItem) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Aggregations

PersistentProjectileEntity (net.minecraft.entity.projectile.PersistentProjectileEntity)38 ItemStack (net.minecraft.item.ItemStack)23 LivingEntity (net.minecraft.entity.LivingEntity)19 PlayerEntity (net.minecraft.entity.player.PlayerEntity)18 Inject (org.spongepowered.asm.mixin.injection.Inject)15 Entity (net.minecraft.entity.Entity)12 Vec3d (net.minecraft.util.math.Vec3d)7 Quaternion (net.minecraft.util.math.Quaternion)5 EnchantmentHelper (net.minecraft.enchantment.EnchantmentHelper)4 ProjectileEntity (net.minecraft.entity.projectile.ProjectileEntity)4 ArrowItem (net.minecraft.item.ArrowItem)4 SoundEvents (net.minecraft.sound.SoundEvents)4 World (net.minecraft.world.World)4 List (java.util.List)3 Vector3f (net.minecraft.client.util.math.Vector3f)3 SnowballEntity (net.minecraft.entity.projectile.thrown.SnowballEntity)3 BowItem (net.minecraft.item.BowItem)3 ServerWorld (net.minecraft.server.world.ServerWorld)3 MeleeRangedEnchantmentList (chronosacaria.mcdw.enchants.lists.MeleeRangedEnchantmentList)2 Comparator (java.util.Comparator)2