All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.nukkit.item.enchantment.EnchantmentDurability Maven / Gradle / Ivy

There is a newer version: 1.20.40-r1
Show newest version
package cn.nukkit.item.enchantment;

import cn.nukkit.api.PowerNukkitOnly;
import cn.nukkit.item.Item;

import java.util.Random;

/**
 * @author MagicDroidX (Nukkit Project)
 */
public class EnchantmentDurability extends Enchantment {
    protected EnchantmentDurability() {
        super(ID_DURABILITY, "durability", Rarity.UNCOMMON, EnchantmentType.BREAKABLE);
    }

    @Override
    public int getMinEnchantAbility(int level) {
        return 5 + (level - 1) * 8;
    }

    @Override
    public int getMaxEnchantAbility(int level) {
        return super.getMinEnchantAbility(level) + 50;
    }

    @Override
    public int getMaxLevel() {
        return 3;
    }

    @Override
    public boolean canEnchant(Item item) {
        return item.getMaxDurability() >= 0 || super.canEnchant(item);
    }

    public static boolean negateDamage(Item item, int level, Random random) {
        return !(item.isArmor() && random.nextFloat() < 0.6f) && random.nextInt(level + 1) > 0;
    }

    @PowerNukkitOnly
    @Override
    public boolean isItemAcceptable(Item item) {
        if (!item.isNull() && item.getMaxDurability() != -1 && !item.isUnbreakable()) {
            return true;
        }
        return super.isItemAcceptable(item);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy