Skip to content

Usage in Modpack

Hantonik edited this page Feb 3, 2024 · 5 revisions

Using AnvilAPI in modpack

Feel free to incorporate this mod into your Modpack as it was specifically designed for that purpose.

Setup

Download

The most recent releases of the AnvilAPI mod are available for download on both CurseForge and Modrinth platforms. Select the version that suits your preferred Modloader. AnvilAPI is compatible with popular Modloaders such as Forge, Fabric, and NeoForge.

Install

AnvilAPI should be installed on both the client and server sides to ensure all features are available.

Create custom recipes

AnvilAPI provides the capability to create your own custom anvil recipes (similar to vanilla recipes), covering basic combinations and specific item repair recipes. Both functionalities are achieved through the use of datapacks. Explore further details about it here.
See examples below:

Create basic recipe

Here is an example JSON illustrating a basic recipe:

{
  "type": "minecraft:anvil",
  "inputs": [
    {
      "item": "minecraft:copper_ingot",
      "count": 2,
      "consume": false
    },
    {
      "item": "minecraft:gold_ingot",
      "count": 5
    }
  ],
  "experience": 15,
  "shapeless": true,
  "result": {
    "count": 3,
    "item": "minecraft:diamond"
  }
}

As you can see, we've created an anvil recipe that allows crafting 3 diamonds from 2 copper ingots and 5 gold ingots, utilizing 15 experience levels. Importantly, with "consume": false, the 2 copper ingots remain untouched throughout the process. Moreover, the recipe is shapeless, meaning we can arrange the ingredients in any configuration.

Note

You can also use tags instead of specific items. More information on this can be found here.

There are also more advanced features for combining recipes. Let's discuss them here:

Remaining item

You can add a remaining item to the recipe. This item is returned in place of the selected ingredient (or dropped onto the anvil if slot is not empty) during the process.
Example:

{
  "type": "minecraft:anvil",
  "inputs": [
    {
      "item": "minecraft:copper_ingot",
      "count": 2,
      "consume": false
    },
    {
      "item": "minecraft:gold_ingot",
      "count": 5,

      // Here ↓
      "return": {
        "count": 6,
        "item": "minecraft:iron_ingot"
      }
    }
  ],
  "experience": 15,
  "shapeless": true,
  "result": {
    "count": 3,
    "item": "minecraft:diamond"
  }
}

In this case, we're modifying our basic recipe slightly so that during crafting, 5 gold ingots are used, and 6 iron ingots take their place.

Note

It's important to highlight that if an input has "consume": false set and has a remaining item, the remaining item will consistently be dropped onto the anvil throughout the crafting process.

Input with durability

If an ingredient has durability, you can utilize it instead of consuming the entire item by including "useDurability": true.
You can do it as shown in this example:

{
  "type": "minecraft:anvil",
  "inputs": [
    {
      "item": "minecraft:copper_ingot",
      "count": 2,
      "consume": false
    },
    {
      "item": "minecraft:golden_pickaxe",
      "count": 5,

      // Here ↓
      "useDurability": true
    }
  ],
  "experience": 15,
  "shapeless": true,
  "result": {
    "count": 3,
    "item": "minecraft:diamond"
  }
}

In this example, we've set up the recipe to use 5 durability points from a golden pickaxe, rather than using up 5 entire pickaxes (which is practically impossible).

Important

In this example, we've intentionally changed gold ingot to golden pickaxe because this feature won't work with ingots since they don't have durability.

Input with NBT Tag

If you wish for the recipe to only accept items with a specific NBT Tag, you can accomplish this using the example below.

{
  "type": "minecraft:anvil",
  "inputs": [
    {
      "item": "minecraft:copper_ingot",
      "count": 2,
      "consume": false
    },
    {
      "item": "minecraft:diamond_sword",
      "count": 5,
      "useDurability": true,

      // Here ↓
      "nbt": "{Enchantments:[{id:\"minecraft:sharpness\",lvl:3s}]}"
    }
  ],
  "experience": 15,
  "shapeless": true,
  "result": {
    "count": 3,
    "item": "minecraft:diamond"
  }
}

As you can see, we've added "nbt": "{Enchantments:[{id:\"minecraft:sharpness\",lvl:3s}]}" to the recipe, making it necessary for the diamond sword to have the Sharpness III enchantment to meet this recipe requirement.

Tip

The ingredient item can include additional NBT Tags, such as other enchantments, and it will still fulfill the recipe requirement. If you desire a strict match for the NBT Tag, include "strictNbt": true.

