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. An unenchanted item starts with base value 0. There will also be an extra cost if the target 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 * 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.

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) For items that have more than one level, the cost is per level.
 * 3) 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&times1 &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 floor(a+b+0.12*m), up to the item's maximum. That is, the sum of the two item durabilities, plus a bonus of 12% of the maximum durability, rounded down.
 * For swords and tools, the bonus comes out to 3 for gold, 7 for wood, 15 for stone, 30 for iron, 187 for diamonds.
 * The cost will be at least one level. You pay an extra level if the sacrifice item has remaining durability of 200-floor(MaxDur * 0.12), and another level every 100 points thereafter.  This is summarized in the following table, but for any item with a maximum durability below 178, the cost will simply be 1 level.

Combining Enchantments
If the sacrifice is enchanted, some or all of its enchantments can be merged into the target. The level cost consists of several components:
 * If the target is damaged, you pay the cost for sacrifice repair, as above.
 * You then pay the base cost of the target item.
 * Next you pay for any enchantments that were added to the item. For each enchantment on the sacrifice, get the "second-slot" cost for the enchantment, regardless of level:
 * If it is incompatible with an enchantment on the target, it is ignored (and not added).
 * If the target has a higher level of the same enchantment, it is ignored (again, does not change the target).
 * If the target and sacrifice have the enchantment at the same level, the target is boosted to the next higher level, and you pay the second-slot cost... unless, both items are already at the maximum level, in which case add half the second slot cost, but the target will not be changed.
 * Otherwise, the target gains the enchantment at the sacrifice's level, and add the second-slot value to the cost.
 * You will also pay a penalty depending on whether the target item has been repaired and/or renamed.  For repairs only, the penalty is 2 levels per repair.  Renaming can modify that, usually reducing it.

Example: For the first slot, take the example above, a sword with sharpness 3, knockback 2 and looting 2. It's 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 value. 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.

铁砧机制

Combining and repairing items
An anvil can combine two items of the same type, merging their enchantments (within certain limits). This will cost experience levels depending on both the items put in, and the item that results. The tables below assume that the items are fully repaired; if they are damaged, it will cost more. Also, if an item has previously been combined or repaired, there will be an additional penalty.

This is for items in general for the anvil (doesn't depend which slot you put it in).


 * 1) The material that the tool is made out of doesn't matter. A wooden sword with looting 3 and bane 4 will cost the same when you put it into an anvil as a diamond sword with the same enchantments.
 * 2) Adding two like enchantments will give you an enchantment of the next level, as long as it doesn't go over the cap (knockback 1 + knockback 1 = knockback 2, but looting 3 + looting 3 = looting 3 still, since there is no looting 4)
 * 3) When combining enchantments, the item in the first slot (left slot) will be the "target" item; that is the item that gets the enchantment. When the anvil process occurs, it takes the enchantments from the item in the second slot and adds them onto the item in the first slot. This also means that if a sword with sharpness 3 and looting 2 is in the first slot, and a sword with bane 2 and looting 2 in the second slot, the sword with sharpness will override the bane sword, giving the final sword sharpness 3 and looting 3. It also means, though, that if the order of the swords are switched (i.e. have bane in first slot and sharpness in second), the final sword would end up having bane 2 and looting 3.
 * 4) Every time an item is put through the anvil, 2 extra levels are added to it. This means that if a sharpness 4 sword is made using two sharpness 3 swords, it will cost 2 more levels than a 'pure' sharpness 4 sword would.
 * 5) The maximum level of items that can be put into an anvil is 40. Once past this, the anvil says it is too expensive and won't do anything to it. In creative, the amount of levels on an anvil is more than normal.
 * 6) The costs are different for the target item and the one that's combined with it.  Putting the more powerfully enchanted of the two items into the first slot, will make the result cost less.
 * 7) The order of the enchantments on an item doesn't matter. A sword with sharpness 4, fire 2 and knockback 1 will cost the same as a sword with knockback 1, sharpness 4 and fire 2

