Example #1
0
  public float a(Block block) {
    float f = this.inventory.a(block);
    float f1 = f;
    int i = EnchantmentManager.getDigSpeedEnchantmentLevel(this.inventory);

    if (i > 0 && this.inventory.b(block)) {
      f1 = f + (float) (i * i + 1);
    }

    if (this.hasEffect(MobEffectList.FASTER_DIG)) {
      f1 *= 1.0F + (float) (this.getEffect(MobEffectList.FASTER_DIG).getAmplifier() + 1) * 0.2F;
    }

    if (this.hasEffect(MobEffectList.SLOWER_DIG)) {
      f1 *= 1.0F - (float) (this.getEffect(MobEffectList.SLOWER_DIG).getAmplifier() + 1) * 0.2F;
    }

    if (this.a(Material.WATER) && !EnchantmentManager.hasWaterWorkerEnchantment(this.inventory)) {
      f1 /= 5.0F;
    }

    if (!this.onGround) {
      f1 /= 5.0F;
    }

    return f1;
  }
Example #2
0
  protected void a(EntityLiving entityliving, Entity entity) {
    if (entity instanceof EntityLiving) {
      EnchantmentManager.a((EntityLiving) entity, (Entity) entityliving);
    }

    EnchantmentManager.b(entityliving, entity);
  }
Example #3
0
  public void die(DamageSource damagesource) {
    Entity entity = damagesource.getEntity();
    EntityLiving entityliving = this.aX();

    if (this.bb >= 0 && entityliving != null) {
      entityliving.b(this, this.bb);
    }

    if (entity != null) {
      entity.a(this);
    }

    this.aU = true;
    if (!this.world.isStatic) {
      int i = 0;

      if (entity instanceof EntityHuman) {
        i = EnchantmentManager.getBonusMonsterLootEnchantmentLevel((EntityLiving) entity);
      }

      if (this.aG() && this.world.getGameRules().getBoolean("doMobLoot")) {
        this.dropDeathLoot(this.lastDamageByPlayerTime > 0, i);
        this.dropEquipment(this.lastDamageByPlayerTime > 0, i);
        if (this.lastDamageByPlayerTime > 0) {
          int j = this.random.nextInt(200) - i;

          if (j < 5) {
            this.getRareDrop(j <= 0 ? 1 : 0);
          }
        }
      }
    }

    this.world.broadcastEntityEffect(this, (byte) 3);
  }
Example #4
0
  protected float c(DamageSource damagesource, float f) {
    if (this instanceof EntityZombie) {
      f = f;
    }

    int i;
    int j;
    float f1;

    if (this.hasEffect(MobEffectList.RESISTANCE) && damagesource != DamageSource.OUT_OF_WORLD) {
      i = (this.getEffect(MobEffectList.RESISTANCE).getAmplifier() + 1) * 5;
      j = 25 - i;
      f1 = f * (float) j;
      f = f1 / 25.0F;
    }

    if (f <= 0.0F) {
      return 0.0F;
    } else {
      i = EnchantmentManager.a(this.getEquipment(), damagesource);
      if (i > 20) {
        i = 20;
      }

      if (i > 0 && i <= 20) {
        j = 25 - i;
        f1 = f * (float) j;
        f = f1 / 25.0F;
      }

      return f;
    }
  }
