Skip to content

Get started

Drex edited this page Feb 26, 2023 · 6 revisions

This page will guide you through the process of creating your own custom Villager Trades data pack.

Generate Default Datapack

To get started it will be useful, to generate a data pack that recreates the current trades. Start a server / open a world, with all the mods you want to play with. Run /villagerconfig generate to generate all necessary files in /config/VillagerConfig/generated.

Create a Datapack

Copy the data folder, you generated above into a folder, with the name of your datapack. Add a pack.mcmeta into your datapack folder and remove all files from villager professions that you don't intend to change. Congratulations, you have created a working datapack. 🎉

Customizing the datapack

To customize your datapack navigate through the files and look for the file of the profession you want to change.

Generator

Manually modifying trade files is quite tedious, and because of that, I've created a trade generator, which has an instant preview panel and an easy to use, user interface for configuring the trade files!

General Structure

Trade data files are json files, structured like this:

{
  "tiers": [
    {
      "groups": [
        {
          "num_to_select": 2,
          "trades": [
            {
              // Tier 1 - Trade 1
            },
            {
              // Tier 1 - Trade 2
            },
            {
              // Tier 1 - Trade 3
            },
            {
              // Tier 1 - Trade 4
            }
          ]
        }
      ],
      "total_exp_required": 0
    },
    {
      "groups": [
        {
          "num_to_select": 1,
          "trades": [
            {
              // Tier 2 - Trade 1
            },
            {
              // Tier 2 - Trade 2
            },
            {
              // Tier 2 - Trade 3
            }
          ]
        }
      ],
      "total_exp_required": 10
    }
   // Other tiers...
  ]
}

Each villager profession can have different trades. Trades are structured by tiers, which can be unlocked by trading (trader_experience) and leveling up villagers. Each tier consists of a list of groups and total_exp_required (which is used to determine when a villager should level up). Each group contains a list of available trades and a number (num_to_select), to choose how many trades should be picked for that group.

Trade Structure

Parameter Type Description Mandatory
cost_a LootPoolEntry First required item Yes
cost_b LootPoolEntry Second required item No
result LootPoolEntry Resulting item Yes
price_multiplier NumberProvider How much the first item price should be adjusted, depending on the demand No, default: 0.2
trader_experience NumberProvider How much trader experience a trade rewards, this is used to unlock higher tiers (see total_exp_required) Yes
max_uses NumberProvider How often a trade can be used, until it is locked and needs to be refreshed No, default: 12
reference_providers Map<String, NumberProvider> This field is required to replicate some vanilla trades, it is not very useful for other trades No
reward_experience boolean Whether trades will reward the player experience No, default: true

Note: Villager trades that have already been generated wont change after applying the datapack. Only new villagers will have the new trades!