Пример #1
0
  /** Called when a lightning bolt hits the entity. */
  public void onStruckByLightning(EntityLightningBolt par1EntityLightningBolt) {
    dealFireDamage(5);
    fire++;

    if (fire == 0) {
      setFire(8);
    }
  }
Пример #2
0
  /** Tries to moves the entity by the passed in displacement. Args: x, y, z */
  public void moveEntity(double par1, double par3, double par5) {
    if (noClip) {
      boundingBox.offset(par1, par3, par5);
      posX = (boundingBox.minX + boundingBox.maxX) / 2D;
      posY = (boundingBox.minY + (double) yOffset) - (double) ySize;
      posZ = (boundingBox.minZ + boundingBox.maxZ) / 2D;
      return;
    }

    Profiler.startSection("move");
    ySize *= 0.4F;
    double d = posX;
    double d1 = posZ;

    if (isInWeb) {
      isInWeb = false;
      par1 *= 0.25D;
      par3 *= 0.05D;
      par5 *= 0.25D;
      motionX = 0.0D;
      motionY = 0.0D;
      motionZ = 0.0D;
    }

    double d2 = par1;
    double d3 = par3;
    double d4 = par5;
    AxisAlignedBB axisalignedbb = boundingBox.copy();
    boolean flag = onGround && isSneaking() && (this instanceof EntityPlayer);

    if (flag) {
      double d5 = 0.05D;

      for (;
          par1 != 0.0D
              && worldObj
                      .getCollidingBoundingBoxes(
                          this, boundingBox.getOffsetBoundingBox(par1, -1D, 0.0D))
                      .size()
                  == 0;
          d2 = par1) {
        if (par1 < d5 && par1 >= -d5) {
          par1 = 0.0D;
          continue;
        }

        if (par1 > 0.0D) {
          par1 -= d5;
        } else {
          par1 += d5;
        }
      }

      for (;
          par5 != 0.0D
              && worldObj
                      .getCollidingBoundingBoxes(
                          this, boundingBox.getOffsetBoundingBox(0.0D, -1D, par5))
                      .size()
                  == 0;
          d4 = par5) {
        if (par5 < d5 && par5 >= -d5) {
          par5 = 0.0D;
          continue;
        }

        if (par5 > 0.0D) {
          par5 -= d5;
        } else {
          par5 += d5;
        }
      }
    }

    List list = worldObj.getCollidingBoundingBoxes(this, boundingBox.addCoord(par1, par3, par5));

    for (int i = 0; i < list.size(); i++) {
      par3 = ((AxisAlignedBB) list.get(i)).calculateYOffset(boundingBox, par3);
    }

    boundingBox.offset(0.0D, par3, 0.0D);

    if (!field_9293_aM && d3 != par3) {
      par1 = par3 = par5 = 0.0D;
    }

    boolean flag1 = onGround || d3 != par3 && d3 < 0.0D;

    for (int j = 0; j < list.size(); j++) {
      par1 = ((AxisAlignedBB) list.get(j)).calculateXOffset(boundingBox, par1);
    }

    boundingBox.offset(par1, 0.0D, 0.0D);

    if (!field_9293_aM && d2 != par1) {
      par1 = par3 = par5 = 0.0D;
    }

    for (int k = 0; k < list.size(); k++) {
      par5 = ((AxisAlignedBB) list.get(k)).calculateZOffset(boundingBox, par5);
    }

    boundingBox.offset(0.0D, 0.0D, par5);

    if (!field_9293_aM && d4 != par5) {
      par1 = par3 = par5 = 0.0D;
    }

    if (stepHeight > 0.0F && flag1 && (flag || ySize < 0.05F) && (d2 != par1 || d4 != par5)) {
      double d6 = par1;
      double d8 = par3;
      double d10 = par5;
      par1 = d2;
      par3 = stepHeight;
      par5 = d4;
      AxisAlignedBB axisalignedbb1 = boundingBox.copy();
      boundingBox.setBB(axisalignedbb);
      List list1 = worldObj.getCollidingBoundingBoxes(this, boundingBox.addCoord(par1, par3, par5));

      for (int j2 = 0; j2 < list1.size(); j2++) {
        par3 = ((AxisAlignedBB) list1.get(j2)).calculateYOffset(boundingBox, par3);
      }

      boundingBox.offset(0.0D, par3, 0.0D);

      if (!field_9293_aM && d3 != par3) {
        par1 = par3 = par5 = 0.0D;
      }

      for (int k2 = 0; k2 < list1.size(); k2++) {
        par1 = ((AxisAlignedBB) list1.get(k2)).calculateXOffset(boundingBox, par1);
      }

      boundingBox.offset(par1, 0.0D, 0.0D);

      if (!field_9293_aM && d2 != par1) {
        par1 = par3 = par5 = 0.0D;
      }

      for (int l2 = 0; l2 < list1.size(); l2++) {
        par5 = ((AxisAlignedBB) list1.get(l2)).calculateZOffset(boundingBox, par5);
      }

      boundingBox.offset(0.0D, 0.0D, par5);

      if (!field_9293_aM && d4 != par5) {
        par1 = par3 = par5 = 0.0D;
      }

      if (!field_9293_aM && d3 != par3) {
        par1 = par3 = par5 = 0.0D;
      } else {
        par3 = -stepHeight;

        for (int i3 = 0; i3 < list1.size(); i3++) {
          par3 = ((AxisAlignedBB) list1.get(i3)).calculateYOffset(boundingBox, par3);
        }

        boundingBox.offset(0.0D, par3, 0.0D);
      }

      if (d6 * d6 + d10 * d10 >= par1 * par1 + par5 * par5) {
        par1 = d6;
        par3 = d8;
        par5 = d10;
        boundingBox.setBB(axisalignedbb1);
      } else {
        double d11 = boundingBox.minY - (double) (int) boundingBox.minY;

        if (d11 > 0.0D) {
          ySize += d11 + 0.01D;
        }
      }
    }

    Profiler.endSection();
    Profiler.startSection("rest");
    posX = (boundingBox.minX + boundingBox.maxX) / 2D;
    posY = (boundingBox.minY + (double) yOffset) - (double) ySize;
    posZ = (boundingBox.minZ + boundingBox.maxZ) / 2D;
    isCollidedHorizontally = d2 != par1 || d4 != par5;
    isCollidedVertically = d3 != par3;
    onGround = d3 != par3 && d3 < 0.0D;
    isCollided = isCollidedHorizontally || isCollidedVertically;
    updateFallState(par3, onGround);

    if (d2 != par1) {
      motionX = 0.0D;
    }

    if (d3 != par3) {
      motionY = 0.0D;
    }

    if (d4 != par5) {
      motionZ = 0.0D;
    }

    double d7 = posX - d;
    double d9 = posZ - d1;

    if (canTriggerWalking() && !flag && ridingEntity == null) {
      distanceWalkedModified += (double) MathHelper.sqrt_double(d7 * d7 + d9 * d9) * 0.6D;
      int l = MathHelper.floor_double(posX);
      int j1 = MathHelper.floor_double(posY - 0.2D - (double) yOffset);
      int l1 = MathHelper.floor_double(posZ);
      int j3 = worldObj.getBlockId(l, j1, l1);

      if (j3 == 0 && worldObj.getBlockId(l, j1 - 1, l1) == Block.fence.blockID) {
        j3 = worldObj.getBlockId(l, j1 - 1, l1);
      }

      if (distanceWalkedModified > (float) nextStepDistance && j3 > 0) {
        nextStepDistance = (int) distanceWalkedModified + 1;
        playStepSound(l, j1, l1, j3);
        Block.blocksList[j3].onEntityWalking(worldObj, l, j1, l1, this);
      }
    }

    int i1 = MathHelper.floor_double(boundingBox.minX + 0.001D);
    int k1 = MathHelper.floor_double(boundingBox.minY + 0.001D);
    int i2 = MathHelper.floor_double(boundingBox.minZ + 0.001D);
    int k3 = MathHelper.floor_double(boundingBox.maxX - 0.001D);
    int l3 = MathHelper.floor_double(boundingBox.maxY - 0.001D);
    int i4 = MathHelper.floor_double(boundingBox.maxZ - 0.001D);

    if (worldObj.checkChunksExist(i1, k1, i2, k3, l3, i4)) {
      for (int j4 = i1; j4 <= k3; j4++) {
        for (int k4 = k1; k4 <= l3; k4++) {
          for (int l4 = i2; l4 <= i4; l4++) {
            int i5 = worldObj.getBlockId(j4, k4, l4);

            if (i5 > 0) {
              Block.blocksList[i5].onEntityCollidedWithBlock(worldObj, j4, k4, l4, this);
            }
          }
        }
      }
    }

    boolean flag2 = isWet();

    if (worldObj.isBoundingBoxBurning(boundingBox.contract(0.001D, 0.001D, 0.001D))) {
      dealFireDamage(1);

      if (!flag2) {
        fire++;

        if (fire == 0) {
          setFire(8);
        }
      }
    } else if (fire <= 0) {
      fire = -fireResistance;
    }

    if (flag2 && fire > 0) {
      worldObj.playSoundAtEntity(
          this, "random.fizz", 0.7F, 1.6F + (rand.nextFloat() - rand.nextFloat()) * 0.4F);
      fire = -fireResistance;
    }

    Profiler.endSection();
  }
