use bevy::prelude::*; use lightyear::prelude::*; use bevy::ecs::system::SystemParam; use serde::{Deserialize, Serialize}; #[derive(Component, PartialEq, Deserialize, Serialize)] pub struct Block; #[derive(SystemParam)] pub struct Blocks<'w, 's> { commands: Commands<'w, 's>, blocks: Query<'w, 's, &'static Transform, With>, } impl Blocks<'_, '_> { pub fn spawn(&mut self, pos: IVec3) { self.commands.spawn(( Block, Transform::from_translation(pos.as_vec3() + Vec3::ONE / 2.), Replicate::to_clients(NetworkTarget::All), )); } /// Gets the position of a block entity, or `None` if not a block. pub fn position(&self, entity: Entity) -> Option { let transform = self.blocks.get(entity).ok(); transform.map(|t| t.translation.floor().as_ivec3()) } }