use std::io::{Read, Seek, Write};
use std::{error::Error, fmt::Display, ops::Range};
use crate::Region;
use crate::{biome::Biome, Block};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct RCoord(pub isize);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct CCoord(pub isize);
#[derive(Debug, Clone, Copy)]
pub enum HeightMode {
Trust, Calculate, }
pub trait Chunk: Send + Sync {
fn status(&self) -> String;
fn surface_height(&self, x: usize, z: usize, mode: HeightMode) -> isize;
fn biome(&self, x: usize, y: isize, z: usize) -> Option<Biome>;
fn block(&self, x: usize, y: isize, z: usize) -> Option<&Block>;
fn y_range(&self) -> Range<isize>;
}
#[derive(Debug)]
pub struct LoaderError(pub(crate) String);
pub type LoaderResult<T> = std::result::Result<T, LoaderError>;
impl Error for LoaderError {}
impl Display for LoaderError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.0)
}
}
pub trait RegionLoader<S>
where
S: Seek + Read + Write,
{
fn region(&self, x: RCoord, z: RCoord) -> LoaderResult<Option<Region<S>>>;
fn list(&self) -> LoaderResult<Vec<(RCoord, RCoord)>>;
}