JimEngine

object JimEngine

The heart of JIM. Compiles each module's TypeScript to JVM bytecode (via JimCompiler), invokes its main() entry point, and dispatches triggers by invoking the named exported function through a cached MethodHandle. No V8, no JNI on the dispatch path.

Minecraft-free on purpose, so the whole pipeline can be exercised from a plain JVM test.

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Receives every console line (chat, Jim.log, errors). The console window registers here.

Link copied to clipboard
Link copied to clipboard

Invoked (on the JS/render thread) after modules load or reload, so the client can re-register script commands with brigadier (commands from post-startup loads are otherwise "unknown").

Link copied to clipboard

Callbacks run on reload/shutdown so MC-side state (e.g. HUD displays) can be cleared.

Link copied to clipboard

Class loader scripts compile against (so import { ChatLib } from 'ratph6.jim.api' resolves).

Link copied to clipboard

Functions

Link copied to clipboard
fun bootstrap(modulesDir: Path, scriptClassLoader: ClassLoader)
Link copied to clipboard
Link copied to clipboard
fun chat(message: String)
Link copied to clipboard
fun clearTimer(id: Int)
Link copied to clipboard
fun consoleLog(level: String, message: String)
Link copied to clipboard
Link copied to clipboard
fun dispatch(type: String, vararg args: Any?): Boolean

Fire all triggers of type. Returns true if any callback cancelled the event. JS thread only.

Link copied to clipboard
fun dispatchAsync(type: String, vararg args: Any?)

Dispatch from any thread (e.g. a mixin on the netty/packet thread): marshalled onto the JS thread, so it's observe-only (the originating call has already proceeded — no inline cancel). Cheaply skips work when no script listens for type, so high-volume sources (packets) are free until something registers.

Link copied to clipboard

Run a client command registered by a script (by name), passing the raw args array.

Link copied to clipboard
fun emitEvent(name: String, args: Array<out Any?>)

Emit a custom event to scripts listening via Jim.on(name, fn).

Link copied to clipboard
Link copied to clipboard
fun evaluate(code: String)

Run a one-off TypeScript snippet (used by /jim eval) on GraalJS, so it gets real ECMAScript (arrays, closures, let, JSON). The JIM API objects (Jim, Event, ChatLib, ...) are bound as globals by GraalRuntime, so no import line is needed.

Link copied to clipboard
fun fireChat(type: String, formatted: String, unformatted: String): Boolean
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
inline fun onJsThread(crossinline block: () -> Unit)
Link copied to clipboard
fun pump()
Link copied to clipboard
fun recentErrors(n: Int = 10): List<JimError>
Link copied to clipboard

A snapshot of recent console lines (for replay when the console opens).

Link copied to clipboard
fun recordError(where: String, detail: String)

Record a script error from a string detail (origin already known).

fun recordError(where: String, t: Throwable)

Record a script error from a Throwable, capturing the full cause chain and stack trace.

Link copied to clipboard
fun registerTrigger(type: String, callback: Any): TriggerMeta
Link copied to clipboard
fun reload()
Link copied to clipboard
fun scheduleTimer(callback: Any, ms: Int, repeat: Boolean): Int
Link copied to clipboard
fun shutdown()
Link copied to clipboard
fun unloadModule(name: String)