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.
79 lines
2.7 KiB
79 lines
2.7 KiB
use valence::prelude::*;
|
|
use valence_anvil::{AnvilChunk, AnvilWorld};
|
|
|
|
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::warn!("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::warn!("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!");
|
|
|
|
/* tracing::info!("Filling chests...");
|
|
|
|
for chunk in instance.chunks() {
|
|
for x in 0..16 {
|
|
for y in 0..256 {
|
|
for z in 0..16 {
|
|
let block = chunk.1.block(x, y, z);
|
|
if block.state() == BlockState::CHEST {
|
|
tracing::debug!(
|
|
"found chest: chunk ({},{}), offset ({}, {}, {}), calculated world pos ({}, {}, {})",
|
|
chunk.0.x,
|
|
chunk.0.z,
|
|
x as i32,
|
|
y as i32,
|
|
z as i32,
|
|
(chunk.0.x * 16) + x as i32,
|
|
y as i32 + 49,
|
|
(chunk.0.z * 16) + z as i32
|
|
);
|
|
let mut inventory = Inventory::new(InventoryKind::Generic9x3);
|
|
inventory.set_slot(0, ItemStack::new(ItemKind::IronSword, 1, None));
|
|
let chest = Chest {
|
|
inventory,
|
|
block_pos: BlockPos::new(
|
|
(chunk.0.x - 1) * 16 + x as i32,
|
|
y as i32 + 49,
|
|
(chunk.0.z + 1) * 16 + z as i32,
|
|
),
|
|
};
|
|
commands.spawn(chest);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
tracing::info!("Filled all (found) chests!"); */
|
|
|
|
commands.spawn(instance);
|
|
}
|