From dc64f06cac520a5b55cbdc32a7fc9f1d5556eb0a Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 12 Sep 2022 20:20:58 -0700 Subject: [PATCH] Clarify chunk space/world space --- src/block_pos.rs | 2 +- src/chunk.rs | 26 +++++++++++++++++--------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/block_pos.rs b/src/block_pos.rs index a02e350..0ae69e8 100644 --- a/src/block_pos.rs +++ b/src/block_pos.rs @@ -5,7 +5,7 @@ use vek::Vec3; use crate::protocol::{Decode, Encode}; -/// Represents an absolute block position in a world. +/// Represents an absolute block position in world space. #[derive(Clone, Copy, Default, PartialEq, Eq, Hash, Debug)] pub struct BlockPos { pub x: i32, diff --git a/src/chunk.rs b/src/chunk.rs index 16f1df2..fd58a50 100644 --- a/src/chunk.rs +++ b/src/chunk.rs @@ -159,11 +159,11 @@ impl Chunks { self.chunks.par_iter_mut().map(|(&pos, chunk)| (pos, chunk)) } - /// Gets the block state at a global position in the world. + /// Gets the block state at an absolute block position in world space. /// /// If the position is not inside of a chunk, then `None` is returned. /// - /// Note: if you need to get a large number of blocks, it is more efficient + /// **Note**: if you need to get a large number of blocks, it is more efficient /// to read from the chunks directly with [`Chunk::get_block_state`]. pub fn get_block_state(&self, pos: impl Into) -> Option { let pos = pos.into(); @@ -186,13 +186,13 @@ impl Chunks { } } - /// Sets the block state at a global position in the world. + /// Sets the block state at an absolute block position in world space. /// - /// If the position is inside of a chunk, then `true` is returned. - /// Otherwise, `false` is returned. The function has no effect if `false` is - /// returned. + /// If the position is inside of a chunk, then `true` is returned and the + /// block is set. Otherwise, `false` is returned and the function has no + /// effect. /// - /// Note: if you need to set a large number of blocks, it may be more + /// **Note**: if you need to set a large number of blocks, it may be more /// efficient write to the chunks directly with /// [`Chunk::set_block_state`]. pub fn set_block_state(&mut self, pos: impl Into, block: BlockState) -> bool { @@ -249,6 +249,10 @@ pub trait Chunk { /// Gets the block state at the provided offsets in the chunk. /// + /// **Note**: The arguments to this function are offsets from the minimum + /// corner of the chunk in _chunk space_ rather than _world space_. You + /// might be looking for [`Chunks::get_block_state`] instead. + /// /// # Panics /// /// Panics if the offsets are outside the bounds of the chunk. @@ -256,6 +260,10 @@ pub trait Chunk { /// Sets the block state at the provided offsets in the chunk. /// + /// **Note**: The arguments to this function are offsets from the minimum + /// corner of the chunk in _chunk space_ rather than _world space_. You + /// might be looking for [`Chunks::set_block_state`] instead. + /// /// # Panics /// /// Panics if the offsets are outside the bounds of the chunk. @@ -263,7 +271,7 @@ pub trait Chunk { /// Gets the biome at the provided biome offsets in the chunk. /// - /// Note: the arguments are **not** block positions. Biomes are 4x4x4 + /// **Note**: the arguments are **not** block positions. Biomes are 4x4x4 /// segments of a chunk, so `x` and `z` are in `0..=4`. /// /// # Panics @@ -273,7 +281,7 @@ pub trait Chunk { /// Sets the biome at the provided biome offsets in the chunk. /// - /// Note: the arguments are **not** block positions. Biomes are 4x4x4 + /// **Note**: the arguments are **not** block positions. Biomes are 4x4x4 /// segments of a chunk, so `x` and `z` are in `0..=4`. /// /// # Panics