User:MentalMouse42/Anvil Mechanics



This page explains the mechanics of the anvil. The anvil is used to repair swords, tools, armor, and even bows, combine enchantments on two items, and rename items. All of these functions cost experience levels, and some also have material costs. There are several basic modes of operation:
 * Repairing an item with units of its material (e.g., iron ingots for iron tools or iron armour). This doesn't work for bows.
 * Repairing an item by combining it with an unenchanted example of its kind. This does work for bows.
 * As an extension of the previous, an anvil can combine two enchanted items, producing one with a combination of their enchantments. This, too, works for bows.
 * An anvil can also rename any item, not just the ones it can repair.

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 item has base value 0.

There will also be an extra cost if the item has previously been altered in an anvil: For repairs (including merging), this will be 2 levels per prior repair. Renaming will reduce (and complicate) the penalty for mergers and repairs, but add a separate penalty for future renaming.

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

Merging one enchanted item into another also involves a "second slot" value, included in these tables. This is constant for the enchantment type, regardless of level or material.

If an item has more than one enchantment on it, an extra value (NumEnchantCost) needs to be added, which can be found from the table below.

Notes:
 * 1) Enchantments marked with a (*) are ones for which the enchantment table cannot produce the highest level.  The anvil can, but this will involve the penalty for prior repair.
 * 2) If an enchantment being added is at maximum level, the value of the second slot should be halved.

Prior Use Penalty: There is also a penalty for the item's having previously been through the anvil. For items which have not been renamed, this is 2 for each repair or merge the item has been through. Renaming an item can reduce this accumulated penalty for a later repair, but increases the cost for another rename.

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 &rarr; 3, 2&times;2 &rarr; 4, and 2&times;4 &rarr; 8 respectively, and another 6 levels for having three of them. 3+4+8+6 &rarr; 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.

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 doesn't work for bows, flint-and-steel, shears, fishing rods, nor carrot-on-a-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-use penalty for next time). The cost in levels to do this is the item's base cost (including prior-use penalty), plus a cost for each unit of material.
 * For most materials and all armor, the cost per unit is 1 for each enchantment on the item, 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.

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, 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 will lose 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 both their maximum and current durability, up to 17 for repairing with a near-intact diamond sword or tool. The formula is L=floor((S+0.12*MaxD)/100), and the results are shown in the table below.
 * You also pay any prior-repair penalties on both items.

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 is not completely understood for multiple enchantments in combination.
 * If the target is damaged, you pay the cost for sacrifice repair (including the base value), as above.
 * If the target is damaged, you first pay the cost for sacrifice repair (including the base value) on the target, as above.
 * Otherwise, you still pay the base value of the target item, plus any penalties for prior anvil use. (Repair would include these.)
 * Next you pay for any enchantments that were added to the item. The complete formulas haven't been worked out, but this much is known:
 * If the enchantment is incompatible with an enchantment on the target, (e.g. adding Smite to Sharpness) it is not added. You do, however, pay 1 per level of the rejected enchantment.
 * If the target already has a higher level of the same enchantment, the target's enchantment is unchanged. You don't seem to pay for this, at least not without other enchantments involved.
 * If the target and sacrifice have the enchantment at the same level, but below its maximum, the target is raised to the next higher level. Lacking other enchantments, you pay the second-slot cost.
 * If the target and sacrifice both have the enchantment at the maximum (or only) level, the target enchantment will not be changed, but you still pay half the second slot cost.
 * Otherwise, the target gains the enchantment at the sacrifice's level. With no other enchantments involved, you pay the second-slot cost.
 * The maximum level of items that can be put into an anvil is 40. Once past this, the anvil says the work is "too expensive" and won't do anything to it. (In creative, the limit is much higher.)
 * In general, putting the more powerfully enchanted item in the first slot will cost less.

Examples:
 * For the first slot, take the example above, a sword with Sharpness 3, Knockback 2 and Looting 2. Its base cost is 21.  To add on a sword that has Sharpness 3 and Looting 2, we look at the second slot values. Since neither sharpness or looting are at their maximum levels, we do not need to halve the second slot values. For sharpness, the value to add is 2 levels, while for looting, it is 8.  Thus the cost will be L=21+2+8=31 levels, for a sword with Sharpness 4, Knockback 2, and Looting 3.  (Its BV is 4+4+12+6 &rarr; 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 sword with Sharpness will override the Bane sword, giving the final sword Sharpness 3 and Looting 3 (BV 18). You pay 14+8&rarr;22 levels.  It also means, though, that 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&rarr;23.
 * And a simple one: A Sharpness 4 sword (BV 5) for the target, and a Looting 2 sword (BV 9) for the sacrifice.  You pay 5+8&rarr;13 levels, for a sword with Sharpness 4, Looting 2 (BV 4+8+3&rarr;15).

铁砧机制