nucleation 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,373 +1,108 @@
1
- # Nucleation
1
+ # Nucleation for JavaScript / TypeScript
2
2
 
3
- **Nucleation** is a high-performance Minecraft schematic engine written in Rust with full support for **Rust**, **WebAssembly/JavaScript**, **Python**, and **FFI-based integrations** like **PHP** and **C**.
4
-
5
- > Built for performance, portability, and parity across ecosystems.
6
-
7
- ---
8
-
9
- [![Crates.io](https://img.shields.io/crates/v/nucleation.svg)](https://crates.io/crates/nucleation)
10
3
  [![npm](https://img.shields.io/npm/v/nucleation.svg)](https://www.npmjs.com/package/nucleation)
11
- [![PyPI](https://img.shields.io/pypi/v/nucleation.svg)](https://pypi.org/project/nucleation)
12
-
13
- ---
14
-
15
- ## Features
16
-
17
- ### Core
18
-
19
- - **Multi-format support**: `.schematic`, `.litematic`, `.nbt`, `.mcstructure`, and more
20
- - **Memory-safe Rust core** with zero-copy deserialization
21
- - **Cross-platform**: Linux, macOS, Windows (x86_64 + ARM64)
22
- - **Multi-language**: Rust, JavaScript/TypeScript (WASM), Python, C/FFI
23
-
24
- ### Schematic Building
25
-
26
- - **SchematicBuilder**: Create schematics with ASCII art and Unicode characters
27
- - **Compositional Design**: Build circuits hierarchically from smaller components
28
- - **Unicode Palettes**: Visual circuit design with intuitive characters (`→`, `│`, `█`, etc.)
29
- - **Template System**: Define circuits in human-readable text format
30
- - **CLI Tool**: Build schematics from command line (`schematic-builder`)
31
-
32
- ### Circuit Simulation
33
-
34
- - **Redstone simulation** via MCHPRS integration (optional `simulation` feature)
35
- - **TypedCircuitExecutor**: High-level API with typed inputs/outputs (Bool, U32, Ascii, etc.)
36
- - **CircuitBuilder**: Fluent API for streamlined executor creation
37
- - **DefinitionRegion**: Advanced region manipulation with boolean ops, filtering, and connectivity analysis
38
- - **Custom IO**: Inject and monitor signal strengths at specific positions
39
- - **Execution Modes**: Fixed ticks, until condition, until stable, until change
40
- - **State Management**: Stateless, stateful, or manual tick control
41
4
 
42
- ### 3D Mesh Generation
5
+ JavaScript / TypeScript bindings for **Nucleation**, a high-performance
6
+ Minecraft schematic engine. Read, edit, build, simulate, and mesh
7
+ `.schematic`, `.litematic`, `.nbt`, and `.mcstructure` files — in the
8
+ browser or in Node.
43
9
 
44
- - **Resource pack loading** from ZIP files or raw bytes
45
- - **GLB/glTF export** for standard 3D viewers and engines
46
- - **USDZ export** for Apple AR Quick Look
47
- - **Raw mesh export** for custom rendering pipelines (positions, normals, UVs, colors, indices)
48
- - **Per-region and per-chunk meshing** for large schematics
49
- - **Greedy meshing** to reduce triangle count
50
- - **Occlusion culling** to skip fully hidden blocks
51
- - **Ambient occlusion** with configurable intensity
52
- - **Resource pack querying** — list/get/add blockstates, models, and textures
53
-
54
- ### Developer Experience
55
-
56
- - **Bracket notation** for blocks: `"minecraft:lever[facing=east,powered=false]"`
57
- - **Feature parity** across all language bindings
58
- - **Comprehensive documentation** in [`docs/`](docs/)
59
- - Seamless integration with [Cubane](https://github.com/Nano112/cubane)
10
+ The core is written in Rust and compiled to WebAssembly via wasm-bindgen.
11
+ A single package works in modern browsers, bundlers, and Node 18+.
60
12
 
61
13
  ---
62
14
 
63
- ## Installation
64
-
65
- ### Rust
66
-
67
- ```bash
68
- cargo add nucleation
69
- ```
70
-
71
- ### JavaScript / TypeScript (WASM)
15
+ ## Install
72
16
 
73
17
  ```bash
74
18
  npm install nucleation
75
19
  ```
76
20
 
77
- ### Python
78
-
79
21
  ```bash
80
- pip install nucleation
22
+ pnpm add nucleation
81
23
  ```
82
24
 
83
- ### C / PHP / FFI
84
-
85
- Download prebuilt `.so` / `.dylib` / `.dll` from [Releases](https://github.com/Schem-at/Nucleation/releases)
86
- or build locally using:
87
-
88
25
  ```bash
89
- ./build-ffi.sh
26
+ bun add nucleation
90
27
  ```
91
28
 
92
29
  ---
93
30
 
94
- ## Quick Examples
95
-
96
- ### Loading and Saving Schematics
97
-
98
- #### Rust
99
-
100
- ```rust
101
- use nucleation::UniversalSchematic;
102
-
103
- let bytes = std::fs::read("example.litematic")?;
104
- let mut schematic = UniversalSchematic::new("my_schematic");
105
- schematic.load_from_data(&bytes)?;
106
- println!("{:?}", schematic.get_info());
107
- ```
108
-
109
- #### JavaScript (WASM)
31
+ ## Quick start
110
32
 
111
33
  ```ts
112
34
  import init from "nucleation";
113
35
  import { Schematic } from "nucleation/api";
114
- await init();
115
-
116
- const bytes = await fetch("example.litematic").then((r) => r.arrayBuffer());
117
- const schem = Schematic.open(new Uint8Array(bytes), { hint: "example.litematic" });
118
- schem.setBlock([0, 0, 0], "minecraft:gold_block");
119
- await schem.save("out.schem");
120
- ```
121
-
122
- #### Python
123
-
124
- ```python
125
- from nucleation import Schematic, sign, text
126
-
127
- # Three explicit constructors (legacy `Schematic("file.schem")` still works):
128
- schem = Schematic.open("example.litematic") # load
129
- fresh = Schematic.new("my_schematic") # blank
130
- templ = Schematic.from_template("ab\ncd") # ASCII template
131
-
132
- # Polished set_block: tuple coords, structured state and NBT, chainable.
133
- schem.set_block((0, 0, 0), "minecraft:repeater",
134
- state={"delay": 4, "facing": "east"})
135
- schem.set_block((0, 1, 0), "minecraft:oak_sign",
136
- state={"rotation": 8},
137
- nbt=sign([text("Hello", color="gold"), "world"]))
138
-
139
- # Format inferred from extension.
140
- schem.save("out.litematic")
141
- ```
142
-
143
- For hot loops placing many blocks, prefer the batch / fast-path APIs:
144
-
145
- ```python
146
- # 30+ M placements/sec — one native call.
147
- schem.set_blocks([(x, 0, 0) for x in range(1_000_000)], "minecraft:stone")
148
-
149
- # 10+ M placements/sec — pre-resolve once, place by index.
150
- stone = schem.prepare_block("minecraft:stone")
151
- place = schem.place
152
- for x, y, z in positions:
153
- place(x, y, z, stone)
154
- ```
155
-
156
- ### Building Schematics with ASCII Art
157
-
158
- ```rust
159
- use nucleation::SchematicBuilder;
160
-
161
- // Use Unicode characters for visual circuit design!
162
- let circuit = SchematicBuilder::new()
163
- .from_template(r#"
164
- # Base layer
165
- ccc
166
- ccc
167
-
168
- # Logic layer
169
- ─→─
170
- │█│
171
- "#)
172
- .build()?;
173
-
174
- // Save as litematic
175
- let bytes = nucleation::litematic::to_litematic(&circuit)?;
176
- std::fs::write("circuit.litematic", bytes)?;
177
- ```
178
-
179
- **Available in Rust, JavaScript, and Python!** See [SchematicBuilder Guide](docs/guide/schematic-builder.md).
180
36
 
181
- ### Compositional Circuit Design
37
+ await init(); // load the wasm module
182
38
 
183
- ```rust
184
- // Build a basic gate
185
- let and_gate = create_and_gate();
186
-
187
- // Use it in a larger circuit
188
- let half_adder = SchematicBuilder::new()
189
- .map_schematic('A', and_gate) // Use entire schematic as palette entry!
190
- .map_schematic('X', xor_gate)
191
- .layers(&[&["AX"]]) // Place side-by-side
192
- .build()?;
193
-
194
- // Stack multiple copies
195
- let four_bit_adder = SchematicBuilder::new()
196
- .map_schematic('F', full_adder)
197
- .layers(&[&["FFFF"]]) // 4 full-adders in a row
198
- .build()?;
199
- ```
200
-
201
- See [4-Bit Adder Example](docs/examples/4-bit-adder.md) for a complete hierarchical design.
202
-
203
- ### CLI Tool
204
-
205
- ```bash
206
- # Build schematic from text template
207
- cat circuit.txt | schematic-builder -o circuit.litematic
208
-
209
- # From file
210
- schematic-builder -i circuit.txt -o circuit.litematic
211
-
212
- # Choose format
213
- schematic-builder -i circuit.txt -o circuit.schem --format schem
214
-
215
- # Export as mcstructure
216
- schematic-builder -i circuit.txt -o circuit.mcstructure --format mcstructure
217
- ```
218
-
219
- ---
220
-
221
- ## Advanced Examples
222
-
223
- ### Setting Blocks with Properties
224
-
225
- ```js
226
- const schematic = new SchematicWrapper();
227
- schematic.set_block(
228
- 0,
229
- 1,
230
- 0,
231
- "minecraft:lever[facing=east,powered=false,face=floor]"
232
- );
233
- schematic.set_block(
234
- 5,
235
- 1,
236
- 0,
237
- "minecraft:redstone_wire[power=15,east=side,west=side]"
238
- );
239
- ```
240
-
241
- [More in `examples/rust.md`](examples/rust.md)
242
-
243
- ### Redstone Circuit Simulation
244
-
245
- ```js
246
- const simWorld = schematic.create_simulation_world();
247
- simWorld.on_use_block(0, 1, 0); // Toggle lever
248
- simWorld.tick(2);
249
- simWorld.flush();
250
- const isLit = simWorld.is_lit(15, 1, 0); // Check if lamp is lit
251
- ```
252
-
253
- ### High-Level Typed Executor
254
-
255
- ```rust
256
- use nucleation::{TypedCircuitExecutor, IoType, Value, ExecutionMode};
257
-
258
- // Create executor with typed IO
259
- let mut executor = TypedCircuitExecutor::new(world, inputs, outputs);
260
-
261
- // Execute with typed values
262
- let mut input_values = HashMap::new();
263
- input_values.insert("a".to_string(), Value::Bool(true));
264
- input_values.insert("b".to_string(), Value::Bool(true));
39
+ const bytes = await fetch("example.litematic").then((r) => r.arrayBuffer());
40
+ const schem = Schematic.open(new Uint8Array(bytes), {
41
+ hint: "example.litematic",
42
+ });
265
43
 
266
- let result = executor.execute(
267
- input_values,
268
- ExecutionMode::FixedTicks { ticks: 100 }
269
- )?;
44
+ schem.setBlock([0, 0, 0], "minecraft:gold_block");
45
+ schem.setBlock([0, 1, 0], "minecraft:repeater", {
46
+ state: { delay: 4, facing: "east" },
47
+ });
270
48
 
271
- // Get typed output
272
- let output = result.outputs.get("result").unwrap();
273
- assert_eq!(*output, Value::Bool(true)); // AND gate result
49
+ const out = await schem.save("out.schem"); // Uint8Array
274
50
  ```
275
51
 
276
- **Supported types**: `Bool`, `U8`, `U16`, `U32`, `I8`, `I16`, `I32`, `Float32`, `Ascii`, `Array`, `Matrix`, `Struct`
277
-
278
- See [TypedCircuitExecutor Guide](docs/guide/typed-executor.md) for execution modes, state management, and more.
279
-
280
- ### 3D Mesh Generation
281
-
282
- ```rust
283
- use nucleation::{UniversalSchematic, meshing::{MeshConfig, ResourcePackSource}};
284
-
285
- // Load schematic and resource pack
286
- let schematic = UniversalSchematic::from_litematic_bytes(&schem_data)?;
287
- let pack = ResourcePackSource::from_file("resourcepack.zip")?;
288
-
289
- // Configure meshing
290
- let config = MeshConfig::new()
291
- .with_greedy_meshing(true)
292
- .with_cull_occluded_blocks(true);
52
+ ### Hot loops
293
53
 
294
- // Generate GLB mesh
295
- let result = schematic.to_mesh(&pack, &config)?;
296
- std::fs::write("output.glb", &result.glb_data)?;
297
-
298
- // Or USDZ for AR
299
- let usdz = schematic.to_usdz(&pack, &config)?;
54
+ ```ts
55
+ // One call into wasm — millions of placements/sec.
56
+ const positions = Array.from({ length: 1_000_000 }, (_, x) => [x, 0, 0]);
57
+ schem.setBlocks(positions, "minecraft:stone");
300
58
 
301
- // Or raw mesh data for custom rendering
302
- let raw = schematic.to_raw_mesh(&pack, &config)?;
303
- println!("Vertices: {}, Triangles: {}", raw.vertex_count(), raw.triangle_count());
59
+ // Pre-resolve once, place by index.
60
+ const stone = schem.prepareBlock("minecraft:stone");
61
+ for (const [x, y, z] of positions) {
62
+ schem.place(x, y, z, stone);
63
+ }
304
64
  ```
305
65
 
306
- ---
307
-
308
- ## Development
309
-
310
- ```bash
311
- # Build the Rust core
312
- cargo build --release
66
+ ### Tile-entity helpers
313
67
 
314
- # Build with simulation support
315
- cargo build --release --features simulation
316
-
317
- # Build with meshing support
318
- cargo build --release --features meshing
319
-
320
- # Build WASM module (includes simulation)
321
- ./build-wasm.sh
322
-
323
- # Build Python bindings locally
324
- maturin develop --features python
325
-
326
- # Build FFI libs
327
- ./build-ffi.sh
68
+ ```ts
69
+ import { chest, sign, text, Item } from "nucleation/api";
328
70
 
329
- # Run tests
330
- cargo test
331
- cargo test --features simulation
332
- cargo test --features meshing
333
- ./test-wasm.sh # WASM tests with simulation
71
+ schem.setBlock([0, 0, 0], "minecraft:chest", {
72
+ state: { facing: "north" },
73
+ nbt: chest([
74
+ Item("minecraft:diamond", { count: 64 }),
75
+ Item("minecraft:elytra"),
76
+ ]),
77
+ });
334
78
 
335
- # Pre-push verification (recommended before pushing)
336
- ./pre-push.sh # Runs all checks that CI runs
79
+ schem.setBlock([0, 1, 0], "minecraft:oak_sign", {
80
+ nbt: sign([text("Loot", { color: "gold" }), "this way →"]),
81
+ });
337
82
  ```
338
83
 
339
84
  ---
340
85
 
341
86
  ## Documentation
342
87
 
343
- ### 📖 Language-Specific Documentation
344
-
345
- Choose your language for complete API reference and examples:
88
+ Full reference, including simulation, meshing, and resource-pack rendering,
89
+ lives in the main repository:
346
90
 
347
- - **[Rust Documentation](docs/rust/)** - Complete Rust API reference
348
- - **[JavaScript/TypeScript Documentation](docs/javascript/)** - WASM API for web and Node.js
349
- - **[Python Documentation](docs/python/)** - Python bindings API
350
- - **[C/FFI Documentation](examples/ffi.md)** - C-compatible FFI for PHP, Go, etc.
91
+ - [Nucleation on GitHub](https://github.com/Schem-at/Nucleation)
92
+ - [JavaScript API reference](https://github.com/Schem-at/Nucleation/blob/master/docs/javascript/README.md)
93
+ - [Schematic Builder guide](https://github.com/Schem-at/Nucleation/blob/master/docs/guide/schematic-builder.md)
351
94
 
352
- ### 📚 Shared Guides
353
-
354
- These guides apply to all languages:
355
-
356
- - [SchematicBuilder Guide](docs/shared/guide/schematic-builder.md) - ASCII art and compositional design
357
- - [TypedCircuitExecutor Guide](docs/shared/guide/typed-executor.md) - High-level circuit simulation
358
- - [Circuit API Guide](docs/shared/guide/circuit-api.md) - CircuitBuilder and DefinitionRegion
359
- - [Unicode Palette Reference](docs/shared/unicode-palette.md) - Visual circuit characters
360
-
361
- ### 🎯 Quick Links
95
+ ---
362
96
 
363
- - [Main Documentation Index](docs/) - Overview and comparison
364
- - [Examples Directory](examples/) - Working code examples
97
+ ## Why Rust + WASM?
365
98
 
366
- ---
99
+ Nucleation's core is shared across Rust, WebAssembly/JS, Python, and C/PHP —
100
+ one engine, one set of behaviour, one set of tests. The npm package you
101
+ install is the same engine that powers the Python and Rust libraries; the
102
+ wasm boundary is the only thing between your JS and native-speed parsing
103
+ and meshing.
367
104
 
368
105
  ## License
369
106
 
370
- Licensed under the **GNU AGPL-3.0-only**.
371
- See [`LICENSE`](./LICENSE) for full terms.
372
-
373
- Made by [@Nano112](https://github.com/Nano112)
107
+ AGPL-3.0-only. See the [main repository](https://github.com/Schem-at/Nucleation)
108
+ for details.
Binary file
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "Nano nano@schem.at"
6
6
  ],
7
7
  "description": "A high-performance Minecraft schematic parser and utility library",
8
- "version": "0.2.1",
8
+ "version": "0.2.2",
9
9
  "license": "AGPL-3.0-only",
10
10
  "repository": {
11
11
  "type": "git",