nucleation 0.1.184 → 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 +63 -305
- package/api.js +608 -0
- package/nucleation-original.js +52 -28
- package/nucleation.d.ts +144 -131
- package/nucleation_bg.wasm +0 -0
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -1,350 +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
|
-
[](https://crates.io/crates/nucleation)
|
|
10
3
|
[](https://www.npmjs.com/package/nucleation)
|
|
11
|
-
[](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
4
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
|
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.
|
|
41
9
|
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
##
|
|
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
|
-
|
|
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
|
-
|
|
26
|
+
bun add nucleation
|
|
90
27
|
```
|
|
91
28
|
|
|
92
29
|
---
|
|
93
30
|
|
|
94
|
-
## Quick
|
|
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
|
-
import
|
|
113
|
-
|
|
114
|
-
const bytes = await fetch("example.litematic").then((r) => r.arrayBuffer());
|
|
115
|
-
const parser = new SchematicParser();
|
|
116
|
-
await parser.fromData(new Uint8Array(bytes));
|
|
117
|
-
console.log(parser.getDimensions());
|
|
118
|
-
```
|
|
119
|
-
|
|
120
|
-
#### Python
|
|
121
|
-
|
|
122
|
-
```python
|
|
123
|
-
from nucleation import Schematic
|
|
124
|
-
|
|
125
|
-
with open("example.litematic", "rb") as f:
|
|
126
|
-
data = f.read()
|
|
127
|
-
|
|
128
|
-
schem = Schematic("my_schematic")
|
|
129
|
-
schem.load_from_bytes(data)
|
|
130
|
-
print(schem.get_info())
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
### Building Schematics with ASCII Art
|
|
134
|
-
|
|
135
|
-
```rust
|
|
136
|
-
use nucleation::SchematicBuilder;
|
|
137
|
-
|
|
138
|
-
// Use Unicode characters for visual circuit design!
|
|
139
|
-
let circuit = SchematicBuilder::new()
|
|
140
|
-
.from_template(r#"
|
|
141
|
-
# Base layer
|
|
142
|
-
ccc
|
|
143
|
-
ccc
|
|
144
|
-
|
|
145
|
-
# Logic layer
|
|
146
|
-
─→─
|
|
147
|
-
│█│
|
|
148
|
-
"#)
|
|
149
|
-
.build()?;
|
|
150
|
-
|
|
151
|
-
// Save as litematic
|
|
152
|
-
let bytes = nucleation::litematic::to_litematic(&circuit)?;
|
|
153
|
-
std::fs::write("circuit.litematic", bytes)?;
|
|
154
|
-
```
|
|
155
|
-
|
|
156
|
-
**Available in Rust, JavaScript, and Python!** See [SchematicBuilder Guide](docs/guide/schematic-builder.md).
|
|
157
|
-
|
|
158
|
-
### Compositional Circuit Design
|
|
159
|
-
|
|
160
|
-
```rust
|
|
161
|
-
// Build a basic gate
|
|
162
|
-
let and_gate = create_and_gate();
|
|
163
|
-
|
|
164
|
-
// Use it in a larger circuit
|
|
165
|
-
let half_adder = SchematicBuilder::new()
|
|
166
|
-
.map_schematic('A', and_gate) // Use entire schematic as palette entry!
|
|
167
|
-
.map_schematic('X', xor_gate)
|
|
168
|
-
.layers(&[&["AX"]]) // Place side-by-side
|
|
169
|
-
.build()?;
|
|
170
|
-
|
|
171
|
-
// Stack multiple copies
|
|
172
|
-
let four_bit_adder = SchematicBuilder::new()
|
|
173
|
-
.map_schematic('F', full_adder)
|
|
174
|
-
.layers(&[&["FFFF"]]) // 4 full-adders in a row
|
|
175
|
-
.build()?;
|
|
176
|
-
```
|
|
177
|
-
|
|
178
|
-
See [4-Bit Adder Example](docs/examples/4-bit-adder.md) for a complete hierarchical design.
|
|
179
|
-
|
|
180
|
-
### CLI Tool
|
|
181
|
-
|
|
182
|
-
```bash
|
|
183
|
-
# Build schematic from text template
|
|
184
|
-
cat circuit.txt | schematic-builder -o circuit.litematic
|
|
185
|
-
|
|
186
|
-
# From file
|
|
187
|
-
schematic-builder -i circuit.txt -o circuit.litematic
|
|
188
|
-
|
|
189
|
-
# Choose format
|
|
190
|
-
schematic-builder -i circuit.txt -o circuit.schem --format schem
|
|
191
|
-
|
|
192
|
-
# Export as mcstructure
|
|
193
|
-
schematic-builder -i circuit.txt -o circuit.mcstructure --format mcstructure
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
---
|
|
197
|
-
|
|
198
|
-
## Advanced Examples
|
|
34
|
+
import init from "nucleation";
|
|
35
|
+
import { Schematic } from "nucleation/api";
|
|
199
36
|
|
|
200
|
-
|
|
37
|
+
await init(); // load the wasm module
|
|
201
38
|
|
|
202
|
-
|
|
203
|
-
const
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
1,
|
|
207
|
-
0,
|
|
208
|
-
"minecraft:lever[facing=east,powered=false,face=floor]"
|
|
209
|
-
);
|
|
210
|
-
schematic.set_block(
|
|
211
|
-
5,
|
|
212
|
-
1,
|
|
213
|
-
0,
|
|
214
|
-
"minecraft:redstone_wire[power=15,east=side,west=side]"
|
|
215
|
-
);
|
|
216
|
-
```
|
|
217
|
-
|
|
218
|
-
[More in `examples/rust.md`](examples/rust.md)
|
|
219
|
-
|
|
220
|
-
### Redstone Circuit Simulation
|
|
221
|
-
|
|
222
|
-
```js
|
|
223
|
-
const simWorld = schematic.create_simulation_world();
|
|
224
|
-
simWorld.on_use_block(0, 1, 0); // Toggle lever
|
|
225
|
-
simWorld.tick(2);
|
|
226
|
-
simWorld.flush();
|
|
227
|
-
const isLit = simWorld.is_lit(15, 1, 0); // Check if lamp is lit
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
### High-Level Typed Executor
|
|
231
|
-
|
|
232
|
-
```rust
|
|
233
|
-
use nucleation::{TypedCircuitExecutor, IoType, Value, ExecutionMode};
|
|
234
|
-
|
|
235
|
-
// Create executor with typed IO
|
|
236
|
-
let mut executor = TypedCircuitExecutor::new(world, inputs, outputs);
|
|
237
|
-
|
|
238
|
-
// Execute with typed values
|
|
239
|
-
let mut input_values = HashMap::new();
|
|
240
|
-
input_values.insert("a".to_string(), Value::Bool(true));
|
|
241
|
-
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
|
+
});
|
|
242
43
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
)
|
|
44
|
+
schem.setBlock([0, 0, 0], "minecraft:gold_block");
|
|
45
|
+
schem.setBlock([0, 1, 0], "minecraft:repeater", {
|
|
46
|
+
state: { delay: 4, facing: "east" },
|
|
47
|
+
});
|
|
247
48
|
|
|
248
|
-
|
|
249
|
-
let output = result.outputs.get("result").unwrap();
|
|
250
|
-
assert_eq!(*output, Value::Bool(true)); // AND gate result
|
|
49
|
+
const out = await schem.save("out.schem"); // Uint8Array
|
|
251
50
|
```
|
|
252
51
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
See [TypedCircuitExecutor Guide](docs/guide/typed-executor.md) for execution modes, state management, and more.
|
|
256
|
-
|
|
257
|
-
### 3D Mesh Generation
|
|
52
|
+
### Hot loops
|
|
258
53
|
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
.with_cull_occluded_blocks(true);
|
|
270
|
-
|
|
271
|
-
// Generate GLB mesh
|
|
272
|
-
let result = schematic.to_mesh(&pack, &config)?;
|
|
273
|
-
std::fs::write("output.glb", &result.glb_data)?;
|
|
274
|
-
|
|
275
|
-
// Or USDZ for AR
|
|
276
|
-
let usdz = schematic.to_usdz(&pack, &config)?;
|
|
277
|
-
|
|
278
|
-
// Or raw mesh data for custom rendering
|
|
279
|
-
let raw = schematic.to_raw_mesh(&pack, &config)?;
|
|
280
|
-
println!("Vertices: {}, Triangles: {}", raw.vertex_count(), raw.triangle_count());
|
|
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");
|
|
58
|
+
|
|
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
|
+
}
|
|
281
64
|
```
|
|
282
65
|
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
## Development
|
|
286
|
-
|
|
287
|
-
```bash
|
|
288
|
-
# Build the Rust core
|
|
289
|
-
cargo build --release
|
|
290
|
-
|
|
291
|
-
# Build with simulation support
|
|
292
|
-
cargo build --release --features simulation
|
|
293
|
-
|
|
294
|
-
# Build with meshing support
|
|
295
|
-
cargo build --release --features meshing
|
|
66
|
+
### Tile-entity helpers
|
|
296
67
|
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
# Pre-push verification (recommended before pushing)
|
|
313
|
-
./pre-push.sh # Runs all checks that CI runs
|
|
68
|
+
```ts
|
|
69
|
+
import { chest, sign, text, Item } from "nucleation/api";
|
|
70
|
+
|
|
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
|
+
});
|
|
78
|
+
|
|
79
|
+
schem.setBlock([0, 1, 0], "minecraft:oak_sign", {
|
|
80
|
+
nbt: sign([text("Loot", { color: "gold" }), "this way →"]),
|
|
81
|
+
});
|
|
314
82
|
```
|
|
315
83
|
|
|
316
84
|
---
|
|
317
85
|
|
|
318
86
|
## Documentation
|
|
319
87
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
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:
|
|
323
90
|
|
|
324
|
-
-
|
|
325
|
-
-
|
|
326
|
-
-
|
|
327
|
-
- **[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)
|
|
328
94
|
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
These guides apply to all languages:
|
|
332
|
-
|
|
333
|
-
- [SchematicBuilder Guide](docs/shared/guide/schematic-builder.md) - ASCII art and compositional design
|
|
334
|
-
- [TypedCircuitExecutor Guide](docs/shared/guide/typed-executor.md) - High-level circuit simulation
|
|
335
|
-
- [Circuit API Guide](docs/shared/guide/circuit-api.md) - CircuitBuilder and DefinitionRegion
|
|
336
|
-
- [Unicode Palette Reference](docs/shared/unicode-palette.md) - Visual circuit characters
|
|
337
|
-
|
|
338
|
-
### 🎯 Quick Links
|
|
95
|
+
---
|
|
339
96
|
|
|
340
|
-
|
|
341
|
-
- [Examples Directory](examples/) - Working code examples
|
|
97
|
+
## Why Rust + WASM?
|
|
342
98
|
|
|
343
|
-
|
|
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.
|
|
344
104
|
|
|
345
105
|
## License
|
|
346
106
|
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
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.
|