Add World struct

We also check now if world exits
This commit is contained in:
Alexander Medvedev committed 2024-08-19 21:14:48 +01:00
1 parent de7b3aa2ea
commit 222b40c8bd
6 files changed
+46 -17

No files matched your search

+1 -1
View File
@@ -2,7 +2,7 @@ use std::collections::HashMap;
use lazy_static::lazy_static;
use crate::world::WorldError;
use crate::level::WorldError;
const BLOCKS_JSON: &str = include_str!("../../assets/blocks.json");
+1 -1
View File
@@ -2,7 +2,7 @@ use std::collections::HashMap;
use fastnbt::LongArray;
use crate::{world::WorldError, WORLD_HEIGHT};
use crate::{level::WorldError, WORLD_HEIGHT};
pub struct ChunkData {
pub blocks: Box<[i32; 16 * 16 * WORLD_HEIGHT]>,
+1 -1
View File
@@ -1,6 +1,6 @@
use std::path::PathBuf;
use crate::world::Level;
use crate::level::Level;
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
pub enum Dimension {
@@ -13,6 +13,7 @@ use tokio::sync::mpsc;
use crate::chunk::ChunkData;
#[allow(dead_code)]
/// The Level represents a
pub struct Level {
root_folder: PathBuf,
region_folder: PathBuf,
@@ -69,8 +70,13 @@ impl Compression {
impl Level {
pub fn from_root_folder(root_folder: PathBuf) -> Self {
// TODO: Check if exists
assert!(root_folder.exists(), "World root folder does not exist!");
let region_folder = root_folder.join("region");
assert!(
region_folder.exists(),
"World region folder does not exist!"
);
Level {
root_folder,
region_folder,
+14 -1
View File
@@ -1,3 +1,5 @@
use level::Level;
pub mod chunk;
pub mod dimension;
pub const WORLD_HEIGHT: usize = 384;
@@ -6,6 +8,17 @@ pub const DIRECT_PALETTE_BITS: u32 = 15;
pub mod block;
mod global_registry;
pub mod item;
mod level;
pub mod radial_chunk_iterator;
pub mod vector3;
mod world;
pub struct World {
pub level: Level,
// entities, players...
}
impl World {
pub fn load(level: Level) -> Self {
Self { level }
}
}