Documentation

Learn how to install and use LiquidBounce with our comprehensive guides

TypeScript Support

Type definitions for the Script API are published to npm as @ccbluex/liquidbounce-script-api, one version per LiquidBounce release. They cover LiquidBounce, Minecraft, the JVM classes the client ships with and the script globals (registerScript, mc, Client, ...). Scripts still need the Script API add-on.

The definitions are generated by reflection and aim at autocompletion. Some generated files do not parse, so tsc prints errors from inside the package; it still writes the JavaScript.

Setup

mkdir my-scripts && cd my-scripts
npm init -y
npm install --save-dev typescript @ccbluex/[email protected]

Install the version that matches your client. The package is about 100 MB unpacked.

tsconfig.json:

{
    "compilerOptions": {
        "target": "es2020",
        "module": "commonjs",
        "outDir": "dist",
        "strict": false,
        "inlineSourceMap": true,
        "inlineSources": true,
        "types": ["@ccbluex/liquidbounce-script-api"]
    },
    "include": ["src/**/*"]
}

Only CommonJS output is supported. The inline source maps let the debugger show and break in the TypeScript source.

Writing a script

src/example.ts:

import { BlockPos } from "@ccbluex/liquidbounce-script-api/net/minecraft/core/BlockPos";

const script = registerScript.apply({
    name: "Example",
    version: "1.0.0",
    authors: ["My Name"]
});

script.registerModule({
    name: "Example",
    category: "Misc",
    description: "Prints the block below the player."
}, (mod) => {
    mod.on("enable", () => {
        const below: BlockPos = mc.player.blockPosition().below();
        Client.displayChatMessage(`Below you: ${mc.level.getBlockState(below)}`);
    });
});

Imports from @ccbluex/liquidbounce-script-api/ become Java.type(...) calls in the client, so the scripts folder needs no node_modules. Give every file at least one import or export {}, otherwise TypeScript treats it as a global script and files clash with each other.

Compile with npx tsc --watch, copy dist/ into the scripts folder (.script browse) or point outDir there, then .script reload.

Limitations

  • Kotlin, Java and TypeScript types do not map one to one. Interfaces with static members, some overloads and some generics come out wrong; cast with as unknown as T where the compiler disagrees with the runtime.
  • Classes the generator cannot reflect on are typed as any.

Problems with the definitions go to the Script API add-on.