Overview#
Rhino is a foundational library mod developed by LatvianModder, specifically designed to serve as the scripting engine for the KubeJS ecosystem. It embeds a fork of the Mozilla Rhino JavaScript engine directly into the Minecraft environment, allowing for the execution of complex scripts that can modify game logic, register new content, and automate server management.
As a library mod, Rhino does not add traditional survival content like ores or biomes by itself. Instead, it provides the technical framework necessary for other mods—primarily KubeJS—to function. It replaces the Nashorn JavaScript engine that was removed from Java in version 15, ensuring that modern Minecraft versions (1.16.5 through 1.21+) maintain high-performance scripting support with full ES6 compatibility.
Technical Architecture#
Rhino works by converting JavaScript code into Java classes at runtime. This allows scripts to interact with Minecraft's underlying Java code with minimal performance overhead. The mod utilizes the Architectury API to ensure cross-platform compatibility between Forge, Fabric, and NeoForge loaders.
Core Engine Features
| Feature | Description |
|---|---|
| ES6 Support | Supports modern JavaScript syntax including arrow functions, classes, and template literals. |
| Java Interop | Seamlessly wraps Minecraft and Forge/Fabric classes into JavaScript objects. |
| Class Mapping | Automatically handles obfuscated mappings, allowing developers to use clean names in scripts. |
| Reflection Optimization | Uses optimized reflection to access private fields and methods within the Minecraft source. |
| No Nashorn Dependency | Operates independently of the built-in Java scripting engine, preventing crashes on newer Java versions. |
Scripting Mechanics#
Rhino categorizes scripts into three distinct types based on when and where they are executed. Upon the first run, the mod generates a kubejs/ folder in the Minecraft directory containing these subdirectories:
Script Types
-
Startup Scripts (
startup_scripts/)- Execution: Loaded once during the initial game launch.
- Purpose: Used for registering new blocks, items, and entities. These cannot be fully reloaded without a game restart because they interact with the game's registry system.
- Reloading: Use
/kubejs reload startup_scripts(limited functionality).
-
Server Scripts (
server_scripts/)- Execution: Loaded when a world or server starts.
- Purpose: Used for modifying recipes, loot tables, tags, and handling server-side events (e.g., player login, block breaking).
- Reloading: Use the
/reloadcommand to refresh all data and scripts.
-
Client Scripts (
client_scripts/)- Execution: Loaded on the player's local machine.
- Purpose: Used for visual changes, tooltips, JEI/REI integration, and asset modification.
- Reloading: Use
F3 + Tor/kubejs reload client_scripts.
Content Registration Framework#
While Rhino is a library, it provides the API that allows users to define custom content. Through the Rhino engine, developers can register the following components:
Custom Blocks and Items
Developers can define properties for new blocks and items using JavaScript objects. The engine handles the conversion to Minecraft's internal registry.
Supported Block Properties:
- Hardness and Resistance
- Light Level (Luminance)
- Tool Requirements (Pickaxe, Axe, etc.)
- Custom Shapes and Hitboxes
- Sound Types (Stone, Wood, Grass)
Supported Item Properties:
- Max Stack Size
- Rarity (Common, Uncommon, Rare, Epic)
- Burn Time (Fuel efficiency)
- Tool Level and Attack Speed
- Custom Tooltips and Glow Effects
Entity and Mob Handling
Rhino enables the creation of custom entity handlers. While it doesn't add a "Rhino Mob," it allows scripts to define behaviors for existing or new entities, including:
- Spawn Logic: Controlling where and when mobs appear.
- Drops: Modifying loot tables dynamically based on the killer or weapon used.
- Stats: Adjusting health, movement speed, and follow range via attribute modifiers.
Recipe and Data Management#
Rhino's primary use case in modpacks is the manipulation of recipes. It supports any mod that utilizes standard Minecraft datapack recipes (JSON format).
Recipe Modification Capabilities
- Addition: Create new shaped, shapeless, smelting, blasting, or smoking recipes.
- Removal: Remove recipes by ID, output item, or input ingredient.
- Transformation: Modify ingredients during crafting (e.g., damaging a tool instead of consuming it, or returning an empty bucket).
- Mod Support: Native support for complex mods like Create, Mekanism, and Thermal Series through specialized addon scripts.
Tag Management
Rhino allows for the dynamic editing of Tags (Item Tags, Block Tags, Fluid Tags, and Entity Type Tags). This is essential for cross-mod compatibility, ensuring that "Copper Ingots" from different mods are treated as the same item in recipes.
Commands and Utilities#
Rhino adds several administrative commands to manage the scripting environment. These are primarily accessed through the /kubejs base command.
| Command | Function |
|---|---|
/kubejs reload server_scripts |
Reloads only the server-side scripts without reloading the entire datapack. |
/kubejs reload client_scripts |
Reloads client-side scripts and assets. |
/kubejs reload startup_scripts |
Attempts to reload startup logic (requires caution). |
/kubejs wiki |
Generates a local dump of available JS methods and classes for documentation. |
/kubejs inventory |
Dumps the player's inventory data to the console for script debugging. |
Debugging and Logs
All script errors and print statements are directed to the logs/kubejs/ folder. The server.txt, client.txt, and startup.txt files provide detailed stack traces if a script fails to compile or execute, making it easier to troubleshoot syntax errors in the Rhino engine.