Search in sources :

Example 11 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 12 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)

Example 13 with AbstractArrowEntity

use of net.minecraft.entity.projectile.AbstractArrowEntity in project ScrapCraft by MultiTeamDevGroup.

the class TapebotEntity method performRangedAttack.

public void performRangedAttack(LivingEntity p_82196_1_, float p_82196_2_) {
    ItemStack itemstack = this.getProjectile(this.getItemInHand(ProjectileHelper.getWeaponHoldingHand(this, Items.BOW)));
    AbstractArrowEntity abstractarrowentity = this.getArrow(itemstack, p_82196_2_);
    if (this.getMainHandItem().getItem() instanceof net.minecraft.item.BowItem)
        abstractarrowentity = ((net.minecraft.item.BowItem) this.getMainHandItem().getItem()).customArrow(abstractarrowentity);
    double d0 = p_82196_1_.getX() - this.getX();
    double d1 = p_82196_1_.getY(0.3333333333333333D) - abstractarrowentity.getY();
    double d2 = p_82196_1_.getZ() - this.getZ();
    double d3 = MathHelper.sqrt(d0 * d0 + d2 * d2);
    abstractarrowentity.shoot(d0, d1 + d3 * (double) 0.2F, d2, 1.6F, (float) (14 - this.level.getDifficulty().getId() * 4));
    this.playSound(SoundEvents.SKELETON_SHOOT, 1.0F, 1.0F / (this.getRandom().nextFloat() * 0.4F + 0.8F));
    this.level.addFreshEntity(abstractarrowentity);
}
Also used : ItemStack(net.minecraft.item.ItemStack) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity)

Example 14 with AbstractArrowEntity

use of net.minecraft.entity.projectile.AbstractArrowEntity in project Enigmatic-Legacy by Aizistral-Studios.

the class EnigmaticEventHandler method onEntityAttacked.

@SubscribeEvent
public void onEntityAttacked(LivingAttackEvent event) {
    if (event.getEntityLiving().world.isRemote)
        return;
    if (event.getEntityLiving() instanceof PlayerEntity) {
        PlayerEntity player = (PlayerEntity) event.getEntityLiving();
        if (EtheriumArmor.hasShield(player)) {
            if (event.getSource().getImmediateSource() instanceof DamagingProjectileEntity || event.getSource().getImmediateSource() instanceof AbstractArrowEntity) {
                event.setCanceled(true);
                player.world.playSound(null, player.getPosition(), EnigmaticLegacy.SHIELD_TRIGGER, SoundCategory.PLAYERS, 1.0F, 0.9F + (float) (Math.random() * 0.1D));
                player.world.playSound(null, player.getPosition(), EnigmaticLegacy.SHIELD_TRIGGER, SoundCategory.PLAYERS, 1.0F, 0.9F + (float) (Math.random() * 0.1D));
            }
        }
        if (SuperpositionHandler.hasCurio(player, EnigmaticLegacy.enigmaticItem))
            if (EnigmaticItem.immunityList.contains(event.getSource().damageType))
                event.setCanceled(true);
        if (SuperpositionHandler.hasCurio(player, EnigmaticLegacy.angelBlessing))
            if (AngelBlessing.immunityList.contains(event.getSource().damageType))
                event.setCanceled(true);
        if (SuperpositionHandler.hasCurio(player, EnigmaticLegacy.oceanStone))
            if (OceanStone.immunityList.contains(event.getSource().damageType))
                event.setCanceled(true);
        if (SuperpositionHandler.hasCurio(player, EnigmaticLegacy.magmaHeart))
            if (MagmaHeart.immunityList.contains(event.getSource().damageType))
                event.setCanceled(true);
        if (SuperpositionHandler.hasCurio(player, EnigmaticLegacy.golemHeart))
            if (GolemHeart.immunityList.contains(event.getSource().damageType))
                event.setCanceled(true);
        if (SuperpositionHandler.hasCurio(player, EnigmaticLegacy.voidPearl)) {
            if (VoidPearl.immunityList.contains(event.getSource().damageType))
                event.setCanceled(true);
            else if (VoidPearl.healList.contains(event.getSource().damageType)) {
                player.heal(event.getAmount());
                event.setCanceled(true);
            } else {
            }
        }
        if (SuperpositionHandler.hasCurio(player, EnigmaticLegacy.eyeOfNebula)) {
            if (EyeOfNebula.immunityList.contains(event.getSource().damageType)) {
                event.setCanceled(true);
            } else if (Math.random() <= ConfigHandler.EYE_OF_NEBULA_DODGE_PROBABILITY.getValue().asMultiplier(false) && player.hurtResistantTime <= 10 && event.getSource().getTrueSource() instanceof LivingEntity) {
                for (int counter = 0; counter <= 32; counter++) {
                    if (SuperpositionHandler.validTeleportRandomly(player, player.world, (int) ConfigHandler.EYE_OF_NEBULA_DODGE_RANGE.getValue()))
                        break;
                }
                player.hurtResistantTime = 20;
                event.setCanceled(true);
            }
        }
    } else if (event.getSource().getImmediateSource() instanceof PlayerEntity) {
        PlayerEntity player = (PlayerEntity) event.getSource().getImmediateSource();
        if (player.getHeldItemMainhand() != null && player.getHeldItemMainhand().getItem() == EnigmaticLegacy.extradimensionalEye)
            if (ItemNBTHelper.verifyExistance(player.getHeldItemMainhand(), "BoundDimension"))
                if (ItemNBTHelper.getInt(player.getHeldItemMainhand(), "BoundDimension", 0) == event.getEntityLiving().dimension.getId()) {
                    event.setCanceled(true);
                    ItemStack stack = player.getHeldItemMainhand();
                    EnigmaticLegacy.packetInstance.send(PacketDistributor.NEAR.with(() -> new PacketDistributor.TargetPoint(event.getEntityLiving().posX, event.getEntityLiving().posY, event.getEntityLiving().posZ, 128, event.getEntityLiving().dimension)), new PacketPortalParticles(event.getEntityLiving().posX, event.getEntityLiving().posY + (event.getEntityLiving().getHeight() / 2), event.getEntityLiving().posZ, 96, 1.5D, false));
                    event.getEntityLiving().world.playSound(null, event.getEntityLiving().getPosition(), SoundEvents.ENTITY_ENDERMAN_TELEPORT, SoundCategory.PLAYERS, 1.0F, (float) (0.8F + (Math.random() * 0.2)));
                    event.getEntityLiving().setPositionAndUpdate(ItemNBTHelper.getDouble(stack, "BoundX", 0D), ItemNBTHelper.getDouble(stack, "BoundY", 0D), ItemNBTHelper.getDouble(stack, "BoundZ", 0D));
                    event.getEntityLiving().world.playSound(null, event.getEntityLiving().getPosition(), SoundEvents.ENTITY_ENDERMAN_TELEPORT, SoundCategory.PLAYERS, 1.0F, (float) (0.8F + (Math.random() * 0.2)));
                    EnigmaticLegacy.packetInstance.send(PacketDistributor.NEAR.with(() -> new PacketDistributor.TargetPoint(event.getEntityLiving().posX, event.getEntityLiving().posY, event.getEntityLiving().posZ, 128, event.getEntityLiving().dimension)), new PacketRecallParticles(event.getEntityLiving().posX, event.getEntityLiving().posY + (event.getEntityLiving().getHeight() / 2), event.getEntityLiving().posZ, 48, false));
                    if (!player.abilities.isCreativeMode)
                        stack.shrink(1);
                }
    }
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) PacketDistributor(net.minecraftforge.fml.network.PacketDistributor) PacketRecallParticles(com.integral.enigmaticlegacy.packets.clients.PacketRecallParticles) DamagingProjectileEntity(net.minecraft.entity.projectile.DamagingProjectileEntity) PacketPortalParticles(com.integral.enigmaticlegacy.packets.clients.PacketPortalParticles) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 15 with AbstractArrowEntity

