Skip to main content

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​

  1. Install the matching Rhino mod alongside Carpet on the dedicated server or in the NeoForge instance that runs the single-player world.
  2. Start the server or restart the game.
  3. Run /script run mc.entities.player('all').length with 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​

GoalWhere 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 libraryApps and commands
Run code when a player joins or on a later tickEvents and scheduling
Find a world, entity, inventory, server, or scoreboard functionAPI 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.