Example #5
0
  public void a(World world, EntityHuman entityhuman, int i, int j, int k, int l) {
    entityhuman.a(StatisticList.C[this.id], 1);
    entityhuman.c(0.025F);
    if (this.b()
        && !isTileEntity[this.id]
        && EnchantmentManager.hasSilkTouchEnchantment(entityhuman.inventory)) {
      ItemStack itemstack = this.a_(l);

      if (itemstack != null) {
        this.a(world, i, j, k, itemstack);
      }
    } else {
      int i1 = EnchantmentManager.getBonusBlockLootEnchantmentLevel(entityhuman.inventory);

      this.b(world, i, j, k, l, i1);
    }
  }
  public boolean m(Entity entity) {
    int i = this.c(entity);

    if (this.hasEffect(MobEffectList.INCREASE_DAMAGE)) {
      i += 3 << this.getEffect(MobEffectList.INCREASE_DAMAGE).getAmplifier();
    }

    if (this.hasEffect(MobEffectList.WEAKNESS)) {
      i -= 2 << this.getEffect(MobEffectList.WEAKNESS).getAmplifier();
    }

    int j = 0;

    if (entity instanceof EntityLiving) {
      i += EnchantmentManager.a((EntityLiving) this, (EntityLiving) entity);
      j += EnchantmentManager.getKnockbackEnchantmentLevel(this, (EntityLiving) entity);
    }

    boolean flag = entity.damageEntity(DamageSource.mobAttack(this), i);

    if (flag) {
      if (j > 0) {
        entity.g(
            (double) (-MathHelper.sin(this.yaw * 3.1415927F / 180.0F) * (float) j * 0.5F),
            0.1D,
            (double) (MathHelper.cos(this.yaw * 3.1415927F / 180.0F) * (float) j * 0.5F));
        this.motX *= 0.6D;
        this.motZ *= 0.6D;
      }

      int k = EnchantmentManager.getFireAspectEnchantmentLevel(this);

      if (k > 0) {
        entity.setOnFire(k * 4);
      }
    }

    return flag;
  }
Example #7
0
  protected ItemStack l(int i) {
    if (i > 0) {
      ItemStack itemstack = new ItemStack(Item.GOLD_SWORD);

      EnchantmentManager.a(this.random, itemstack, 5);
      return itemstack;
    }
    int j = this.random.nextInt(3);

    if (j == 0) return new ItemStack(Item.GOLD_INGOT.id, 1, 0);
    if (j == 1) return new ItemStack(Item.GOLD_SWORD.id, 1, 0);
    if (j == 2) {
      return new ItemStack(Item.GOLD_HELMET.id, 1, 0);
    }
    return null;
  }
Example #8
0
  public void die(DamageSource damagesource) {
    Entity entity = damagesource.getEntity();
    EntityLiving entityliving = this.aS();

    if (this.bb >= 0 && entityliving != null) {
      entityliving.b(this, this.bb);
    }

    if (entity != null) {
      entity.a(this);
    }

    this.aU = true;
    if (!this.world.isStatic) {
      int i = 0;

      if (entity instanceof EntityHuman) {
        i = EnchantmentManager.getBonusMonsterLootEnchantmentLevel((EntityLiving) entity);
      }

      if (!this.isBaby() && this.world.getGameRules().getBoolean("doMobLoot")) {
        this.dropDeathLoot(this.lastDamageByPlayerTime > 0, i);
        this.dropEquipment(this.lastDamageByPlayerTime > 0, i);
        if (false
            && this.lastDamageByPlayerTime
                > 0) { // CraftBukkit - move rare item drop call to dropDeathLoot
          int j = this.random.nextInt(200) - i;

          if (j < 5) {
            this.l(j <= 0 ? 1 : 0);
          }
        }
      } else { // CraftBukkit
        CraftEventFactory.callEntityDeathEvent(this); // CraftBukkit
      }
    }

    this.world.broadcastEntityEffect(this, (byte) 3);
  }
Example #9
0
  protected int b(DamageSource damagesource, int i) {
    int j = super.b(damagesource, i);

    if (j <= 0) {
      return 0;
    } else {
      int k = EnchantmentManager.a(this.inventory, damagesource);

      if (k > 20) {
        k = 20;
      }

      if (k > 0 && k <= 20) {
        int l = 25 - k;
        int i1 = j * l + this.ar;

        j = i1 / 25;
        this.ar = i1 % 25;
      }

      return j;
    }
  }
Example #10
0
  public boolean isDamaged(int i, Random random) {
    if (!this.g()) {
      return false;
    } else {
      if (i > 0) {
        int j = EnchantmentManager.getEnchantmentLevel(Enchantment.DURABILITY.id, this);
        int k = 0;

        for (int l = 0; j > 0 && l < i; ++l) {
          if (EnchantmentDurability.a(this, j, random)) {
            ++k;
          }
        }

        i -= k;
        if (i <= 0) {
          return false;
        }
      }

      this.damage += i;
      return this.damage > this.l();
    }
  }
