Пример #1
0
  /** Applies a velocity to each of the entities pushing them away from each other. Args: entity */
  public void applyEntityCollision(Entity par1Entity) {
    if (par1Entity.riddenByEntity == this || par1Entity.ridingEntity == this) {
      return;
    }

    double d = par1Entity.posX - posX;
    double d1 = par1Entity.posZ - posZ;
    double d2 = MathHelper.abs_max(d, d1);

    if (d2 >= 0.01D) {
      d2 = MathHelper.sqrt_double(d2);
      d /= d2;
      d1 /= d2;
      double d3 = 1.0D / d2;

      if (d3 > 1.0D) {
        d3 = 1.0D;
      }

      d *= d3;
      d1 *= d3;
      d *= 0.05D;
      d1 *= 0.05D;
      d *= 1.0F - entityCollisionReduction;
      d1 *= 1.0F - entityCollisionReduction;
      addVelocity(-d, 0.0D, -d1);
      par1Entity.addVelocity(d, 0.0D, d1);
    }
  }
Пример #2
0
  /** Pushes all entities inside the list away from the enderdragon. */
  private void collideWithEntities(List par1List) {
    double var2 =
        (this.dragonPartBody.boundingBox.minX + this.dragonPartBody.boundingBox.maxX) / 2.0D;
    double var4 =
        (this.dragonPartBody.boundingBox.minZ + this.dragonPartBody.boundingBox.maxZ) / 2.0D;
    Iterator var6 = par1List.iterator();

    while (var6.hasNext()) {
      Entity var7 = (Entity) var6.next();

      if (var7 instanceof EntityLivingBase) {
        double var8 = var7.posX - var2;
        double var10 = var7.posZ - var4;
        double var12 = var8 * var8 + var10 * var10;
        var7.addVelocity(var8 / var12 * 4.0D, 0.20000000298023224D, var10 / var12 * 4.0D);
      }
    }
  }
Пример #3
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);
   }
 }
Пример #4
0
  /** Applies a velocity to each of the entities pushing them away from each other. Args: entity */
  public void applyEntityCollision(Entity par1Entity) {
    if (worldObj.isRemote) {
      return;
    }

    if (par1Entity == riddenByEntity) {
      return;
    }

    if ((par1Entity instanceof EntityLiving)
        && !(par1Entity instanceof EntityPlayer)
        && !(par1Entity instanceof EntityIronGolem)
        && minecartType == 0
        && motionX * motionX + motionZ * motionZ > 0.01D
        && riddenByEntity == null
        && par1Entity.ridingEntity == null) {
      par1Entity.mountEntity(this);
    }

    double d = par1Entity.posX - posX;
    double d1 = par1Entity.posZ - posZ;
    double d2 = d * d + d1 * d1;

    if (d2 >= 10.0E-005D) {
      d2 = MathHelper.sqrt_double(d2);
      d /= d2;
      d1 /= d2;
      double d3 = 1.0D / d2;

      if (d3 > 1.0D) {
        d3 = 1.0D;
      }

      d *= d3;
      d1 *= d3;
      d *= 0.1D;
      d1 *= 0.1D;
      d *= 1.0F - entityCollisionReduction;
      d1 *= 1.0F - entityCollisionReduction;
      d *= 0.5D;
      d1 *= 0.5D;

      if (par1Entity instanceof EntityMinecart) {
        double d4 = par1Entity.motionX + motionX;
        double d5 = par1Entity.motionZ + motionZ;

        if (((EntityMinecart) par1Entity).minecartType == 2 && minecartType != 2) {
          motionX *= 0.2D;
          motionZ *= 0.2D;
          addVelocity(par1Entity.motionX - d, 0.0D, par1Entity.motionZ - d1);
          par1Entity.motionX *= 0.95D;
          par1Entity.motionZ *= 0.95D;
        } else if (((EntityMinecart) par1Entity).minecartType != 2 && minecartType == 2) {
          par1Entity.motionX *= 0.2D;
          par1Entity.motionZ *= 0.2D;
          par1Entity.addVelocity(motionX + d, 0.0D, motionZ + d1);
          motionX *= 0.95D;
          motionZ *= 0.95D;
        } else {
          d4 /= 2D;
          d5 /= 2D;
          motionX *= 0.2D;
          motionZ *= 0.2D;
          addVelocity(d4 - d, 0.0D, d5 - d1);
          par1Entity.motionX *= 0.2D;
          par1Entity.motionZ *= 0.2D;
          par1Entity.addVelocity(d4 + d, 0.0D, d5 + d1);
        }
      } else {
        addVelocity(-d, 0.0D, -d1);
        par1Entity.addVelocity(d / 4D, 0.0D, d1 / 4D);
      }
    }
  }
