MerchantJS
This mod is an addon for KubeJS, expanding its functionality in the trading system.
介绍
MerchantJS
This mod is an addon for KubeJS, expanding its functionality in the trading system.
Create Custom Trades Anywhere
This mod allows you to initiate trades anywhere — trade with pigs, with End Stone, with Enchanted Golden Apples, or even out of thin air!
// server_scripts
ItemEvents.entityInteracted(event => {
// Check if the interacted entity is a pig
if (event.getTarget().type === "minecraft:pig") {
// Create a complete trade offer
let offer0 = MerchantJSUtils.createMerchantOffer({
buy: Item.of("minecraft:potato").toNBT(),
buyB: Item.of("minecraft:bread").toNBT(),
sell: Item.of("minecraft:stone").toNBT(),
uses: 0,
maxUses: 50,
xp: 5,
priceMultiplier: 0,
demand: 0
});
// Create a simple trade offer
let offer1 = MerchantJSUtils.createMerchantOffer({
buy: Item.of("minecraft:beef").toNBT(),
sell: Item.of("minecraft:egg").toNBT()
});
// Open a custom trading GUI with the given player, title, and offers
MerchantJSUtils.openMerchant(
event.player,
Component.translatable("Little Piggy’s Cartoon House"),
[offer0, offer1]
);
}
});
The above example lets players trade with pigs, with a fully customizable trading GUI!
And if you need deeper customization — read on.
Selective Trade Availability
Let’s first explain the meaning of each parameter:
let offer0 = MerchantJSUtils.createMerchantOffer({
buy: Item.of("minecraft:potato").toNBT(), // Input item A (required)
buyB: Item.of("minecraft:bread").toNBT(), // Input item B (optional, defaults to empty)
sell: Item.of("minecraft:stone").toNBT(), // Output item (required)
uses: 0, // Number of times used (optional, default 0)
maxUses: 50, // Maximum uses (optional, default 99)
xp: 5, // Experience reward (optional, default 0)
priceMultiplier: 0, // Price fluctuation multiplier (optional, default 0)
demand: 0 // Initial demand value (optional, default 0)
});
Setting maxUses to 0 will make the trade appear unavailable.
Now combine it with this event for dynamic trade control:
// client_scripts
MerchantEvents.switchTrade(event => {
if (event.titleKey == "Little Piggy’s Cartoon House") {
// Check if it’s the pig’s trading window (works with vanilla ones too!)
if (event.getOffer().getMaxUses() == 0) {
Client.player.tell("This trade is locked...");
}
}
});
With this, you can selectively enable or disable trades, which is perfect for stage-based gameplay or progression systems.
Vanilla Trade Compatibility
Vanilla trading already has many mechanics.
MerchantJS mainly focuses on creating additional trades easily.
For features like restocking, experience, demand, or price fluctuation — you’ll need to handle those yourself.
At minimum, you’ll need a place to store trade-related data (like inventory or stock info),
since each call to openMerchant defines the offers anew.
Fortunately, KubeJS’s persistentData works great for this.
Then, all that’s left is triggering data refresh when needed.
// server_scripts
MerchantEvents.afterTrade(event => {
event.player.tell(`Thank you for purchasing ${event.getOffer().result.id}! Come again soon!`);
event.player.addXP(event.getOffer().xp);
});
This event fires after any trade occurs — and works for vanilla trades too!
If you want to trigger additional actions after trading, this is the place to do it.
As for restocking — just check the time interval whenever you open the trade window.
Future Plans
None for now — but feel free to make a wish!
常见问题
MerchantJS 支持哪些 Minecraft 版本?
MerchantJS 支持 Minecraft Java 版 1.20.1–1.20.6,共 6 个版本,可用的加载器:Forge。下载时注意选择和你游戏版本一致的文件。
MerchantJS 怎么安装?
先用 PCL2 或 HMCL 启动器安装对应版本的 Forge,再把下载的 .jar 文件放进游戏目录的 mods 文件夹,重新启动游戏即可。开启了版本隔离的,mods 文件夹在 versions/版本名 下面。运行环境:客户端和服务端都要装。
MerrySnow 的其他作品
查看全部 →TaCZ addon
一个为 TaCZ 提供更完善配件管理功能的扩展模组。
One Enough Lib
用于简化OE系列开发的前置库
One Enough Item
使用OEI,你可以轻松将重复物品替换为单一指定代表物品。
Moves Like Mafuyu
A lightweight action-oriented mod designed to optimize movement experience during exploration and building.
评论
登录后评论和评分