You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.2 KiB
43 lines
1.2 KiB
use valence::{
|
|
anvil::{AnvilChunk, AnvilWorld},
|
|
prelude::*,
|
|
};
|
|
|
|
pub fn setup(
|
|
mut commands: Commands,
|
|
server: Res<Server>,
|
|
dimensions: Query<&DimensionType>,
|
|
biomes: Query<&Biome>,
|
|
) {
|
|
let mut anvil = AnvilWorld::new("world");
|
|
let mut instance = Instance::new(ident!("overworld"), &dimensions, &biomes, &server);
|
|
|
|
tracing::info!("Loading world...");
|
|
|
|
for z in -25..25 {
|
|
for x in -25..25 {
|
|
let Ok(Some(AnvilChunk {data, ..})) = anvil.read_chunk(x, z) else {
|
|
tracing::debug!("Failed to load chunk ({x}, {z}); could not read Anvil chunk");
|
|
continue
|
|
};
|
|
|
|
let mut chunk = Chunk::new(24);
|
|
|
|
let Ok(_) = valence::anvil::to_valence(&data, &mut chunk, 4, |_| BiomeId::default()) else {
|
|
tracing::debug!("Failed to load chunk ({x}, {z}); could not convert Anvil chunk to Valence chunk");
|
|
continue
|
|
};
|
|
|
|
chunk.optimize();
|
|
|
|
instance.insert_chunk([x, z], chunk);
|
|
|
|
tracing::debug!("Successfully loaded chunk at ({x}, {z})")
|
|
}
|
|
}
|
|
|
|
tracing::info!("Successfully loaded world!");
|
|
|
|
commands.spawn(instance);
|
|
}
|