diff --git a/src/world.rs b/src/world.rs index 3601425..a91802e 100644 --- a/src/world.rs +++ b/src/world.rs @@ -62,6 +62,17 @@ impl World { name: name.to_string(), } } + /// Get mutable access to the tile at `pos`. + /// + /// Loads or generates the containing chunk if necessary. + pub fn tile_at_mut(&mut self, pos: TilePos, worldgen: &Worldgen) -> &mut Tile { + let (chk, local) = pos.to_chunk_and_local(); + let chk = self + .chunks + .entry(chk) + .or_insert_with(|| Chunk::load_or_gen(chk, worldgen, &self.name)); + chk.at_mut(local) + } pub fn save(&self) { let result = std::fs::create_dir(&self.name); log::info!("{result:?}"); @@ -156,20 +167,6 @@ struct WorldMetaSave { ticks: u64, } -impl World { - /// Get mutable access to the tile at `pos`. - /// - /// Loads or generates the containing chunk if necessary. - pub fn tile_at_mut(&mut self, pos: TilePos, worldgen: &Worldgen) -> &mut Tile { - let (chk, local) = pos.to_chunk_and_local(); - let chk = self - .chunks - .entry(chk) - .or_insert_with(|| Chunk::load_or_gen(chk, worldgen, &self.name)); - chk.at_mut(local) - } -} - #[derive(Debug, Clone, Copy)] pub struct TilePos { pub x: TPosSc,