Search in sources :

Example 11 with EntityTippedArrow

use of net.minecraft.entity.projectile.EntityTippedArrow in project minecolonies by Minecolonies.

the class EntityAIRangeGuard method attackEntityWithRangedAttack.

@Override
public void attackEntityWithRangedAttack(@NotNull final EntityLivingBase entityToAttack, final float baseDamage) {
    final EntityTippedArrow arrowEntity = new GuardArrow(CompatibilityUtils.getWorld(worker), worker);
    final double xVector = entityToAttack.posX - worker.posX;
    final double yVector = entityToAttack.getEntityBoundingBox().minY + entityToAttack.height / AIM_HEIGHT - arrowEntity.posY;
    final double zVector = entityToAttack.posZ - worker.posZ;
    final double distance = (double) MathHelper.sqrt(xVector * xVector + zVector * zVector);
    double damage = baseDamage;
    // Lower the variable higher the chance that the arrows hits the target.
    final double chance = HIT_CHANCE_DIVIDER / (worker.getCitizenData().getLevel() + 1);
    arrowEntity.shoot(xVector, yVector + distance * AIM_SLIGHTLY_HIGHER_MULTIPLIER, zVector, (float) ARROW_SPEED, (float) chance);
    if (worker.getHealth() <= 2) {
        damage *= 2;
    }
    addEffectsToArrow(arrowEntity, damage);
    worker.faceEntity(entityToAttack, (float) TURN_AROUND, (float) TURN_AROUND);
    worker.getLookHelper().setLookPositionWithEntity(entityToAttack, (float) TURN_AROUND, (float) TURN_AROUND);
    final double xDiff = targetEntity.posX - worker.posX;
    final double zDiff = targetEntity.posZ - worker.posZ;
    final double goToX = xDiff > 0 ? MOVE_MINIMAL : -MOVE_MINIMAL;
    final double goToZ = zDiff > 0 ? MOVE_MINIMAL : -MOVE_MINIMAL;
    worker.move(MoverType.SELF, goToX, 0, goToZ);
    worker.swingArm(EnumHand.MAIN_HAND);
    worker.playSound(SoundEvents.ENTITY_SKELETON_SHOOT, (float) BASIC_VOLUME, (float) getRandomPitch());
    worker.world.spawnEntity(arrowEntity);
    worker.damageItemInHand(1);
}
Also used : EntityTippedArrow(net.minecraft.entity.projectile.EntityTippedArrow)

Example 12 with EntityTippedArrow

use of net.minecraft.entity.projectile.EntityTippedArrow in project minecolonies by Minecolonies.

the class EntityAIAttackArcher method attack.

/**
 * AI for an Entity to attack the target
 *
 * @param target The target to attack
 */
private void attack(final EntityLivingBase target) {
    final EntityTippedArrow arrowEntity = new EntityTippedArrow(CompatibilityUtils.getWorld(entity), entity);
    final double xVector = target.posX - entity.posX;
    final double yVector = target.getEntityBoundingBox().minY + target.height / AIM_HEIGHT - arrowEntity.posY;
    final double zVector = target.posZ - entity.posZ;
    final double distance = (double) MathHelper.sqrt(xVector * xVector + zVector * zVector);
    // Lower the variable higher the chance that the arrows hits the target.
    arrowEntity.shoot(xVector, yVector + distance * AIM_SLIGHTLY_HIGHER_MULTIPLIER, zVector, (float) ARROW_SPEED, (float) HIT_CHANCE);
    entity.faceEntity(target, (float) HALF_ROTATION, (float) HALF_ROTATION);
    entity.getLookHelper().setLookPositionWithEntity(target, (float) HALF_ROTATION, (float) HALF_ROTATION);
    if (entity.getDistance(target) >= MAX_ATTACK_DISTANCE || !entity.canEntityBeSeen(target)) {
        entity.getNavigator().tryMoveToEntityLiving(target, ATTACK_SPEED);
    } else if (lastAttack <= 0 && entity.canEntityBeSeen(target)) {
        CompatibilityUtils.spawnEntity(CompatibilityUtils.getWorld(entity), arrowEntity);
        entity.swingArm(EnumHand.MAIN_HAND);
        entity.playSound(SoundEvents.ENTITY_SKELETON_SHOOT, (float) 1.0D, (float) getRandomPitch());
        lastAttack = CYCLES_TO_WAIT;
    }
    if (lastAttack > 0) {
        lastAttack -= 1;
    }
}
Also used : EntityTippedArrow(net.minecraft.entity.projectile.EntityTippedArrow)

