Home Commands Examples Getting Started With Scripts Global Keywords
BracketDumpers BracketHandlers BracketValidators ResourceLocationBracketHandler

VillagerTrades

Importing the class

If you need to reference this type directly, like when casting an Array, or as a parameter, you will need to import it. Simply add the import at the top of the file.

script.zs
import crafttweaker.api.villagers.VillagerTrades;

Description

Members

addTrade(profession as VillagerProfession, villagerLevel as int, offerGenerator as BiFunction<MerchantOffer, Entity, RandomSource>)
Adds a new custom trade with the selling and buying items determined by the custom MerchantOffer generator.


The function will only run when the villager resolves the trade.

script.zs
// CTVillagerTrades.addTrade(profession as VillagerProfession, villagerLevel as int, offerGenerator as BiFunction<MerchantOffer, Entity, RandomSource>);
myCTVillagerTrades.addTrade(<profession:minecraft:farmer>, 1, (entity, random) => {
return new MerchantOffer(<item:minecraft:dirt>, <item:minecraft:diamond>, 16, 0, 5);
});

Parameters:

profession Type: VillagerProfession - What profession this trade should be for.
villagerLevel Type: int - The level the Villager needs to be.
offerGenerator Type: BiFunction<MerchantOffer, Entity, RandomSource> - A generator method to make a new MerchantOffer.
addTrade(profession as VillagerProfession, villagerLevel as int, emeralds as int, forSale as ItemStack, maxTrades as int, xp as int, priceMult as float = 1.0)
Adds a Villager Trade for emeralds for an Item. An example being, giving a villager 2 emeralds for an arrow.
script.zs
// CTVillagerTrades.addTrade(profession as VillagerProfession, villagerLevel as int, emeralds as int, forSale as ItemStack, maxTrades as int, xp as int, priceMult as float = 1.0);
myCTVillagerTrades.addTrade(<profession:minecraft:farmer>, 1, 16, <item:minecraft:diamond>, 5, 2, 0.05);

Parameters:

profession Type: VillagerProfession - What profession this trade should be for.
villagerLevel Type: int - The level the Villager needs to be.
emeralds Type: int - The amount of Emeralds.
forSale Type: ItemStack - What ItemStack is being sold (by the Villager).
maxTrades Type: int - How many times can this trade be done.
xp Type: int - How much Experience is given by trading.
priceMult (optional) Type: float - When this trade is discounted, how much should it be discounted by.

Default Value: 1.0

addTrade(profession as VillagerProfession, villagerLevel as int, input1 as ItemStack, forSale as ItemStack, maxTrades as int, xp as int, priceMult as float = 1.0)
Adds a Villager Trade for an Item for an Item. An example being, giving a villager 2 diamonds for an arrow.
script.zs
// CTVillagerTrades.addTrade(profession as VillagerProfession, villagerLevel as int, input1 as ItemStack, forSale as ItemStack, maxTrades as int, xp as int, priceMult as float = 1.0);
myCTVillagerTrades.addTrade(<profession:minecraft:farmer>, 1, <item:minecraft:dirt> * 16, <item:minecraft:diamond>, 5, 2, 0.05);

Parameters:

profession Type: VillagerProfession - What profession this trade should be for.
villagerLevel Type: int - The level the Villager needs to be.
input1 Type: ItemStack - The ItemStack that is being given to the Villager.
forSale Type: ItemStack - What ItemStack is being sold (by the Villager).
maxTrades Type: int - How many times can this trade be done.
xp Type: int - How much Experience is given by trading.
priceMult (optional) Type: float - When this trade is discounted, how much should it be discounted by.

Default Value: 1.0

addTrade(profession as VillagerProfession, villagerLevel as int, input1 as ItemStack, input2 as ItemStack, forSale as ItemStack, maxTrades as int, xp as int, priceMult as float = 1.0)
Adds a Villager Trade for two Items for an Item. An example being, giving a villager 2 diamonds and 2 dirt for an arrow.
script.zs
// CTVillagerTrades.addTrade(profession as VillagerProfession, villagerLevel as int, input1 as ItemStack, input2 as ItemStack, forSale as ItemStack, maxTrades as int, xp as int, priceMult as float = 1.0);
myCTVillagerTrades.addTrade(<profession:minecraft:farmer>, 1, <item:minecraft:diamond> * 2, <item:minecraft:dirt> * 2, <item:minecraft:arrow>, 5, 2, 0.05);

