Anvil mechanics/Before 1.8



This page explains the mechanics of the anvil. The anvil is primarily used to repair tools, armor, and weapons, which it can do without stripping their enchantments. It can also be used to combine the enchantments of two items, or to give an item an individual name. All its functions cost experience levels, and some also have material costs. The anvil offers four basic capabilities:
 * Repairing an item with units of its material (e.g., iron ingots for iron tools or iron armor). This works only for armor and tools with their material in their default name (e.g. Iron Sword, Leather Helmet).  It does work for chainmail, which is repaired with iron ingots.
 * Repairing an item by combining it with an unenchanted example of its kind. This works for anything that has durability, including not just armor and tools, but bows, shears, and so forth.
 * As an extension of the previous, an anvil can combine two enchanted items, producing one with a combination of their enchantments. This also works for bows and shears.
 * An anvil can also rename any item, not just the ones it can repair. Besides entertainment value, this can save on the costs of repeated repairs.

In survival mode, the anvil can only apply 39 levels worth of work in a single operation. If the job would cost 40 or more levels, it will be rejected as "Too Expensive!". This does not apply in creative mode. Some such jobs can be done piecewise: First rename, then repair, then combine. However, it is possible to produce items so heavily enchanted that they cannot be worked on at all.

Base value of items
The most important concept for using an anvil is the "base value" of an item, figured in experience levels. Almost any change made to an item will cost its base value, plus costs according to the change. An item's base value is the sum of the costs of its enchantments, plus a charge for the number of its enchantments. Note that the item's material does not affect its base cost, nor does the order of its enchantments. An unenchanted (or unenchantable) item has base value 0.

As formulas:
 * For each Enchantment, ECost = Cost-per-level&times;level
 * For the item, BaseValue == ECost1 (+ Ecost2 + ...) + NumEnchantCost

Finally, an extra value (NumEnchantCost) needs to be added based on how many enchantments the item has, which can be found from the table below.

Notes:
 * 1) Enchantments marked with an asterisk (*) are ones for which the enchantment table cannot produce the highest level.  The anvil can, but this will involve the penalty for prior repair.

Example: Say we have a sword with Sharpness 3, Knockback 2 and Looting 2. Referring to the table we see that the Enchantments will cost 3&times;1 → 3, 2&times;2 → 4, and 2&times;4 → 8 respectively, and another 6 levels for having three of them. 3+4+8+6 → 21. In the anvil for the first time, this sword will cost at least 21 levels to work on, even before considering what to do with it.

Prior Work penalty
Regardless of the work being done, be it rename, repair, or combine, there will be an extra cost, the "prior work penalty", to work on an item which has previously been altered in an anvil.


 * If the item has been renamed at any point, the penalty is always 2 levels, regardless of further alterations.
 * For an un-renamed item, the prior-work penalty is 2 levels for each repair or combination an item has been through, not including this one. If combining two items, you pay both their penalties.

Renaming
Renaming something with durability costs (Base Value + Prior Work Penalty) + 7 the first time, later renames cost (Base Value + Prior Work Penalty) + 10.
 * Simultaneously renaming and repairing an object costs both charges, but you only pay for base value and the (current) penalty once. For example, consider an item with base value of 5 never renamed before, with two prior works (penalty of 4). Then this item is altered a third time, for a repair costing 3 (over Base+Penalty). Repairing and renaming it simultaneously would cost (5+4)+3+7=19, as opposed to 5+4+3=12 for a repair alone or 5+4+7=16 for a rename alone.
 * An item which has been renamed has its prior-work penalty set to 2, remaining so regardless of later work. Renaming the item back to its default name (e.g. "Iron Sword") does not revert prior-work to full cost.
 * As a consequence of the above, and using the same example, if you then damage that item slightly so that the next (fourth) repair cost would be 3 levels (over BV+Penalty), the renamed item will cost (5+2)+3=10 levels to repair, while if the item was not renamed before it would cost (5+6)+3=14 levels (4 more).

Renaming an item without durability costs 5 the first time, then stays 9 for all later renames. This includes the implicit prior-work penalty, and of course the base value is 0.
 * Stackable items can be renamed as a stack; you do pay for each item, but the total cost is capped at 39 levels, for which you can rename a full stack.
 * Note that renamed items in general will not stack with normal items, and renamed blocks lose their name when placed.

