From a0260acd8b3930cc6b0a6333f5b92b200a398c8d Mon Sep 17 00:00:00 2001 From: DaniD3v Date: Sat, 24 Aug 2024 22:57:42 +0200 Subject: [PATCH] `WORLD_Y_START_AT` refactor Renamed `WORLD_Y_START_AT` to `WORLD_LOWEST_Y`. Added `WORLD_Y_END_AT`. Changed the type to i16 for ergonomics. Moved the constants under the use statements for readability. --- pumpkin-world/src/coordinates.rs | 12 ++++++------ pumpkin-world/src/lib.rs | 10 ++++++---- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/pumpkin-world/src/coordinates.rs b/pumpkin-world/src/coordinates.rs index eea7430a9..0873d0e80 100644 --- a/pumpkin-world/src/coordinates.rs +++ b/pumpkin-world/src/coordinates.rs @@ -1,6 +1,6 @@ use std::ops::Deref; -use crate::{WORLD_HEIGHT, WORLD_Y_START_AT}; +use crate::{WORLD_LOWEST_Y, WORLD_MAX_Y}; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct Height { @@ -9,20 +9,20 @@ pub struct Height { impl Height { pub fn new(height: i16) -> Self { - assert!(height <= (WORLD_HEIGHT as i16 - WORLD_Y_START_AT.abs() as i16)); - assert!(height >= WORLD_Y_START_AT as i16); + assert!(height <= WORLD_MAX_Y); + assert!(height >= WORLD_LOWEST_Y); Self { height } } pub fn from_absolute(height: u16) -> Self { - Self::new(height as i16 - WORLD_Y_START_AT.abs() as i16) + Self::new(height as i16 - WORLD_LOWEST_Y.abs()) } /// Absolute height ranges from `0..WORLD_HEIGHT` - /// instead of `WORLD_Y_START_AT..(WORLD_HEIGHT-WORLD_Y_START_AT)` + /// instead of `WORLD_LOWEST_Y..WORLD_MAX_Y` pub fn get_absolute(&self) -> u16 { - (self.height + WORLD_Y_START_AT.abs() as i16) as u16 + (self.height + WORLD_LOWEST_Y.abs()) as u16 } } diff --git a/pumpkin-world/src/lib.rs b/pumpkin-world/src/lib.rs index 4bd5c2cc0..b204eef2b 100644 --- a/pumpkin-world/src/lib.rs +++ b/pumpkin-world/src/lib.rs @@ -1,18 +1,20 @@ use level::Level; +pub mod block; pub mod chunk; pub mod coordinates; pub mod dimension; -pub const WORLD_HEIGHT: usize = 384; -pub const WORLD_Y_START_AT: i32 = -64; -pub const DIRECT_PALETTE_BITS: u32 = 15; -pub mod block; pub mod global_registry; pub mod item; mod level; pub mod radial_chunk_iterator; pub mod vector3; +pub const WORLD_HEIGHT: usize = 384; +pub const WORLD_LOWEST_Y: i16 = -64; +pub const WORLD_MAX_Y: i16 = WORLD_HEIGHT as i16 - WORLD_LOWEST_Y.abs(); +pub const DIRECT_PALETTE_BITS: u32 = 15; + pub struct World { pub level: Level, // entities, players...