This tutorial assumes that you know how to install mods from CurseForge.
The problem #
Do you have tons of useless items which have nowhere to go? For example, you have built a chicken XP farm and it produces stacks of feathers, raw chicken, and eggs.
You can trade feathers with fletchers, and trade raw chicken with butchers, but what about the eggs? You should already have stacks of seeds to breed the chicken and there is no need to hatch more chickens with eggs. Although some mods add some more recipes to make the eggs more useful, most of them are related to food, and you still can't consume so many eggs.
CraftTweaker #
That's where CraftTweaker come to rescue! CraftTweaker is a Minecraft mod which lets you customize the game to your heart's content, from simple things like changing recipes or adding tooltips to items, to more advanced things like subscribing to events or changing properties about items.
Besides its power, it's also a very popular mod, supporting both Forge and Fabric mod loader, which means you have probably already installed this mod in your mod pack! What's more, it has detailed documentation with many languages available, and you can customize your game in your own way!
Writing the script #
To check the documentation of modifying villager trade, navigate to "Vanilla - Villager - VillagerTrades". The method we are using here is addTrade
. There are many ways to use the method, technically called overloading. Here we are using "an Item for an Item" mode. For example, giving the farmer a stack of eggs and earning an emerald reads:
import crafttweaker.api.villagers.VillagerTrades;
villagerTrades.addTrade(<profession:minecraft:farmer>, 1, <item:minecraft:egg> * 16, <item:minecraft:emerald>, 16, 2, 0.05);
The 1st, 3rd and 4th arguments of the addTrade
method are straightforward.
The 2nd argument is villagerLevel
, i.e. the villager need to be a novice, apprentice, journeyman, expert, or master. Setting it to 1
means the trad is available from the novice.
The 5th argument is maxTrades
, i.e. how many trades before the trade gets locked.
The 6th argument is xp
, i.e. the experience for the villager
The 7th argument is priceMult
, i.e how much should the trade be discounted by. And this argument is optional.
If you have no idea what is the reasonable value, you can always refer to the vilalger trading table. For example, a butcher wants 14 raw chicken for an emerald, allowing 16 trades before the trade gets locked, and earning 2 XP per trade. Thus the numbers I set in the above script are reasonable.
Applying the script #
There is a detailed tutorial in CraftTweaker's documentation. You just need to create a new file called egg_or_whateverz_you_want.zs
in the scripts/
directory (which should be next to mods/
, and you can create it if it doesn't exist), and paste the script above into it. Then restart the game and new farmers can buy eggs!