Slot and other costs
To find out the level cost of combining two items, various factors must be taken into account. For completely unused items, they can be found by adding the following values:
 * 1) The "first slot" cost for each enchantment of the item in the first slot. These vary with the level of the enchantment, with each enchantment type having a given cost per level.
 * 2) A penalty for the number of enchantments on the first item. That is 1 for a single enchantment, 3 for two, 6 for three, or 10 levels for 4 enchantments.
 * 3) The "second slot" cost for each enchantment of the item in the second slot. These costs are constant for each enchantment type, but the cost is halved when combining two enchantments that are both at maximum level, and waived when the one in the second slot is weaker.  Note that "maximum level" can be above what you could get at an enchantment table.
 * 4) An additional penalty of 2 levels for each time either item has been been altered an anvil.  Repair and renaming count, even for otherwise unenchanted weapons.

Example
Say we make a sword with sharpness 3, knockback 2 and looting 2. To calculate the level it will be when going into the anvil, one must use the tables from the first slot section. The base cost of sharpness 3 is 3, the base cost of knockback 2 is 4 and the base cost of looting 2 is 8. This sword has 2 extra enchantments on it, so by looking at the table above for the extra enchantments, it can be seen that we need to add an extra 6 levels to the cost. This means that when this sword is put it into the anvil, it should cost 3+4+8+6=21 levels. If another sword is then enchanted and gets sharpness 3 and looting 2 on it, these two items can be combined to get a sword with sharpness 4, looting 3 and knockback 2. To calculate how much this would cost, we need to look at the tables in the second slot section. To add sharpness 3 costs 2 levels, and to add looting 2 costs 8 levels. This means, that if the first sword is in the first slot, thus starting with the 21 levels from before, to add the sharpness 4 and looting 2 sword would cost 21+2+8=31 levels.

First sword in anvil. It costs 21 levels, as predicted



Second sword in the anvil



Final sword costing the amount predicted, with the enchantments predicted



Formulas
This section deals with some formulas for those who prefer formulas to tables. While there still are some tables in this section, they are very short and more centered to be used for the formulas:

Formulas
To find the level cost of an enchantment, one must use the following formula:

To find the level of the item in the first slot, you use:

LF=Bk+(nk-1)*Ik+E+2*A

Where:
 * LF is the total level of the first item
 * B is the base cost of the item
 * n is the tier of enchantment (sharpness 3 would be tier 3)
 * I is the increment value
 * E is the extra cost depending on the number of enchantments on the item
 * A is the amount of times the item has been through the anvil process

When there are subscript letters (such as Bk, nk or Ik), the k is there for each enchantment. For an item with only 1 enchantment, you would only need to add (n-1)*I, while for an item with 4 enchantments, you would do (n-1)*I for each enchantment, along with the base cost of each enchantment

To find the total cost of combining two items, you use:

L=LF+Ik

Where:
 * L is the total level from the anvil process
 * LF is the level cost of the first item (from above)
 * I is the increment value

Once again, when there is a subscript k, you must add on the value for each enchantment.

Looking at the example above:

For the first slot, a sword with sharpness 3, knockback 2 and looting 2.

For the sharpness: The base cost is 1, the level is 3 and the increment is 1. For the knockback: The base cost is 2, the level is 2 and the increment is 2. For the looting: The base cost is 4, the level is 2 and the increment is 4. There are 3 enchantments total, which means E=6 This sword has not been through the anvil process at all, so A=0

This means:

LF=1+(3-1)*1+2+(2-1)*2+4+(2-1)*4+6+2*0

So, our value of LF becomes:

LF=1+2*1+2+1*2+4+1*4+6+0=21 levels

Which is the same as what we found before

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 value. For sharpness, the value to add is 2 levels, while for looting, it is 8

This makes:

L=21+2+8=31 levels

This gives the same values as found before

铁砧机制