Java Code Examples for net.minecraft.item.Item#getItemEnchantability()

The following examples show how to use net.minecraft.item.Item#getItemEnchantability() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
public void updateEnchantmentOptions(boolean validate) {
    int numoptions = slotEnchantment.size();
    slotEnchantment.clear();

    ItemStack toolstack = getSlot(0).getStack();
    if (toolstack.isEmpty()) {
        percentscrolled = 0;
        return;
    }

    Item item = toolstack.getItem();
    int enchantablity = item.getItemEnchantability(toolstack);
    if (enchantablity == 0 && validate) {
        percentscrolled = 0;
        return;
    }

    for (Enchantment enchantment : Enchantment.REGISTRY) {
        if (enchantment == null || enchantment.type == null || (!enchantment.type.canEnchantItem(item) && validate)) {
            continue;
        }
        int state = 0;
        int level = -1;
        if (NEIServerUtils.stackHasEnchantment(toolstack, Enchantment.getEnchantmentID(enchantment))) {
            state = 2;
            level = NEIServerUtils.getEnchantmentLevel(toolstack, Enchantment.getEnchantmentID(enchantment));
        } else if (NEIServerUtils.doesEnchantmentConflict(NEIServerUtils.getEnchantments(toolstack), enchantment) && validate) {
            state = 1;
        }
        slotEnchantment.add(new EnchantmentHash(enchantment, state, level));
    }
    if (numoptions != slotEnchantment.size()) {
        percentscrolled = 0;
    }
}
 
Example 2
public void updateEnchantmentOptions(boolean validate) {
    int numoptions = slotEnchantment.size();
    slotEnchantment.clear();

    ItemStack toolstack = getSlot(0).getStack();
    if (toolstack == null) {
        percentscrolled = 0;
        return;
    }

    Item item = toolstack.getItem();
    int enchantablity = item.getItemEnchantability();
    if (enchantablity == 0 && validate) {
        percentscrolled = 0;
        return;
    }

    for (Enchantment e : Enchantment.enchantmentsList) {
        if (e == null || e.type == null || (!e.type.canEnchantItem(item) && validate)) {
            continue;
        }
        int state = 0;
        int level = -1;
        if (NEIServerUtils.stackHasEnchantment(toolstack, e.effectId)) {
            state = 2;
            level = NEIServerUtils.getEnchantmentLevel(toolstack, e.effectId);
        } else if (NEIServerUtils.doesEnchantmentConflict(NEIServerUtils.getEnchantments(toolstack), e) && validate) {
            state = 1;
        }
        slotEnchantment.add(new EnchantmentHash(e, state, level));
    }
    if (numoptions != slotEnchantment.size()) {
        percentscrolled = 0;
    }
}