/** Performs a ranged attack according to the AI's rangedAttackID. */
  private void doRangedAttack() {
    // 43% chance to "miss"
    int chanceToMiss = entityHost.isPotionActive(Potion.moveSpeed) ? 10 : 43;
    if (worldObj.rand.nextInt(100) < chanceToMiss) {
      AMCore.instance.proxy.particleManager.BoltFromPointToPoint(
          worldObj,
          entityHost.posX,
          entityHost.posY + entityHost.getEyeHeight(),
          entityHost.posZ,
          attackTarget.posX + worldObj.rand.nextFloat() - 0.5f,
          attackTarget.posY + attackTarget.getEyeHeight() + worldObj.rand.nextFloat() - 0.5f,
          attackTarget.posZ + worldObj.rand.nextFloat() - 0.5f,
          2,
          -1);
    } else {
      AMCore.instance.proxy.particleManager.BoltFromEntityToEntity(
          worldObj, entityHost, entityHost, attackTarget, this.damage, 2, -1);
      float manaDrained =
          this.manaDrainedPerCasterLevel * ExtendedProperties.For(attackTarget).getMagicLevel();
      ExtendedProperties.For(attackTarget)
          .setCurrentMana(ExtendedProperties.For(attackTarget).getCurrentMana() - (manaDrained));
      ExtendedProperties.For(attackTarget).forceSync();

      attackTarget.attackEntityFrom(
          DamageSource.causeIndirectMagicDamage(entityHost, entityHost), this.damage);

      if (manaDrained > 100) {
        entityHost.heal(1);
        if (entityHost.worldObj.difficultySetting == EnumDifficulty.HARD) {
          attackTarget.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 40, 1, true));
          entityHost.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 40, 3, true));
        }
      }
    }
  }
 @Override
 public void startExecuting() {
   if (attacker.getHealth() <= 150)
     attacker.getNavigator().setPath(entityPathEntity, speedTowardsTarget);
   else attacker.getNavigator().setPath(entityPathEntity, 0);
   findAttemptCount = 0;
 }
  /** Updates the task */
  @Override
  public void updateTask() {
    double d = 25D; // 5 blocks away
    double d1 =
        entityHost.getDistanceSq(
            attackTarget.posX, attackTarget.boundingBox.minY, attackTarget.posZ);
    boolean flag = entityHost.getEntitySenses().canSee(attackTarget);

    if (flag) {
      stuckTime++;
    } else {
      stuckTime = 0;
    }

    if (d1 > d || stuckTime < 20) {
      entityHost.getNavigator().tryMoveToEntityLiving(attackTarget, moveSpeed);
    } else {
      entityHost.getNavigator().clearPathEntity();
    }

    entityHost.getLookHelper().setLookPositionWithEntity(attackTarget, 30F, 30F);
    rangedAttackTime = Math.max(rangedAttackTime - 1, 0);

    if (rangedAttackTime > 0) {
      return;
    }

    if (d1 > d || !flag) {
      return;
    } else {
      doRangedAttack();
      rangedAttackTime = maxRangedAttackTime;
      return;
    }
  }