Example #11
0
  protected int h(int i) {
    int j = EnchantmentManager.getOxygenEnchantmentLevel(this);

    return j > 0 && this.random.nextInt(j + 1) > 0 ? i : i - 1;
  }
Example #12
0
  public void h() {
    super.h();
    if (this.lastPitch == 0.0F && this.lastYaw == 0.0F) {
      float f = MathHelper.sqrt(this.motX * this.motX + this.motZ * this.motZ);

      this.lastYaw =
          this.yaw = (float) (Math.atan2(this.motX, this.motZ) * 180.0D / 3.1415927410125732D);
      this.lastPitch =
          this.pitch = (float) (Math.atan2(this.motY, (double) f) * 180.0D / 3.1415927410125732D);
    }

    Block block = this.world.getType(this.d, this.e, this.f);

    if (block.getMaterial() != Material.AIR) {
      block.updateShape(this.world, this.d, this.e, this.f);
      AxisAlignedBB axisalignedbb = block.a(this.world, this.d, this.e, this.f);

      if (axisalignedbb != null && axisalignedbb.a(Vec3D.a(this.locX, this.locY, this.locZ))) {
        this.inGround = true;
      }
    }

    if (this.shake > 0) {
      --this.shake;
    }

    if (this.inGround) {
      int i = this.world.getData(this.d, this.e, this.f);

      if (block == this.g && i == this.h) {
        ++this.at;
        if (this.at == 1200) {
          this.die();
        }
      } else {
        this.inGround = false;
        this.motX *= (double) (this.random.nextFloat() * 0.2F);
        this.motY *= (double) (this.random.nextFloat() * 0.2F);
        this.motZ *= (double) (this.random.nextFloat() * 0.2F);
        this.at = 0;
        this.au = 0;
      }
    } else {
      ++this.au;
      Vec3D vec3d = Vec3D.a(this.locX, this.locY, this.locZ);
      Vec3D vec3d1 = Vec3D.a(this.locX + this.motX, this.locY + this.motY, this.locZ + this.motZ);
      MovingObjectPosition movingobjectposition =
          this.world.rayTrace(vec3d, vec3d1, false, true, false);

      vec3d = Vec3D.a(this.locX, this.locY, this.locZ);
      vec3d1 = Vec3D.a(this.locX + this.motX, this.locY + this.motY, this.locZ + this.motZ);
      if (movingobjectposition != null) {
        vec3d1 =
            Vec3D.a(
                movingobjectposition.pos.a, movingobjectposition.pos.b, movingobjectposition.pos.c);
      }

      Entity entity = null;
      List list =
          this.world.getEntities(
              this, this.boundingBox.a(this.motX, this.motY, this.motZ).grow(1.0D, 1.0D, 1.0D));
      double d0 = 0.0D;

      int j;
      float f1;

      for (j = 0; j < list.size(); ++j) {
        Entity entity1 = (Entity) list.get(j);

        if (entity1.Q() && (entity1 != this.shooter || this.au >= 5)) {
          f1 = 0.3F;
          AxisAlignedBB axisalignedbb1 =
              entity1.boundingBox.grow((double) f1, (double) f1, (double) f1);
          MovingObjectPosition movingobjectposition1 = axisalignedbb1.a(vec3d, vec3d1);

          if (movingobjectposition1 != null) {
            double d1 =
                vec3d.distanceSquared(
                    movingobjectposition1.pos); // CraftBukkit - distance efficiency

            if (d1 < d0 || d0 == 0.0D) {
              entity = entity1;
              d0 = d1;
            }
          }
        }
      }

      if (entity != null) {
        movingobjectposition = new MovingObjectPosition(entity);
      }

      if (movingobjectposition != null
          && movingobjectposition.entity != null
          && movingobjectposition.entity instanceof EntityHuman) {
        EntityHuman entityhuman = (EntityHuman) movingobjectposition.entity;

        if (entityhuman.abilities.isInvulnerable
            || this.shooter instanceof EntityHuman
                && !((EntityHuman) this.shooter).a(entityhuman)) {
          movingobjectposition = null;
        }
      }

      float f2;
      float f3;

      if (movingobjectposition != null) {
        org.bukkit.craftbukkit.event.CraftEventFactory.callProjectileHitEvent(
            this); // CraftBukkit - Call event

        if (movingobjectposition.entity != null) {
          f2 =
              MathHelper.sqrt(
                  this.motX * this.motX + this.motY * this.motY + this.motZ * this.motZ);
          int k = MathHelper.f((double) f2 * this.damage);

          if (this.isCritical()) {
            k += this.random.nextInt(k / 2 + 2);
          }

          DamageSource damagesource = null;

          if (this.shooter == null) {
            damagesource = DamageSource.arrow(this, this);
          } else {
            damagesource = DamageSource.arrow(this, this.shooter);
          }

          // CraftBukkit start - Moved damage call
          if (movingobjectposition.entity.damageEntity(damagesource, k)) {
            if (this.isBurning()
                && !(movingobjectposition.entity instanceof EntityEnderman)
                && (!(movingobjectposition.entity instanceof EntityPlayer)
                    || !(this.shooter instanceof EntityPlayer)
                    || this.world
                        .pvpMode)) { // CraftBukkit - abide by pvp setting if destination is a
                                     // player
              EntityCombustByEntityEvent combustEvent =
                  new EntityCombustByEntityEvent(
                      this.getBukkitEntity(), entity.getBukkitEntity(), 5);
              org.bukkit.Bukkit.getPluginManager().callEvent(combustEvent);

              if (!combustEvent.isCancelled()) {
                movingobjectposition.entity.setOnFire(combustEvent.getDuration());
              }
              // CraftBukkit end
            }

            // if (movingobjectposition.entity.damageEntity(damagesource, (float) k)) { //
            // CraftBukkit - moved up
            if (movingobjectposition.entity instanceof EntityLiving) {
              EntityLiving entityliving = (EntityLiving) movingobjectposition.entity;

              if (!this.world.isStatic) {
                entityliving.p(entityliving.aY() + 1);
              }

              if (this.knockbackStrength > 0) {
                f3 = MathHelper.sqrt(this.motX * this.motX + this.motZ * this.motZ);
                if (f3 > 0.0F) {
                  movingobjectposition.entity.g(
                      this.motX
                          * (double) this.knockbackStrength
                          * 0.6000000238418579D
                          / (double) f3,
                      0.1D,
                      this.motZ
                          * (double) this.knockbackStrength
                          * 0.6000000238418579D
                          / (double) f3);
                }
              }

              if (this.shooter != null && this.shooter instanceof EntityLiving) {
                EnchantmentManager.a(entityliving, this.shooter);
                EnchantmentManager.b((EntityLiving) this.shooter, entityliving);
              }

              if (this.shooter != null
                  && movingobjectposition.entity != this.shooter
                  && movingobjectposition.entity instanceof EntityHuman
                  && this.shooter instanceof EntityPlayer) {
                ((EntityPlayer) this.shooter)
                    .playerConnection.sendPacket(new PacketPlayOutGameStateChange(6, 0.0F));
              }
            }

            this.makeSound("random.bowhit", 1.0F, 1.2F / (this.random.nextFloat() * 0.2F + 0.9F));
            if (!(movingobjectposition.entity instanceof EntityEnderman)) {
              this.die();
            }
          } else {
            this.motX *= -0.10000000149011612D;
            this.motY *= -0.10000000149011612D;
            this.motZ *= -0.10000000149011612D;
            this.yaw += 180.0F;
            this.lastYaw += 180.0F;
            this.au = 0;
          }
        } else {
          this.d = movingobjectposition.b;
          this.e = movingobjectposition.c;
          this.f = movingobjectposition.d;
          this.g = this.world.getType(d, e, f); // CraftBukkit - Get correct block for storage
          this.h = this.world.getData(this.d, this.e, this.f);
          this.motX = (double) ((float) (movingobjectposition.pos.a - this.locX));
          this.motY = (double) ((float) (movingobjectposition.pos.b - this.locY));
          this.motZ = (double) ((float) (movingobjectposition.pos.c - this.locZ));
          f2 =
              MathHelper.sqrt(
                  this.motX * this.motX + this.motY * this.motY + this.motZ * this.motZ);
          this.locX -= this.motX / (double) f2 * 0.05000000074505806D;
          this.locY -= this.motY / (double) f2 * 0.05000000074505806D;
          this.locZ -= this.motZ / (double) f2 * 0.05000000074505806D;
          this.makeSound("random.bowhit", 1.0F, 1.2F / (this.random.nextFloat() * 0.2F + 0.9F));
          this.inGround = true;
          this.shake = 7;
          this.setCritical(false);
          if (this.g.getMaterial() != Material.AIR) {
            this.g.a(this.world, this.d, this.e, this.f, (Entity) this);
          }
        }
      }

      if (this.isCritical()) {
        for (j = 0; j < 4; ++j) {
          this.world.addParticle(
              "crit",
              this.locX + this.motX * (double) j / 4.0D,
              this.locY + this.motY * (double) j / 4.0D,
              this.locZ + this.motZ * (double) j / 4.0D,
              -this.motX,
              -this.motY + 0.2D,
              -this.motZ);
        }
      }

      this.locX += this.motX;
      this.locY += this.motY;
      this.locZ += this.motZ;
      f2 = MathHelper.sqrt(this.motX * this.motX + this.motZ * this.motZ);
      this.yaw = (float) (Math.atan2(this.motX, this.motZ) * 180.0D / 3.1415927410125732D);

      for (this.pitch = (float) (Math.atan2(this.motY, (double) f2) * 180.0D / 3.1415927410125732D);
          this.pitch - this.lastPitch < -180.0F;
          this.lastPitch -= 360.0F) {;
      }

      while (this.pitch - this.lastPitch >= 180.0F) {
        this.lastPitch += 360.0F;
      }

      while (this.yaw - this.lastYaw < -180.0F) {
        this.lastYaw -= 360.0F;
      }

      while (this.yaw - this.lastYaw >= 180.0F) {
        this.lastYaw += 360.0F;
      }

      this.pitch = this.lastPitch + (this.pitch - this.lastPitch) * 0.2F;
      this.yaw = this.lastYaw + (this.yaw - this.lastYaw) * 0.2F;
      float f4 = 0.99F;

      f1 = 0.05F;
      if (this.L()) {
        for (int l = 0; l < 4; ++l) {
          f3 = 0.25F;
          this.world.addParticle(
              "bubble",
              this.locX - this.motX * (double) f3,
              this.locY - this.motY * (double) f3,
              this.locZ - this.motZ * (double) f3,
              this.motX,
              this.motY,
              this.motZ);
        }

        f4 = 0.8F;
      }

      if (this.K()) {
        this.extinguish();
      }

      this.motX *= (double) f4;
      this.motY *= (double) f4;
      this.motZ *= (double) f4;
      this.motY -= (double) f1;
      this.setPosition(this.locX, this.locY, this.locZ);
      this.H();
    }
  }
