Cleaning up blocks a little bit.
This commit is contained in:
parent
accf01e1fb
commit
64ec2e4d3b
1413
blocks/src/lib.rs
1413
blocks/src/lib.rs
File diff suppressed because it is too large
Load Diff
|
@ -30,31 +30,18 @@ pub const SOLID: Material = Material {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const NON_SOLID: Material = Material {
|
pub const NON_SOLID: Material = Material {
|
||||||
renderable: true,
|
|
||||||
never_cull: false,
|
|
||||||
should_cull_against: false,
|
should_cull_against: false,
|
||||||
force_shade: false,
|
|
||||||
transparent: false,
|
|
||||||
absorbed_light: 1,
|
absorbed_light: 1,
|
||||||
emitted_light: 0,
|
..SOLID
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const TRANSPARENT: Material = Material {
|
pub const TRANSPARENT: Material = Material {
|
||||||
renderable: true,
|
|
||||||
never_cull: false,
|
|
||||||
should_cull_against: false,
|
|
||||||
force_shade: false,
|
|
||||||
transparent: true,
|
transparent: true,
|
||||||
absorbed_light: 1,
|
..NON_SOLID
|
||||||
emitted_light: 0,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const LEAVES: Material = Material {
|
pub const LEAVES: Material = Material {
|
||||||
renderable: true,
|
|
||||||
never_cull: true,
|
never_cull: true,
|
||||||
should_cull_against: false,
|
|
||||||
force_shade: true,
|
force_shade: true,
|
||||||
transparent: false,
|
..NON_SOLID
|
||||||
absorbed_light: 1,
|
|
||||||
emitted_light: 0,
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||||
|
pub enum Axis {
|
||||||
|
Y,
|
||||||
|
Z,
|
||||||
|
X,
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Axis {
|
||||||
|
pub fn as_string(&self) -> &'static str {
|
||||||
|
match *self {
|
||||||
|
Axis::X => "x",
|
||||||
|
Axis::Y => "y",
|
||||||
|
Axis::Z => "z",
|
||||||
|
Axis::None => "none",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn index(&self) -> usize {
|
||||||
|
match *self {
|
||||||
|
Axis::Y => 0,
|
||||||
|
Axis::Z => 2,
|
||||||
|
Axis::X => 1,
|
||||||
|
Axis::None => 3,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,11 @@
|
||||||
|
|
||||||
|
use axis::Axis;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||||
pub enum Direction {
|
pub enum Direction {
|
||||||
Invalid,
|
Invalid,
|
||||||
Up,
|
|
||||||
Down,
|
Down,
|
||||||
|
Up,
|
||||||
North,
|
North,
|
||||||
South,
|
South,
|
||||||
West,
|
West,
|
||||||
|
@ -12,7 +15,7 @@ pub enum Direction {
|
||||||
impl Direction {
|
impl Direction {
|
||||||
pub fn all() -> Vec<Direction> {
|
pub fn all() -> Vec<Direction> {
|
||||||
vec![
|
vec![
|
||||||
Direction::Up, Direction::Down,
|
Direction::Down, Direction::Up,
|
||||||
Direction::North, Direction::South,
|
Direction::North, Direction::South,
|
||||||
Direction::West, Direction::East,
|
Direction::West, Direction::East,
|
||||||
]
|
]
|
||||||
|
@ -20,8 +23,8 @@ impl Direction {
|
||||||
|
|
||||||
pub fn from_string(val: &str) -> Direction {
|
pub fn from_string(val: &str) -> Direction {
|
||||||
match val {
|
match val {
|
||||||
"up" => Direction::Up,
|
|
||||||
"down" => Direction::Down,
|
"down" => Direction::Down,
|
||||||
|
"up" => Direction::Up,
|
||||||
"north" => Direction::North,
|
"north" => Direction::North,
|
||||||
"south" => Direction::South,
|
"south" => Direction::South,
|
||||||
"west" => Direction::West,
|
"west" => Direction::West,
|
||||||
|
@ -32,8 +35,8 @@ impl Direction {
|
||||||
|
|
||||||
pub fn opposite(&self) -> Direction {
|
pub fn opposite(&self) -> Direction {
|
||||||
match *self {
|
match *self {
|
||||||
Direction::Up => Direction::Down,
|
|
||||||
Direction::Down => Direction::Up,
|
Direction::Down => Direction::Up,
|
||||||
|
Direction::Up => Direction::Down,
|
||||||
Direction::North => Direction::South,
|
Direction::North => Direction::South,
|
||||||
Direction::South => Direction::North,
|
Direction::South => Direction::North,
|
||||||
Direction::West => Direction::East,
|
Direction::West => Direction::East,
|
||||||
|
@ -44,8 +47,8 @@ impl Direction {
|
||||||
|
|
||||||
pub fn clockwise(&self) -> Direction {
|
pub fn clockwise(&self) -> Direction {
|
||||||
match *self {
|
match *self {
|
||||||
Direction::Up => Direction::Up,
|
|
||||||
Direction::Down => Direction::Down,
|
Direction::Down => Direction::Down,
|
||||||
|
Direction::Up => Direction::Up,
|
||||||
Direction::East => Direction::South,
|
Direction::East => Direction::South,
|
||||||
Direction::West => Direction::North,
|
Direction::West => Direction::North,
|
||||||
Direction::South => Direction::West,
|
Direction::South => Direction::West,
|
||||||
|
@ -56,8 +59,8 @@ impl Direction {
|
||||||
|
|
||||||
pub fn counter_clockwise(&self) -> Direction {
|
pub fn counter_clockwise(&self) -> Direction {
|
||||||
match *self {
|
match *self {
|
||||||
Direction::Up => Direction::Up,
|
|
||||||
Direction::Down => Direction::Down,
|
Direction::Down => Direction::Down,
|
||||||
|
Direction::Up => Direction::Up,
|
||||||
Direction::East => Direction::North,
|
Direction::East => Direction::North,
|
||||||
Direction::West => Direction::South,
|
Direction::West => Direction::South,
|
||||||
Direction::South => Direction::East,
|
Direction::South => Direction::East,
|
||||||
|
@ -68,8 +71,8 @@ impl Direction {
|
||||||
|
|
||||||
pub fn get_offset(&self) -> (i32, i32, i32) {
|
pub fn get_offset(&self) -> (i32, i32, i32) {
|
||||||
match *self {
|
match *self {
|
||||||
Direction::Up => (0, 1, 0),
|
|
||||||
Direction::Down => (0, -1, 0),
|
Direction::Down => (0, -1, 0),
|
||||||
|
Direction::Up => (0, 1, 0),
|
||||||
Direction::North => (0, 0, -1),
|
Direction::North => (0, 0, -1),
|
||||||
Direction::South => (0, 0, 1),
|
Direction::South => (0, 0, 1),
|
||||||
Direction::West => (-1, 0, 0),
|
Direction::West => (-1, 0, 0),
|
||||||
|
@ -80,8 +83,8 @@ impl Direction {
|
||||||
|
|
||||||
pub fn as_string(&self) -> &'static str {
|
pub fn as_string(&self) -> &'static str {
|
||||||
match *self {
|
match *self {
|
||||||
Direction::Up => "up",
|
|
||||||
Direction::Down => "down",
|
Direction::Down => "down",
|
||||||
|
Direction::Up => "up",
|
||||||
Direction::North => "north",
|
Direction::North => "north",
|
||||||
Direction::South => "south",
|
Direction::South => "south",
|
||||||
Direction::West => "west",
|
Direction::West => "west",
|
||||||
|
@ -92,8 +95,8 @@ impl Direction {
|
||||||
|
|
||||||
pub fn index(&self) -> usize {
|
pub fn index(&self) -> usize {
|
||||||
match *self {
|
match *self {
|
||||||
Direction::Up => 0,
|
Direction::Down => 0,
|
||||||
Direction::Down => 1,
|
Direction::Up => 1,
|
||||||
Direction::North => 2,
|
Direction::North => 2,
|
||||||
Direction::South => 3,
|
Direction::South => 3,
|
||||||
Direction::West => 4,
|
Direction::West => 4,
|
||||||
|
@ -101,4 +104,23 @@ impl Direction {
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn horizontal_index(&self) -> usize {
|
||||||
|
match *self {
|
||||||
|
Direction::North => 2,
|
||||||
|
Direction::South => 0,
|
||||||
|
Direction::West => 1,
|
||||||
|
Direction::East => 3,
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn axis(&self) -> Axis {
|
||||||
|
match *self {
|
||||||
|
Direction::Down | Direction::Up => Axis::Y,
|
||||||
|
Direction::North | Direction::South => Axis::Z,
|
||||||
|
Direction::West | Direction::East => Axis::X,
|
||||||
|
_ => unreachable!(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
|
|
||||||
|
pub mod axis;
|
||||||
|
pub use axis::Axis;
|
||||||
|
|
||||||
pub mod direction;
|
pub mod direction;
|
||||||
pub use direction::Direction;
|
pub use direction::Direction;
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ use cgmath;
|
||||||
use collision::Aabb;
|
use collision::Aabb;
|
||||||
use sdl2::keyboard::Keycode;
|
use sdl2::keyboard::Keycode;
|
||||||
use types::Gamemode;
|
use types::Gamemode;
|
||||||
use shared::Position;
|
use shared::{Axis, Position};
|
||||||
use format;
|
use format;
|
||||||
|
|
||||||
mod sun;
|
mod sun;
|
||||||
|
@ -230,7 +230,7 @@ impl Server {
|
||||||
|
|
||||||
if x*x + z*z > 16*16 && rng.gen_weighted_bool(80) {
|
if x*x + z*z > 16*16 && rng.gen_weighted_bool(80) {
|
||||||
for i in 0 .. 5 {
|
for i in 0 .. 5 {
|
||||||
server.world.set_block(Position::new(x, h + 1 + i, z), block::Log{ axis: block::Axis::Y, variant: block::TreeVariant::Oak });
|
server.world.set_block(Position::new(x, h + 1 + i, z), block::Log{ axis: Axis::Y, variant: block::TreeVariant::Oak });
|
||||||
}
|
}
|
||||||
for xx in -2 .. 3 {
|
for xx in -2 .. 3 {
|
||||||
for zz in -2 .. 3 {
|
for zz in -2 .. 3 {
|
||||||
|
|
Loading…
Reference in New Issue