Create repair recipe

Beyond the capability to craft custom anvil combining recipes, AnvilAPI also offers the option to create your own repair recipes for damageable items. This is accomplished in a similar way as mentioned above.

Here is a JSON demonstrating an example repair recipe:

{
  "type": "minecraft:anvil_repair",
  "baseItem": "minecraft:golden_axe",
  "repairItem": {
    "item": "minecraft:apple"
  }
}

As you can see in this example, we've created a repair recipe that allows repairing a golden axe using apples. The entire repair process follows the same mechanics as in vanilla Minecraft.

Note

You can also use tags instead of specific items. More information on this can be found here.

Disable existing recipes

Starting from version 5.1.1.0-beta, AnvilAPI introduces the capability to disable specific vanilla anvil recipes, such as item repair, repair items, item enchantment, or enchantment combination. You can achieve this by configuring the config file anvilapi\disabled_vanilla_recipes.json. The file is created automatically upon the first launch of the game with this mod.
Practical examples are provided below.

Disable repair recipe

If you want to disable all repair recipes for a specific item, you can achieve this by adding the item ID to the repair array.
Example:

{
  "repair": [
    "minecraft:diamond_sword"
  ],
  "repairItems": [],
  "enchantments": []
}

In this example, we are disabling all repair recipes for the diamond sword.

Important

The diamond sword has repair recipes, including combining two swords and repairing with diamonds. Both of these recipes will be disabled.

On the other hand, if you wish to disable a specific repair recipe for a particular item, you can accomplish this using the following example:

{
  "repair": [
    {
      "baseItem": "minecraft:wooden_axe",
      "repairItem": "minecraft:birch_planks"
    }
  ],
  "repairItems": [],
  "enchantments": []
}

In this example, we've specifically disabled the repair recipe for the wooden axe but limited it to birch planks, allowing all other types of wood to remain unaffected.

Note

If you want to disable the repair recipe for the wooden axe for all types of wood, you can do so by using tags. More information on this can be found here.

Disable repair item

If you wish to disable all repair recipes that require a specific repair item, you can do so as shown in the example here:

{
  "repair": [],
  "repairItems": [
    "minecraft:gold_ingot"
  ],
  "enchantments": []
}

The provided configuration disables all repair recipes that involve a gold ingot as the required material item.

Note

If you'd like, you have the option to use tags instead of an item ID in this scenario. More information on this can be found here.

Disable enchantment recipe

If you need, you can also disable the recipe for enchanting an item using an enchanted book, as shown in the example below.

{
  "repair": [],
  "repairItems": [],
  "enchantments": [
    "minecraft:sharpness"
  ]
}

In this example, we are disabling all enchantment recipes that use a book with the Sharpness enchantment at any level.

However, if you prefer to disable only the recipes using enchantments at a specific level, you can do so using this example:

{
  "repair": [],
  "repairItems": [],
  "enchantments": [
    {
      "enchantment": "minecraft:sharpness",
      "level": 3
    }
  ]
}

Here, we're disabling all enchantment recipes that use a book with Sharpness III enchantment.

There is also an option to disable only the enchantment recipe for a specific enchantment on a specific item.
Example:

{
  "repair": [],
  "repairItems": [],
  "enchantments": [
    {
      "baseItem": "minecraft:iron_chestplate",
      "enchantment": "minecraft:fire_protection"
    }
  ]
}

Here, we're disabling the enchanting recipe for an iron chestplate with a fire protection enchantment.

Enchantment combination recipe

If you desire to disable the recipe for combining specific enchantments, you can utilize this option as demonstrated in the following example:

{
  "repair": [],
  "repairItems": [],
  "enchantments": [
    {
      "combining": [
        {
          "enchantment": "minecraft:bane_of_arthropods"
        },
        {
          "enchantment": "minecraft:looting",
          "level": 3
        }
      ]
    }
  ]
}

In this example, the combination of a bane of arthropods enchantment book with a looting III enchantment book will be disabled.

However, if you wish to straightforwardly disable the recipe for combining identical enchantments, you can achieve it as demonstrated in this example:

{
  "repair": [],
  "repairItems": [],
  "enchantments": [
    {
      "combining": [
        {
          "enchantment": "minecraft:protection",
          "level": 2
        }
      ]
    }
  ]
}

Here, we are disabling the recipe for combining two enchanted books with Protection II.

Integrations

TODO

JEI integration

TODO

REI integration

TODO

CraftTweaker integration

TODO