Example #13
0
  public void e() {
    ItemStack itemstack = this.g.getItem(0);

    this.a = 0;
    int i = 0;
    byte b0 = 0;
    int j = 0;

    if (itemstack == null) {
      this.f.setItem(0, (ItemStack) null);
      this.a = 0;
    } else {
      ItemStack itemstack1 = itemstack.cloneItemStack();
      ItemStack itemstack2 = this.g.getItem(1);
      Map map = EnchantmentManager.a(itemstack1);
      boolean flag = false;
      int k =
          b0 + itemstack.getRepairCost() + (itemstack2 == null ? 0 : itemstack2.getRepairCost());

      this.l = 0;
      int l;
      int i1;
      int j1;
      int k1;
      int l1;
      Iterator iterator;
      Enchantment enchantment;

      if (itemstack2 != null) {
        flag =
            itemstack2.id == Item.ENCHANTED_BOOK.id && Item.ENCHANTED_BOOK.g(itemstack2).size() > 0;
        if (itemstack1.g() && Item.byId[itemstack1.id].a(itemstack, itemstack2)) {
          l = Math.min(itemstack1.j(), itemstack1.l() / 4);
          if (l <= 0) {
            this.f.setItem(0, (ItemStack) null);
            this.a = 0;
            return;
          }

          for (i1 = 0; l > 0 && i1 < itemstack2.count; ++i1) {
            j1 = itemstack1.j() - l;
            itemstack1.setData(j1);
            i += Math.max(1, l / 100) + map.size();
            l = Math.min(itemstack1.j(), itemstack1.l() / 4);
          }

          this.l = i1;
        } else {
          if (!flag && (itemstack1.id != itemstack2.id || !itemstack1.g())) {
            this.f.setItem(0, (ItemStack) null);
            this.a = 0;
            return;
          }

          if (itemstack1.g() && !flag) {
            l = itemstack.l() - itemstack.j();
            i1 = itemstack2.l() - itemstack2.j();
            j1 = i1 + itemstack1.l() * 12 / 100;
            int i2 = l + j1;

            k1 = itemstack1.l() - i2;
            if (k1 < 0) {
              k1 = 0;
            }

            if (k1 < itemstack1.getData()) {
              itemstack1.setData(k1);
              i += Math.max(1, j1 / 100);
            }
          }

          Map map1 = EnchantmentManager.a(itemstack2);

          iterator = map1.keySet().iterator();

          while (iterator.hasNext()) {
            j1 = ((Integer) iterator.next()).intValue();
            enchantment = Enchantment.byId[j1];
            k1 =
                map.containsKey(Integer.valueOf(j1))
                    ? ((Integer) map.get(Integer.valueOf(j1))).intValue()
                    : 0;
            l1 = ((Integer) map1.get(Integer.valueOf(j1))).intValue();
            int j2;

            if (k1 == l1) {
              ++l1;
              j2 = l1;
            } else {
              j2 = Math.max(l1, k1);
            }

            l1 = j2;
            int k2 = l1 - k1;
            boolean flag1 = enchantment.canEnchant(itemstack);

            if (this.n.abilities.canInstantlyBuild
                || itemstack.id == ItemEnchantedBook.ENCHANTED_BOOK.id) {
              flag1 = true;
            }

            Iterator iterator1 = map.keySet().iterator();

            while (iterator1.hasNext()) {
              int l2 = ((Integer) iterator1.next()).intValue();

              if (l2 != j1 && !enchantment.a(Enchantment.byId[l2])) {
                flag1 = false;
                i += k2;
              }
            }

            if (flag1) {
              if (l1 > enchantment.getMaxLevel()) {
                l1 = enchantment.getMaxLevel();
              }

              map.put(Integer.valueOf(j1), Integer.valueOf(l1));
              int i3 = 0;

              switch (enchantment.getRandomWeight()) {
                case 1:
                  i3 = 8;
                  break;

                case 2:
                  i3 = 4;

                case 3:
                case 4:
                case 6:
                case 7:
                case 8:
                case 9:
                default:
                  break;

                case 5:
                  i3 = 2;
                  break;

                case 10:
                  i3 = 1;
              }

              if (flag) {
                i3 = Math.max(1, i3 / 2);
              }

              i += i3 * k2;
            }
          }
        }
      }

      if (this.m != null
          && this.m.length() > 0
          && !this.m.equalsIgnoreCase(this.n.getLocale().c(itemstack.a()))
          && !this.m.equals(itemstack.getName())) {
        j = itemstack.g() ? 7 : itemstack.count * 5;
        i += j;
        if (itemstack.hasName()) {
          k += j / 2;
        }

        itemstack1.c(this.m);
      }

      l = 0;

      for (iterator = map.keySet().iterator(); iterator.hasNext(); k += l + k1 * l1) {
        j1 = ((Integer) iterator.next()).intValue();
        enchantment = Enchantment.byId[j1];
        k1 = ((Integer) map.get(Integer.valueOf(j1))).intValue();
        l1 = 0;
        ++l;
        switch (enchantment.getRandomWeight()) {
          case 1:
            l1 = 8;
            break;

          case 2:
            l1 = 4;

          case 3:
          case 4:
          case 6:
          case 7:
          case 8:
          case 9:
          default:
            break;

          case 5:
            l1 = 2;
            break;

          case 10:
            l1 = 1;
        }

        if (flag) {
          l1 = Math.max(1, l1 / 2);
        }
      }

      if (flag) {
        k = Math.max(1, k / 2);
      }

      this.a = k + i;
      if (i <= 0) {
        itemstack1 = null;
      }

      if (j == i && j > 0 && this.a >= 40) {
        this.h
            .getLogger()
            .info("Naming an item only, cost too high; giving discount to cap cost to 39 levels");
        this.a = 39;
      }

      if (this.a >= 40 && !this.n.abilities.canInstantlyBuild) {
        itemstack1 = null;
      }

      if (itemstack1 != null) {
        i1 = itemstack1.getRepairCost();
        if (itemstack2 != null && i1 < itemstack2.getRepairCost()) {
          i1 = itemstack2.getRepairCost();
        }

        if (itemstack1.hasName()) {
          i1 -= 9;
        }

        if (i1 < 0) {
          i1 = 0;
        }

        i1 += 2;
        itemstack1.setRepairCost(i1);
        EnchantmentManager.a(map, itemstack1);
      }

      this.f.setItem(0, itemstack1);
      this.b();
    }
  }