use of net.minecraft.entity.projectile.AbstractArrowEntity in project Enigmatic-Legacy by Aizistral-Studios.

the class AngelBlessing method redirect.

public void redirect(LivingEntity bearer, Entity redirected) {
    if (redirected instanceof UltimateWitherSkullEntity || redirected instanceof WitherSkullEntity)
        return;
    /*if (redirected instanceof TridentEntity)
	 	 if (((TridentEntity)redirected).getShooter() == bearer)
	 		 return;*/
    Vector3 entityPos = Vector3.fromEntityCenter(redirected);
    Vector3 bearerPos = Vector3.fromEntityCenter(bearer);
    Vector3 redirection = entityPos.subtract(bearerPos);
    redirection = redirection.normalize();
    if (redirected instanceof AbstractArrowEntity && ((AbstractArrowEntity) redirected).getShooter() == bearer) {
        if (redirected instanceof TridentEntity) {
            TridentEntity trident = (TridentEntity) redirected;
            if (trident.returningTicks > 0)
                return;
        }
        redirected.setMotion(redirected.getMotion().x * 1.75D, redirected.getMotion().y * 1.75D, redirected.getMotion().z * 1.75D);
    } else
        redirected.setMotion(redirection.x, redirection.y, redirection.z);
    if (redirected instanceof DamagingProjectileEntity) {
        DamagingProjectileEntity redirectedProjectile = (DamagingProjectileEntity) redirected;
        redirectedProjectile.accelerationX = (redirection.x / 4.0);
        redirectedProjectile.accelerationY = (redirection.y / 4.0);
        redirectedProjectile.accelerationZ = (redirection.z / 4.0);
    }
}
Also used : UltimateWitherSkullEntity(com.integral.enigmaticlegacy.entities.UltimateWitherSkullEntity) DamagingProjectileEntity(net.minecraft.entity.projectile.DamagingProjectileEntity) Vector3(com.integral.enigmaticlegacy.helpers.Vector3) TridentEntity(net.minecraft.entity.projectile.TridentEntity) UltimateWitherSkullEntity(com.integral.enigmaticlegacy.entities.UltimateWitherSkullEntity) WitherSkullEntity(net.minecraft.entity.projectile.WitherSkullEntity) AbstractArrowEntity(net.minecraft.entity.projectile.AbstractArrowEntity)

Aggregations

AbstractArrowEntity (net.minecraft.entity.projectile.AbstractArrowEntity)46 ItemStack (net.minecraft.item.ItemStack)22 PlayerEntity (net.minecraft.entity.player.PlayerEntity)18 ArrowItem (net.minecraft.item.ArrowItem)10 Entity (net.minecraft.entity.Entity)6 DamagingProjectileEntity (net.minecraft.entity.projectile.DamagingProjectileEntity)6 LivingEntity (net.minecraft.entity.LivingEntity)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