parent
b6ac56aba4
commit
ff8578fd82
8 changed files with 59 additions and 29 deletions
@ -0,0 +1,7 @@ |
||||
[package] |
||||
name = "bevy-bloxel-classic-common" |
||||
version = "0.1.0" |
||||
edition = "2024" |
||||
|
||||
[dependencies] |
||||
bevy = { workspace = true } |
||||
@ -0,0 +1,26 @@ |
||||
use bevy::ecs::system::SystemParam; |
||||
use bevy::prelude::*; |
||||
|
||||
#[derive(Component)] |
||||
pub struct Block; |
||||
|
||||
#[derive(SystemParam)] |
||||
pub struct Blocks<'w, 's> { |
||||
commands: Commands<'w, 's>, |
||||
blocks: Query<'w, 's, &'static Transform, With<Block>>, |
||||
} |
||||
|
||||
impl Blocks<'_, '_> { |
||||
pub fn spawn(&mut self, pos: IVec3) { |
||||
self.commands.spawn(( |
||||
Block, |
||||
Transform::from_translation(pos.as_vec3() + Vec3::ONE / 2.), |
||||
)); |
||||
} |
||||
|
||||
/// Gets the position of a block entity, or `None` if not a block.
|
||||
pub fn position(&self, entity: Entity) -> Option<IVec3> { |
||||
let transform = self.blocks.get(entity).ok(); |
||||
transform.map(|t| t.translation.floor().as_ivec3()) |
||||
} |
||||
} |
||||
@ -0,0 +1 @@ |
||||
pub mod block; |
||||
Loading…
Reference in new issue