@Override
 public boolean onLeftClickEntity(
     ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, Entity entity) {
   super.onLeftClickEntity(par1ItemStack, par2EntityPlayer, entity);
   entity.setFire(60);
   return false;
 }
Esempio n. 2
0
 @Override
 public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) {
   super.onLeftClickEntity(stack, player, entity);
   if (type == CalculatorItems.FireDiamond) {
     entity.setFire(4);
   }
   return false;
 }
 // set entity burn if that waling on.
 public void onEntityCollidedWithBlock(
     World par1World, int par2, int par3, int par4, Entity par5Entity) {
   if (this.getUnderMaterial(par1World, par2, par3, par4)
       && (par5Entity instanceof EntityLiving || par5Entity instanceof EntityPlayer)) {
     par5Entity.setFire(30);
     if (par5Entity instanceof EntityPlayer) {
       ((EntityPlayer) par5Entity).triggerAchievement(AchievementRegister.burnOnTeppan);
     }
   }
 }
Esempio n. 4
0
  public boolean attackEntityAsMob(Entity par1Entity) {
    boolean flag = super.attackEntityAsMob(par1Entity);

    if (flag
        && this.getHeldItem() == null
        && this.isBurning()
        && this.rand.nextFloat() < (float) this.worldObj.difficultySetting * 0.3F) {
      par1Entity.setFire(2 * this.worldObj.difficultySetting);
    }

    return flag;
  }
  @Override
  public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {

    if (world.isRemote) return;

    entity.setFire(15);
    long t = entity.getEntityData().getLong("mfr:laserTime"), t2 = world.getTotalWorldTime();
    t = t2 - t;
    long d = t / 20 >= 5 ? 1 : entity.getEntityData().getLong("mfr:laserDamage") | 1;
    d &= -1L >>> 1L;
    if (t > 10 && entity.attackEntityFrom(laserDamage, d)) {
      entity.getEntityData().setLong("mfr:laserTime", t2 + (d == 1 ? 20 : 0));
      entity.getEntityData().setLong("mfr:laserDamage", d * 2);
    }
  }
Esempio n. 6
0
  @Override
  public boolean attackEntityAsMob(Entity par1Entity) {
    float attackDamage =
        (float) this.getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue();
    int knockback = 0;

    if (par1Entity instanceof EntityLivingBase) {
      attackDamage +=
          EnchantmentHelper.getEnchantmentModifierLiving(this, (EntityLivingBase) par1Entity);
      knockback += EnchantmentHelper.getKnockbackModifier(this, (EntityLivingBase) par1Entity);
    }

    boolean flag = par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this), attackDamage);

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

      int j = EnchantmentHelper.getFireAspectModifier(this);
      if (j > 0) par1Entity.setFire(j * 4);

      if (par1Entity instanceof EntityLivingBase)
        EnchantmentHelper.func_151384_a((EntityLivingBase) par1Entity, this);

      EnchantmentHelper.func_151385_b(this, par1Entity);
    }

    return flag;
  }
Esempio n. 7
0
  @Override
  public boolean attackEntityAsMob(Entity par1Entity) {
    float var2 = 33;

    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;

    if (par1Entity instanceof EntityLivingBase) {
      var2 += EnchantmentHelper.getEnchantmentModifierLiving(this, (EntityLivingBase) par1Entity);
      var3 += EnchantmentHelper.getKnockbackModifier(this, (EntityLivingBase) par1Entity);
      ((EntityLivingBase) par1Entity)
          .addPotionEffect(new PotionEffect(Potion.blindness.id, 4 * 20, 2));
    }

    boolean var4 = par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this), var2);

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

      int var5 = EnchantmentHelper.getFireAspectModifier(this);

      if (var5 > 0) {
        par1Entity.setFire(var5 * 4);
      }
    }
    return var4;
  }