Ejemplo n.º 4
0
  @Override
  public void moveEntityWithHeading(float moveStrafe, float moveForward) {
    // This controls the rider spider while it is mounted by the player.
    if (riddenByEntity != null) {
      final int level = getLevel();

      prevRotationYaw = rotationYaw = riddenByEntity.rotationYaw;
      rotationPitch = riddenByEntity.rotationPitch * 0.5F;
      setRotation(rotationYaw, rotationPitch);
      rotationYawHead = renderYawOffset = rotationYaw;

      if (level == 3) {
        moveStrafe = ((EntityLivingBase) riddenByEntity).moveStrafing * level * 0.5F / 4;
        moveForward = ((EntityLivingBase) riddenByEntity).moveForward * level * 0.6F / 4;
      } else if (level == 2) {
        moveStrafe = ((EntityLivingBase) riddenByEntity).moveStrafing * level * 0.4F / 3;
        moveForward = ((EntityLivingBase) riddenByEntity).moveForward * level * 0.5F / 3;
      } else {
        moveStrafe = ((EntityLivingBase) riddenByEntity).moveStrafing * level * 0.7F / 3;
        moveForward = ((EntityLivingBase) riddenByEntity).moveForward * level * 0.8F / 3;
      }

      if (moveForward <= 0.0F) {
        moveForward *= 0.25F;
      }

      stepHeight = 1.0F;
      jumpMovementFactor = getAIMoveSpeed() * 0.1F;

      if (!worldObj.isRemote) {
        setAIMoveSpeed(
            (float) getEntityAttribute(SharedMonsterAttributes.movementSpeed).getAttributeValue());
        super.moveEntityWithHeading(moveStrafe, moveForward);
      }

      prevLimbSwingAmount = limbSwingAmount;
      final double d1 = posX - prevPosX;
      final double d0 = posZ - prevPosZ;
      float f4 = MathHelper.sqrt_double(d1 * d1 + d0 * d0) * 4.0F;

      if (f4 > 1.0F) {
        f4 = 1.0F;
      }

      limbSwingAmount += (f4 - limbSwingAmount) * 0.4F;
      limbSwing += limbSwingAmount;
    } else {
      stepHeight = 0.5F;
      jumpMovementFactor = 0.02F;
      super.moveEntityWithHeading(moveStrafe, moveForward);
    }
  }
 @Override
 public boolean shouldExecute() {
   EntityLivingBase entitylivingbase = attacker.getAttackTarget();
   if (entitylivingbase == null) return false;
   else if (!entitylivingbase.isEntityAlive()) return false;
   else if (classTarget != null && !classTarget.isAssignableFrom(entitylivingbase.getClass()))
     return false;
   else if (--findAttemptCount <= 0) {
     entityPathEntity = attacker.getNavigator().getPathToEntityLiving(entitylivingbase);
     findAttemptCount = 4 + attacker.getRNG().nextInt(7);
     return entityPathEntity != null;
   } else return true;
 }
 @Override
 public boolean continueExecuting() {
   EntityLivingBase entitylivingbase = attacker.getAttackTarget();
   return entitylivingbase == null
       ? false
       : !entitylivingbase.isEntityAlive()
           ? false
           : !longMemory
               ? !attacker.getNavigator().noPath()
               : attacker.isWithinHomeDistance(
                   MathHelper.floor_double(entitylivingbase.posX),
                   MathHelper.floor_double(entitylivingbase.posY),
                   MathHelper.floor_double(entitylivingbase.posZ));
 }
 @SuppressWarnings("unchecked")
 protected Entity areaOfEffect() {
   List<EntityLivingBase> list =
       worldObj.getEntitiesWithinAABB(
           EntityLivingBase.class,
           AxisAlignedBB.getBoundingBox(
                   attacker.boundingBox.minX,
                   attacker.boundingBox.minY,
                   attacker.boundingBox.minZ,
                   attacker.boundingBox.maxX,
                   attacker.boundingBox.maxY,
                   attacker.boundingBox.maxZ)
               .expand(8D, 1D, 8D));
   for (int i = 0; i < list.size(); i++) {
     Entity entity = list.get(i);
     if (entity != null)
       if (entity instanceof EntityLivingBase
           && !(entity instanceof EntityTarantulaMiniboss)
           && !(entity instanceof EntityTarantula)
           && !(entity instanceof EntityTarantulaBaby)) {
         float Knockback = 2;
         entity.attackEntityFrom(DamageSource.causeMobDamage(attacker), 8.0F);
         entity.addVelocity(
             -MathHelper.sin(attacker.rotationYaw * 3.141593F / 180.0F) * Knockback * 0.5F,
             0.4D,
             MathHelper.cos(attacker.rotationYaw * 3.141593F / 180.0F) * Knockback * 0.5F);
         attacker.playSound("erebus:blamsound", 1.5F, 1.0F);
         ((EntityLivingBase) entity)
             .addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 8 * 20, 0));
         ((EntityLivingBase) entity)
             .addPotionEffect(new PotionEffect(Potion.blindness.id, 5 * 20, 0));
       }
   }
   return null;
 }
