diff --git a/assets/UV_map_example.png b/assets/UV_map_example.png deleted file mode 100644 index 4584e98..0000000 Binary files a/assets/UV_map_example.png and /dev/null differ diff --git a/assets/blocks.png b/assets/blocks.png new file mode 100644 index 0000000..da6442d Binary files /dev/null and b/assets/blocks.png differ diff --git a/src/block_reg.rs b/src/block_reg.rs index 4647367..0142fc7 100644 --- a/src/block_reg.rs +++ b/src/block_reg.rs @@ -8,24 +8,29 @@ pub const AIR: Block = 0; pub const DIRT: Block = 1; pub const GRASS: Block = 2; pub const STONE: Block = 3; -pub const LIGHT_MAGIC: Block = 4; -pub const DARK_MAGIC: Block = 5; -pub const TRANSPERENT: Block = 6; -pub const WOOD_DARK_GREY: Block = 7; -pub const PINK_LEAVES: Block = 8; +pub const BRICKS: Block = 4; +pub const LOG: Block = 5; +pub const WOOD: Block = 6; +pub const LEAVES: Block = 7; +pub const GLASS: Block = 8; +pub const GLOWSTONE: Block = 9; pub const VOXEL_DIMS: [f32; 3] = [1.0, 1.0, 1.0]; +const ATLAS_CORDS: [u32; 2] = [24, 24]; +const PADDING: f32 = 0.0625; + #[derive(Resource, Clone)] pub struct BlockRegistry { grass_block: Mesh, dirt_block: Mesh, stone_block: Mesh, - light_magic_block: Mesh, - dark_magic_block: Mesh, - transperent_block: Mesh, - wood_dark_grey_block: Mesh, - pink_leaves: Mesh, + bricks_block: Mesh, + log_block: Mesh, + wood_block: Mesh, + leaves_block: Mesh, + glass_block: Mesh, + glowstone_block: Mesh, } impl Default for BlockRegistry { @@ -33,7 +38,7 @@ impl Default for BlockRegistry { BlockRegistry { grass_block: generate_voxel_mesh( VOXEL_DIMS, - [4, 4], + ATLAS_CORDS, [ (Top, [0, 0]), (Bottom, [2, 0]), @@ -42,12 +47,12 @@ impl Default for BlockRegistry { (Forward, [1, 0]), (Back, [1, 0]), ], - 0.1, + PADDING, Some(0.75), ), dirt_block: generate_voxel_mesh( VOXEL_DIMS, - [4, 4], + ATLAS_CORDS, [ (Top, [2, 0]), (Bottom, [2, 0]), @@ -56,12 +61,12 @@ impl Default for BlockRegistry { (Forward, [2, 0]), (Back, [2, 0]), ], - 0.1, + PADDING, Some(0.75), ), stone_block: generate_voxel_mesh( VOXEL_DIMS, - [4, 4], + ATLAS_CORDS, [ (Top, [3, 0]), (Bottom, [3, 0]), @@ -70,77 +75,91 @@ impl Default for BlockRegistry { (Forward, [3, 0]), (Back, [3, 0]), ], - 0.1, + PADDING, Some(0.75), ), - light_magic_block: generate_voxel_mesh( + bricks_block: generate_voxel_mesh( VOXEL_DIMS, - [4, 4], + ATLAS_CORDS, [ - (Top, [2, 1]), - (Bottom, [2, 1]), - (Right, [2, 1]), - (Left, [2, 1]), - (Forward, [2, 1]), - (Back, [2, 1]), + (Top, [4, 0]), + (Bottom, [4, 0]), + (Right, [4, 0]), + (Left, [4, 0]), + (Forward, [4, 0]), + (Back, [4, 0]), ], - 0.1, + PADDING, Some(0.75), ), - dark_magic_block: generate_voxel_mesh( + log_block: generate_voxel_mesh( + VOXEL_DIMS, + ATLAS_CORDS, + [ + (Top, [5, 0]), + (Bottom, [5, 0]), + (Right, [6, 0]), + (Left, [6, 0]), + (Forward, [6, 0]), + (Back, [6, 0]), + ], + PADDING, + Some(0.90), + ), + wood_block: generate_voxel_mesh( VOXEL_DIMS, - [4, 4], + ATLAS_CORDS, [ - (Top, [1, 1]), - (Bottom, [1, 1]), - (Right, [1, 1]), - (Left, [1, 1]), - (Forward, [1, 1]), - (Back, [1, 1]), + (Top, [7, 0]), + (Bottom, [7, 0]), + (Right, [7, 0]), + (Left, [7, 0]), + (Forward, [7, 0]), + (Back, [7, 0]), ], - 0.1, + PADDING, Some(0.75), ), - transperent_block: generate_voxel_mesh( + leaves_block: generate_voxel_mesh( VOXEL_DIMS, - [4, 4], + ATLAS_CORDS, [ - (Top, [3, 1]), - (Bottom, [3, 1]), - (Right, [3, 1]), - (Left, [3, 1]), - (Forward, [3, 1]), - (Back, [3, 1]), + (Top, [8, 0]), + (Bottom, [8, 0]), + (Right, [8, 0]), + (Left, [8, 0]), + (Forward, [8, 0]), + (Back, [8, 0]), ], - 0.1, + PADDING, Some(0.75), ), - wood_dark_grey_block: generate_voxel_mesh( + glass_block: generate_voxel_mesh( VOXEL_DIMS, - [4, 4], + ATLAS_CORDS, [ - (Top, [0, 2]), - (Bottom, [0, 2]), - (Right, [0, 2]), - (Left, [0, 2]), - (Forward, [0, 2]), - (Back, [0, 2]), + (Top, [9, 0]), + (Bottom, [9, 0]), + (Right, [9, 0]), + (Left, [9, 0]), + (Forward, [9, 0]), + (Back, [9, 0]), ], - 0.1, + PADDING, Some(0.75), ), - pink_leaves: generate_voxel_mesh( + glowstone_block: generate_voxel_mesh( VOXEL_DIMS, - [4, 4], + ATLAS_CORDS, [ - (Top, [1, 2]), - (Bottom, [1, 2]), - (Right, [1, 2]), - (Left, [1, 2]), - (Forward, [1, 2]), - (Back, [1, 2]), + (Top, [10, 0]), + (Bottom, [10, 0]), + (Right, [10, 0]), + (Left, [10, 0]), + (Forward, [10, 0]), + (Back, [10, 0]), ], - 0.1, + PADDING, Some(0.75), ), } @@ -168,7 +187,7 @@ impl VoxelRegistry for BlockRegistry { } fn is_covering(&self, voxel: &Self::Voxel, _side: prelude::Face) -> bool { - *voxel != AIR && *voxel != PINK_LEAVES && *voxel != TRANSPERENT + *voxel != AIR && *voxel != LEAVES && *voxel != GLASS } fn get_mesh(&self, voxel: &Self::Voxel) -> VoxelMesh<&Mesh> { @@ -177,11 +196,12 @@ impl VoxelRegistry for BlockRegistry { DIRT => VoxelMesh::NormalCube(&self.dirt_block), GRASS => VoxelMesh::NormalCube(&self.grass_block), STONE => VoxelMesh::NormalCube(&self.stone_block), - LIGHT_MAGIC => VoxelMesh::NormalCube(&self.light_magic_block), - DARK_MAGIC => VoxelMesh::NormalCube(&self.dark_magic_block), - TRANSPERENT => VoxelMesh::NormalCube(&self.transperent_block), - WOOD_DARK_GREY => VoxelMesh::NormalCube(&self.wood_dark_grey_block), - PINK_LEAVES => VoxelMesh::NormalCube(&self.pink_leaves), + BRICKS => VoxelMesh::NormalCube(&self.bricks_block), + LOG => VoxelMesh::NormalCube(&self.log_block), + WOOD => VoxelMesh::NormalCube(&self.wood_block), + LEAVES => VoxelMesh::NormalCube(&self.leaves_block), + GLASS => VoxelMesh::NormalCube(&self.glass_block), + GLOWSTONE => VoxelMesh::NormalCube(&self.glowstone_block), _ => VoxelMesh::Null, } } diff --git a/src/chunk/mod.rs b/src/chunk/mod.rs index d4ce555..9c62372 100644 --- a/src/chunk/mod.rs +++ b/src/chunk/mod.rs @@ -57,16 +57,18 @@ impl Plugin for ChunkPlugin { ( spawn_and_despawn_chunks, frame_chunk_update, - (update_closby_chunks, update_mesh_frame) - .run_if(in_state(InitialChunkLoadState::Complete)), + (update_closby_chunks).run_if(in_state(InitialChunkLoadState::Complete)), ), ); app.add_systems( PostUpdate, - (cull_sides_of_mesh.run_if( - in_state(InitialChunkLoadState::Complete) - .and_then(resource_changed::()), - ),), + ( + cull_sides_of_mesh.run_if( + in_state(InitialChunkLoadState::Complete) + .and_then(resource_changed::()), + ), + update_mesh_frame, + ), ); // Resources diff --git a/src/chunk/systems.rs b/src/chunk/systems.rs index 900183a..0241ea6 100644 --- a/src/chunk/systems.rs +++ b/src/chunk/systems.rs @@ -87,7 +87,9 @@ pub(crate) fn update_mesh_frame( .expect("Can't find chunk mesh in internal assets"); update_mesh(mesh_ref_mut, &mut chunk.meta_data, &*breg.clone()); if let Some(aabb) = mesh_ref_mut.compute_aabb() { - commands.entity(ent).insert(aabb).remove::(); + if let Some(mut comm) = commands.get_entity(ent) { + comm.insert(aabb).remove::(); + } } else { warn!("Couldn't compute Aabb for mesh after updating"); } diff --git a/src/inventory.rs b/src/inventory.rs index f859d43..d84b2ae 100644 --- a/src/inventory.rs +++ b/src/inventory.rs @@ -13,14 +13,7 @@ impl Default for Inventory { Inventory { current: 0, items: vec![ - STONE, - GRASS, - DIRT, - LIGHT_MAGIC, - DARK_MAGIC, - TRANSPERENT, - WOOD_DARK_GREY, - PINK_LEAVES, + GRASS, DIRT, STONE, BRICKS, LOG, WOOD, LEAVES, GLASS, GLOWSTONE, ], } } diff --git a/src/main.rs b/src/main.rs index 7c540c7..98c1244 100644 --- a/src/main.rs +++ b/src/main.rs @@ -27,7 +27,7 @@ pub use utils::*; // const FACTOR: usize = CHUNK_DIMS.0; // Render distance should be above 1. -pub const RENDER_DISTANCE: i32 = 8; +pub const RENDER_DISTANCE: i32 = 6; pub const GEN_SEED: u32 = 5; const CROSSHAIR_SIZE: f32 = 22.0; @@ -68,7 +68,7 @@ fn main() { .init_resource::() .insert_resource(AmbientLight { - brightness: 1.2, color: Color::ANTIQUE_WHITE}) + brightness: 0.75, color: Color::ANTIQUE_WHITE}) .insert_resource(CycleTimer(Timer::new( bevy::utils::Duration::from_millis(50), TimerMode::Repeating,))) @@ -102,7 +102,7 @@ fn setup( asset_server: Res, mut camera_query: Query<&mut Projection>, ) { - let texture_handle: Handle = asset_server.load("UV_map_example.png"); + let texture_handle: Handle = asset_server.load("blocks.png"); let mat = materials.add(StandardMaterial { base_color_texture: Some(texture_handle), reflectance: 0.0, @@ -114,7 +114,7 @@ fn setup( commands.spawn(LoadedChunks(0)); let mut projection = camera_query.get_single_mut().unwrap(); if let Projection::Perspective(ref mut perspective) = *projection { - perspective.fov = PI / 3.0; + perspective.fov = PI / 3.5; } } diff --git a/src/player/movement.rs b/src/player/movement.rs index 5207884..f04854f 100644 --- a/src/player/movement.rs +++ b/src/player/movement.rs @@ -126,13 +126,21 @@ pub(super) fn player_move( (HALF_CAGE_I as i32) as usize, (HALF_CAGE_I + dz as i32) as usize, ]; + let xzblock_cords = [ + (HALF_CAGE_I + dx as i32) as usize, + (HALF_CAGE_I as i32) as usize, + (HALF_CAGE_I + dz as i32) as usize, + ]; let xblock = one_d_cords(xblock_cords, CAGE_DIMS); let yblock = one_d_cords(yblock_cords, CAGE_DIMS); let zblock = one_d_cords(zblock_cords, CAGE_DIMS); + let xzblock = one_d_cords(xzblock_cords, CAGE_DIMS); let xblock = cage.blocks[xblock]; let yblock = cage.blocks[yblock]; let zblock = cage.blocks[zblock]; + let xzblock = cage.blocks[xzblock]; + if xblock == AIR { transform.translation.x = new_pos.x; } else if (pos.x - pos.x.round() + 0.5 * dx.signum() * -1.0).abs() > 0.5 { @@ -145,7 +153,7 @@ pub(super) fn player_move( transform.translation.y += velocity.y * (pos.y - pos.y.round() + 0.5 * dy.signum() * -1.0).powi(2); } - if zblock == AIR { + if zblock == AIR && xzblock == AIR { transform.translation.z = new_pos.z; } else if (pos.z - pos.z.round() + 0.5 * dz.signum() * -1.0).abs() > 0.5 { transform.translation.z +=