Пример #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);
      }
    }
  }
Пример #6
0
  /** Applies a velocity to each of the entities pushing them away from each other. Args: entity */
  public void applyEntityCollision(Entity par1Entity) {
    if (!this.worldObj.isRemote) {
      if (par1Entity != this.riddenByEntity) {
        if (par1Entity instanceof EntityLiving
            && !(par1Entity instanceof EntityPlayer)
            && !(par1Entity instanceof EntityIronGolem)
            && this.minecartType == 0
            && this.motionX * this.motionX + this.motionZ * this.motionZ > 0.01D
            && this.riddenByEntity == null
            && par1Entity.ridingEntity == null) {
          par1Entity.mountEntity(this);
        }

        double var2 = par1Entity.posX - this.posX;
        double var4 = par1Entity.posZ - this.posZ;
        double var6 = var2 * var2 + var4 * var4;

        if (var6 >= 9.999999747378752E-5D) {
          var6 = (double) MathHelper.sqrt_double(var6);
          var2 /= var6;
          var4 /= var6;
          double var8 = 1.0D / var6;

          if (var8 > 1.0D) {
            var8 = 1.0D;
          }

          var2 *= var8;
          var4 *= var8;
          var2 *= 0.10000000149011612D;
          var4 *= 0.10000000149011612D;
          var2 *= (double) (1.0F - this.entityCollisionReduction);
          var4 *= (double) (1.0F - this.entityCollisionReduction);
          var2 *= 0.5D;
          var4 *= 0.5D;

          if (par1Entity instanceof EntityMinecart) {
            double var10 = par1Entity.posX - this.posX;
            double var12 = par1Entity.posZ - this.posZ;
            Vec3 var14 =
                this.worldObj.getWorldVec3Pool().getVecFromPool(var10, 0.0D, var12).normalize();
            Vec3 var15 =
                this.worldObj
                    .getWorldVec3Pool()
                    .getVecFromPool(
                        (double) MathHelper.cos(this.rotationYaw * (float) Math.PI / 180.0F),
                        0.0D,
                        (double) MathHelper.sin(this.rotationYaw * (float) Math.PI / 180.0F))
                    .normalize();
            double var16 = Math.abs(var14.dotProduct(var15));

            if (var16 < 0.800000011920929D) {
              return;
            }

            double var18 = par1Entity.motionX + this.motionX;
            double var20 = par1Entity.motionZ + this.motionZ;

            if (((EntityMinecart) par1Entity).minecartType == 2 && this.minecartType != 2) {
              this.motionX *= 0.20000000298023224D;
              this.motionZ *= 0.20000000298023224D;
              this.addVelocity(par1Entity.motionX - var2, 0.0D, par1Entity.motionZ - var4);
              par1Entity.motionX *= 0.949999988079071D;
              par1Entity.motionZ *= 0.949999988079071D;
            } else if (((EntityMinecart) par1Entity).minecartType != 2 && this.minecartType == 2) {
              par1Entity.motionX *= 0.20000000298023224D;
              par1Entity.motionZ *= 0.20000000298023224D;
              par1Entity.addVelocity(this.motionX + var2, 0.0D, this.motionZ + var4);
              this.motionX *= 0.949999988079071D;
              this.motionZ *= 0.949999988079071D;
            } else {
              var18 /= 2.0D;
              var20 /= 2.0D;
              this.motionX *= 0.20000000298023224D;
              this.motionZ *= 0.20000000298023224D;
              this.addVelocity(var18 - var2, 0.0D, var20 - var4);
              par1Entity.motionX *= 0.20000000298023224D;
              par1Entity.motionZ *= 0.20000000298023224D;
              par1Entity.addVelocity(var18 + var2, 0.0D, var20 + var4);
            }
          } else {
            this.addVelocity(-var2, 0.0D, -var4);
            par1Entity.addVelocity(var2 / 4.0D, 0.0D, var4 / 4.0D);
          }
        }
      }
    }
  }