Пример #3
0
 /** Called whenever the entity is walking inside of lava. */
 protected void setOnFireFromLava() {
   if (!isImmuneToFire) {
     attackEntityFrom(DamageSource.lava, 4);
     setFire(15);
   }
 }
Пример #4
0
 public void attackTargetEntityWithCurrentItem(Entity entity) {
   int i = inventory.getDamageVsEntity(entity);
   if (isPotionActive(Potion.damageBoost)) {
     i += 3 << getActivePotionEffect(Potion.damageBoost).getAmplifier();
   }
   if (isPotionActive(Potion.weakness)) {
     i -= 2 << getActivePotionEffect(Potion.weakness).getAmplifier();
   }
   int j = 0;
   int k = 0;
   if (entity instanceof EntityLiving) {
     k = EnchantmentHelper.getEnchantmentModifierLiving(inventory, (EntityLiving) entity);
     j += EnchantmentHelper.getKnockbackModifier(inventory, (EntityLiving) entity);
   }
   if (isSprinting()) {
     j++;
   }
   if (i > 0 || k > 0) {
     boolean flag =
         fallDistance > 0.0F
             && !onGround
             && !isOnLadder()
             && !isInWater()
             && !isPotionActive(Potion.blindness)
             && ridingEntity == null
             && (entity instanceof EntityLiving);
     if (flag) {
       i += rand.nextInt(i / 2 + 2);
     }
     i += k;
     boolean flag1 = entity.attackEntityFrom(DamageSource.causePlayerDamage(this), i);
     if (flag1) {
       if (j > 0) {
         entity.addVelocity(
             -MathHelper.sin((rotationYaw * 3.141593F) / 180F) * (float) j * 0.5F,
             0.10000000000000001D,
             MathHelper.cos((rotationYaw * 3.141593F) / 180F) * (float) j * 0.5F);
         motionX *= 0.59999999999999998D;
         motionZ *= 0.59999999999999998D;
         setSprinting(false);
       }
       if (flag) {
         onCriticalHit(entity);
       }
       if (k > 0) {
         func_40183_c(entity);
       }
       if (i >= 18) {
         triggerAchievement(AchievementList.overkill);
       }
     }
     ItemStack itemstack = getCurrentEquippedItem();
     if (itemstack != null && (entity instanceof EntityLiving)) {
       itemstack.hitEntity((EntityLiving) entity, this);
       if (itemstack.stackSize <= 0) {
         itemstack.onItemDestroyedByUse(this);
         destroyCurrentEquippedItem();
       }
     }
     if (entity instanceof EntityLiving) {
       if (entity.isEntityAlive()) {
         alertWolves((EntityLiving) entity, true);
       }
       addStat(StatList.damageDealtStat, i);
       int l = EnchantmentHelper.getFireAspectModifier(inventory, (EntityLiving) entity);
       if (l > 0) {
         entity.setFire(l * 4);
       }
     }
     addExhaustion(0.3F);
   }
 }
