Example #1
0
  /**
   * Attempts to damage the ItemStack with par1 amount of damage, If the ItemStack has the
   * Unbreaking enchantment there is a chance for each point of damage to be negated. Returns true
   * if it takes more damage than getMaxDamage(). Returns false otherwise or if the ItemStack can't
   * be damaged or if all points of damage are negated.
   */
  public boolean attemptDamageItem(int par1, Random par2Random) {
    if (!this.isItemStackDamageable()) {
      return false;
    } else {
      if (par1 > 0) {
        int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.unbreaking.effectId, this);
        int k = 0;

        for (int l = 0; j > 0 && l < par1; ++l) {
          if (EnchantmentDurability.negateDamage(this, j, par2Random)) {
            ++k;
          }
        }

        par1 -= k;

        if (par1 <= 0) {
          return false;
        }
      }

      setItemDamage(getItemDamage() + par1); // Redirect through Item's callback if applicable.
      /** gets the damage of an itemstack */
      return getItemDamage() > getMaxDamage();
    }
  }
Example #2
0
  public boolean a(int i0, Random random) {
    if (!this.e()) {
      return false;
    } else {
      if (i0 > 0) {
        int i1 = EnchantmentHelper.a(Enchantment.t.B, this);
        int i2 = 0;

        for (int i3 = 0; i1 > 0 && i3 < i0; ++i3) {
          if (EnchantmentDurability.a(this, i1, random)) {
            ++i2;
          }
        }

        i0 -= i2;
        if (i0 <= 0) {
          return false;
        }
      }

      this.f += i0;
      return this.f > this.j();
    }
  }