Java 类net.minecraft.enchantment.EnchantmentDurability 实例源码

项目:Toms-Mod    文件:ItemDamagableCrafting.java   
/**
 * 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(ItemStack stack, int amount, Random rand) {
    if (amount > 0) {
        int i = EnchantmentHelper.getEnchantmentLevel(Enchantments.UNBREAKING, stack);
        int j = 0;

        for (int k = 0;i > 0 && k < amount;++k) {
            if (EnchantmentDurability.negateDamage(stack, i, rand)) {
                ++j;
            }
        }

        amount -= j;

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

    setItemDamage(stack, getItemDamage(stack) + amount); // Redirect through
                                                            // Item's
                                                            // callback if
                                                            // applicable.
    return getItemDamage(stack) > getDurability(stack);
}
项目:RuneCraftery    文件:ItemStack.java   
public boolean func_96631_a(int p_96631_1_, Random p_96631_2_) {
   if(!this.func_77984_f()) {
      return false;
   } else {
      if(p_96631_1_ > 0) {
         int var3 = EnchantmentHelper.func_77506_a(Enchantment.field_77347_r.field_77352_x, this);
         int var4 = 0;

         for(int var5 = 0; var3 > 0 && var5 < p_96631_1_; ++var5) {
            if(EnchantmentDurability.func_92097_a(this, var3, p_96631_2_)) {
               ++var4;
            }
         }

         p_96631_1_ -= var4;
         if(p_96631_1_ <= 0) {
            return false;
         }
      }

      this.field_77991_e += p_96631_1_;
      return this.field_77991_e > this.func_77958_k();
   }
}
项目:AgeCraft-Old    文件:ACUtil.java   
public static boolean attemptDamageItem(ItemStack stack, int damage, Random rand) {
    if(!isItemStackDamageable(stack)) {
        return false;
    } else {
        if(damage > 0) {
            int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.unbreaking.effectId, stack);
            int k = 0;
            for(int l = 0; j > 0 && l < damage; ++l) {
                if(EnchantmentDurability.negateDamage(stack, j, rand)) {
                    k++;
                }
            }
            damage -= k;
            if(damage <= 0) {
                return false;
            }
        }
        stack.setItemDamage(stack.getItemDamage() + damage);
        return stack.getItemDamage() > stack.getMaxDamage();
    }
}
项目:DecompiledMinecraft    文件:ItemStack.java   
/**
 * 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 amount, Random rand)
{
    if (!this.isItemStackDamageable())
    {
        return false;
    }
    else
    {
        if (amount > 0)
        {
            int i = EnchantmentHelper.getEnchantmentLevel(Enchantment.unbreaking.effectId, this);
            int j = 0;

            for (int k = 0; i > 0 && k < amount; ++k)
            {
                if (EnchantmentDurability.negateDamage(this, i, rand))
                {
                    ++j;
                }
            }

            amount -= j;

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

        this.itemDamage += amount;
        return this.itemDamage > this.getMaxDamage();
    }
}
项目:DecompiledMinecraft    文件:ItemStack.java   
/**
 * 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 amount, Random rand)
{
    if (!this.isItemStackDamageable())
    {
        return false;
    }
    else
    {
        if (amount > 0)
        {
            int i = EnchantmentHelper.getEnchantmentLevel(Enchantment.unbreaking.effectId, this);
            int j = 0;

            for (int k = 0; i > 0 && k < amount; ++k)
            {
                if (EnchantmentDurability.negateDamage(this, i, rand))
                {
                    ++j;
                }
            }

            amount -= j;

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

        this.itemDamage += amount;
        return this.itemDamage > this.getMaxDamage();
    }
}
项目:BaseClient    文件:ItemStack.java   
/**
 * 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 amount, Random rand)
{
    if (!this.isItemStackDamageable())
    {
        return false;
    }
    else
    {
        if (amount > 0)
        {
            int i = EnchantmentHelper.getEnchantmentLevel(Enchantment.unbreaking.effectId, this);
            int j = 0;

            for (int k = 0; i > 0 && k < amount; ++k)
            {
                if (EnchantmentDurability.negateDamage(this, i, rand))
                {
                    ++j;
                }
            }

            amount -= j;

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

        this.itemDamage += amount;
        return this.itemDamage > this.getMaxDamage();
    }
}
项目:BaseClient    文件:ItemStack.java   
/**
 * 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 amount, Random rand)
{
    if (!this.isItemStackDamageable())
    {
        return false;
    }
    else
    {
        if (amount > 0)
        {
            int i = EnchantmentHelper.getEnchantmentLevel(Enchantment.unbreaking.effectId, this);
            int j = 0;

            for (int k = 0; i > 0 && k < amount; ++k)
            {
                if (EnchantmentDurability.negateDamage(this, i, rand))
                {
                    ++j;
                }
            }

            amount -= j;

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

        this.itemDamage += amount;
        return this.itemDamage > this.getMaxDamage();
    }
}
项目:Backmemed    文件:ItemStack.java   
/**
 * 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 amount, Random rand)
{
    if (!this.isItemStackDamageable())
    {
        return false;
    }
    else
    {
        if (amount > 0)
        {
            int i = EnchantmentHelper.getEnchantmentLevel(Enchantments.UNBREAKING, this);
            int j = 0;

            for (int k = 0; i > 0 && k < amount; ++k)
            {
                if (EnchantmentDurability.negateDamage(this, i, rand))
                {
                    ++j;
                }
            }

            amount -= j;

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

        this.itemDamage += amount;
        return this.itemDamage > this.getMaxDamage();
    }
}
项目:CustomWorldGen    文件:ItemStack.java   
/**
 * 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 amount, Random rand)
{
    if (!this.isItemStackDamageable())
    {
        return false;
    }
    else
    {
        if (amount > 0)
        {
            int i = EnchantmentHelper.getEnchantmentLevel(Enchantments.UNBREAKING, this);
            int j = 0;

            for (int k = 0; i > 0 && k < amount; ++k)
            {
                if (EnchantmentDurability.negateDamage(this, i, rand))
                {
                    ++j;
                }
            }

            amount -= j;

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

        setItemDamage(getItemDamage() + amount); //Redirect through Item's callback if applicable.
        return getItemDamage() > getMaxDamage();
    }
}
项目:Resilience-Client-Source    文件:ItemStack.java   
/**
 * 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 var3 = EnchantmentHelper.getEnchantmentLevel(Enchantment.unbreaking.effectId, this);
            int var4 = 0;

            for (int var5 = 0; var3 > 0 && var5 < par1; ++var5)
            {
                if (EnchantmentDurability.negateDamage(this, var3, par2Random))
                {
                    ++var4;
                }
            }

            par1 -= var4;

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

        this.itemDamage += par1;
        return this.itemDamage > this.getMaxDamage();
    }
}
项目:ExpandedRailsMod    文件:ItemStack.java   
/**
 * 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 amount, Random rand)
{
    if (!this.isItemStackDamageable())
    {
        return false;
    }
    else
    {
        if (amount > 0)
        {
            int i = EnchantmentHelper.getEnchantmentLevel(Enchantments.UNBREAKING, this);
            int j = 0;

            for (int k = 0; i > 0 && k < amount; ++k)
            {
                if (EnchantmentDurability.negateDamage(this, i, rand))
                {
                    ++j;
                }
            }

            amount -= j;

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

        setItemDamage(getItemDamage() + amount); //Redirect through Item's callback if applicable.
        return getItemDamage() > getMaxDamage();
    }
}
项目:Cauldron    文件:ItemStack.java   
public boolean attemptDamageItem(int p_96631_1_, Random p_96631_2_)
{
    if (!this.isItemStackDamageable())
    {
        return false;
    }
    else
    {
        if (p_96631_1_ > 0)
        {
            int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.unbreaking.effectId, this);
            int k = 0;

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

            p_96631_1_ -= k;

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

        setItemDamage(getItemDamage() + p_96631_1_); //Redirect through Item's callback if applicable.
        return getItemDamage() > getMaxDamage();
    }
}
项目:ShadowsOfPhysis    文件:ItemPhysisNBTDamage.java   
private boolean attemptNBTDamage(ItemStack stack, int damage, Random rand) {
    if (!this.isItemStackNBTDamageable(stack))
       {
           return false;
       }
       else
       {
           if (damage > 0)
           {
               int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.unbreaking.effectId, stack);
               int k = 0;

               for (int l = 0; j > 0 && l < damage; ++l)
               {
                   if (EnchantmentDurability.negateDamage(stack, j, rand))
                   {
                       ++k;
                   }
               }

               damage -= k;

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

           setNBTDamage(stack, getNBTDamage(stack) + damage);

           return getNBTDamage(stack) > getNBTMaxDamage(stack);
       }
}
项目:RuneCraftery    文件:ItemStack.java   
/**
 * 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.
        return getItemDamage() > getMaxDamage();
    }
}
项目:BetterNutritionMod    文件:ItemStack.java   
/**
 * 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.
        return getItemDamage() > getMaxDamage();
    }
}
项目:Cauldron    文件:ItemStack.java   
public boolean isDamaged(int p_96631_1_, Random p_96631_2_, EntityLivingBase entitylivingbase)
{
    // Spigot end
    if (!this.isItemStackDamageable())
    {
        return false;
    }
    else
    {
        if (p_96631_1_ > 0)
        {
            int j = EnchantmentHelper.getEnchantmentLevel(Enchantment.unbreaking.effectId, this);
            int k = 0;

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

            p_96631_1_ -= k;

            // Spigot start
            if (entitylivingbase instanceof EntityPlayerMP)
            {
                org.bukkit.craftbukkit.inventory.CraftItemStack item = org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(this);
                org.bukkit.event.player.PlayerItemDamageEvent event = new org.bukkit.event.player.PlayerItemDamageEvent((org.bukkit.entity.Player) entitylivingbase.getBukkitEntity(), item, p_96631_1_);
                org.bukkit.Bukkit.getServer().getPluginManager().callEvent(event);

                if (event.isCancelled())
                {
                    return false;
                }

                p_96631_1_ = event.getDamage();
            }

            // Spigot end

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

        setItemDamage(getItemDamage() + p_96631_1_); //Redirect through Item's callback if applicable.
        return getItemDamage() > getMaxDamage();
    }
}