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