Parameters:

profession Type: VillagerProfession - What profession this trade should be for.
villagerLevel Type: int - The level the Villager needs to be.
input1 Type: ItemStack - The main ItemStack that is being given to the Villager.
input2 Type: ItemStack - The secondary ItemStack that is being given to the Villager.
forSale Type: ItemStack - What ItemStack is being sold (by the Villager).
maxTrades Type: int - How many times can this trade be done.
xp Type: int - How much Experience is given by trading.
priceMult (optional) Type: float - When this trade is discounted, how much should it be discounted by.

Default Value: 1.0

addTrade(profession as VillagerProfession, villagerLevel as int, trade as ItemListing)
Adds the specified VillagerTrades.ItemListing trade.
script.zs
// CTVillagerTrades.addTrade(profession as VillagerProfession, villagerLevel as int, trade as ItemListing);
myCTVillagerTrades.addTrade(<profession:minecraft:farmer>, 1, TreasureMapForEmeralds.create(1, <resource:minecraft:ruined_portal>, "display Name", <constant:minecraft:world/map/decorationtype:mansion>, 16, 8));

Parameters:

profession Type: VillagerProfession - What profession this trade should be for.
villagerLevel Type: int - The level the Villager needs to be.
trade Type: ItemListing - The trade to add.
addWanderingTrade(rarity as int, trade as ItemListing)
Adds the specific VillagerTrades.ItemListing trade to the Wandering Trader
script.zs
// CTVillagerTrades.addWanderingTrade(rarity as int, trade as ItemListing);
myCTVillagerTrades.addWanderingTrade(1, TreasureMapForEmeralds.create(1, <resource:minecraft:ruined_portal>, "display Name", <constant:minecraft:world/map/decorationtype:mansion>, 16, 8));

Parameters:

rarity Type: int - The rarity of the Trade. Valid options are 1 or 2. A Wandering Trader can only spawn with a single trade of rarity 2.
trade Type: ItemListing - The trade to add.
addWanderingTrade(rarity as int, emeralds as int, forSale as ItemStack, maxTrades as int, xp as int)
Adds a Wandering Trader Trade for emeralds for an Item. An example being, giving a Wandering Trader 2 emeralds for an arrow.
script.zs
// CTVillagerTrades.addWanderingTrade(rarity as int, emeralds as int, forSale as ItemStack, maxTrades as int, xp as int);
myCTVillagerTrades.addWanderingTrade(1, 16, <item:minecraft:diamond>, 16, 2);

Parameters:

rarity Type: int - The rarity of the Trade. Valid options are 1 or 2. A Wandering Trader can only spawn with a single trade of rarity 2.
emeralds Type: int - The amount of Emeralds.
forSale Type: ItemStack - What ItemStack is being sold (by the Wandering Trader).
maxTrades Type: int - How many times can this trade be done.
xp Type: int - How much Experience is given by trading.
addWanderingTrade(rarity as int, price as IItemStack, forSale as IItemStack, maxTrades as int, xp as int)
Adds a Wandering Trader Trade for emeralds for an Item. An example being, giving a Wandering Trader 2 emeralds for an arrow.
script.zs
// CTVillagerTrades.addWanderingTrade(rarity as int, price as IItemStack, forSale as IItemStack, maxTrades as int, xp as int);
myCTVillagerTrades.addWanderingTrade(1, <item:minecraft:dirt>, <item:minecraft:diamond>, 16, 2);

Parameters:

rarity Type: int - The rarity of the Trade. Valid options are 1 or 2. A Wandering Trader can only spawn with a single trade of rarity 2.
price Type: IItemStack - The ItemStack being given to the Wandering Trader.
forSale Type: IItemStack - What ItemStack is being sold (by the Wandering Trader).
maxTrades Type: int - How many times can this trade be done.
xp Type: int - How much Experience is given by trading.
removeAllTrades(profession as VillagerProfession, villagerLevel as int)
Removes all the trades for the given profession and villagerLevel
script.zs
// CTVillagerTrades.removeAllTrades(profession as VillagerProfession, villagerLevel as int);
myCTVillagerTrades.removeAllTrades(<profession:minecraft:farmer>, 1);