Example #14
0
  public void a(ItemStack itemstack, World world, EntityHuman entityhuman, int i) {
    boolean flag =
        entityhuman.abilities.canInstantlyBuild
            || EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_INFINITE.id, itemstack) > 0;

    if (flag || entityhuman.inventory.b(Items.ARROW)) {
      int j = this.d(itemstack) - i;
      float f = (float) j / 20.0F;

      f = (f * f + f * 2.0F) / 3.0F;
      if ((double) f < 0.1D) {
        return;
      }

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

      EntityArrow entityarrow = new EntityArrow(world, entityhuman, f * 2.0F);
      entityarrow.damage = 2.3D;

      if (f == 1.0F) {
        entityarrow.setCritical(true);
      }

      int k = EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_DAMAGE.id, itemstack);

      if (k > 0) {
        entityarrow.b(entityarrow.j() + (double) k * 0.5D + 0.5D);
      }

      int l = EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_KNOCKBACK.id, itemstack);

      if (l > 0) {
        entityarrow.a(l);
      }

      if (EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_FIRE.id, itemstack) > 0) {
        EntityCombustEvent event = new EntityCombustEvent(entityarrow.getBukkitEntity(), 100);
        entityarrow.world.getServer().getPluginManager().callEvent(event);

        if (!event.isCancelled()) {
          entityarrow.setOnFire(event.getDuration());
        }
      }

      // CraftBukkit start
      EntityShootBowEvent event =
          CraftEventFactory.callEntityShootBowEvent(entityhuman, itemstack, entityarrow, f);
      if (event.isCancelled()) {
        event.getProjectile().remove();
        return;
      }

      if (event.getProjectile() == entityarrow.getBukkitEntity()) {
        world.addEntity(entityarrow);
      }
      // CraftBukkit end

      itemstack.damage(1, entityhuman);

      world.makeSound(
          entityhuman, "random.bow", 1.0F, 1.0F / (g.nextFloat() * 0.4F + 1.2F) + f * 0.5F);
      if (flag) {
        entityarrow.fromPlayer = 2;
      } else {
        entityhuman.inventory.a(Items.ARROW);
      }

      entityhuman.b(StatisticList.USE_ITEM_COUNT[Item.getId(this)]);
    }
  }