Esempio n. 8
0
 private void burn(Entity entity) {
   entity.setFire(20);
   entity.attackEntityFrom(getFlamethrowerDamage(), DAMAGE);
 }
 @Override
 public void fire(World world, double[] xyz) {
   if (world.isRemote) return;
   for (float i = 0; i <= this.getMaxRange(); i += 0.5F) {
     double dx = i * Math.cos(Math.toRadians(theta)) * Math.cos(Math.toRadians(-phi + 90));
     double dy = i * Math.sin(Math.toRadians(theta));
     double dz = i * Math.cos(Math.toRadians(theta)) * Math.sin(Math.toRadians(-phi + 90));
     int r = 1;
     AxisAlignedBB light =
         AxisAlignedBB.getBoundingBox(
                 xCoord + dx, yCoord + dy, zCoord + dz, xCoord + dx, yCoord + dy, zCoord + dz)
             .expand(r, r, r);
     List<Entity> in = world.getEntitiesWithinAABB(Entity.class, light);
     for (Entity e : in) {
       if (e instanceof TargetEntity) {
         ((TargetEntity) e).onLaserBeam(this);
       }
       if (e instanceof EntityLivingBase) {
         e.attackEntityFrom(DamageSource.lava, 4);
         e.setFire(7);
       }
     }
     int x = xCoord + (int) dx;
     int y = yCoord + (int) dy;
     int z = zCoord + (int) dz;
     Block id = world.getBlock(x, y, z);
     int meta = world.getBlockMetadata(x, y, z);
     Block id2 = this.getAffectedID(id, meta);
     int meta2 = this.getAffectedMetadata(id2, meta);
     // ReikaJavaLibrary.pConsole(id+"  to  "+id2+"  @  "+x+", "+y+", "+z);
     // ReikaJavaLibrary.pConsole(theta);
     if (ConfigRegistry.ATTACKBLOCKS.getState()) {
       if (id2 != id || meta2 != meta) {
         world.setBlock(x, y, z, id2, meta2, 3);
         world.markBlockForUpdate(x, y, z);
         this.setRange((int) i + 1);
         return;
       }
       if (id == Blocks.netherrack) {
         world.newExplosion(null, x + 0.5, y + 0.5, z + 0.5, 3F, true, true);
         world.markBlockForUpdate(x, y, z);
         this.setRange((int) i + 1);
         return;
       }
       if (id == Blocks.tnt) {
         world.setBlockToAir(x, y, z);
         EntityTNTPrimed var6 = new EntityTNTPrimed(world, x + 0.5D, y + 0.5D, z + 0.5D, null);
         world.spawnEntityInWorld(var6);
         world.playSoundAtEntity(var6, "random.fuse", 1.0F, 1.0F);
         world.spawnParticle(
             "lava", x + rand.nextFloat(), y + rand.nextFloat(), z + rand.nextFloat(), 0, 0, 0);
         this.setRange((int) i + 1);
         return;
       }
     }
     if (id != Blocks.air && id.isOpaqueCube()) {
       this.setRange((int) i + 1);
       return;
     }
     if (i == this.getMaxRange()) {
       this.setRange(this.getMaxRange());
     }
   }
 }
 @Override
 public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
   entity.setFire(10);
   entity.motionX *= 0.5D;
   entity.motionZ *= 0.5D;
 }
