This document introduces two client-side structure preview features:
- In-world projection preview (
/pm_preview): renders the structure as a ghost/outline/block-model projection. - GUI structure preview (ModularUI) (
/pm_preview_ui): shows materials/BOM with 3D and layer views (optionally with world-scan comparison).
This is a developer/debugging oriented feature: it is fully client-side rendering, and does not place blocks or modify the world.
Chinese original:
Client commands:
/pm_preview <structureId> [sliceCount] [distance] [mode]/pm_preview off(or/pm_preview stop)
Parameters:
structureId: structure id (from JSONidor code registration)sliceCount: optional; overrides the preview slice count for slice structuresdistance: optional; max render distance (blocks)mode: optional; render mode
Implementation:
src/main/kotlin/client/preview/StructurePreviewClientCommand.kt
Client command:
/pm_preview_ui <structureId> [sliceCount]
This opens a read-only ModularUI screen for structure preview and BOM browsing.
Implementation:
src/main/kotlin/client/preview/ui/StructurePreviewUiClientCommand.kt
ghost(default): translucent blocks (faster)outline: wireframe outlinesboth: ghost + outlineblock_model/block/model: render real block models (slower; best for small structures)
By default the projection follows the player's facing (front/top). You can lock and rotate at any time:
R: lock/unlock projection orientation[/]: rotate (negative/positive)
Rotation axis selection (modifier keys):
- no modifier: Yaw (rotate around UP)
Shift: Pitch (rotate around EAST)Ctrl: Roll (rotate around SOUTH)
This system is based on StructureOrientation(front, top), hence the 24 orthogonal poses.
Keybinding implementation:
src/main/kotlin/client/preview/ProjectionKeyBindings.kt
HUD/chat messages use lang keys:
- preview commands:
pm.preview.* - projection HUD/chat:
pm.projection.* - keybind names:
key.pm.preview.*
Language files:
src/main/resources/assets/prototypemachinery/lang/en_us.langsrc/main/resources/assets/prototypemachinery/lang/zh_cn.lang
- Large projections can be CPU/GPU heavy, especially with
block_model. - Rendering/caching budgets are centralized in
ProjectionConfig:src/main/kotlin/client/preview/ProjectionConfig.kt
The projection expands structure entries/statuses and renders in batches under a budget. A "gradually filling" effect is expected.
A large example structure is included for stress testing:
- JSON:
src/main/resources/assets/prototypemachinery/structures/examples/huge_preview_64x16x64.json - Generator:
scripts/generate_huge_structure.py
It is used to validate loading, preview expansion, and render/cache strategies under extreme size.
- World projection manager:
src/main/kotlin/client/preview/WorldProjectionManager.kt - Ray marcher (DDA):
src/main/kotlin/client/preview/ProjectionRayMarcher.kt - HUD renderer:
src/main/kotlin/client/preview/ProjectionHudRenderer.kt - Preview model API:
src/main/kotlin/api/machine/structure/preview/StructurePreviewModel.kt
The GUI preview aims to be host-agnostic read-only UI + optional world scan/cache + reusable 3D widget.
- 3D block-model view: render block models inside the GUI, aiming for world-like rendering.
- Layer mode: view a single Y layer with a layer slider.
- Collapsible menus and clipping: top/bottom/left panels slide and clip within their rectangles.
- Wireframe overlay toggle: compare wireframe boundaries/axes and block models.
- Optional client world scan: scan the world at an anchor and produce MATCH/MISMATCH/UNLOADED/UNKNOWN statuses.
- gated by host config: read-only hosts (e.g. JEI) may disable scanning.
- Mode toggle: bottom
layer_previewacts as a toggle.- off: 3D view
- on: Layer view + right-side slider enabled
- Camera (3D):
- drag: rotate
- wheel: zoom
- top
preview_reset: reset zoom/camera
- Wireframe toggle: bottom
replace_blockbutton is currently reused as the wireframe overlay toggle.
For detailed layout/interaction specs, see:
src/main/resources/assets/prototypemachinery/textures/gui/gui_structure_preview/gui_structure_preview.md
GUI supports optional client-side world scan to map the StructurePreviewModel onto actual world blocks and compute statuses.
- Scan cache:
src/main/kotlin/client/preview/scan/StructurePreviewWorldScanCache.kt - Scanner:
src/main/kotlin/client/preview/scan/StructurePreviewWorldScanner.kt - Host config:
src/main/kotlin/client/preview/ui/StructurePreviewUiHostConfig.kt- when
allowWorldScan=false, the UI must not accessmc.world(JEI/read-only host).
- when
StructurePreview3DWidget is designed to render without depending on the real world (JEI-friendly):
- inputs:
StructurePreviewModel+ optionalstatusProvider(from world scan) - block model building:
BlockRendererDispatcher.renderBlock(...)fills aBufferBuilder, then uploads to VBO - neighbor culling: builds an in-structure
IBlockAccessto provide neighbor states torenderBlockand get world-like face culling - performance:
- group blocks into fixed-size chunks (e.g.
$16^3$ ) - incremental VBO build cursor and per-frame render budget
-
dispose()releases VBOs when UI closes to avoid GPU memory leaks
- group blocks into fixed-size chunks (e.g.
- world-like passes:
- SOLID/CUTOUT: depth test on, depth writes, usually no blending
- TRANSLUCENT: rendered last with blending, and may disable depthMask when needed
Key files:
- GUI entry:
src/main/kotlin/client/preview/ui/StructurePreviewUiScreen.kt - GUI command:
src/main/kotlin/client/preview/ui/StructurePreviewUiClientCommand.kt - 3D widget:
src/main/kotlin/client/preview/ui/widget/StructurePreview3DWidget.kt
GUI textures:
src/main/resources/assets/prototypemachinery/textures/gui/gui_structure_preview/
Spec document:
.../textures/gui/gui_structure_preview/gui_structure_preview.md
The structure preview UI currently references stable sliced PNG paths directly.