MerchantJS

MerchantJS

This mod is an addon for KubeJS, expanding its functionality in the trading system.

by
7.1K Downloads
forgeeconomyutility
Rent Server with this Mod

About this Mod

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!

Available Versions

MerchantJS 1.0.0release
MC 1.20.1, 1.20.2, 1.20.3, 1.20.4, 1.20.5, 1.20.6forge
October 26, 2025

How to Install MerchantJS on Your Server

1

Order Server

Order a Minecraft Java server with at least 3 GB RAM (4 GB recommended).

2

Set forge Loader

In the panel under "Egg", select the forge loader and matching Minecraft version (1.20.6).

3

Install Mod

Open the mod browser in the dashboard and search for "MerchantJS". Click "Install" – done! Alternatively, upload the .jar via SFTP to the /mods folder.

Compatibility

Mod Loaders

forge

Minecraft Versions

1.20.6, 1.20.5, 1.20.4 (+3 more)

Server-side

Required

Recommended RAM

4 GB(min. 3 GB)

Frequently Asked Questions

MerchantJS server crashes on startup – what to do?

Most common cause: wrong forge version or insufficient RAM. Check the server log (latest.log) for "OutOfMemoryError" or "Mixin" errors. With Mado Hosting: ensure at least 3 GB RAM is allocated and the loader matches the mod version (1.20.6). You can switch loaders with one click in the panel.

Is MerchantJS compatible with forge?

MerchantJS officially supports forge for Minecraft 1.20.6, 1.20.5, 1.20.4. The Mado dashboard automatically detects incompatible loader combinations.

Server lagging with MerchantJS – how to optimize performance?

Recommended RAM: 4 GB (per 8 players). Use /spark profiler to check if MerchantJS consumes the most tick time. Common fixes: reduce server view-distance to 8-10, install "performant" or "starlight" as supplementary mods on Forge. With Mado Hosting, your server runs on NVMe SSDs with dedicated CPU cores for minimal latency.

Rent Modded Server

Install MerchantJS with just one click on your server.

Recommended RAM
4 GBab €8/mo
Min. 3 GB | +1 GB pro 8 Spieler
Create Server Now
1-Click Mod Install
NVMe SSD Storage
DDoS Protection included

Details

License
GNU General Public License v3.0 only
Server-side
Required

Supported Versions

1.20.61.20.51.20.41.20.31.20.21.20.1