Ejemplo n.º 8
0
 @Override
 public void writeEntityToNBT(NBTTagCompound nbt) {
   super.writeEntityToNBT(nbt);
   nbt.setString("Name", getName());
   nbt.setString("Model", dataWatcher.getWatchableObjectString(4));
   if (npcLocation == null) npcLocation = SpawnLocation.Land;
   nbt.setInteger("trainerLocation", npcLocation.index);
 }
Ejemplo n.º 9
0
  @Override
  protected void dropFewItems(boolean hitByPlayerRecently, int lootingLevel) {
    super.dropFewItems(hitByPlayerRecently, lootingLevel);

    if (hitByPlayerRecently && (rand.nextInt(3) == 0 || rand.nextInt(1 + lootingLevel) > 0)) {
      dropItem(Items.spider_eye, 1);
    }
  }
Ejemplo n.º 10
0
  public void func_70636_d() {
    this.func_82168_bl();
    float var1 = this.func_70013_c(1.0F);
    if (var1 > 0.5F) {
      this.field_70708_bq += 2;
    }

    super.func_70636_d();
  }
Ejemplo n.º 11
0
  @Override
  public void onStruckByLightning(EntityLightningBolt lightning) {
    super.onStruckByLightning(lightning);

    // Boom spiders can become charged by lightning.
    if (this.getSpiderType() == EnumSpiderType.BOOM) {
      this.dataWatcher.updateObject(20, Byte.valueOf((byte) 1));
    }
  }
 public EntityAIAvoidEntity(
     EntityCreature par1EntityCreature, Class par2Class, float par3, double par4, double par6) {
   this.theEntity = par1EntityCreature;
   this.targetEntityClass = par2Class;
   this.distanceFromEntity = par3;
   this.farSpeed = par4;
   this.nearSpeed = par6;
   this.entityPathNavigate = par1EntityCreature.getNavigator();
   this.setMutexBits(1);
 }
Ejemplo n.º 13
0
 @Override
 public void onUpdate() {
   // no homePos chosen yet OR home chest is missing
   if (homePos.x == 0 && homePos.y == 0 && homePos.z == 0
       || Block.getIdFromBlock(worldObj.getBlock(homePos.x, homePos.y, homePos.z)) != CHEST_ID) {
     locateHome();
   }
   this.foodStats.onUpdate(this);
   super.onUpdate();
 }
  /** Returns whether the EntityAIBase should begin execution. */
  @Override
  public boolean shouldExecute() {
    EntityLivingBase entityliving = entityHost.getAttackTarget();

    if (entityliving == null) {
      return false;
    } else {
      attackTarget = entityliving;
      return true;
    }
  }
Ejemplo n.º 15
0
 @Override
 public void readEntityFromNBT(NBTTagCompound nbt) {
   super.readEntityFromNBT(nbt);
   spiderType = EnumSpiderType.byId(nbt.getInteger("spiderType"));
   abilityCounter = nbt.getInteger("abilityCounter");
   abilityThreshold = nbt.getInteger("abilityThreshold");
   killsUntilLevelUp = nbt.getInteger("killsUntilLevelUp");
   owner = new UUID(nbt.getLong("ownerMSB"), nbt.getLong("ownerLSB"));
   final NBTTagList tagList = nbt.getTagList("inventory", 10);
   inventory.loadInventoryFromNBT(tagList);
 }
Ejemplo n.º 16
0
 @Override
 public void writeEntityToNBT(NBTTagCompound nbt) {
   super.writeEntityToNBT(nbt);
   nbt.setInteger("spiderType", spiderType.getId());
   nbt.setInteger("abilityCounter", abilityCounter);
   nbt.setInteger("abilityThreshold", abilityThreshold);
   nbt.setInteger("killsUntilLevelUp", killsUntilLevelUp);
   nbt.setLong("ownerMSB", owner.getMostSignificantBits());
   nbt.setLong("ownerLSB", owner.getLeastSignificantBits());
   nbt.setTag("inventory", inventory.saveInventoryToNBT());
 }
