Skip to main content

nucleation/
lib.rs

1// src/lib.rs
2
3// Core modules
4// Vendored Minecraft block database (was the standalone `blockpedia` crate);
5// block tables are generated by build.rs from data/blockpedia/*.json.gz.
6pub mod blockpedia;
7
8pub mod block_entity;
9pub mod block_entity_store;
10pub mod block_position;
11mod block_state;
12mod bounding_box;
13pub mod building;
14mod chunk;
15pub mod dataconverter;
16pub mod definition_region;
17pub mod diff;
18mod entity;
19pub mod fingerprint;
20pub mod formats;
21pub mod insign;
22mod item;
23mod metadata;
24pub mod nbt;
25mod print_utils;
26mod region;
27pub mod schematic_builder;
28pub mod sdf;
29pub mod selection;
30pub mod store;
31pub mod store_io;
32mod transforms;
33mod universal_schematic;
34pub mod utils;
35
36// Feature-specific modules
37#[cfg(feature = "autostack")]
38pub mod autostack;
39#[cfg(feature = "bridge")]
40pub mod bridge;
41#[cfg(feature = "meshing")]
42pub mod meshing;
43#[cfg(feature = "rendering")]
44pub mod rendering;
45#[cfg(any(feature = "scripting-lua", feature = "scripting-js"))]
46pub mod scripting;
47#[cfg(feature = "simulation")]
48pub mod simulation;
49
50// The Diplomat wasm module carries no wasm-bindgen glue, so getrandom's "js" source is
51// unavailable; register a deterministic splitmix64 stream instead. Non-crypto by design:
52// rand only feeds seeded shuffles and cosmetic jitter here (see Cargo.toml note).
53#[cfg(target_arch = "wasm32")]
54mod wasm_entropy {
55    use std::sync::atomic::{AtomicU64, Ordering};
56
57    static STATE: AtomicU64 = AtomicU64::new(0x9E3779B97F4A7C15);
58
59    pub fn getrandom_fallback(buf: &mut [u8]) -> Result<(), getrandom::Error> {
60        for chunk in buf.chunks_mut(8) {
61            let mut z = STATE.fetch_add(0x9E3779B97F4A7C15, Ordering::Relaxed);
62            z = (z ^ (z >> 30)).wrapping_mul(0xBF58476D1CE4E5B9);
63            z = (z ^ (z >> 27)).wrapping_mul(0x94D049BB133111EB);
64            z ^= z >> 31;
65            let bytes = z.to_le_bytes();
66            chunk.copy_from_slice(&bytes[..chunk.len()]);
67        }
68        Ok(())
69    }
70}
71#[cfg(target_arch = "wasm32")]
72getrandom::register_custom_getrandom!(wasm_entropy::getrandom_fallback);
73
74// Public re-exports
75pub use block_state::BlockState;
76pub use bounding_box::BoundingBox;
77pub use entity::Entity;
78pub use formats::{litematic, schematic, world_stream};
79pub use print_utils::{format_json_schematic, format_schematic};
80pub use region::Region;
81pub use schematic_builder::{
82    palettes, IoMarker, IoType as BuilderIoType, PaletteEntry, SchematicBuilder,
83};
84pub use selection::{
85    connected_components, connected_components_collect, flood, AndMask, BlocklistMask, Component,
86    Connectivity, Continue, Limits, Mask, NotAirMask, NotMask, OrMask, StopReason, VisitedSet,
87};
88pub use store::{MemStore, Store, StoreError};
89pub use universal_schematic::UniversalSchematic;