Villager - roidrole/Roids-Tweaker GitHub Wiki

Allows Addition and removal of villager professions, careers and trades. Comprised of two classes

Foreword

First, if you don't know how Minecraft villagers work under the hood, we'll need to define a few terms :

  • Profession : any appearance a villager can take. In vanilla, that is the color of the robe. In CT, it is reference with a string namespace:path, like minecraft:farmer. You can get them with /ct villager professions
  • Career : Determines the name of the villager and its trade pool. It belongs to a profession. In CT, it is referred to by its name as string. You can get them by running /ct villager careers. If adding one, you should add a lang entry for entity.Villager.INSERT_career_NaMe
  • Level : Much like in 1.14+, villagers level up. There is a 1/1 chance that a trade causes a level up the first time it is used, and a 1/5 chances afterwards. The process of levelling up is how a villager unlocks new trades. There is no maximal level a villager could have. They start at level 1.
  • Trade : Trades belong to both a career and a level, and consist of a function(merchant, recipeList, random). The items in the trade have to be ItemStacks, but can be chosen randomly when the trade is added to a villager (that is what happens when you add a trade using an IIngredient)

It is also necessary to mention that all methods in the Villager class should be called during #loader preinit or #loader contenttweaker to maximize compatibility. If pertinent to load them later, the mod will. Anything in IVillagerCareer should be called when the items are available (#loader crafttweaker)

Villager :

The core class of the package, used for registering villagers and getting professions and careers

Import :

import mods.roidtweaker.minecraft.villager.Villager;
Method Parameters Description
addProfession name as string, @Optional texture as string, @Optional zombieTexture as string registers a new villager profession. The name should start with crafttweaker:. Textures default to roidtweaker:textures/entity/villager/[name].png
addCareer profession as string, name as string Adds a new career to a profession
addCareer profession as string, name as string[] Adds new careers to the specified profession. Recommended over calling the preceding function multiple times.
removeProfession profession as string Prevents any profession with this resource location from being registered.
clearCareers profession as string Removes all careers from a profession. Note : Minecraft reacts quite poorly to a profession having no careers. You should add at least one to compensate.
removeCareer career as string Prevents any career with this name from being registered. Requires config:mixin category.villager category.allowDisablingCareers=true
getCareer profession as string, careerIndex as int returns an IVillagerCareer object corresponding to the given profession and career id. Index is relative to the state of the registry after all removals, but otherwise current
getCareer profession as string, career as string Idem, but will try to find a profession whose name matches provided by looping through all.

IVillagerCareer

Represents a Villager Career. Is used to add and remove trades. It is recommended to save this object to a value if adding multiple

Import :

import mods.roidtweaker.minecraft.villager.IVillagerCareer;

Adding trades

All parameters using IIngredients will pick a random ItemStack from the item list when generating a trade

Supports meta wildcards if config:mixin category.villager category.allowMetaWildcards=true

Basic

addTrade(level as int, sell as IIngredient, buy1 as IIngredient, @Optional buy2 as IIngredient, @Optional getOutput as function(random as IRandom, sell as IIngredient) as IItemStack);

The sell parameter of the getOutput function is just the sell parameter of the addTrade

Enchanted item output

Will pick a random level between min and max and enchant the output (like an enchanting table would)

addTradeForEnchantedItem(level as int, sell as IIngredient, buy1 as IIngredient, @Optional buy2 as IIngredient, @Optional minLevel as int = 5, @Optional maxLevel as int = 20);

Potion item output

Will populate the chosen output's Potion tag with a random element from the provided array if specified, or from all registered potion types otherwise

addTradeForPotionItem(level as int, sell as IIngredient, buy1 as IIngredient, @Optional buy2 as IIngredient, @Optional potionKeys as string[]);

Advanced

If you need more control, take this method

addTradeAdvanced(level as int, function(random as IRandom) as IItemStack[]);

The provided function should output an IItemStack[] of length 3 containing, in this order, [sell, buy1, buy2]. To disable the recipe, return an array of incorrect length or with a null output

Removing trades

method Parameters Description
removeTrade @Optional level as int, @Optional index as int Removes the trade at the specified index. You can get the index by running /ct villager trades. If any parameter is unspecified, the level/profession's trades are cleared