for (StackEnchantment bookEnch : bookEnchantments) {
if (!StackUtils.isEnchantmentCompatible(outputStack, stackEnchants.values(), bookEnch))
continue;
StackEnchantment stackEnch = stackEnchants.get(bookEnch.ench.effectId);
// Calculate enchantment cost.
int level = (bookEnch.getLevel() - ((stackEnch != null) ? stackEnch.getLevel() : 0));
experienceCost += calculateCost(bookEnch, (stackEnch == null), numEnchants);
// Set enchantment level of output item.
if (stackEnch != null) stackEnch.setLevel(bookEnch.getLevel());
else outputStack.addEnchantment(bookEnch.ench, bookEnch.getLevel());
canApply = true;
}