# Anvil

Placed anvils have tiers `[1, 8]` and a special tier 1,916,169.

## Construction recipes

Inputs come from the player's main inventory; an input `count` totals across stacks. Each non-empty entry of each output position is granted independently, with probability equal to its weight divided by the position's total weight. When the [`lbsm` condition](https://movblock.mov/ntm-next/26.3/wiki/recipes/conditions.md) holds and `lbsm.unlock_anvil` is enabled, `tier` and a `tier_upper` other than -1 load as 1.

### Fields

| Field | Meaning and default | Range |
| - | - | - |
| `type` | Selects the `hbm:anvil_construction` recipe format. | |
| `name` (Optional) | Internal lookup name; defaults to the last segment of the recipe resource path. | |
| `input_items` | Ordered counted item inputs; defaults to an empty list. | |
| `input_items.ingredient` | Item ID, item tag, or loader ingredient object. | |
| `input_items.count` (Optional) | Items required from one stack; default 1. The item stack limit bounds a usable count. | `[1, i32::MAX]` |
| `input_items.components` (Optional) | Exact item-component values. | |
| `input_items.predicates` (Optional) | Item-component predicates. | |
| `output_items` | Fixed or weighted item-output positions; defaults to an empty list. | |
| `output_items.item ID` | Fixed output: String form for one item. | |
| `output_items.id` | Item ID in a stack object. | |
| `output_items.count` (Optional) | Stack size; default 1. | `[1, 99]` |
| `output_items.components` (Optional) | Item-component values. | |
| `output_items.chance` (Optional) | Output chance; omit for a guaranteed output. Some machines roll each item of the stack separately. | Rounds to weight `[1, 999]` of 1000 |
| `output_items.data` | Weighted choice: Stack object or an empty object for no output. | |
| `output_items.weight` | Relative selection weight; a positive total selects an output. | `[0, i32::MAX]` each; $\sum_i w_i \le \texttt{i32::MAX}$ |
| `order` (Optional) | Sort position within the recipe table; lower values first, default 2147483647. | `i32` |
| `overlay` | Anvil GUI category and badge: `none`, `construction`, `recycling`, or `smithing`. A `recycling` recipe is listed with its first input as icon. | |
| `tier` (Optional) | Minimum anvil tier; default 0. | `i32` |
| `tier_upper` (Optional) | Maximum anvil tier; default -1, which leaves it unbounded. | `i32` |

### Example

Source path: `data/hbm/recipe/anvil_construction/anvil.coal.json`

```json
{
  "type": "hbm:anvil_construction",
  "input_items": [
    {
      "ingredient": "#c:dusts/coal"
    }
  ],
  "order": 24,
  "output_items": [
    "minecraft:coal"
  ],
  "overlay": "smithing",
  "tier": 3
}
```

## Smithing recipes

`input_items` holds two positions: 0 for the left slot and 1 for the right slot. The anvil applies the first matching row by `order` whose `tier` does not exceed its own.

| `kind` | Left slot | Right slot | Result |
| - | - | - | - |
| `plain` | Matches position 0; consumes its `count` | Matches position 1; consumes its `count` | First `output_items` position |
| `hot` | As `plain`; a heated NTM item needs at least half heat and no component changes other than heat | As the left slot | As `plain`; a heated result takes the inputs' average heat |
| `mold` | Template, kept: exactly the position-0 `count`, matching `shape` when set, otherwise position 0; undamaged | Matches position 1; consumes its `count` | First `output_items` position |
| `poison` | Any food; consumes the position-0 `count` | Matches position 1; consumes its `count` | One left item with the red-pill additive when the right item is `hbm:pill_red`, otherwise cyanide; `output_items` is ignored |
| `rename` | Any item; consumes the position-0 `count` | Matches position 1 and has a custom name; kept | One left item with the right item's name; `output_items` is ignored |

### Fields

| Field | Meaning and default | Range |
| - | - | - |
| `type` | Selects the `hbm:anvil_smithing` recipe format. | |
| `name` (Optional) | Internal lookup name; defaults to the last segment of the recipe resource path. | |
| `input_items` | Ordered counted item inputs; defaults to an empty list. | |
| `input_items.ingredient` | Item ID, item tag, or loader ingredient object. | |
| `input_items.count` (Optional) | Items required from one stack; default 1. The item stack limit bounds a usable count. | `[1, i32::MAX]` |
| `input_items.components` (Optional) | Exact item-component values. | |
| `input_items.predicates` (Optional) | Item-component predicates. | |
| `output_items` | Fixed or weighted item-output positions; defaults to an empty list. | |
| `output_items.item ID` | Fixed output: String form for one item. | |
| `output_items.id` | Item ID in a stack object. | |
| `output_items.count` (Optional) | Stack size; default 1. | `[1, 99]` |
| `output_items.components` (Optional) | Item-component values. | |
| `output_items.chance` (Optional) | Output chance; omit for a guaranteed output. Some machines roll each item of the stack separately. | Rounds to weight `[1, 999]` of 1000 |
| `output_items.data` | Weighted choice: Stack object or an empty object for no output. | |
| `output_items.weight` | Relative selection weight; a positive total selects an output. | `[0, i32::MAX]` each; $\sum_i w_i \le \texttt{i32::MAX}$ |
| `order` (Optional) | Sort position within the recipe table; lower values first, default 2147483647. | `i32` |
| `tier` (Optional) | Minimum anvil tier; default 1. | `i32` |
| `kind` (Optional) | Smithing behavior: `plain`, `hot`, `mold`, `poison`, or `rename`; default `plain`. | |
| `shapeless` (Optional) | For `plain` and `hot`, also matches with the slots swapped when true; default false. | |
| `shape` (Optional) | For `mold`, the left slot matches any item in a `c` or `hbm` item tag whose path starts with `<shape>/`, in place of the position-0 ingredient. | |

### Example

Source path: `data/hbm/recipe/anvil_smithing/smith.ingot_gunmetal.json`

```json
{
  "type": "hbm:anvil_smithing",
  "input_items": [
    {
      "ingredient": "#c:ingots/copper"
    },
    {
      "ingredient": "#c:ingots/aluminum"
    }
  ],
  "order": 38,
  "output_items": [
    "hbm:ingot_gunmetal"
  ]
}
```
