Overview

What this is

Vanilla Joban Client Mod (JCM) lets resource packs write dynamic display scripts in JavaScript. The Yanyang fork adds C++ native scripting on top: scripts are compiled into native shared libraries (.dll / .so / .dylib) that the mod loads in game and drives frame by frame.

C++ and JS scripts can be mixed within the same declaration entry and rendered side by side. The mod detects the language automatically from file characteristics โ€” .js is JavaScript; anything else is parsed as a C++ module. Each side captures its own draw commands and replays them independently, without interfering with the other.

๐Ÿงฉ

Same script model

The create / render / dispose lifecycle and per-instance persistent state are exactly the same as JS; snapshot wrappers line up with the JS Wrappers field by field.

โšก

Zero-JNI transport

Java โ†” C++ communicates over a shared-memory polling plane (any JDK โ‰ฅ 16) or Panama FFM (JDK 22+), never through JNI; just one host crossing per frame per instance.

๐Ÿ–ฅ๏ธ

Native bridges for 8 platforms

windows-x64 / windows-arm64 / linux-x64 / linux-arm64 / android-arm64 / macos-x64 / macos-arm64 / ios-arm64 are all bundled in the jar and matched automatically by system architecture.

๐Ÿ›ก๏ธ

Crash isolation

A script crash disables only the faulty module and leaves a single log line; the game process is unaffected. C++ exceptions thrown inside the module are intercepted by the same crash guard.

The journey of a frame

Resource packmtr_custom_resources.json declarations
natives/<platform>/ library files
โ†’
JCM host (Java)Discovers modules ยท allocates state blocks
Serializes compact snapshots every frame
Transport (zero JNI)Shared-memory polling plane ยท Panama FFM plane
Your C++ modulemtrCreate โ†’ mtrRender โ†’ mtrDispose
Reads snapshots ยท writes draw records
โ†’
Replay the drawsText / textures / models / sounds
The same render path as JS scripts
Data flows to the right: the snapshot (POD structs + a string pool) enters the module; the module writes a flat stream of draw records into the five output arenas, which the host replays through the same code path as JS. Drawing, fonts, and pixels all stay on the native side โ€” snapshot marshaling is the only mandatory Java crossing each frame.

A PIDS script in fifteen lines

examples/pids_arrivals.cpp โ€” arrival display
#include <mtr/script.hpp>

struct ArrivalState {};

struct ArrivalDisplay : mtr::PidsScript<ArrivalState> {
    static constexpr auto ID = "example:arrivals";

    void render(mtr::PidsContext& ctx, ArrivalState&, const mtr::Pids& pids) override {
        for (int row = 0; row < pids.rows(); row++) {
            if (pids.is_row_hidden(row)) continue;
            std::string text = pids.get_custom_message(row).str();
            if (text.empty() && row < pids.arrivals().size())
                text = pids.arrivals().at(row).destination().str();
            if (!text.empty())
                mtr::Text::create().text(text.c_str())
                    .pos(2, row * 10.0 + 2).size(pids.width() - 4, 9).draw(ctx);
        }
    }
};

MTR_REGISTER_PIDS_SCRIPT(ArrivalDisplay)

No JNI, no reflection, no per-call boxing โ€” pids.rows() and arrivals().at(i).destination() are plain memory reads over a compact snapshot.

When to choose C++

ScenarioRecommendation
High-resolution LCDs / dot-matrix screens repainting large numbers of pixels every frameC++ Gfx2D software rasterizer + dirty-rectangle uploads; pixels never cross the JVM
Heavy string processing / per-frame sorting / mathC++ Native computation, zero allocations
Needs to call lots of Java APIs (networking, files, sound managers)Either Both sides reach the same set of public objects through Api
Simple one-off display logicJS No toolchain needed; faster iteration

Compatibility

ItemRequirement
Minecraft1.17.1 โ€“ 1.20.4 (Fabric / Forge)
PrerequisitesMinecraft Transit Railway 4.0.5+ (required); the Fabric build also needs Fabric API
Java16 or newer; 22+ automatically enables the end-to-end zero-JNI FFM plane
ABIThe host accepts ABI 6โ€“13 modules; the current SDK builds ABI 13
ToolchainC++17; MSVC / GCC / Clang; CMake โ‰ฅ 3.16 (recommended)

Documentation contents