JavaScript Scripting
Carpet (NeoForge) runs server-side JavaScript apps through Rhino. This guide covers Carpet 1.0-beta.2 for Minecraft 26.1.2.
Enable scripting
- Install the matching Rhino mod alongside Carpet on the dedicated server or in the NeoForge instance that runs the single-player world.
- Start the server or restart the game.
- Run
/script run mc.entities.player('all').lengthwith a source that can run JavaScript. It returns the number of online players.
Without Rhino, /script is unavailable. Other Carpet features still work. commandScript controls access to /script and commandScriptACE controls direct evaluation and app management. The default for commandScriptACE is ops.
Choose how to run your code
| Goal | Where to start |
|---|---|
| Try a short expression in-game | /script run mc.server.current_dimension() |
| Keep code in a file, expose a command, or reuse a library | Apps and commands |
| Run code when a player joins or on a later tick | Events and scheduling |
| Find a world, entity, inventory, server, or scoreboard function | API reference |
Migrate from Scarpet
Rewrite .sc apps as .js and .scl libraries as .lib.js. Use JavaScript variables, arrays, objects, control flow, and functions. In callbacks, pass a JavaScript function where the API needs to evaluate code later or in a different context.
Minecraft-facing functions generally retain their Carpet names. For example, use mc.entities.query(player, "pos") for a player's coordinates. The API reference explains how arrays, plain objects, and Minecraft handles cross the API boundary.