mirror of
https://github.com/Pumpkin-MC/Pumpkin.git
synced 2026-08-30 20:14:23 +00:00
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:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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...
|
||||
|
||||
Reference in New Issue
Block a user