Dynamic Villager Trades logo

Dynamic Villager Trades

Mod

by orlouge

Makes villager trading more interesting

Downloads

2,716,071

Type

Mod

CurseForge ID

720337

Last Updated

Apr 9, 2026

Description

.ggdsnPT.png

Example trades from a librarian specialized in max-level, armor and water-related enchantments.

 

A revisitation of the Villager trading mechanics that aims to get rid of those big trading halls filled with villagers with mostly useless trades, instead allowing you to get everything you need from a smaller number of villagers, which can become specialized in the long term through deliberate trading. To achieve this, the mod makes these two changes:

  • Villagers choose their trades based on previous player interactions. For instance, a librarian you've bought many Looting books from is more likely to offer sword enchantments and luck related enchantments in the future.
  • Villagers change their trades every time they restock/every day (configurable). This makes it unnecessary to breed a large number of villagers in hope that they sell what you need, and adds a little challenge to the trading mechanics. The more you buy or sell a specific item, the more likely the villager will choose that trade after restocking.

Additionally, this mod allows you to add or replace villager trades through datapacks. In multiplayer, the mod is only required on the server.

Note about mods that add their own trades: The default configuration is automatically generated with all the modded trades that would be present without this mod installed, and the generator does its best to make meaningful associations between the trades, based on tool materials, enchantment names, etc.. If you want to tweak those trades, you can create a datapack with the current configuration using the "/dynamicvillagertrades export" command. Some modded trades cannot be encoded in the datapack (e.g. random map from Supplementaries) and cause the export for that profession to fail, but those trades are still added at runtime if the profession is not being replaced by a datapack altogether; in such cases, additional trades can be configured with a datapack that doesn't replace the faulty profession (see below).

Note about mods that replace vanilla trades: These will never be compatible with DVT. This includes other mods that allow trade configuration via JSON, DVT has its own system for this and that's what you should use.

Note about NeoForge 1.21+: You can use Sinytra Connector to make the Fabric version work with it.

 

Datapack format

You can refer to the generated vanilla datapack for some examples of configured trades. Each JSON file expands or replaces (if replace is true) the trades of a particular profession, which are specified in the offers dictionary. Each entry in the dictionary represents a group of trades and specifies the min_trades and max_trades that can be selected from the group, and, optionally, the affinity of the group (more on this later) and the randomness within the group (lower values indicate that the villager will quickly settle on specific trades). If replace is false, the trades will be added to the preexisting group with the same name, otherwise the group is replaced altogether. Although the name of the group (the key) is arbitrary, it does affect the order in which the trades appear in the GUI, which is why the names of the groups in the default datapack begin with a number (otherwise the order would be alphabetical). Each entry in the trade list specifies the minimum level at which the trade can be selected (e.g. apprentice), the type of offer (documented in the SJVT wiki* for 1.18-1.20, refer to the new example datapack for 1.21+), the increment of the attributes that the trades applies to the villager when it's used and, optionally, the affinity. The attributes of a villager represent the memory of the past interactions with the players and function as a sort of sub-profession that gives more weight to some trades compared to others. Each attribute consists of an arbitrary name (e.g. "luck") and a numeric value that is initially set to 0 and is adjusted each time a trade with that attribute is used (e.g. when purchasing a Looting or Fortune book), based on the "attributes" increments specified in the trade (note that each villager possesses all the attributes mentioned in your configuration, so you don't need to "declare" them, it's always valid to increase an attribute with any name). On the other hand, the trade's affinity to each attribute determines how the value of the attribute of the villager affects the likelihood of selecting that trade. If the affinities are not explicitly defined, they're automatically calculated from the attribute increments (higher increments result in higher affinities). If you want a trade to increase an attribute without having affinity with it, or vice versa, you can specify both the attributes and the affinities of the trade. As mentioned earlier, the affinity dictionary can also appear in a group of trades instead of a trade. This makes it so that the trades between different groups don't directly compete against each other, as the mod will first select a group based on the affinity and then choose a trade inside of the group. This is useful if the number of trades in each group is highly unbalanced, as it prevents larger groups from being selected more frequently solely because of their size. It only makes sense if max_trades > min_trades.

