Пример #1
0
  public void onLivingUpdate() {
    if (!this.onGround && this.motionY < 0.0D) {
      this.motionY *= 0.8D;
    }

    for (int var5 = 0; var5 < 2; ++var5) {
      // "witchMagic"
      this.worldObj.spawnParticle(
          EnumParticleTypes.SPELL_WITCH,
          this.posX + (this.rand.nextDouble() - 0.5D) * (double) this.width,
          this.posY + this.rand.nextDouble() * (double) this.height,
          this.posZ + (this.rand.nextDouble() - 0.5D) * (double) this.width,
          0.0D,
          0.0D,
          0.0D);
    }

    EntitySpider mob;
    if (this.getHealth() < EntityAttributes.maxHealth2 * 0.75F
        && this.getHealth() > 0.0F
        && this.spawn == 0
        && !this.worldObj.isRemote) {
      mob = new EntitySpider(this.worldObj);
      mob.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, 0.0F);
      // mob.onSpawnWithEgg((IEntityLivingData)null);
      mob.onInitialSpawn(
          this.worldObj.getDifficultyForLocation(new BlockPos(mob)), (IEntityLivingData) null);
      this.worldObj.spawnEntityInWorld(mob);
      this.spawn = 1;
    }

    if (this.getHealth() < EntityAttributes.maxHealth2 * 0.25F
        && this.getHealth() > 0.0F
        && this.spawn == 1
        && !this.worldObj.isRemote) {
      mob = new EntitySpider(this.worldObj);
      mob.setLocationAndAngles(this.posX, this.posY, this.posZ, this.rotationYaw, 0.0F);
      // mob.onSpawnWithEgg((IEntityLivingData)null);
      mob.onInitialSpawn(
          this.worldObj.getDifficultyForLocation(new BlockPos(mob)), (IEntityLivingData) null);
      this.worldObj.spawnEntityInWorld(mob);
      this.spawn = 2;
    }

    if (!this.worldObj.isRemote) {
      if (this.getAggressive()) {
        if (this.witchAttackTimer-- <= 0) {
          this.setAggressive(false);
          ItemStack var6 = this.getHeldItem();
          this.setCurrentItemOrArmor(0, (ItemStack) null);
          if (var6 != null && var6.getItem() == Items.potionitem) {
            List var2 = Items.potionitem.getEffects(var6);
            if (var2 != null) {
              Iterator var3 = var2.iterator();

              while (var3.hasNext()) {
                PotionEffect var4 = (PotionEffect) var3.next();
                this.addPotionEffect(new PotionEffect(var4));
              }
            }
          }

          this.getEntityAttribute(SharedMonsterAttributes.movementSpeed)
              .removeModifier(field_110185_bq);
        }
      } else {
        short var7 = -1;
        if (this.rand.nextFloat() < 0.15F
            && this.isInsideOfMaterial(Material.water)
            && !this.isPotionActive(Potion.waterBreathing)) {
          var7 = 8237;
        } else if (this.rand.nextFloat() < 0.15F
            && this.isBurning()
            && !this.isPotionActive(Potion.fireResistance)) {
          var7 = 16307;
        } else if (this.rand.nextFloat() < 0.05F && this.getHealth() < this.getMaxHealth()) {
          var7 = 16341;
        } else if (this.rand.nextFloat() < 0.25F
            && this.getAttackTarget() != null
            && !this.isPotionActive(Potion.moveSpeed)
            && this.getAttackTarget().getDistanceSqToEntity(this) > 121.0D) {
          var7 = 16274;
        } else if (this.rand.nextFloat() < 0.25F
            && this.getAttackTarget() != null
            && !this.isPotionActive(Potion.moveSpeed)
            && this.getAttackTarget().getDistanceSqToEntity(this) > 121.0D) {
          var7 = 16274;
        }

        if (var7 > -1) {
          this.setCurrentItemOrArmor(0, new ItemStack(Items.potionitem, 1, var7));
          this.witchAttackTimer = this.getHeldItem().getMaxItemUseDuration();
          this.setAggressive(true);
          IAttributeInstance iattributeinstance =
              this.getEntityAttribute(SharedMonsterAttributes.movementSpeed);
          iattributeinstance.removeModifier(field_110185_bq);
          iattributeinstance.applyModifier(field_110185_bq);
        }
      }

      if (this.rand.nextFloat() < 7.5E-4F) {
        this.worldObj.setEntityState(this, (byte) 15);
      }
    }

    super.onLivingUpdate();
  }