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.
This commit is contained in:
DaniD3v
2024-08-24 22:57:42 +02:00
parent be98a730b0
commit a0260acd8b
2 changed files with 12 additions and 10 deletions

View File

@@ -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
}
}

View File

@@ -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...