Unit Repair
This is the process of repairing an item by adding units of its material: leather, wood planks, cobblestone blocks, iron ingots, gold ingots, or diamonds. This works only for "tiered" armor and tools.It does not work for bows, flint-and-steel, shears, fishing rods, nor carrots-on-sticks. Each unit can restore up to 25% of the item's maximum durability, and multiple units can be used at once (incurring only a single prior-work penalty for next time). The cost in levels to do this is the item's base cost, plus prior-work penalty, plus a cost for each unit of material.
 * Chainmail can be repaired with iron ingots.
 * For most materials and all armor, the cost per unit is 1 for each enchantment on the target, plus 1.
 * For diamond tools (including swords), each unit again costs 1 per enchantment, but then 1 to 3 more. For a multi-unit repair, all but the last unit cost 3 apiece.  However, the last or only unit can cost less, depending on how much durability it restores:  Up to 199 durability costs 1 level, 200 to 299 costs 2 levels, and from 300 to 390 (the unit max) costs 3 levels.

Combining Items
The anvil can be used to combine two items of the same type. The first item here is the target item, which will receive any repair or extra enchantments. The second item will be destroyed, it is the sacrifice item. For greater control, you may want to use + to show the numeric durability of your items (in the inventory tooltips).

Sacrifice Repair
If the second item is non-magical, or if its only enchantments are already higher power in the target item, the combination will simply repair the target. This works for anything with durability. You always pay the base cost for the target item, and the prior-repair penalties of both items, but the additional costs vary by material, and sometimes the durability of the sacrifice item:
 * The resulting durability will be D=floor(T+S+0.12*MaxD), up to the item's maximum. Here, T is the durability of the target item, S is the durability of the sacrifice item, and MaxD is the maximum durability for the item type. That is, the sum of the two item durabilities, plus a bonus of 12% of the maximum durability, rounded down. This means, that to get the most out of repairing, the durability of the target and sacrifice items should not total more than 88% of the total durability of the item, otherwise you don't get some of the 12% bonus.
 * For swords and tools, the bonus comes out to 3 for gold, 7 for wood, 15 for stone, 30 for iron and 187 for diamonds.
 * For any item with a maximum durability below 178, the cost will only be 1 level. Items with higher maximum durability can pay more. The exact amount depends on the maximum durability, and the current durability of the sacrifice item.  This can range up to 17 levels, for repairing a diamond sword or tool with a near-intact sacrifice.  The formula for the level cost is L=floor((S+0.12*MaxD)/100) with a minimum cost of 1, and the results are shown in the table below.

Combining Enchantments
If the sacrifice is enchanted, some or all of its enchantments can be merged into the target, with a few special cases. The level cost can be fairly complex, and adding multiple enchantments can add up quickly. In general, putting the more powerfully enchanted item in the first slot will cost less, but repair costs can reverse that, especially for diamond tools. Some particular notes:
 * For each enchantment that the sacrifice has that the target doesn't, or which the sacrifice has at a higher level, the target will gain the sacrifice's enchantment, and you pay per level gained.
 * If both items have an enchantment at the same level but not maxed out, it will be increased by 1 on target, and you pay for that increase. If both were at maximum it will not be increased, but you pay something anyway.
 * If the sacrifice has an enchantment at lower level than the target, the target's enchantment is unchanged and you don't pay for that.
 * Some groups of enchantments are incompatible; an item can have only one of them no matter what, and whichever is already on the target takes precedence. (You do pay something for trying.)  The incompatible groups of enchantments are:
 * Sharpness, Smite, and Bane of Arthropods
 * Protection, Fire Protection, Blast Protection, and Projectile Protection
 * Fortune and Silk Touch
 * Remember that except in Creative mode, there is a limit of 40 levels for all work in an anvil; if it costs more than that, the anvil will refuse the job. Some such jobs can be done piecewise:  First rename, then repair, then combine.
 * If the sacrifice is a book, costs are significantly cheaper than sacrificing a matching item with same enchantment. This can allow enchantments or renamings that wouldn't be possible otherwise.  However, it also makes it easier to produce an item that its Base Value alone is so high that it can't even be repaired afterwards.

Costs For Combining Enchanted Items

 * The target's base value
 * If also repairing or renaming, their respective costs. Base value and prior work is only paid once, and prior work is paid for both target and sacrifice.
 * For sacrifice enchantments which are incompatible with the target: 1 per level of each such enchantments.
 * For each gained level of new or increased enchantments, the cost-per-level, doubled.
 * If both items have the same enchantment at maximum level, add the cost per level (of a single level), once.
 * If new enchantments are added, an extra cost of X×(T-1)+1, X being the number of enchantments added and T the total number of enchantments on the result.