Parameters:

profession Type: VillagerProfession - hat profession to remove from.
villagerLevel Type: int - The level the Villager needs to be.
removeAllWanderingTrades(rarity as int)
Removes all wandering trades of the given rarity
script.zs
// CTVillagerTrades.removeAllWanderingTrades(rarity as int);
myCTVillagerTrades.removeAllWanderingTrades(myInt);

Parameters:

rarity Type: int - The rarity of the Trade. Valid options are 1 or 2. A Wandering Trader can only spawn with a single trade of rarity 2.
removeBasicTrade(profession as VillagerProfession, villagerLevel as int, forSale as IItemStack, price as IItemStack = <item:minecraft:air>, price2 as IItemStack = <item:minecraft:air>)
Removes a BasicTrade Villager trade. BasicTrades are trades that allow any item, to any other item. It is only really used for mod recipes and is not used for any vanilla villager trade.
script.zs
// CTVillagerTrades.removeBasicTrade(profession as VillagerProfession, villagerLevel as int, forSale as IItemStack, price as IItemStack = <item:minecraft:air>, price2 as IItemStack = <item:minecraft:air>);
myCTVillagerTrades.removeBasicTrade(<profession:minecraft:farmer>, 1, <item:minecraft:arrow>, <item:minecraft:stick>, <item:minecraft:emerald>);

Parameters:

profession Type: VillagerProfession - What profession this trade should be for.
villagerLevel Type: int - The level the Villager needs to be.
forSale Type: IItemStack - What ItemStack is being sold (by the Villager).
price (optional) Type: IItemStack

Default Value: <item:minecraft:air>

price2 (optional) Type: IItemStack

Default Value: <item:minecraft:air>

removeDyedArmorForEmeraldsTrade(profession as VillagerProfession, villagerLevel as int, buyingItem as Item)
Removes a Villager trade for Items for Dyed leather armor. An example being, giving a villager Leather Leggings and 3 Emeralds and getting a Blue Dyed Leather Leggings.
script.zs
// CTVillagerTrades.removeDyedArmorForEmeraldsTrade(profession as VillagerProfession, villagerLevel as int, buyingItem as Item);
myCTVillagerTrades.removeDyedArmorForEmeraldsTrade(<profession:minecraft:leatherworker>, 1, <item:minecraft:leather_chestplate>);

Parameters:

profession Type: VillagerProfession - What profession this trade should be for.
villagerLevel Type: int - The level the Villager needs to be.
buyingItem Type: ItemDefinition - The base ItemStack that a random Dye colour will be applied to. E.G. A leather chestplate with no effect applied.
removeEmeraldForItemsTrade(profession as VillagerProfession, villagerLevel as int, tradeFor as IItemStack)
Removes a Villager trade for Emeralds for Items. An example being, giving a villager 20 Wheat and getting an Emerald from the villager.
script.zs
// CTVillagerTrades.removeEmeraldForItemsTrade(profession as VillagerProfession, villagerLevel as int, tradeFor as IItemStack);
myCTVillagerTrades.removeEmeraldForItemsTrade(<profession:minecraft:farmer>, 1, <item:minecraft:potato>.definition);

Parameters:

profession Type: VillagerProfession - What profession this trade should be for.
villagerLevel Type: int - The level the Villager needs to be.
tradeFor Type: IItemStack - What ItemStack is being sold (by the Villager).
removeEnchantBookForEmeraldsTrade(profession as VillagerProfession, villagerLevel as int)
Removes a Villager trade for an Enchanted Book. An example being, giving a villager Emeralds and getting an Enchanted Book with a random Enchantment.
script.zs
// CTVillagerTrades.removeEnchantBookForEmeraldsTrade(profession as VillagerProfession, villagerLevel as int);
myCTVillagerTrades.removeEnchantBookForEmeraldsTrade(<profession:minecraft:librarian>, 1);

Parameters:

profession Type: VillagerProfession - What profession this trade should be for.
villagerLevel Type: int - The level the Villager needs to be.
removeEnchantedItemForEmeraldsTrade(profession as VillagerProfession, villagerLevel as int, buyingItem as IItemStack)
Removes a Villager trade for an Enchanted Item. An example being, giving a villager 3 Emeralds and getting an Enchanted Pickaxe.
script.zs
// CTVillagerTrades.removeEnchantedItemForEmeraldsTrade(profession as VillagerProfession, villagerLevel as int, buyingItem as IItemStack);
myCTVillagerTrades.removeEnchantedItemForEmeraldsTrade(<profession:minecraft:armorer>, 1, <item:minecraft:diamond_boots>);

Parameters:

profession Type: VillagerProfession - What profession this trade should be for.
villagerLevel Type: int - The level the Villager needs to be.
buyingItem Type: IItemStack - The ItemStack that the Villager is selling (including any NBT).
removeItemsAndEmeraldsToItemsTrade(profession as VillagerProfession, villagerLevel as int, sellingItem as IItemStack, buyingItem as IItemStack)
Removes a Villager trade for Emeralds and Items for Items. An example being, giving a villager 6 uncooked Cod and an Emerald and getting back 6 Cooked Cod.
script.zs
// CTVillagerTrades.removeItemsAndEmeraldsToItemsTrade(profession as VillagerProfession, villagerLevel as int, sellingItem as IItemStack, buyingItem as IItemStack);
myCTVillagerTrades.removeItemsAndEmeraldsToItemsTrade(<profession:minecraft:fisherman>, 1, <item:minecraft:cooked_cod>, <item:minecraft:cod>);

Parameters:

profession Type: VillagerProfession - What profession this trade should be for.
villagerLevel Type: int - The level the Villager needs to be.
sellingItem Type: IItemStack - What ItemStack is being given to the Villager.
buyingItem Type: IItemStack - The item that the Villager is selling.
removeItemsForEmeraldsTrade(profession as VillagerProfession, villagerLevel as int, sellingItem as IItemStack)
Removes a Villager trade for Items for Emeralds. An example being, giving a villager an Emerald and getting 4 Pumpkin Pies from the villager.
script.zs
// CTVillagerTrades.removeItemsForEmeraldsTrade(profession as VillagerProfession, villagerLevel as int, sellingItem as IItemStack);
myCTVillagerTrades.removeItemsForEmeraldsTrade(<profession:minecraft:farmer>, 1, <item:minecraft:apple>);

Parameters:

profession Type: VillagerProfession - What profession this trade should be for.
villagerLevel Type: int - The level the Villager needs to be.
sellingItem Type: IItemStack - What ItemStack is being given to the Villager.
removeSuspiciousStewForEmeraldTrade(profession as VillagerProfession, villagerLevel as int)
Removes a Villager trade for Suspicious Stew. An example being, giving a villager an Emerald and getting a bowl of Suspicious Stew back.
script.zs
// CTVillagerTrades.removeSuspiciousStewForEmeraldTrade(profession as VillagerProfession, villagerLevel as int);
myCTVillagerTrades.removeSuspiciousStewForEmeraldTrade(<profession:minecraft:farmer>, 1);

Parameters:

profession Type: VillagerProfession - What profession this trade should be for.
villagerLevel Type: int - The level the Villager needs to be.
removeTippedArrowForItemsAndEmeraldsTrade(profession as VillagerProfession, villagerLevel as int, potionStack as IItemStack, sellingItem as Item)
Removes a Villager trade for Items for an Item with a PotionEffect. An example being, giving a villager an Arrow and an Emerald and getting a Tipped Arrow with night vision.
script.zs
// CTVillagerTrades.removeTippedArrowForItemsAndEmeraldsTrade(profession as VillagerProfession, villagerLevel as int, potionStack as IItemStack, sellingItem as Item);
myCTVillagerTrades.removeTippedArrowForItemsAndEmeraldsTrade(<profession:minecraft:fletcher>, 1, <item:minecraft:tipped_arrow>, <item:minecraft:arrow>);

Parameters:

profession Type: VillagerProfession - What profession this trade should be for.
villagerLevel Type: int - The level the Villager needs to be.
potionStack Type: IItemStack - The base ItemStack that a random potion effect will be applied to. E.G. A tipped Arrow with no effect applied.
sellingItem Type: ItemDefinition - What ItemStack is being given to the Villager.
removeTrade(profession as VillagerProfession, villagerLevel as int, buying as IIngredient, selling as IIngredient, secondBuying as IIngredient = <item:minecraft:air>)
Removes the specified trade for the given profession and villagerLevel.
script.zs
// CTVillagerTrades.removeTrade(profession as VillagerProfession, villagerLevel as int, buying as IIngredient, selling as IIngredient, secondBuying as IIngredient = <item:minecraft:air>);
myCTVillagerTrades.removeTrade(<profession:minecraft:farmer>, 1, <item:minecraft:potato>, <item:minecraft:emerald>, <item:minecraft:air>);

Parameters:

profession Type: VillagerProfession - That profession to remove from.
villagerLevel Type: int - The level the Villager needs to be.
buying Type: IIngredient - The first item that you are giving to the villager.
selling Type: IIngredient - The item that the villager is selling to you.
secondBuying (optional) Type: IIngredient - The second item that you are giving to the villager. Will default to air if not provided.

Default Value: <item:minecraft:air>

removeTradesBuying(profession as VillagerProfession, villagerLevel as int, buying as IIngredient)
Removes all trades that have the specified item as the buying item for the given profession and villagerLevel.
script.zs
// CTVillagerTrades.removeTradesBuying(profession as VillagerProfession, villagerLevel as int, buying as IIngredient);
myCTVillagerTrades.removeTradesBuying(<profession:minecraft:farmer>, 1, <item:minecraft:potato>);

Parameters:

profession Type: VillagerProfession - That profession to remove from.
villagerLevel Type: int - The level the Villager needs to be.
buying Type: IIngredient - The first item that you are giving to the villager.
removeTradesBuying(profession as VillagerProfession, villagerLevel as int, buying as IIngredient, secondBuying as IIngredient)
Removes all trades that have the specified items as the buying items for the given profession and villagerLevel.
script.zs
// CTVillagerTrades.removeTradesBuying(profession as VillagerProfession, villagerLevel as int, buying as IIngredient, secondBuying as IIngredient);
myCTVillagerTrades.removeTradesBuying(<profession:minecraft:farmer>, 1, <item:minecraft:potato>, <item:minecraft:air>);

Parameters:

profession Type: VillagerProfession - That profession to remove from.
villagerLevel Type: int - The level the Villager needs to be.
buying Type: IIngredient - The first item that you are giving to the villager.
secondBuying Type: IIngredient - The second item that you are giving to the villager. Will default to air if not provided.
removeTradesSelling(profession as VillagerProfession, villagerLevel as int, selling as IIngredient)
Removes all trades that sell the specified item for the given profession and villagerLevel.
script.zs
// CTVillagerTrades.removeTradesSelling(profession as VillagerProfession, villagerLevel as int, selling as IIngredient);
myCTVillagerTrades.removeTradesSelling(<profession:minecraft:farmer>, 1, <item:minecraft:emerald>);

Parameters:

profession Type: VillagerProfession - That profession to remove from.
villagerLevel Type: int - The level the Villager needs to be.
selling Type: IIngredient - The item that the villager is selling to you.
removeTreasureMapForEmeraldsTrade(profession as VillagerProfession, villagerLevel as int)
Removes a Villager trade for a Map. An example being, giving a villager 13 Emeralds and getting a Map to a structure.
script.zs
// CTVillagerTrades.removeTreasureMapForEmeraldsTrade(profession as VillagerProfession, villagerLevel as int);
myCTVillagerTrades.removeTreasureMapForEmeraldsTrade(<profession:minecraft:cartographer>, 1);

Parameters:

profession Type: VillagerProfession - What profession this trade should be for.
villagerLevel Type: int - The level the Villager needs to be.
removeWanderingTrade(rarity as int, tradeFor as IIngredient)
Removes a Wandering Trader trade for Emeralds for Items. An example being, giving a Wandering Trader 2 Emeralds for an Arrow.
script.zs
// CTVillagerTrades.removeWanderingTrade(rarity as int, tradeFor as IIngredient);
myCTVillagerTrades.removeWanderingTrade(2, <item:minecraft:arrow>);

Parameters:

rarity Type: int - The rarity of the Trade. Valid options are 1 or 2. A Wandering Trader can only spawn with a single trade of rarity 2.
tradeFor Type: IIngredient - What ItemStack is being sold (by the Villager).