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

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

Go to download

A Minecraft Bedrock Edition server software implementation made in Java from scratch which supports all new features.

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

import cn.nukkit.item.Item;

import java.util.Random;

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

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

    @Override
    public int getMaxEnchantAbility(int level) {
        return this.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;
    }
    
    @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