Esempio n. 11
0
 /**
  * Triggered whenever an entity collides with this block (enters into the block). Args: world, x,
  * y, z, entity
  */
 public void onEntityCollidedWithBlock(World var1, int var2, int var3, int var4, Entity var5) {
   var5.attackEntityFrom(DamageSource.cactus, 8);
   var5.setFire(20);
 }
  /*
   * Tick毎に呼ばれる更新処理。
   * 速度の更新、衝突判定などをここで行う。
   */
  @Override
  public void onUpdate() {
    super.onUpdate();

    livingTimeCount++;

    // その1、爆発処理
    byte exp = this.isExploded();
    if (exp == 1) {
      this.setDead();
    } else if (exp > 1) {
      AMTLogger.debugInfo("current explode int :" + exp);
      this.worldObj.spawnParticle(
          "hugeexplosion",
          this.posX,
          this.posY + 1.0D,
          this.posZ,
          this.motionX,
          this.motionY,
          this.motionZ);
      exp--;
      this.setTimeCount(exp);
    }

    // その2、アクティブか否か
    if (livingTimeCount > 3 && !this.active) {
      this.active = true;
      this.setActive((byte) 1);
      this.playSound("defeatedcrow:knock", 0.5F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
    }

    boolean explode = false;

    // 以降、アクティブか否かで動作が変わる。
    if (this.active) {
      double dx = -(double) (MathHelper.sin(this.rotationYaw / 180.0F * (float) Math.PI));
      double dz = -(double) (MathHelper.cos(this.rotationYaw / 180.0F * (float) Math.PI));
      for (int i = 0; i < 4; ++i) {
        this.worldObj.spawnParticle(
            "crit",
            this.posX + dx,
            this.posY,
            this.posZ + dz,
            -this.motionX,
            -this.motionY + 0.2D,
            -this.motionZ);
      }
    }

    // 直前のパラメータと新パラメータを一致させているところ。
    // また、速度に応じてエンティティの向きを調整し、常に進行方向に前面が向くようにしている。
    if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) {
      float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
      this.prevRotationYaw =
          this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
      this.prevRotationPitch =
          this.rotationPitch = (float) (Math.atan2(this.motionY, f) * 180.0D / Math.PI);
    }

    // 激突したブロックを確認している
    Block i = this.worldObj.getBlock(this.xTile, this.yTile, this.zTile);
    boolean air = this.worldObj.isAirBlock(xTile, yTile, zTile);

    // 空気じゃないブロックに当たった&ブロック貫通エンティティでない時
    if (i != null && i.getMaterial() != Material.air) {
      i.setBlockBoundsBasedOnState(this.worldObj, this.xTile, this.yTile, this.zTile);
      AxisAlignedBB axisalignedbb =
          i.getCollisionBoundingBoxFromPool(this.worldObj, this.xTile, this.yTile, this.zTile);

      // 当たり判定に接触しているかどうか
      if (axisalignedbb != null
          && axisalignedbb.isVecInside(Vec3.createVectorHelper(this.posX, this.posY, this.posZ))) {
        this.inGround = true;
      }
    }

    // 空気じゃないブロックに当たった
    if (this.inGround) {
      Block j = this.worldObj.getBlock(this.xTile, this.yTile, this.zTile);
      int k = this.worldObj.getBlockMetadata(this.xTile, this.yTile, this.zTile);

      /*
       * 前のTickに確認した埋まりブロックのIDとメタを照合している。違ったら埋まり状態を解除、一致したら埋まり状態を継続。
       * /* 埋まり状態2tick継続でこのエンティティを消す
       */
      if (j == this.inTile && k == this.inData) {
        ++this.ticksInGround;
        // ブロック貫通の場合、20tick(1秒間)はブロック中にあっても消えないようになる。
        int limit = 2;

        if (this.ticksInGround > limit) {
          explode = true;
        }
      } else // 埋まり状態の解除処理
      {
        this.inGround = false;
        this.motionX *= this.rand.nextFloat() * 0.1F;
        this.motionY *= this.rand.nextFloat() * 0.1F;
        this.motionZ *= this.rand.nextFloat() * 0.1F;
        this.ticksInGround = 0;
        this.ticksInAir = 0;
      }
    } else // 埋まってない時。速度の更新。
    {
      ++this.ticksInAir;
      // ブロックとの衝突判定
      Vec3 vec3 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
      Vec3 vec31 =
          Vec3.createVectorHelper(
              this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);
      MovingObjectPosition movingobjectposition =
          this.worldObj.func_147447_a(vec3, vec31, false, true, false);
      vec3 = Vec3.createVectorHelper(this.posX, this.posY, this.posZ);
      vec31 =
          Vec3.createVectorHelper(
              this.posX + this.motionX, this.posY + this.motionY, this.posZ + this.motionZ);

      // ブロックに当たった
      if (movingobjectposition != null) {
        vec31 =
            Vec3.createVectorHelper(
                movingobjectposition.hitVec.xCoord,
                movingobjectposition.hitVec.yCoord,
                movingobjectposition.hitVec.zCoord);
      }

      // Entityとの衝突判定。
      List list =
          this.worldObj.getEntitiesWithinAABBExcludingEntity(
              this,
              this.boundingBox
                  .addCoord(this.motionX, this.motionY, this.motionZ)
                  .expand(1.0D, 1.0D, 1.0D));
      double d0 = 0.0D;
      int l;
      float f1;

      MovingObjectPosition entityTarget = null;

      // 1ブロック分の範囲内にいるエンティティ全てに対して繰り返す
      for (l = 0; l < list.size(); ++l) {
        Entity entity1 = (Entity) list.get(l);
        Entity entity = null;

        // ターゲットの場合
        if (entity1 instanceof EntityLivingBase || entity1 instanceof EntityDragonPart) {
          f1 = 0.3F;
          AxisAlignedBB axisalignedbb1 = entity1.boundingBox.expand(f1, f1, f1);
          MovingObjectPosition movingobjectposition1 =
              axisalignedbb1.calculateIntercept(vec3, vec31);

          if (movingobjectposition1 != null) {
            double d1 = vec3.distanceTo(movingobjectposition1.hitVec);

            if (d1 < d0 || d0 == 0.0D) {
              // arrowと異なり、あたったEntityすべてをリストに入れる
              entityTarget = new MovingObjectPosition(entity1);
              d0 = d1;
              break;
            }
          }
        }
      }

      /*
       * 当たったエンティティそれそれについての判定部分。
       * ここで特定の種類のエンティティに当たらないようにできる。
       */
      boolean canAttack = false;
      if (entityTarget != null) {
        Entity target = entityTarget.entityHit;

        if (target instanceof EntityPlayer) {
          // プレイヤーに当たった時
          EntityPlayer entityplayer = (EntityPlayer) target;

          if (entityplayer.capabilities.disableDamage
              || this.shootingEntity instanceof EntityPlayer
                  && !((EntityPlayer) this.shootingEntity).canAttackPlayer(entityplayer)) {
            // PvPが許可されていないと当たらない
            canAttack = false;
          } else if (entityplayer == this.shootingEntity) {
            // 対象が撃った本人の場合も当たらない
            canAttack = false;
          } else if (DCsConfig.PvPProhibitionMode && entityplayer instanceof EntityPlayer) {
            canAttack = false;
          }
        } else if (target instanceof EntityTameable || target instanceof EntityHorse) {
          // 事故防止の為、EntityTameable(犬や猫などのペット)、馬にも当たらないようにする
          canAttack = false;
        } else {
          canAttack = true;
        }
      }

      float f2;
      float f3;

      // 当たったあとの処理
      // まずはリストから
      if (canAttack) {
        Entity target = entityTarget.entityHit;

        int i1 = MathHelper.ceiling_double_int(1.0D * this.damage);
        // 0~2程度の乱数値を上乗せ
        i1 += this.rand.nextInt(3);

        DamageSource damagesource = null;

        // 別メソッドでダメージソースを確認
        damagesource = this.thisDamageSource(this.shootingEntity);

        // バニラ矢と同様、このエンティティが燃えているなら対象に着火することも出来る
        if (this.isBurning() && !(target instanceof EntityEnderman)) {
          target.setFire(5);
        } else if (target instanceof IProjectile) {
          // 対象が矢などの飛翔Entityの場合、打ち消すことが出来る
          target.setDead();
        } else {
          // ダメージを与える処理を呼ぶ
          if (target.attackEntityFrom(damagesource, i1)) {
            // ダメージを与えることに成功したら以下の処理を行う
            if (target instanceof EntityLivingBase) {
              EntityLivingBase entitylivingbase = (EntityLivingBase) target;

              // ノックバック
              if (this.knockbackStrength > 0) {
                f3 =
                    MathHelper.sqrt_double(
                        this.motionX * this.motionX + this.motionZ * this.motionZ);

                if (f3 > 0.0F) {
                  // Y方向に大きめに打ち上げる
                  target.addVelocity(
                      this.motionX * this.knockbackStrength * 0.2000000238418579D / f3,
                      0.3D,
                      this.motionZ * this.knockbackStrength * 0.2000000238418579D / f3);
                }
              }

              // 無敵時間はなし
              target.hurtResistantTime = 0;

              // マルチプレイ時に、両者がプレイヤーだった時のパケット送信処理
              if (this.shootingEntity != null
                  && target != this.shootingEntity
                  && target instanceof EntityPlayer
                  && this.shootingEntity instanceof EntityPlayerMP) {
                ((EntityPlayerMP) this.shootingEntity)
                    .playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(6, 0.0F));
              }
            }

            // ここでヒット時の効果音がなる
            this.playSound("random.bowhit", 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));

            // 当たったあと、弾を消去する。エンティティ貫通がONの弾種はそのまま残す。
            explode = true;
          }
        }
      }

      if (movingobjectposition != null) // blockのみ
      {
        this.xTile = movingobjectposition.blockX;
        this.yTile = movingobjectposition.blockY;
        this.zTile = movingobjectposition.blockZ;
        this.inTile = this.worldObj.getBlock(this.xTile, this.yTile, this.zTile);
        this.inData = this.worldObj.getBlockMetadata(this.xTile, this.yTile, this.zTile);
        this.motionX = ((float) (movingobjectposition.hitVec.xCoord - this.posX));
        this.motionY = ((float) (movingobjectposition.hitVec.yCoord - this.posY));
        this.motionZ = ((float) (movingobjectposition.hitVec.zCoord - this.posZ));
        f2 =
            MathHelper.sqrt_double(
                this.motionX * this.motionX
                    + this.motionY * this.motionY
                    + this.motionZ * this.motionZ);
        this.posX -= this.motionX / f2 * 0.05000000074505806D;
        this.posY -= this.motionY / f2 * 0.05000000074505806D;
        this.posZ -= this.motionZ / f2 * 0.05000000074505806D;
        this.playSound("random.bowhit", 1.0F, 1.2F / (this.rand.nextFloat() * 0.2F + 0.9F));
        this.inGround = true;

        if (this.inTile != null) {
          // Block側に衝突を伝える
          this.inTile.onEntityCollidedWithBlock(
              this.worldObj, this.xTile, this.yTile, this.zTile, this);
        }
      }
    }

    // さいごに爆発処理
    int live = (targetEntity != null && targetEntity.isEntityAlive()) ? 10 : 600;

    if (explode || this.livingTimeCount > live) {
      if (this.isExploded() == 0) {
        AMTLogger.debugInfo("explosion");
        this.setExplosion();
        if (!DCsConfig.disableMissileExplosion && !worldObj.isRemote) {
          float f = 5.0F;
          CustomExplosion explosion =
              new CustomExplosion(
                  worldObj,
                  this,
                  shootingEntity,
                  this.posX,
                  this.posY,
                  this.posZ,
                  f,
                  CustomExplosion.Type.Anchor,
                  true);
          explosion.doExplosion();
        }
      }
    }

    // 追尾
    if (active) {
      if (targetEntity != null && targetEntity.isEntityAlive()) {
        double dx = targetEntity.posX - this.posX;
        double dy = targetEntity.boundingBox.minY + (targetEntity.height / 2.0D) - this.posY;
        double dz = targetEntity.posZ - this.posZ;
        double d3 = MathHelper.sqrt_double(dx * dx + dz * dz);

        if (d3 >= 1.0E-7D) {
          float f4 = (float) d3 * 0.2F;
          double dy2 = dy + f4;

          float ff = MathHelper.sqrt_double(dx * dx + dy2 * dy2 + dz * dz);
          dx /= ff;
          dy /= ff;
          dz /= ff;

          this.motionX = (this.motionX + dx) / 2;
          this.motionY = (this.motionY + dy) / 2;
          this.motionZ = (this.motionZ + dz) / 2;

          this.motionX *= 1.25D;
          this.motionY *= 1.25D;
          this.motionZ *= 1.25D;
        }
      }
    }

    // 直前のパラメータと新パラメータを一致させているところ。
    // また、速度に応じてエンティティの向きを調整し、常に進行方向に前面が向くようにしている。
    if (this.prevRotationPitch == 0.0F && this.prevRotationYaw == 0.0F) {
      float f = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
      this.prevRotationYaw =
          this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
      this.prevRotationPitch =
          this.rotationPitch = (float) (Math.atan2(this.motionY, f) * 180.0D / Math.PI);
    }

    // 改めてポジションに速度を加算。向きも更新。
    this.posX += this.motionX;
    this.posY += this.motionY;
    this.posZ += this.motionZ;
    float f2 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
    this.rotationYaw = (float) (Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
    this.rotationPitch = (float) (Math.atan2(this.motionY, f2) * 180.0D / Math.PI);

    while (this.rotationPitch - this.prevRotationPitch < -180.0F) {
      this.prevRotationPitch -= 360.0F;
    }

    while (this.rotationPitch - this.prevRotationPitch >= 180.0F) {
      this.prevRotationPitch += 360.0F;
    }

    while (this.rotationYaw - this.prevRotationYaw < -180.0F) {
      this.prevRotationYaw -= 360.0F;
    }

    while (this.rotationYaw - this.prevRotationYaw >= 180.0F) {
      this.prevRotationYaw += 360.0F;
    }

    this.rotationPitch =
        this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
    this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;

    // 水中に有る
    if (this.isInWater()) {
      // 泡パーティクルが出る
      for (int j1 = 0; j1 < 4; ++j1) {
        float f3 = 0.25F;
        this.worldObj.spawnParticle(
            "bubble",
            this.posX - this.motionX * f3,
            this.posY - this.motionY * f3,
            this.posZ - this.motionZ * f3,
            this.motionX,
            this.motionY,
            this.motionZ);
      }
    }

    this.setPosition(this.posX, this.posY, this.posZ);
    this.func_145775_I();
  }
  /**
   * @author gabizou - April 8th, 2016
   * @reason Rewrites the attackTargetEntityWithCurrentItem to throw an {@link AttackEntityEvent}
   *     prior to the ensuing {@link DamageEntityEvent}. This should cover all cases where players
   *     are attacking entities and those entities override {@link
   *     EntityLivingBase#attackEntityFrom(DamageSource, float)} and effectively bypass our damage
   *     event hooks.
   * @param targetEntity The target entity
   */
  @Overwrite
  public void attackTargetEntityWithCurrentItem(net.minecraft.entity.Entity targetEntity) {
    // Sponge Start - Add SpongeImpl hook to override in forge as necessary
    if (!SpongeImplHooks.checkAttackEntity((EntityPlayer) (Object) this, targetEntity)) {
      return;
    }
    // Sponge End
    if (targetEntity.canAttackWithItem()) {
      if (!targetEntity.hitByEntity((EntityPlayer) (Object) this)) {
        // Sponge Start - Prepare our event values
        // float baseDamage =
        // this.getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue();
        final double originalBaseDamage =
            this.getEntityAttribute(SharedMonsterAttributes.attackDamage).getAttributeValue();
        float baseDamage = (float) originalBaseDamage;
        // Sponge End
        int knockbackModifier = 0;
        float enchantmentModifierAmount = 0.0F;

        // Sponge Start - gather the attack modifiers
        final List<Tuple<DamageModifier, Function<? super Double, Double>>> originalFunctions =
            new ArrayList<>();

        final EnumCreatureAttribute creatureAttribute =
            targetEntity instanceof EntityLivingBase
                ? ((EntityLivingBase) targetEntity).getCreatureAttribute()
                : EnumCreatureAttribute.UNDEFINED;
        final List<Tuple<DamageModifier, Function<? super Double, Double>>>
            enchantmentModifierFunctions =
                DamageEventHandler.createAttackEnchamntmentFunction(
                    this.getHeldItem(), creatureAttribute);
        // if (targetEntity instanceof EntityLivingBase) {
        //     enchantmentModifierAmount =
        // EnchantmentHelper.getModifierForCreature(this.getHeldItem(), creatureAttribute);
        // } else {
        //     enchantmentModifierAmount =
        // EnchantmentHelper.getModifierForCreature(this.getHeldItem(),
        // EnumCreatureAttribute.UNDEFINED);
        // }
        enchantmentModifierAmount =
            (float)
                enchantmentModifierFunctions
                    .stream()
                    .map(Tuple::getSecond)
                    .mapToDouble(function -> function.apply(originalBaseDamage))
                    .sum();
        originalFunctions.addAll(enchantmentModifierFunctions);
        // Sponge End

        knockbackModifier =
            knockbackModifier
                + EnchantmentHelper.getKnockbackModifier((EntityPlayer) (Object) this);

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

        if (baseDamage > 0.0F || enchantmentModifierAmount > 0.0F) {
          boolean fallingCriticalHit =
              this.fallDistance > 0.0F
                  && !this.onGround
                  && !this.isOnLadder()
                  && !this.isInWater()
                  && !this.isPotionActive(Potion.blindness)
                  && this.ridingEntity == null
                  && targetEntity instanceof EntityLivingBase;

          if (fallingCriticalHit && baseDamage > 0.0F) {
            // Sponge - Add the function for critical attacking
            originalFunctions.add(
                DamageEventHandler.provideCriticalAttackTuple((EntityPlayer) (Object) this));
            // baseDamage *= 1.5F; Sponge - remove since it's handled in the event
          }

          // baseDamage = baseDamage + enchantmentModifierAmount; // Sponge - remove since it is
          // delegated through the event.
          boolean targetLitOnFire = false;
          int fireAspectLevel =
              EnchantmentHelper.getFireAspectModifier((EntityPlayer) (Object) this);

          if (targetEntity instanceof EntityLivingBase
              && fireAspectLevel > 0
              && !targetEntity.isBurning()) {
            targetLitOnFire = true;
            targetEntity.setFire(1);
          }

          double targetMotionX = targetEntity.motionX;
          double targetMotionY = targetEntity.motionY;
          double targetMotionZ = targetEntity.motionZ;

          // Sponge Start - Create the event and throw it
          final DamageSource damageSource =
              DamageSource.causePlayerDamage((EntityPlayer) (Object) this);
          final AttackEntityEvent event =
              SpongeEventFactory.createAttackEntityEvent(
                  Cause.source(damageSource).build(),
                  originalFunctions,
                  EntityUtil.fromNative(targetEntity),
                  knockbackModifier,
                  originalBaseDamage);
          SpongeImpl.postEvent(event);
          if (event.isCancelled()) {
            if (targetLitOnFire) {
              targetEntity.extinguish();
            }
            return;
          }
          baseDamage = (float) event.getFinalOutputDamage();
          knockbackModifier = event.getKnockbackModifier();
          boolean attackSucceded =
              targetEntity.attackEntityFrom(damageSource, (float) event.getFinalOutputDamage());
          // Sponge End
          if (attackSucceded) {
            if (knockbackModifier > 0) {
              targetEntity.addVelocity(
                  (double)
                      (-MathHelper.sin(this.rotationYaw * (float) Math.PI / 180.0F)
                          * (float) knockbackModifier
                          * 0.5F),
                  0.1D,
                  (double)
                      (MathHelper.cos(this.rotationYaw * (float) Math.PI / 180.0F)
                          * (float) knockbackModifier
                          * 0.5F));
              this.motionX *= 0.6D;
              this.motionZ *= 0.6D;
              this.setSprinting(false);
            }

            if (targetEntity instanceof EntityPlayerMP && targetEntity.velocityChanged) {
              ((EntityPlayerMP) targetEntity)
                  .playerNetServerHandler.sendPacket(new S12PacketEntityVelocity(targetEntity));
              targetEntity.velocityChanged = false;
              targetEntity.motionX = targetMotionX;
              targetEntity.motionY = targetMotionY;
              targetEntity.motionZ = targetMotionZ;
            }

            if (fallingCriticalHit) {
              this.onCriticalHit(targetEntity);
            }

            if (enchantmentModifierAmount > 0.0F) {
              this.onEnchantmentCritical(targetEntity);
            }

            if (baseDamage >= 18.0F) {
              this.triggerAchievement(AchievementList.overkill);
            }

            this.setLastAttacker(targetEntity);

            if (targetEntity instanceof EntityLivingBase) {
              EnchantmentHelper.applyThornEnchantments(
                  (EntityLivingBase) targetEntity, (EntityPlayer) (Object) this);
            }

            EnchantmentHelper.applyArthropodEnchantments(
                (EntityPlayer) (Object) this, targetEntity);
            ItemStack itemstack = this.getCurrentEquippedItem();
            net.minecraft.entity.Entity entity = targetEntity;

            if (targetEntity instanceof EntityDragonPart) {
              IEntityMultiPart ientitymultipart = ((EntityDragonPart) targetEntity).entityDragonObj;

              if (ientitymultipart instanceof EntityLivingBase) {
                entity = (EntityLivingBase) ientitymultipart;
              }
            }

            if (itemstack != null && entity instanceof EntityLivingBase) {
              itemstack.hitEntity((EntityLivingBase) entity, (EntityPlayer) (Object) this);

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

            if (targetEntity instanceof EntityLivingBase) {
              this.addStat(StatList.damageDealtStat, Math.round(baseDamage * 10.0F));

              if (fireAspectLevel > 0) {
                targetEntity.setFire(fireAspectLevel * 4);
              }
            }

            this.addExhaustion(0.3F);
          } else if (targetLitOnFire) {
            targetEntity.extinguish();
          }
        }
      }
    }
  }
  @SubscribeEvent
  public void onAttackEntity(AttackEntityEvent event) {
    if (event.entityLiving.worldObj.isRemote) return;

    EntityLivingBase attacker = event.entityLiving;
    EntityPlayer player = event.entityPlayer;
    Entity target = event.target;
    ItemStack stack = attacker.getEquipmentInSlot(0);
    if (stack != null && stack.getItem().onLeftClickEntity(stack, player, target)) return;

    if (target.canAttackWithItem()) {
      if (!target.hitByEntity(target)) {
        float damageAmount = TFC_MobData.STEVE_DAMAGE;
        if (stack != null) {
          damageAmount =
              (float)
                  player
                      .getEntityAttribute(SharedMonsterAttributes.attackDamage)
                      .getAttributeValue();
          // player.addChatMessage("Damage: " + i);
          if (damageAmount == 1.0f) {
            damageAmount = TFC_MobData.STEVE_DAMAGE;
            // i = player.inventory.getCurrentItem().getItem().getDamageVsEntity(target,
            // player.inventory.getCurrentItem());
          }
        }

        if (player.isPotionActive(Potion.damageBoost))
          damageAmount += 3 << player.getActivePotionEffect(Potion.damageBoost).getAmplifier();

        if (player.isPotionActive(Potion.weakness))
          damageAmount -= 2 << player.getActivePotionEffect(Potion.weakness).getAmplifier();

        int knockback = 0;
        float enchantmentDamage = 0;

        if (target instanceof EntityLiving) {
          enchantmentDamage =
              EnchantmentHelper.getEnchantmentModifierLiving(player, (EntityLiving) target);
          knockback += EnchantmentHelper.getKnockbackModifier(player, (EntityLiving) target);
        }

        if (player.isSprinting()) ++knockback;

        if (damageAmount > 0 || enchantmentDamage > 0) {
          boolean criticalHit =
              player.fallDistance > 0.0F
                  && !player.onGround
                  && !player.isOnLadder()
                  && !player.isInWater()
                  && !player.isPotionActive(Potion.blindness)
                  && player.ridingEntity == null
                  && target instanceof EntityLiving;

          if (criticalHit && damageAmount > 0)
            damageAmount += event.entity.worldObj.rand.nextInt((int) (damageAmount / 2 + 2));

          damageAmount += enchantmentDamage;
          boolean onFire = false;
          int fireAspect = EnchantmentHelper.getFireAspectModifier(player);

          if (target instanceof EntityLiving && fireAspect > 0 && !target.isBurning()) {
            onFire = true;
            target.setFire(1);
          }

          boolean entityAttacked =
              target.attackEntityFrom(DamageSource.causePlayerDamage(player), damageAmount);

          if (entityAttacked) {
            if (knockback > 0) {
              target.addVelocity(
                  -MathHelper.sin(player.rotationYaw * (float) Math.PI / 180.0F) * knockback * 0.5F,
                  0.1D,
                  MathHelper.cos(player.rotationYaw * (float) Math.PI / 180.0F) * knockback * 0.5F);
              player.motionX *= 0.6D;
              player.motionZ *= 0.6D;
              player.setSprinting(false);
            }

            if (criticalHit) player.onCriticalHit(target);

            if (enchantmentDamage > 0) player.onEnchantmentCritical(target);

            if (damageAmount >= 18) player.triggerAchievement(AchievementList.overkill);

            player.setLastAttacker(target);

            if (target instanceof EntityLiving)
              target.attackEntityFrom(DamageSource.causeThornsDamage(attacker), damageAmount);
          }

          ItemStack itemstack = player.getCurrentEquippedItem();
          Object object = target;

          if (target instanceof EntityDragonPart) {
            IEntityMultiPart ientitymultipart = ((EntityDragonPart) target).entityDragonObj;
            if (ientitymultipart instanceof EntityLiving) object = ientitymultipart;
          }

          if (itemstack != null && object instanceof EntityLiving) {
            itemstack.hitEntity((EntityLiving) object, player);
            if (itemstack.stackSize <= 0) player.destroyCurrentEquippedItem();
          }

          if (target instanceof EntityLivingBase) {
            player.addStat(StatList.damageDealtStat, Math.round(damageAmount * 10.0f));
            if (fireAspect > 0 && entityAttacked) target.setFire(fireAspect * 4);
            else if (onFire) target.extinguish();
          }

          player.addExhaustion(0.3F);
        }
      }
    }
    event.setCanceled(true);
  }
Esempio n. 15
0
  @Override
  public boolean onLeftClickEntity(ItemStack stack, EntityPlayer player, Entity entity) {
    if (entity.canAttackWithItem()) {
      if (!entity.hitByEntity(player)) {
        float damage = (float) getAttackDamage(stack);
        int i = 0;
        float extraDamage = 0.0F;
        if (entity instanceof EntityLivingBase) {
          extraDamage =
              EnchantmentHelper.getEnchantmentModifierLiving(player, (EntityLivingBase) entity);
          i += EnchantmentHelper.getKnockbackModifier(player, (EntityLivingBase) entity);
        }
        if (player.isSprinting()) {
          i++;
        }
        if (damage > 0.0F || extraDamage > 0.0F) {
          boolean criricalHit =
              player.fallDistance > 0.0F
                  && !player.onGround
                  && !player.isOnLadder()
                  && !player.isInWater()
                  && !player.isPotionActive(Potion.blindness)
                  && player.ridingEntity == null
                  && entity instanceof EntityLivingBase;
          if (criricalHit && damage > 0.0F) {
            damage *= 1.5F;
          }
          damage += extraDamage;
          boolean fire = false;
          int j = EnchantmentHelper.getFireAspectModifier(player);
          if (entity instanceof EntityLivingBase && j > 0 && !entity.isBurning()) {
            fire = true;
            entity.setFire(1);
          }
          boolean attack = entity.attackEntityFrom(DamageSource.causePlayerDamage(player), damage);
          if (attack) {
            if (i > 0) {
              entity.addVelocity(
                  (double)
                      (-MathHelper.sin(player.rotationYaw * (float) Math.PI / 180.0F)
                          * (float) i
                          * 0.5F),
                  0.1D,
                  (double)
                      (MathHelper.cos(player.rotationYaw * (float) Math.PI / 180.0F)
                          * (float) i
                          * 0.5F));
              player.motionX *= 0.6D;
              player.motionZ *= 0.6D;
              player.setSprinting(false);
            }
            if (criricalHit) {
              player.onCriticalHit(entity);
            }
            if (extraDamage > 0.0F) {
              player.onEnchantmentCritical(entity);
            }
            if (damage >= 18.0F) {
              player.triggerAchievement(AchievementList.overkill);
            }
            player.setLastAttacker(entity);
            if (entity instanceof EntityLivingBase) {
              EnchantmentHelper.func_151384_a((EntityLivingBase) entity, player);
            }
          }

          ItemStack itemstack = player.getCurrentEquippedItem();
          Object object = entity;

          if (entity instanceof EntityDragonPart) {
            IEntityMultiPart entityMultipart = ((EntityDragonPart) entity).entityDragonObj;
            if (entityMultipart != null && entityMultipart instanceof EntityLivingBase) {
              object = (EntityLivingBase) entityMultipart;
            }
          }
          if (itemstack != null && object instanceof EntityLivingBase) {
            itemstack.hitEntity((EntityLivingBase) object, player);
            if (itemstack.stackSize <= 0) {
              player.destroyCurrentEquippedItem();
            }
          }
          if (entity instanceof EntityLivingBase) {
            player.addStat(StatList.damageDealtStat, Math.round(damage * 10.0F));
            if (j > 0 && attack) {
              entity.setFire(j * 4);
            } else if (fire) {
              entity.extinguish();
            }
          }
          player.addExhaustion(0.3F);
        }
      }
    }
    return true;
  }
 @Override
 public boolean onHitEntity(Entity entityHit, DamageSource source, float ammount) {
   source.setFireDamage();
   entityHit.setFire(3);
   return false;
 }
Esempio n. 17
0
 public void scorch(World world, int x, int y, int z, int metadata) {
   boolean blocked = false;
   int step;
   if (power > MINPOWER) { // 524+ kW (real military laser)
     int maxdist = this.getRange();
     for (step = 1;
         step < maxdist && (step < this.getMaxRange() || this.getMaxRange() == -1) && !blocked;
         step++) {
       int id = world.getBlockId(x + step * xstep, y + step * ystep, z + step * zstep);
       if (id != 0
           && Block.blocksList[id].isFlammable(
               world,
               x + step * xstep,
               y + step * ystep,
               z + step * zstep,
               world.getBlockMetadata(x + step * xstep, y + step * ystep, z + step * zstep),
               ForgeDirection.UP))
         this.ignite(world, x + step * xstep, y + step * ystep, z + step * zstep, metadata, step);
       if (this.makeBeam(
           world,
           x,
           y,
           z,
           metadata,
           step,
           world.getBlockId(x + step * xstep, y + step * ystep, z + step * zstep),
           maxdist)) {
         blocked = true;
         tickcount = 0;
       }
       if (Block.opaqueCubeLookup[
           world.getBlockId(x + step * xstep, y + step * ystep, z + step * zstep)])
         blocked = true; // break loop
       /*if (world.getBlockId(x+step*xstep, y+step*ystep, z+step*zstep) == 0)
       ReikaWorldHelper.legacySetBlockWithNotify(world, x+step*xstep, y+step*ystep, z+step*zstep, 4);*/
       // ModLoader.getMinecraftInstance().ingameGUI.addChatMessage(String.format("%d %d ", step,
       // world.getBlockId(x+step*xstep, y+step*ystep, z+step*zstep))+String.valueOf(blocked));
       world.markBlockForUpdate(x + xstep * step, y + ystep * step, z + zstep * step);
     }
     // ModLoader.getMinecraftInstance().ingameGUI.addChatMessage(String.format("%d %d ", step,
     // world.getBlockId(x+step*xstep, y+step*ystep, z+step*zstep))+String.valueOf(blocked));
     AxisAlignedBB zone = this.getBurnZone(metadata, step);
     List inzone = worldObj.getEntitiesWithinAABB(Entity.class, zone);
     // ModLoader.getMinecraftInstance().ingameGUI.addChatMessage(String.format("%d",
     // inzone.size()));
     for (int i = 0; i < inzone.size(); i++) {
       if (inzone.get(i) instanceof Entity) {
         Entity caught = (Entity) inzone.get(i);
         if (!(caught instanceof EntityItem)) // Do not burn drops
         caught.setFire(
               this.getBurnTime()); // 1 Hearts worth of fire at min power, +1 heart for every 65kW
         // extra
         if (caught instanceof EntityTNTPrimed)
           world.spawnParticle(
               "lava",
               caught.posX + rand.nextFloat(),
               caught.posY + rand.nextFloat(),
               caught.posZ + rand.nextFloat(),
               0,
               0,
               0);
       }
     }
   }
 }