feat: add some more entity logic

This commit is contained in:
Alexander Medvedev committed 2026-08-13 17:28:56 +02:00
1 parent 24d9dbdc6b
commit 5a5bc19bbb
39 files changed
+6811 -245

No files matched your search

@@ -1,12 +1,19 @@
use std::pin::Pin;
use std::sync::Arc;
use crossbeam::atomic::AtomicCell;
use pumpkin_data::sound::{Sound, SoundCategory};
use pumpkin_nbt::compound::NbtCompound;
use pumpkin_util::math::position::BlockPos;
use uuid::Uuid;
use crate::world::World;
use super::BlockEntity;
pub struct CreakingHeartBlockEntity {
pub position: BlockPos,
pub creaking_uuid: AtomicCell<Option<Uuid>>,
}
impl BlockEntity for CreakingHeartBlockEntity {
@@ -18,18 +25,28 @@ impl BlockEntity for CreakingHeartBlockEntity {
self.position
}
fn from_nbt(_nbt: &pumpkin_nbt::compound::NbtCompound, position: BlockPos) -> Self
fn from_nbt(nbt: &pumpkin_nbt::compound::NbtCompound, position: BlockPos) -> Self
where
Self: Sized,
{
Self { position }
let creaking_uuid = nbt
.get_string("creaking_uuid")
.and_then(|uuid_str| Uuid::parse_str(uuid_str).ok());
Self {
position,
creaking_uuid: AtomicCell::new(creaking_uuid),
}
}
fn write_nbt<'a>(
&'a self,
_nbt: &'a mut NbtCompound,
nbt: &'a mut NbtCompound,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'a>> {
Box::pin(async {})
Box::pin(async move {
if let Some(uuid) = self.creaking_uuid.load() {
nbt.put_string("creaking_uuid", uuid.to_string());
}
})
}
fn as_any(&self) -> &dyn std::any::Any {
@@ -39,8 +56,30 @@ impl BlockEntity for CreakingHeartBlockEntity {
impl CreakingHeartBlockEntity {
pub const ID: &'static str = "minecraft:creaking_heart";
#[must_use]
pub const fn new(position: BlockPos) -> Self {
Self { position }
Self {
position,
creaking_uuid: AtomicCell::new(None),
}
}
pub fn is_protector(&self, creaking_uuid: Uuid) -> bool {
self.creaking_uuid
.load()
.is_none_or(|uuid| uuid == creaking_uuid)
}
pub fn set_creaking_uuid(&self, uuid: Option<Uuid>) {
self.creaking_uuid.store(uuid);
}
pub fn creaking_hurt(&self, world: &Arc<World>) {
world.play_sound(
Sound::BlockCreakingHeartHurt,
SoundCategory::Blocks,
&self.position.to_f64(),
);
}
}