Ejemplo n.º 17
0
 @Override
 public void readEntityFromNBT(NBTTagCompound nbt) {
   super.readEntityFromNBT(nbt);
   setName(nbt.getString("Name"));
   if (nbt.hasKey("Model")) {
     dataWatcher.updateObject(4, nbt.getString("Model"));
   }
   if (nbt.hasKey("trainerLocation"))
     npcLocation = SpawnLocation.getFromIndex(nbt.getInteger("trainerLocation"));
   else npcLocation = SpawnLocation.Land;
   init(getName());
 }
Ejemplo n.º 18
0
 @Override
 public void onUpdate() {
   super.onUpdate();
   if (this.getEntityBoundingBox() != null) {
     for (int i = 0; i < 4; i++) {
       Vec3d particle = Utils.randomPointInAABB(this.getEntityBoundingBox());
       if (rand.nextInt(2) == 0) {
         // getEntityWorld().spawnParticle(EnumParticleTypes.CRIT, particle.xCoord,
         // particle.yCoord, particle.zCoord, 0, 0, 0, 0);
       }
     }
   }
 }
Ejemplo n.º 19
0
  @Override
  public void onUpdate() {
    super.onUpdate();
    updateEntityAttributes();
    updateAbility();
    setHitboxSize();

    if (!worldObj.isRemote) {
      setBesideClimbableBlock(isCollidedHorizontally);

      if (getHealth() > 0) {
        // Since attributes can change over this spider's life time, consistently update the
        // attributes.
        updateEntityAttributes();
      }

      // Always try to follow the owner first.
      if (!tryFollowOwnerPlayer()) {
        // If we can't, then attack our target if we have one.
        if (target != null && !target.isDead) {
          attackEntity(target, 3.5F);
        }

        // Or if our target is now dead, reset the target and register it as a kill.
        else if (target != null && target.isDead) {
          registerKill();
          target = null;
        } else // With no target, find one.
        {
          target = findEntityToAttack();
        }

        // Move to the spider rod inline with attacking to keep the spider in range of the rod
        // but still be able to defend itself.
        tryMoveToSpiderRod();
      }

      // The pack spider scans the area for items and picks them up if they're within 3 blocks.
      if (this.getSpiderType() == EnumSpiderType.PACK) {
        for (Entity entity :
            RadixLogic.getAllEntitiesOfTypeWithinDistance(EntityItem.class, this, 3)) {
          EntityItem item = (EntityItem) entity;
          item.setDead();

          inventory.addItemStackToInventory(item.getEntityItem());
        }
      }
    }
  }
Ejemplo n.º 20
0
  /**
   * Called frequently so the entity can update its state every tick as required. For example,
   * zombies and skeletons use this to react to sunlight and start to burn.
   */
  public void onLivingUpdate() {
    super.onLivingUpdate();

    if (this.worldObj.isClient) {
      this.setScaleForAge(this.isChild());
    } else {
      int var1 = this.getGrowingAge();

      if (var1 < 0) {
        ++var1;
        this.setGrowingAge(var1);
      } else if (var1 > 0) {
        --var1;
        this.setGrowingAge(var1);
      }
    }
  }
Ejemplo n.º 21
0
  @Override
  public void onDeath(DamageSource source) {
    super.onDeath(source);

    // The boom spider explodes on death. Double the size if charged.
    if (spiderType == EnumSpiderType.BOOM) {
      if (getPowered()) {
        worldObj.createExplosion(this, posX, posY, posZ, 10.0F, false);
      } else {
        worldObj.createExplosion(this, posX, posY, posZ, 5.0F, false);
      }
    }

    // Make sure to dismount the player when the rider spider dies.
    if (spiderType == EnumSpiderType.RIDER && riddenByEntity != null) {
      final EntityPlayer player = (EntityPlayer) riddenByEntity;
      player.dismountEntity(this);
      player.ridingEntity = null;
    }
  }