Note that if a configuration is missing for a specific profession (for instance, a modded one), the mod will automatically generate one at run-time. The trades in this configuration will closely resemble the vanilla ones, but the offers that are not guaranteed to be present in vanilla will each have their own unique attribute and will belong to a group with the trades of the same level (basically, the villager specializes in specific trades, but only those for which the villager would normally have to make a choice in vanilla, and trades between different levels don't compete against each other).

* This mod adds two more offer types, enchant_specific_book and sell_specific_potion_holding_item.

 

Notes on adding enchanted book trades to the librarian profession

The default librarian configuration is generated at runtime and uses four identical groups for enchanted book trades, with the only difference being the experience given, so that the trades resemble the vanilla ones as much as possible. This means that, unless you want to replace the librarian profession altogether, you should add each new trade to all four groups. As for the attributes, you're recommended to use the preexisting ones (offense, defense, bow, etc.) to keep the trade weights balanced. When choosing the attributes, keep in mind that:

  • Trades with excessively similar affinities might prevent the villager from specializing in the trades that the player wants. For instance, if you add a trade with affinities for both the "tool" and "fast" attributes, a villager specialized in those attributes will randomly switch between Efficiency and the new book, no matter how many times the player buys either of those books. This is not necessarily a bad thing when the player might actually want to buy those books from the same villager, as reducing the size of the trading halls is one of the objectives of this mod.
  • Trades with affinities that are too dissimilar from most other trades can also make it hard to specialize in those trades, because most of the time the player will get trades that won't cause an increase in the desired attributes. For instance, if you add two trades with two new unique attributes, the only way for the player to make the villager specialize in those books is by buying those two books. However, since there are so many books, those two trades will rarely appear initially and the player will have to wait for the villager to restock numerous times in hope that either of those books will be selected as a trade. On the other hand, if the attributes of those trades were a new custom one and "fire", the player would be able to increase the chance of getting those books by buying books like Fire Aspect.
  • Attribute increments and affinities should only be negative if the books are actually meant to be incompatible with those attributes. For instance, if you want it to be highly unlikely for your book to appear together with Fire Aspect (perhaps because it's water-related), you can set "fire" to a negative value. Most of the time this is probably a bad idea.
  • The default configuration uses 1 for the increment of the enchanter attribute (favors enchanted books over other trades), from -1 to 0.5 for the increment of the low_level attribute (favors low level books, note that the level is relative to the maximum level of that enchantment, which is why Fire Aspect II and Efficiency V both decrease it by 1, while Efficiency II increases it by 0.5), 1 for the primary category of the book (armor, sword, tool, bow, fishing, trident, crossbow, all) and 1 split between the secondary categories (for instance, if a book belongs to "melee", "luck" and "resource", each attribute is increased by 0.333). Try to follow these rules when adding trades, as it will keep things balanced. Categories are attributes just like each other and you're free to invent new ones, but, as mentioned earlier, doing so can make your trades harder to obtain.

 

 

Options

global_randomness (default 1.0): Lower values cause the villagers to quickly settle on a subset of its trades, higher values increase the time required to get the desired trades. This is multiplied by the group randomness specified in the datapack.

refresh_delay (default 0): How many times the villager has to restock before its trades are changed. Note that they're always changed when it levels up regardless of this value.

no_book_duplicates (default true): Whether each librarian should not sell books with the same enchantment at the same time (e.g. Protection III and Protection IV).

enchant_repair_compat (default false): Adds the Curse of Vanishing to every book sold by librarians (for compatibility with Enchant & Repair).

 

Credits

The source code of this mod is based on SimpleJsonVillagerTrades

Similar Mods

Included in Modpacks

External Resources