Initial commit and progress blocking out

This commit is contained in:
Nicholas Novak
2023-09-26 13:26:10 -07:00
commit cef39ef57a
8 changed files with 1602 additions and 0 deletions

11
src/storage/interface.rs Normal file
View File

@@ -0,0 +1,11 @@
use crate::storage::world::{BlockID, BlockPos};
enum StorageInterface {
/// `ChangeBlock` changes the block at the world position given by `world_position` to the
/// target block id `BlockID`
ChangeBlock {
target_state: BlockID,
world_position: BlockPos,
},
ChangeBlockRange(BlockID, BlockPos, BlockPos),
}

2
src/storage/mod.rs Normal file
View File

@@ -0,0 +1,2 @@
mod interface;
mod world;

32
src/storage/world.rs Normal file
View File

@@ -0,0 +1,32 @@
type ChunkCoordinate = isize;
const SECTIONS_PER_CHUNK: usize = 16;
struct ChunkData {
x: ChunkCoordinate,
y: ChunkCoordinate,
sections: [ChunkSection; SECTIONS_PER_CHUNK],
}
// https://wiki.vg/Chunk_Format
struct ChunkSection {
/// The number of non-empty blocks in the section. If completely full, the
/// section contains a 16 x 16 x 16 cube of blocks = 4096 blocks
/// If the section is empty, this is skipped
block_count: u16,
block_states: [BlockID; 4096],
}
/// `BlockPos` represents the location of a block in world space
pub struct BlockPos {
x: isize,
y: isize,
z: isize,
}
/// BlockID represents the type of block stored
#[repr(u8)]
pub enum BlockID {
Empty,
Generic,
}