Ejemplo n.º 22
0
  @Override
  protected void attackEntity(Entity entity, float damage) {
    // Prevent attacks during death.
    if (this.getHealth() <= 0.0F) {
      return;
    }

    super.attackEntity(entity, damage);

    double distance = RadixMath.getDistanceToEntity(this, entity);

    if (distance > 3.0F) {
      setAttackPath(entity);
    } else {
      final EntityLivingBase living = (EntityLivingBase) entity;

      // The tank spider can poison its targets.
      if (spiderType == EnumSpiderType.TANK) {
        PotionEffect poison = new PotionEffect(Potion.poison.id, Time.SECOND * 5 * getLevel());
        EntityLivingBase entityLiving = (EntityLivingBase) entity;

        if (entityLiving.isPotionApplicable(poison)
            && !entityLiving.isPotionActive(Potion.poison)) {
          entityLiving.addPotionEffect(poison);
        }
      }

      entity.attackEntityFrom(DamageSource.causeMobDamage(this), getAttackDamage());
    }

    if (onGround && distance < 3.0F) {
      final double dX = entity.posX - posX;
      final double dY = entity.posZ - posZ;
      final float f2 = MathHelper.sqrt_double(dX * dX + dY * dY);
      motionX = dX / f2 * 0.5D * 0.8D + motionX * 0.2D;
      motionZ = dY / f2 * 0.5D * 0.8D + motionZ * 0.2D;
      motionY = 0.4D;
    }
  }
Ejemplo n.º 23
0
  @Override
  public boolean attackEntityFrom(DamageSource source, float damage) {
    super.attackEntityFrom(source, damage);

    if (source.getSourceOfDamage() instanceof EntityLivingBase) {
      setTarget(source.getSourceOfDamage());

      // Alert other spiders that this one is being attacked.
      List<Entity> entities =
          RadixLogic.getAllEntitiesWithinDistanceOfCoordinates(worldObj, posX, posY, posZ, 15);

      for (Entity entity : entities) {
        if (entity instanceof EntitySpiderEx) {
          EntitySpiderEx spider = (EntitySpiderEx) entity;

          if (spider.owner.equals(owner)) {
            spider.setTarget(source.getSourceOfDamage());
          }
        }
      }
    }

    return true;
  }
Ejemplo n.º 24
0
 @Override
 public void writeToNBT(NBTTagCompound tagCompound) {
   tagCompound.setString("playerID", getOwnerId());
   super.writeToNBT(tagCompound);
 }
Ejemplo n.º 25
0
 @Override
 public void readFromNBT(NBTTagCompound tagCompound) {
   this.dataWatcher.updateObject(17, tagCompound.getString("playerID"));
   super.readFromNBT(tagCompound);
 }
Ejemplo n.º 26
0
 @Override
 protected void entityInit() {
   super.entityInit();
   this.isAirBorne = true;
 }
Ejemplo n.º 27
0
 @Override
 protected void applyEntityAttributes() {
   super.applyEntityAttributes();
   getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.6D);
   getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(25.0D);
 }
Ejemplo n.º 28
0
 @Override
 public void onUpdate() {
   super.onUpdate();
   if (!worldObj.isRemote && onGround && randJump() && !isEating) jump();
 }
Ejemplo n.º 29
0
 @Override
 protected void entityInit() {
   super.entityInit();
   dataWatcher.addObject(16, new Byte((byte) 0));
   dataWatcher.addObject(20, Byte.valueOf((byte) 0));
 }
Ejemplo n.º 30
0
 public void func_70071_h_() {
   super.func_70071_h_();
   if (!this.field_70170_p.field_72995_K && this.field_70170_p.field_73013_u == 0) {
     this.func_70106_y();
   }
 }