Пример #5
0
  /**
   * Attacks for the player the targeted entity with the currently equipped item. The equipped item
   * has hitEntity called on it. Args: targetEntity
   */
  public void attackTargetEntityWithCurrentItem(Entity par1Entity) {
    if (!ForgeHooks.onEntityInteract(this, par1Entity, true)) {
      return;
    }
    ItemStack stack = getCurrentEquippedItem();
    if (stack != null && stack.getItem().onLeftClickEntity(stack, this, par1Entity)) {
      return;
    }

    if (par1Entity.canAttackWithItem()) {
      int var2 = this.inventory.getDamageVsEntity(par1Entity);

      if (this.isPotionActive(Potion.damageBoost)) {
        var2 += 3 << this.getActivePotionEffect(Potion.damageBoost).getAmplifier();
      }

      if (this.isPotionActive(Potion.weakness)) {
        var2 -= 2 << this.getActivePotionEffect(Potion.weakness).getAmplifier();
      }

      int var3 = 0;
      int var4 = 0;

      if (par1Entity instanceof EntityLiving) {
        var4 =
            EnchantmentHelper.getEnchantmentModifierLiving(
                this.inventory, (EntityLiving) par1Entity);
        var3 += EnchantmentHelper.getKnockbackModifier(this.inventory, (EntityLiving) par1Entity);
      }

      if (this.isSprinting()) {
        ++var3;
      }

      if (var2 > 0 || var4 > 0) {
        boolean var5 =
            this.fallDistance > 0.0F
                && !this.onGround
                && !this.isOnLadder()
                && !this.isInWater()
                && !this.isPotionActive(Potion.blindness)
                && this.ridingEntity == null
                && par1Entity instanceof EntityLiving;

        if (var5) {
          var2 += this.rand.nextInt(var2 / 2 + 2);
        }

        var2 += var4;
        boolean var6 = par1Entity.attackEntityFrom(DamageSource.causePlayerDamage(this), var2);

        if (var6) {
          if (var3 > 0) {
            par1Entity.addVelocity(
                (double)
                    (-MathHelper.sin(this.rotationYaw * (float) Math.PI / 180.0F)
                        * (float) var3
                        * 0.5F),
                0.1D,
                (double)
                    (MathHelper.cos(this.rotationYaw * (float) Math.PI / 180.0F)
                        * (float) var3
                        * 0.5F));
            this.motionX *= 0.6D;
            this.motionZ *= 0.6D;
            this.setSprinting(false);
          }

          if (var5) {
            this.onCriticalHit(par1Entity);
          }

          if (var4 > 0) {
            this.onEnchantmentCritical(par1Entity);
          }

          if (var2 >= 18) {
            this.triggerAchievement(AchievementList.overkill);
          }

          this.setLastAttackingEntity(par1Entity);
        }

        ItemStack var7 = this.getCurrentEquippedItem();

        if (var7 != null && par1Entity instanceof EntityLiving) {
          var7.hitEntity((EntityLiving) par1Entity, this);

          if (var7.stackSize <= 0) {
            var7.onItemDestroyedByUse(this);
            this.destroyCurrentEquippedItem();
          }
        }

        if (par1Entity instanceof EntityLiving) {
          if (par1Entity.isEntityAlive()) {
            this.alertWolves((EntityLiving) par1Entity, true);
          }

          this.addStat(StatList.damageDealtStat, var2);
          int var8 =
              EnchantmentHelper.getFireAspectModifier(this.inventory, (EntityLiving) par1Entity);

          if (var8 > 0) {
            par1Entity.setFire(var8 * 4);
          }
        }

        this.addExhaustion(0.3F);
      }
    }
  }