use basalt_types::Slot;
#[derive(Debug, Clone)]
pub enum BlockEntity {
Chest {
slots: Box<[Slot; 27]>,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum BlockEntityKind {
Chest,
}
impl BlockEntity {
pub fn empty_chest() -> Self {
Self::Chest {
slots: Box::new(std::array::from_fn(|_| Slot::empty())),
}
}
pub fn kind(&self) -> BlockEntityKind {
match self {
Self::Chest { .. } => BlockEntityKind::Chest,
}
}
}
impl From<&BlockEntity> for BlockEntityKind {
fn from(be: &BlockEntity) -> Self {
be.kind()
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn empty_chest_has_27_empty_slots() {
let be = BlockEntity::empty_chest();
match &be {
BlockEntity::Chest { slots } => {
assert_eq!(slots.len(), 27);
assert!(slots.iter().all(|s| s.is_empty()));
}
}
}
#[test]
fn empty_chest_has_chest_kind() {
let be = BlockEntity::empty_chest();
assert_eq!(be.kind(), BlockEntityKind::Chest);
assert_eq!(BlockEntityKind::from(&be), BlockEntityKind::Chest);
}
}