Example #15
0
  public void attack(Entity entity) {
    if (entity.k_()) {
      int i = this.inventory.a(entity);

      if (this.hasEffect(MobEffectList.INCREASE_DAMAGE)) {
        i += 3 << this.getEffect(MobEffectList.INCREASE_DAMAGE).getAmplifier();
      }

      if (this.hasEffect(MobEffectList.WEAKNESS)) {
        i -= 2 << this.getEffect(MobEffectList.WEAKNESS).getAmplifier();
      }

      int j = 0;
      int k = 0;

      if (entity instanceof EntityLiving) {
        k = EnchantmentManager.a(this.inventory, (EntityLiving) entity);
        j += EnchantmentManager.getKnockbackEnchantmentLevel(this.inventory, (EntityLiving) entity);
      }

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

      if (i > 0 || k > 0) {
        boolean flag =
            this.fallDistance > 0.0F
                && !this.onGround
                && !this.t()
                && !this.aU()
                && !this.hasEffect(MobEffectList.BLINDNESS)
                && this.vehicle == null
                && entity instanceof EntityLiving;

        if (flag) {
          i += this.random.nextInt(i / 2 + 2);
        }

        i += k;
        boolean flag1 = entity.damageEntity(DamageSource.playerAttack(this), i);

        if (flag1) {
          if (j > 0) {
            entity.b_(
                (double) (-MathHelper.sin(this.yaw * 3.1415927F / 180.0F) * (float) j * 0.5F),
                0.1D,
                (double) (MathHelper.cos(this.yaw * 3.1415927F / 180.0F) * (float) j * 0.5F));
            this.motX *= 0.6D;
            this.motZ *= 0.6D;
            this.setSprinting(false);
          }

          if (flag) {
            this.c(entity);
          }

          if (k > 0) {
            this.d(entity);
          }

          if (i >= 18) {
            this.a((Statistic) AchievementList.E);
          }

          this.g(entity);
        }

        ItemStack itemstack = this.U();

        if (itemstack != null && entity instanceof EntityLiving) {
          itemstack.a((EntityLiving) entity, this);
          if (itemstack.count <= 0) {
            itemstack.a(this);
            this.V();
          }
        }

        if (entity instanceof EntityLiving) {
          if (entity.isAlive()) {
            this.a((EntityLiving) entity, true);
          }

          this.a(StatisticList.w, i);
          int l =
              EnchantmentManager.getFireAspectEnchantmentLevel(
                  this.inventory, (EntityLiving) entity);

          if (l > 0) {
            entity.setOnFire(l * 4);
          }
        }

        this.c(0.3F);
      }
    }
  }
