Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
added water
Browse files Browse the repository at this point in the history
  • Loading branch information
Adamkob12 committed Oct 17, 2023
1 parent 65edcbf commit cc6041d
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
Binary file modified assets/blocks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 29 additions & 1 deletion src/block_reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub const WOOD: Block = 6;
pub const LEAVES: Block = 7;
pub const GLASS: Block = 8;
pub const GLOWSTONE: Block = 9;
pub const WATER: Block = 10;

pub const VOXEL_DIMS: [f32; 3] = [1.0, 1.0, 1.0];

Expand All @@ -31,11 +32,28 @@ pub struct BlockRegistry {
leaves_block: Mesh,
glass_block: Mesh,
glowstone_block: Mesh,
water_block: Mesh,
}

impl Default for BlockRegistry {
fn default() -> Self {
BlockRegistry {
water_block: generate_voxel_mesh(
VOXEL_DIMS,
ATLAS_CORDS,
[
(Top, [11, 0]),
(Bottom, [11, 0]),
(Right, [11, 0]),
(Left, [11, 0]),
(Forward, [11, 0]),
(Back, [11, 0]),
],
PADDING,
Some(0.75),
0.8,
),

grass_block: generate_voxel_mesh(
VOXEL_DIMS,
ATLAS_CORDS,
Expand All @@ -49,6 +67,7 @@ impl Default for BlockRegistry {
],
PADDING,
Some(0.75),
1.0,
),
dirt_block: generate_voxel_mesh(
VOXEL_DIMS,
Expand All @@ -63,6 +82,7 @@ impl Default for BlockRegistry {
],
PADDING,
Some(0.75),
1.0,
),
stone_block: generate_voxel_mesh(
VOXEL_DIMS,
Expand All @@ -77,6 +97,7 @@ impl Default for BlockRegistry {
],
PADDING,
Some(0.75),
1.0,
),
bricks_block: generate_voxel_mesh(
VOXEL_DIMS,
Expand All @@ -91,6 +112,7 @@ impl Default for BlockRegistry {
],
PADDING,
Some(0.75),
1.0,
),
log_block: generate_voxel_mesh(
VOXEL_DIMS,
Expand All @@ -105,6 +127,7 @@ impl Default for BlockRegistry {
],
PADDING,
Some(0.90),
1.0,
),
wood_block: generate_voxel_mesh(
VOXEL_DIMS,
Expand All @@ -119,6 +142,7 @@ impl Default for BlockRegistry {
],
PADDING,
Some(0.75),
1.0,
),
leaves_block: generate_voxel_mesh(
VOXEL_DIMS,
Expand All @@ -133,6 +157,7 @@ impl Default for BlockRegistry {
],
PADDING,
Some(0.75),
1.0,
),
glass_block: generate_voxel_mesh(
VOXEL_DIMS,
Expand All @@ -147,6 +172,7 @@ impl Default for BlockRegistry {
],
PADDING,
Some(0.75),
1.0,
),
glowstone_block: generate_voxel_mesh(
VOXEL_DIMS,
Expand All @@ -161,6 +187,7 @@ impl Default for BlockRegistry {
],
PADDING,
Some(0.75),
1.0,
),
}
}
Expand All @@ -187,7 +214,7 @@ impl VoxelRegistry for BlockRegistry {
}

fn is_covering(&self, voxel: &Self::Voxel, _side: prelude::Face) -> bool {
*voxel != AIR && *voxel != LEAVES && *voxel != GLASS
*voxel != AIR && *voxel != LEAVES && *voxel != GLASS && *voxel != WATER
}

fn get_mesh(&self, voxel: &Self::Voxel) -> VoxelMesh<&Mesh> {
Expand All @@ -202,6 +229,7 @@ impl VoxelRegistry for BlockRegistry {
LEAVES => VoxelMesh::NormalCube(&self.leaves_block),
GLASS => VoxelMesh::NormalCube(&self.glass_block),
GLOWSTONE => VoxelMesh::NormalCube(&self.glowstone_block),
WATER => VoxelMesh::NormalCube(&self.water_block),
_ => VoxelMesh::Null,
}
}
Expand Down
18 changes: 9 additions & 9 deletions src/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ impl Default for Inventory {
Inventory {
current: 0,
items: vec![
GRASS, DIRT, STONE, BRICKS, LOG, WOOD, LEAVES, GLASS, GLOWSTONE,
GRASS, DIRT, STONE, BRICKS, LOG, WOOD, LEAVES, GLASS, GLOWSTONE, WATER,
],
}
}
Expand All @@ -39,35 +39,35 @@ fn input_inventory(mut inv: ResMut<Inventory>, keys: Res<Input<KeyCode>>) {
inv.current = 2;
inv.current = inv.current % inv.items.len();
}
if keys.just_pressed(KeyCode::Key3) {
if keys.just_pressed(KeyCode::Key3) || keys.just_pressed(KeyCode::R) {
inv.current = 3;
inv.current = inv.current % inv.items.len();
}
if keys.just_pressed(KeyCode::Key4) {
if keys.just_pressed(KeyCode::Key4) || keys.just_pressed(KeyCode::Z) {
inv.current = 4;
inv.current = inv.current % inv.items.len();
}
if keys.just_pressed(KeyCode::Key5) {
if keys.just_pressed(KeyCode::Key5) || keys.just_pressed(KeyCode::X) {
inv.current = 5;
inv.current = inv.current % inv.items.len();
}
if keys.just_pressed(KeyCode::Key6) {
if keys.just_pressed(KeyCode::Key6) || keys.just_pressed(KeyCode::C) {
inv.current = 6;
inv.current = inv.current % inv.items.len();
}
if keys.just_pressed(KeyCode::Key7) {
if keys.just_pressed(KeyCode::Key7) || keys.just_pressed(KeyCode::V) {
inv.current = 7;
inv.current = inv.current % inv.items.len();
}
if keys.just_pressed(KeyCode::Key8) {
if keys.just_pressed(KeyCode::Key8) || keys.just_pressed(KeyCode::G) {
inv.current = 8;
inv.current = inv.current % inv.items.len();
}
if keys.just_pressed(KeyCode::Key9) {
if keys.just_pressed(KeyCode::Key9) || keys.just_pressed(KeyCode::T) {
inv.current = 9;
inv.current = inv.current % inv.items.len();
}
if keys.just_pressed(KeyCode::Key0) {
if keys.just_pressed(KeyCode::Key0) || keys.just_pressed(KeyCode::F) {
inv.current = 0;
inv.current = inv.current % inv.items.len();
}
Expand Down

0 comments on commit cc6041d

Please sign in to comment.