Script Compilation

ModularMC includes built-in TypeScript and JavaScript compilation using Esbuild. This allows you to write modern TypeScript code and have it automatically compiled and integrated into your addon.

Defining Scripts

Use the SCRIPTS export in your _map.ts file to specify which files should be compiled:

export const SCRIPTS = [
    "zombie_ai.ts",
    "zombie_events.js", 
    "utils/zombie_utils.ts"
];

Scripts are paths relative to the module directory:

📂 my_entity/
    ⚙️ _map.ts
    📄 zombie.behavior.json
    📄 zombie_ai.ts          # Script file
    📄 zombie_events.js      # Script file
    📂 utils/
        📄 zombie_utils.ts   # Nested script file

Compilation Process

ModularMC uses a project-based compilation approach that differs from some other script-compiling filters like gametests.

How ModularMC Script Compilation Works

ModularMC compiles scripts directly from your project directory, not from the temporary location that Regolith creates when running filters. It performs the following steps:

  1. Collects paths to all scripts from all modules in the temporary location

  2. Resolves script paths to their corresponding files in the project directory

  3. Runs Esbuild compilation using files from the project

  4. Exports compiled bundle to both the temporary location and optionally to buildPath (if specified)

This approach results in faster compilation because the node_modules folder is not copied to the temporary location. However, a crucial implication is that changes made to your TypeScript files by other Regolith filters will not affect the compilation; ModularMC always compiles from your original project files.

Esbuild Configuration

The detail of configuration is described in the configuration section of the documentation.

Script Dependencies

ModularMC allows you to define dependencies in the deno.json file. If you put the deno.json file in the root of your project, ModularMC will use it to resolve dependencies. Adding it is not required, but without it you will have to limit yourself to the built-in moudles accessible to Minecraft.