Modular Machinery Reborn · Explained · Advanced
Modular Machinery Reborn KubeJS Guide: Scripting Custom Recipes
Modular Machinery Reborn is an empty canvas until you populate your custom multiblocks with functional processing rules. In this guide, you will learn how to write KubeJS server scripts to dynamically inject complex recipes into your machines without writing verbose raw JSON files. Mastering this allows you to balance processing ticks, combine item, fluid, and energy inputs, and design probability-based byproduct systems for an advanced modpack experience.
What you need
- Modular Machinery Reborn installed
- KubeJS installed
- A global datapack loader (such as Paxi or Open Loader) or an active world save
- At least one defined custom machine with a valid Registry ID (e.g., modular_machinery_reborn:arc_furnace)
- A physical multiblock built in-game using Machine Casings, a Machine Controller, and tiered Input/Output Buses and Hatches for testing
- A code editor (like VS Code) to edit your .js script files
Step by step
1Set Up the KubeJS Server Script
Navigate to your Minecraft instance folder and open the kubejs/server_scripts directory. Create a new file named mmr_recipes.js and open it in your code editor. Begin by calling the standard KubeJS recipe event listener: ServerEvents.recipes(event => { ... }); which acts as the entry point for injecting custom data during server reload.
Tip: Keep your Modular Machinery Reborn scripts in a dedicated file rather than mixing them with standard crafting table tweaks to make debugging syntax errors much easier.
2Initialize the Machine Recipe Builder
Inside the event block, access the Modular Machinery Reborn recipe namespace by calling event.recipes.modular_machinery_reborn.machine_recipe('namespace:machine_id', ticks). The first parameter must match the exact registry name of the custom multiblock you created, and the second integer sets the total base duration of the craft in game ticks (where 20 ticks equal 1 second).
Tip: Chain .id('custom_pack:unique_recipe_name') at the very end of your builder to prevent KubeJS from generating random hash IDs, which helps if you need to overwrite or reference the recipe later.
3Add Item Inputs and Outputs
Chain requirement methods onto your recipe builder to demand physical items from your multiblock's Item Input Buses. Use .requireItem('2x minecraft:iron_ingot') for inputs and .produceItem('minecraft:steel_ingot') for outputs that will be routed to the Item Output Bus. You can chain multiple item calls if your recipe requires several distinct catalysts or reagents.
Tip: You can pass item tags instead of specific items by using the # prefix inside your ingredient string, allowing flexible ore dictionary inputs.
4Configure Fluid Requirements
To make your machine consume or generate liquids through its Fluid Input and Output Hatches, chain .requireFluid(Fluid.of('minecraft:lava', 500)) or .produceFluid(Fluid.of('minecraft:water', 1000)). The integer represents the volume in millibuckets (mB) consumed or produced for the entire recipe cycle. Ensure the volume does not exceed the maximum capacity of the specific hatch tier installed on your multiblock.
Tip: Always verify exact fluid registry names in-game using JEI with advanced tooltips enabled (F3 + H).
5Define Per-Tick Energy Consumption
Powering your multiblock requires pulling Forge Energy (FE) from an Energy Input Hatch. Chain .requireEnergy(100) or .requireEnergyPerTick(100) depending on your version's builder syntax to drain power during the active processing state. If you are creating a custom generator multiblock, use the corresponding produce method to push power into an Energy Output Hatch.
Tip: Balance your energy per tick against the transfer rate limits of your Tiny, Small, or Reinforced Energy Hatches so the recipe does not stall mid-process.
6Implement Chance-Based Outputs and Inputs
To add rng-based byproducts or non-consumable catalysts, pass a float value between 0.0 and 1.0 as an optional chance argument to your item or fluid methods. For example, .produceItem('minecraft:slag', 0.25) gives a 25% chance to yield slag at the end of the cycle. Conversely, setting a 0.0 consumption chance on an input requirement turns that item into a permanent catalyst that must be present in the Tiny or Normal Input Bus without being destroyed.
Tip: Check your JEI recipe preview after reloading to verify that the percentage text appears correctly over the item slot.
7Format the JEI Progress Bar Alignment
Modular Machinery Reborn dynamically renders recipe layouts in JEI, which can sometimes look cramped if you have six different inputs. You can adjust the visual position of the progress arrow or recipe elements using builder properties like .progressX(x) and .progressY(y) if your current mod version supports layout offsets. Run the /kubejs reload server_scripts and /reload commands in-game to compile your script and verify the recipe inside the Machine Controller GUI.
Tip: Check the kubejs/logs/server.log file immediately after reloading if your recipe fails to show up in JEI.
How it works
Under the hood, Modular Machinery Reborn relies on Minecraft's native Datapack RecipeManager to load machine processes. When you write a KubeJS script, you are not changing how the machine ticks; instead, KubeJS intercepts the server datapack reload phase and dynamically compiles your JavaScript method chains into virtual JSON recipe objects in memory. This bypasses the need to manage hundreds of individual JSON files in a datapack loader while yielding the exact same in-game performance.
When a built multiblock forms around a Machine Controller, it scans all attached buses and hatches and caches their inventories. On each recipe check, the controller evaluates your scripted requirements sequentially. Instant requirements like items and fluids are checked at the start of the cycle (and outputs are checked for available space in the Output Buses), while continuous requirements like Energy Per Tick are evaluated every single tick for the duration you defined. If an Energy Input Hatch runs dry on tick 150 of a 200-tick recipe, the controller halts progress or resets depending on the machine's failure configuration.
Chance logic is resolved by the controller at the exact moment the requirement phase triggers. Input consumption chances are rolled during the initial recipe start—if a catalyst rolls a 'do not consume' result, the item stack remains untouched in the Input Bus while the machine enters its working state. Output production chances are rolled on the final completion tick right before the controller pushes items into the Item Output Bus.
Common mistakes
- Mismatched Machine Registry IDs: Passing an invalid or misspelled machine ID as the first argument in the recipe builder will cause the recipe to silently fail or bind to a non-existent machine. Always double-check the exact namespace and ID defined in your machine creation file.
- Exceeding Hatch Tier Capacities: Writing a recipe that demands 16,000 mB of fluid at once when the player's multiblock only uses a Tiny Fluid Input Hatch (which holds much less) makes the recipe impossible to start. Either lower the requirement or add multiple/higher-tier hatches to the multiblock structure.
- Confusing Total Energy with Per-Tick Energy: Draining 10,000 FE per tick over 200 ticks requires 2,000,000 FE total. Always check your JEI recipe view after scripting to confirm whether your method call registered as a flat cost or a per-tick drain.
- Placing Scripts in Client or Startup Folders: Recipe events exclusively fire on the server side. Putting your mmr_recipes.js file inside client_scripts or startup_scripts will result in KubeJS throwing an unknown event error.
FAQ
Why does my recipe show up in JEI, but the Machine Controller refuses to start crafting?
This usually happens when your Output Buses or Hatches are missing or too small to hold the recipe results, or when your Input Hatch tier cannot supply the required FE/t. Check the Machine Controller GUI status message to see which requirement is failing.
Can I create the multiblock structure itself using KubeJS instead of JSON?
Yes, Modular Machinery Reborn supports KubeJS integration for both machines and recipes. However, machine structure registration happens during a different event lifecycle than ServerEvents.recipes, so consult the mod's test KubeJS scripts for the exact machine builder event name for your mod version.
How do I reload my KubeJS recipe changes without restarting the entire game?
Save your script file, then run the /reload command in-game. This forces Minecraft to re-evaluate all datapacks and KubeJS server scripts, updating the Machine Controller logic and JEI displays within a few seconds.
How can I require multiple separate stacks of the same item without them merging?
Chain two separate .requireItem() calls in your recipe builder. Be aware that the player will need enough inventory slots across their installed Item Input Buses to hold the separated stacks.
By leveraging KubeJS server scripts with Modular Machinery Reborn, you can rapidly prototype, balance, and scale intricate multiblock processing chains using clean JavaScript method chaining instead of tedious raw JSON files.