Bloxel sandbox game similar to Minecraft "Classic" (2009) in Rust with Bevy
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

39 lines
993 B

use bevy::ecs::system::SystemParam;
use bevy::prelude::*;
#[derive(Component)]
pub struct Block;
#[derive(SystemParam)]
pub struct Blocks<'w, 's> {
commands: Commands<'w, 's>,
block_resources: Res<'w, BlockResources>,
}
impl Blocks<'_, '_> {
pub fn spawn(&mut self, pos: IVec3) {
self.commands.spawn((
Block,
Mesh3d(self.block_resources.mesh.clone()),
MeshMaterial3d(self.block_resources.material.clone()),
Transform::from_translation(pos.as_vec3() + Vec3::ONE / 2.),
));
}
}
#[derive(Resource)]
pub struct BlockResources {
mesh: Handle<Mesh>,
material: Handle<StandardMaterial>,
}
pub fn setup_blocks(
mut commands: Commands,
mut meshes: ResMut<Assets<Mesh>>,
mut materials: ResMut<Assets<StandardMaterial>>,
) {
commands.insert_resource(BlockResources {
mesh: meshes.add(Cuboid::new(1.0, 1.0, 1.0)),
material: materials.add(Color::srgb_u8(124, 144, 255)),
});
}