Example 13 with EntityTippedArrow

use of net.minecraft.entity.projectile.EntityTippedArrow in project takumicraft by TNTModders.

the class EntityArrowCreeper method superJump.

protected void superJump() {
    this.motionY = 75d;
    if (this.isPotionActive(MobEffects.JUMP_BOOST)) {
        this.motionY += (this.getActivePotionEffect(MobEffects.JUMP_BOOST).getAmplifier() + 1) * 0.1F;
    }
    if (this.isSprinting()) {
        float f = this.rotationYaw * 0.017453292F;
        this.motionX -= MathHelper.sin(f) * 0.2F;
        this.motionZ += MathHelper.cos(f) * 0.2F;
    }
    this.move(MoverType.SELF, motionX, motionY, motionZ);
    this.isAirBorne = true;
    ForgeHooks.onLivingJump(this);
    for (int t = 0; t < 1000 * (this.getPowered() ? 2 : 1); t++) {
        Random rand = new Random();
        double x = this.posX + this.rand.nextInt(10) - 5;
        double y = this.posY + this.rand.nextInt(10) - 5;
        double z = this.posZ + this.rand.nextInt(10) - 5;
        EntityTippedArrow entityarrow = new EntityTippedArrow(this.world, x, y, z);
        entityarrow.setDamage(this.world.getDifficulty().getDifficultyId() * 8);
        entityarrow.setIsCritical(true);
        entityarrow.setKnockbackStrength(10);
        if (this.getPowered()) {
            entityarrow.setFire(100);
        }
        entityarrow.pickupStatus = PickupStatus.CREATIVE_ONLY;
        entityarrow.motionX = 0;
        entityarrow.motionY = -5;
        entityarrow.motionZ = 0;
        entityarrow.setPosition(x, y, z);
        if (!this.world.isRemote) {
            this.world.spawnEntity(entityarrow);
        }
    }
}
Also used : EntityTippedArrow(net.minecraft.entity.projectile.EntityTippedArrow) Random(java.util.Random)

Example 14 with EntityTippedArrow

use of net.minecraft.entity.projectile.EntityTippedArrow in project Galacticraft by micdoodle8.

the class EntitySkeletonBoss method attackEntityWithRangedAttack.

@Override
public void attackEntityWithRangedAttack(EntityLivingBase target, float f) {
    if (!this.getPassengers().isEmpty()) {
        return;
    }
    EntityTippedArrow arrow = new EntityTippedArrow(this.world, this);
    double d0 = target.posX - this.posX;
    double d1 = target.getEntityBoundingBox().minY + (double) (target.height / 3.0F) - arrow.posY;
    double d2 = target.posZ - this.posZ;
    double d3 = MathHelper.sqrt(d0 * d0 + d2 * d2);
    arrow.shoot(d0, d1 + d3 * 0.20000000298023224D, d2, 1.6F, (float) (14 - this.world.getDifficulty().getDifficultyId() * 4));
    this.playSound(SoundEvents.ENTITY_SKELETON_SHOOT, 1.0F, 1.0F / (this.getRNG().nextFloat() * 0.4F + 0.8F));
    this.world.spawnEntity(arrow);
}
Also used : EntityTippedArrow(net.minecraft.entity.projectile.EntityTippedArrow)

Aggregations

EntityTippedArrow (net.minecraft.entity.projectile.EntityTippedArrow)14 ItemStack (net.minecraft.item.ItemStack)5 EntityArrow (net.minecraft.entity.projectile.EntityArrow)3 Random (java.util.Random)2 ItemArrow (net.minecraft.item.ItemArrow)2 PotionEffect (net.minecraft.potion.PotionEffect)2 ItemSentientBow (WayofTime.bloodmagic.item.soul.ItemSentientBow)1 Entity (net.minecraft.entity.Entity)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EntitySpectralArrow (net.minecraft.entity.projectile.EntitySpectralArrow)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 Vec3d (net.minecraft.util.math.Vec3d)1 IItemHandler (net.minecraftforge.items.IItemHandler)1 ItemAshenMask (net.tropicraft.core.common.item.armor.ItemAshenMask)1