use super::BlockEntity; use pumpkin_nbt::compound::NbtCompound; use pumpkin_util::math::position::BlockPos; use std::sync::Mutex; pub struct SculkCatalystBlockEntity { pub position: BlockPos, pub decay_delay: Mutex, } impl BlockEntity for SculkCatalystBlockEntity { fn resource_location(&self) -> &'static str { Self::ID } fn get_position(&self) -> BlockPos { self.position } fn from_nbt(nbt: &pumpkin_nbt::compound::NbtCompound, position: BlockPos) -> Self where Self: Sized, { let decay_delay = nbt.get_int("decay_delay").unwrap_or(0); Self { position, decay_delay: Mutex::new(decay_delay), } } fn write_nbt(&self, nbt: &mut NbtCompound) { if let Ok(decay_delay) = self.decay_delay.lock() { nbt.put_int("decay_delay", *decay_delay); } } fn chunk_data_nbt(&self) -> Option { let mut nbt = NbtCompound::new(); nbt.put_int("decay_delay", *self.decay_delay.try_lock().ok()?); Some(nbt) } fn as_any(&self) -> &dyn std::any::Any { self } } impl SculkCatalystBlockEntity { pub const ID: &'static str = "minecraft:sculk_catalyst"; #[must_use] pub const fn new(position: BlockPos) -> Self { Self { position, decay_delay: Mutex::new(0), } } }