Customizing MoLang Scripts & Animations
Relevant source files
The following files were used as context for generating this wiki page:
The HoloPrint system utilizes Minecraft's MoLang scripting language to manage dynamic holograms within Resource Packs. MoLang allows the resource pack to handle logic such as layer switching, transparency adjustments, and block validation without the need for Behavior Packs or external mods. This is achieved by injecting generated scripts into Armor Stand entities and Player render controllers during the pack generation process.
Customization is driven by the web interface, which maps user-defined settings (like item criteria for controls) into MoLang variables and state machine transitions.
Script Generation Pipeline
The generation of MoLang scripts occurs primarily in the makePack function. The system takes configuration objects and converts them into MoLang strings that are then embedded into the JSON files of the resource pack.
Variable Injection Logic
The application uses helper utilities like functionToMolang and itemCriteriaToMolang to translate JavaScript logic and configuration into a format compatible with Minecraft's client-side engine. Key variables include:
v.hologram.rendering: Toggles the visibility of the structure.v.hologram.layer: Tracks the currently selected Y-level.v.hologram.structure_index: Identifies which structure in a multi-structure pack is being displayed.v.hologram.layer_mode: Determines if a single layer or all layers below the current index are shown.
Sources: src/HoloPrint.js:316-339, src/index.js:304-320
Animation Controllers and State Machines
HoloPrint generates complex Animation Controllers to manage the state of the hologram. These controllers act as state machines, transitioning based on MoLang expressions that evaluate player interactions or internal variables.
Layer Transition Logic
Layer management is handled by makeLayerAnimations. It creates animation states for every Y-level in the structure. The transitions between these states are controlled by the v.hologram.layer variable and the v.hologram.layer_mode enum.
| State Name | Transition Condition | Action |
|---|---|---|
default | v.hologram.layer == -1 | Show full structure |
l_{y} | v.hologram.layer == y && mode == SINGLE | Isolate specific layer |
l_{y}- | v.hologram.layer == y && mode == ALL_BELOW | Show layer and those below |
Bounding Box and Validation Particles
The system dynamically generates particle effect scripts to provide visual feedback.
- Bounding Box: Controlled via
addBoundingBoxParticles, which uses MoLang to set the size (v.size), direction (v.dir), and color (v.r,v.g,v.b) of the outline based on the structure dimensions. - Block Validation: The
addBlockValidationParticlesfunction creates states that trigger particles only whenv.hologram.validatingis true and the specific block coordinates match the user's position.
Sources: src/HoloPrint.js:538-608, src/HoloPrint.js:615-645
In-Game Player Controls
To allow players to interact with the hologram, HoloPrint patches the vanilla player.render_controllers.json. This is a specialized technique that allows passing data from the player to the hologram entity by utilizing MoLang variables within the texture or material fields of the player's render controller.
Control Item Mapping
The ItemCriteria system allows users to define which items (by ID or Tag) trigger specific actions.
Action Configuration Table
These controls are defined in DEFAULT_PLAYER_CONTROLS and can be overridden in the UI.
| Control Action | Default Item | MoLang Purpose |
|---|---|---|
TOGGLE_RENDERING | Brick | Toggles v.hologram.rendering |
CHANGE_LAYER | Leather | Increments v.hologram.layer |
MOVE_HOLOGRAM | Stick | Adjusts offset variables |
ROTATE_HOLOGRAM | Copper Ingot | Modifies v.hologram.rotation |
TOGGLE_VALIDATING | Iron Ingot | Enables block check particles |
Sources: src/HoloPrint.js:25-50, src/HoloPrint.js:724-746, src/index.html:132-154
Implementation Details
Armor Stand Initialization
When a pack is generated, an initialization script is injected into the armor stand. This script sets the starting state for all HoloPrint variables.
// Example of initialization injection in src/HoloPrint.js
entityDescription["scripts"]["initialize"].push(functionToMolang(entityScripts.armorStandInitialization, {
structureSize: structureSizes[0],
initialOffset: config.INITIAL_OFFSET,
defaultTextureIndex,
singleLayerMode: HOLOGRAM_LAYER_MODES.SINGLE,
structureCount: structureFiles.length
}));
Sources: src/HoloPrint.js:308-315
Coordinate Lock Logic
If the "Coordinate Lock" feature is enabled in the UI (settings.coordinate_lock), the script generation omits relative offset logic and instead generates hardcoded MoLang expressions that pin the hologram to specific global coordinates. This is handled by switching between animation.holoprint.hologram.offset and animation.holoprint.hologram.coordinate_lock.
Sources: src/HoloPrint.js:291-304, src/index.js:210-230
Conclusion
MoLang customization in HoloPrint is the bridge between the static structure data and an interactive in-game experience. By dynamically generating animation controllers and patching render controllers, the system provides a robust building tool that remains performant within the limitations of the Minecraft Bedrock Edition engine.