Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding villager trades in Minecraft: trash for treasure #185

Open
AllanChain opened this issue Jul 15, 2022 · 0 comments
Open

Adding villager trades in Minecraft: trash for treasure #185

AllanChain opened this issue Jul 15, 2022 · 0 comments
Labels
blog: moments |108686982-1caed800-7531-11eb-8d5d-3c60aff36bff.png @post This is a blog post tag: minecraft |178273615-88ec3d90-4dee-4754-93ea-8810bf3c28cb.png

Comments

@AllanChain
Copy link
Owner

AllanChain commented Jul 15, 2022

View Post on Blog

Image

This is a simple tutorial with detailed examples for adding custom villager's trades in Minecraft using the mod CraftTweaker.


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.

Simple chicken farm

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.

CraftTweaker Logo

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!

Villager buying eggs

@AllanChain AllanChain added blog: moments |108686982-1caed800-7531-11eb-8d5d-3c60aff36bff.png @post This is a blog post tag: minecraft |178273615-88ec3d90-4dee-4754-93ea-8810bf3c28cb.png labels Jul 15, 2022
@AllanChain AllanChain changed the title Easily modify villager's trade in Minecraft: turning trash into treasure Adding villager trades in Minecraft: trash for treasure Aug 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blog: moments |108686982-1caed800-7531-11eb-8d5d-3c60aff36bff.png @post This is a blog post tag: minecraft |178273615-88ec3d90-4dee-4754-93ea-8810bf3c28cb.png
Projects
None yet
Development

No branches or pull requests

1 participant