Examples:
 * For the first slot, a sword with Sharpness 3, Knockback 2 and Looting 2. Its base value is 21.  Combined on second slot with a sword that has Sharpness 3 and Looting 2.  Both sharpness and looting are equal to the target, but not maxed out, so we add twice the increment for each, 2 and 8 respectively.  Thus the cost will be L=21+2+8=31 levels, producing a sword with Sharpness 4, Knockback 2, and Looting 3.  (Its BV is 4+4+12+6 → 26, but it will also have a 2-level penalty for the next repair or merger.)
 * Consider a sword with Sharpness 3 and Looting 2 (BV 14) in the first slot, and a sword with Bane 2 and Looting 2 (BV 15) in the second slot, both "virgin". The Bane will be blocked by the Sharpness, but cost 2 levels anyway.  The Looting will combine as above, costing 8 levels.  The final sword has Sharpness 3 and Looting 3 (BV 18). You pay 14+8+2→24 levels.  If the order of the swords are switched (Bane in first slot and Sharpness in second), the final sword would end up having Bane 2 and Looting 3 (BV 19), at a cost of 15+8+3→26.
 * And a simple one: A Sharpness 4 sword (BV 5) for the target, and a Looting 2 sword for the sacrifice.  Adding the looting costs 4 (per level) &times; 2 (levels) &times; 2 (double cost) → 4&times;2&times;2→16.   We have one new enchantment, leaving the target with two, so X=1, T=2, and we pay 1&times;(2-1)+1→2.  Total cost is 5+16+2→23 levels, for a sword with Sharpness 4, Looting 2 (BV 4+8+3→15).
 * Don't do this: Take a helmet with Protection 4, and Respiration 3, and add a helmet with Blast Protection 4 and Respiration 3.  You pay 4 levels for the incompatible Blast Protection, and another 4 for the maxed-out Respiration.  With the base value of 19, you've just paid 27 levels (and a heavily-enchanted helmet) for nothing.  (You could still be repairing the target, but that costs extra....)

Costs For Combining an Item with an Enchanted Book

 * First, the following costs are added together:
 * The target's modified base value, where cost-per-level of each old enchantment is halved to a minimum of 1 per level.
 * The prior repair penalties (see above) for target.
 * 1 per number of enchantments previously on target.
 * For each gained level on target (from a new or upgraded enchantment) the cost-per-level halved to a minimum of 1 per level.
 * If both have the same enchantment at maximum level, the enchantment cost-per-level (of a single level).
 * The above sum is then halved and rounded down. It can round down to 0.
 * If the enchantment is incompatible with the target: add 1 per enchantment level.
 * For each gained level on target (from a new or upgraded enchantment), add (again) the cost-per-level halved to a minimum of 1 per level.

Notes:
 * Trying to combine a book containing an incompatible or (duplicate) maxed-out enchant may seem illogical, but since cost of Base Value is reduced to almost 1/4 and of Prior Work is halved, it may make possible to Rename an item which would otherwise cost more than Anvil's 40-level limit, reducing its Prior Work cost for future Anvil operations (see the Rename section), allowing it to be repaired once again.
 * Ignoring the above corner-case scenario, and considering only the common usage of actually adding new enchantments or upgrading levels, the total cost can be roughly approximated to: BaseValue/4 + PriorWork/2 + NumberOfEnchaments/2 + levels gained * cost-per-level * 3/4. That is not accurate due to the many roundings and minimums and the fact that Modified BV is actually slightly larger than BV/4, but works fine as a quick estimative.

Examples:
 * Starting simple, enchanting a newly-crafted Bow with an Infinity I Book: the only cost is 1 * cost-per-level * 3/4 = 8 * 3/4 = 6. No rounding was needed in any steps, so that result is exact.
 * Adding Infinity I to a Bow already enchanted with Power III and Flame I, with Prior Work = 6: Original Base Value is 3*1 + 1*4 + (3*2/2) = 10, and the Modified Base Value is 3*1 + 1*(4/2) + (3*2/2) = 8, 2 enchants, and halved cost-per-level is 1*8/2 = 4. So (8+6+2+4)/2 + 4 = 14 levels. If Infinity I was obtained from another bow instead of a book it would cost 29 levels, 15 more.
 * A Sharpness 4 sword (BV 5, MBV also 5) for the target, and a Looting 2 Book for the sacrifice. Looting costs 4 (per level) × 2 (levels) / 2 (half cost) → 4×2/2→4, and target already has 1 enchantment, so (5+1+4)/2 + 4 → 9 (rather than 23 from item+item sacrifice)