Example #16
0
  /**
   * called when the player releases the use item button. Args: itemstack, world, entityplayer,
   * itemInUseCount
   */
  public void a(ItemStack var1, World var2, EntityHuman var3, int var4) {
    // Forge start
    int var5 = this.a(var1) - var4;
    ArrowLooseEvent var6 = new ArrowLooseEvent(var3, var1, var5);
    MinecraftForge.EVENT_BUS.post(var6);

    if (var6.isCanceled()) {
      return;
    }
    var5 = var6.charge;
    // Forge end
    boolean var7 =
        var3.abilities.canInstantlyBuild
            || EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_INFINITE.id, var1) > 0;

    if (var7 || var3.inventory.e(Item.ARROW.id)) {
      float var8 = (float) var5 / 20.0F;
      var8 = (var8 * var8 + var8 * 2.0F) / 3.0F;

      if ((double) var8 < 0.1D) {
        return;
      }

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

      EntityArrow var9 = new EntityArrow(var2, var3, var8 * 2.0F);

      if (var8 == 1.0F) {
        var9.e(true);
      }

      int var10 = EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_DAMAGE.id, var1);

      if (var10 > 0) {
        var9.b(var9.c() + (double) var10 * 0.5D + 0.5D);
      }

      int var11 = EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_KNOCKBACK.id, var1);

      if (var11 > 0) {
        var9.a(var11);
      }

      if (EnchantmentManager.getEnchantmentLevel(Enchantment.ARROW_FIRE.id, var1) > 0) {
        var9.setOnFire(100);
      }

      // CraftBukkit start
      org.bukkit.event.entity.EntityShootBowEvent event =
          org.bukkit.craftbukkit.event.CraftEventFactory.callEntityShootBowEvent(
              var3, var1, var9, var8);
      if (event.isCancelled()) {
        event.getProjectile().remove();
        return;
      }

      if (event.getProjectile() == var9.getBukkitEntity()) {
        var2.addEntity(var9);
      }
      // CraftBukkit end

      var1.damage(1, var3);
      var2.makeSound(var3, "random.bow", 1.0F, 1.0F / (d.nextFloat() * 0.4F + 1.2F) + var8 * 0.5F);

      if (var7) {
        var9.fromPlayer = 2;
      } else {
        var3.inventory.d(Item.ARROW.id);
      }
    }
  }
Example #17
0
  protected int b_(int i) {
    int j = EnchantmentManager.getOxygenEnchantmentLevel(this.inventory);

    return j > 0 && this.random.nextInt(j + 1) > 0 ? i : super.b_(i);
  }