2019-06-06 14:48:41 +00:00
|
|
|
use crate::vol::Vox;
|
2019-04-29 20:37:19 +00:00
|
|
|
use serde_derive::{Deserialize, Serialize};
|
2019-08-14 21:28:37 +00:00
|
|
|
use std::ops::Deref;
|
2019-01-23 20:01:58 +00:00
|
|
|
use vek::*;
|
|
|
|
|
2019-08-19 23:31:11 +00:00
|
|
|
#[derive(Copy, Clone, Debug, Hash, Eq, PartialEq, Serialize, Deserialize)]
|
2019-08-14 21:28:37 +00:00
|
|
|
#[repr(u8)]
|
|
|
|
pub enum BlockKind {
|
|
|
|
Air,
|
|
|
|
Normal,
|
|
|
|
Dense,
|
|
|
|
Water,
|
2019-08-21 17:22:05 +00:00
|
|
|
LargeCactus,
|
|
|
|
BarrelCactus,
|
2019-09-01 19:04:03 +00:00
|
|
|
RoundCactus,
|
|
|
|
ShortCactus,
|
|
|
|
MedFlatCactus,
|
|
|
|
ShortFlatCactus,
|
2019-08-21 17:22:05 +00:00
|
|
|
BlueFlower,
|
|
|
|
PinkFlower,
|
|
|
|
PurpleFlower,
|
|
|
|
RedFlower,
|
|
|
|
WhiteFlower,
|
|
|
|
YellowFlower,
|
|
|
|
Sunflower,
|
2019-08-19 23:31:11 +00:00
|
|
|
LongGrass,
|
2019-08-21 17:22:05 +00:00
|
|
|
MediumGrass,
|
|
|
|
ShortGrass,
|
|
|
|
Apple,
|
2019-09-01 19:04:03 +00:00
|
|
|
Mushroom,
|
|
|
|
Liana,
|
2019-09-25 20:22:39 +00:00
|
|
|
Velorite,
|
2019-10-17 20:59:36 +00:00
|
|
|
VeloriteFrag,
|
2019-10-09 19:28:05 +00:00
|
|
|
Chest,
|
2020-01-18 05:24:48 +00:00
|
|
|
Leaves,
|
2020-01-25 11:14:02 +00:00
|
|
|
Pumpkin,
|
|
|
|
Welwitch,
|
|
|
|
LingonBerry,
|
|
|
|
LeafyPlant,
|
|
|
|
Fern,
|
|
|
|
DeadBush,
|
|
|
|
Blueberry,
|
2020-04-10 19:08:21 +00:00
|
|
|
Ember,
|
2020-04-13 23:13:03 +00:00
|
|
|
Corn,
|
|
|
|
WheatYellow,
|
|
|
|
WheatGreen,
|
|
|
|
Cabbage,
|
2020-04-17 23:29:01 +00:00
|
|
|
Flax,
|
|
|
|
Carrot,
|
|
|
|
Tomato,
|
|
|
|
Radish,
|
2020-04-13 23:13:03 +00:00
|
|
|
Coconut,
|
2019-08-14 21:28:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl BlockKind {
|
2019-09-26 13:03:41 +00:00
|
|
|
pub fn is_tangible(&self) -> bool {
|
2019-09-25 14:56:57 +00:00
|
|
|
match self {
|
|
|
|
BlockKind::Air => false,
|
|
|
|
kind => !kind.is_fluid(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-14 21:28:37 +00:00
|
|
|
pub fn is_air(&self) -> bool {
|
|
|
|
match self {
|
|
|
|
BlockKind::Air => true,
|
2019-10-04 18:27:12 +00:00
|
|
|
BlockKind::LargeCactus => true,
|
2019-08-21 17:22:05 +00:00
|
|
|
BlockKind::BarrelCactus => true,
|
2019-09-01 19:04:03 +00:00
|
|
|
BlockKind::RoundCactus => true,
|
|
|
|
BlockKind::ShortCactus => true,
|
|
|
|
BlockKind::MedFlatCactus => true,
|
|
|
|
BlockKind::ShortFlatCactus => true,
|
2019-08-21 17:22:05 +00:00
|
|
|
BlockKind::BlueFlower => true,
|
|
|
|
BlockKind::PinkFlower => true,
|
|
|
|
BlockKind::PurpleFlower => true,
|
|
|
|
BlockKind::RedFlower => true,
|
|
|
|
BlockKind::WhiteFlower => true,
|
|
|
|
BlockKind::YellowFlower => true,
|
|
|
|
BlockKind::Sunflower => true,
|
2019-08-19 23:31:11 +00:00
|
|
|
BlockKind::LongGrass => true,
|
2019-08-21 17:22:05 +00:00
|
|
|
BlockKind::MediumGrass => true,
|
|
|
|
BlockKind::ShortGrass => true,
|
|
|
|
BlockKind::Apple => true,
|
2019-09-01 19:04:03 +00:00
|
|
|
BlockKind::Mushroom => true,
|
|
|
|
BlockKind::Liana => true,
|
2019-09-25 20:22:39 +00:00
|
|
|
BlockKind::Velorite => true,
|
2019-10-17 20:59:36 +00:00
|
|
|
BlockKind::VeloriteFrag => true,
|
2019-10-09 19:28:05 +00:00
|
|
|
BlockKind::Chest => true,
|
2020-01-25 11:14:02 +00:00
|
|
|
BlockKind::Welwitch => true,
|
|
|
|
BlockKind::LingonBerry => true,
|
|
|
|
BlockKind::LeafyPlant => true,
|
|
|
|
BlockKind::Fern => true,
|
|
|
|
BlockKind::DeadBush => true,
|
|
|
|
BlockKind::Blueberry => true,
|
2020-04-10 19:08:21 +00:00
|
|
|
BlockKind::Ember => true,
|
2020-04-13 23:13:03 +00:00
|
|
|
BlockKind::Corn => true,
|
|
|
|
BlockKind::WheatYellow => true,
|
|
|
|
BlockKind::WheatGreen => true,
|
2020-04-17 23:29:01 +00:00
|
|
|
BlockKind::Cabbage => false,
|
|
|
|
BlockKind::Pumpkin => false,
|
|
|
|
BlockKind::Flax => true,
|
|
|
|
BlockKind::Carrot => true,
|
|
|
|
BlockKind::Tomato => false,
|
|
|
|
BlockKind::Radish => true,
|
2020-04-13 23:13:03 +00:00
|
|
|
BlockKind::Coconut => true,
|
2019-08-14 21:28:37 +00:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_fluid(&self) -> bool {
|
|
|
|
match self {
|
2020-04-11 00:13:48 +00:00
|
|
|
BlockKind::Water => true,
|
2019-08-14 21:28:37 +00:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn is_opaque(&self) -> bool {
|
|
|
|
match self {
|
|
|
|
BlockKind::Air => false,
|
|
|
|
BlockKind::Water => false,
|
2019-08-21 17:22:05 +00:00
|
|
|
BlockKind::LargeCactus => false,
|
|
|
|
BlockKind::BarrelCactus => false,
|
2019-09-01 19:04:03 +00:00
|
|
|
BlockKind::RoundCactus => false,
|
|
|
|
BlockKind::ShortCactus => false,
|
|
|
|
BlockKind::MedFlatCactus => false,
|
|
|
|
BlockKind::ShortFlatCactus => false,
|
2019-08-21 17:22:05 +00:00
|
|
|
BlockKind::BlueFlower => false,
|
|
|
|
BlockKind::PinkFlower => false,
|
|
|
|
BlockKind::PurpleFlower => false,
|
|
|
|
BlockKind::RedFlower => false,
|
|
|
|
BlockKind::WhiteFlower => false,
|
|
|
|
BlockKind::YellowFlower => false,
|
|
|
|
BlockKind::Sunflower => false,
|
2019-08-19 23:31:11 +00:00
|
|
|
BlockKind::LongGrass => false,
|
2019-08-21 17:22:05 +00:00
|
|
|
BlockKind::MediumGrass => false,
|
|
|
|
BlockKind::ShortGrass => false,
|
|
|
|
BlockKind::Apple => false,
|
2019-09-01 19:04:03 +00:00
|
|
|
BlockKind::Mushroom => false,
|
|
|
|
BlockKind::Liana => false,
|
2019-09-25 20:22:39 +00:00
|
|
|
BlockKind::Velorite => false,
|
2019-10-17 20:59:36 +00:00
|
|
|
BlockKind::VeloriteFrag => false,
|
2019-10-09 19:28:05 +00:00
|
|
|
BlockKind::Chest => false,
|
2020-04-14 00:50:58 +00:00
|
|
|
BlockKind::Pumpkin => false,
|
2020-01-25 11:14:02 +00:00
|
|
|
BlockKind::Welwitch => false,
|
|
|
|
BlockKind::LingonBerry => false,
|
|
|
|
BlockKind::LeafyPlant => false,
|
|
|
|
BlockKind::Fern => false,
|
|
|
|
BlockKind::DeadBush => false,
|
2020-04-11 00:13:48 +00:00
|
|
|
BlockKind::Blueberry => false,
|
|
|
|
BlockKind::Ember => false,
|
2020-04-13 23:13:03 +00:00
|
|
|
BlockKind::Corn => false,
|
|
|
|
BlockKind::WheatYellow => false,
|
|
|
|
BlockKind::WheatGreen => false,
|
|
|
|
BlockKind::Cabbage => false,
|
2020-04-17 23:29:01 +00:00
|
|
|
BlockKind::Flax => false,
|
|
|
|
BlockKind::Carrot => false,
|
|
|
|
BlockKind::Tomato => false,
|
|
|
|
BlockKind::Radish => false,
|
2020-04-13 23:13:03 +00:00
|
|
|
BlockKind::Coconut => false,
|
2019-08-14 21:28:37 +00:00
|
|
|
_ => true,
|
|
|
|
}
|
|
|
|
}
|
2019-08-16 11:38:59 +00:00
|
|
|
|
|
|
|
pub fn is_solid(&self) -> bool {
|
|
|
|
match self {
|
|
|
|
BlockKind::Air => false,
|
|
|
|
BlockKind::Water => false,
|
2019-08-21 17:22:05 +00:00
|
|
|
BlockKind::LargeCactus => true,
|
|
|
|
BlockKind::BarrelCactus => true,
|
2019-09-01 19:04:03 +00:00
|
|
|
BlockKind::RoundCactus => true,
|
|
|
|
BlockKind::ShortCactus => true,
|
|
|
|
BlockKind::MedFlatCactus => true,
|
|
|
|
BlockKind::ShortFlatCactus => true,
|
2019-08-21 17:22:05 +00:00
|
|
|
BlockKind::BlueFlower => false,
|
|
|
|
BlockKind::PinkFlower => false,
|
|
|
|
BlockKind::PurpleFlower => false,
|
|
|
|
BlockKind::RedFlower => false,
|
|
|
|
BlockKind::WhiteFlower => false,
|
|
|
|
BlockKind::YellowFlower => false,
|
|
|
|
BlockKind::Sunflower => false,
|
2019-08-19 23:31:11 +00:00
|
|
|
BlockKind::LongGrass => false,
|
2019-08-21 17:22:05 +00:00
|
|
|
BlockKind::MediumGrass => false,
|
|
|
|
BlockKind::ShortGrass => false,
|
|
|
|
BlockKind::Apple => true,
|
2019-09-01 19:04:03 +00:00
|
|
|
BlockKind::Mushroom => false,
|
|
|
|
BlockKind::Liana => false,
|
2019-10-09 19:28:05 +00:00
|
|
|
BlockKind::Chest => true,
|
2020-04-17 23:29:01 +00:00
|
|
|
BlockKind::Pumpkin => false,
|
2020-01-25 11:14:02 +00:00
|
|
|
BlockKind::Welwitch => false,
|
|
|
|
BlockKind::LingonBerry => false,
|
|
|
|
BlockKind::LeafyPlant => false,
|
|
|
|
BlockKind::Fern => false,
|
|
|
|
BlockKind::DeadBush => false,
|
|
|
|
BlockKind::Blueberry => false,
|
2020-04-10 19:08:21 +00:00
|
|
|
BlockKind::Ember => false,
|
2020-04-13 23:13:03 +00:00
|
|
|
BlockKind::Corn => false,
|
|
|
|
BlockKind::WheatYellow => false,
|
|
|
|
BlockKind::WheatGreen => false,
|
|
|
|
BlockKind::Cabbage => false,
|
2020-04-17 23:29:01 +00:00
|
|
|
BlockKind::Flax => false,
|
|
|
|
BlockKind::Carrot => false,
|
|
|
|
BlockKind::Tomato => true,
|
|
|
|
BlockKind::Radish => false,
|
2020-04-13 23:13:03 +00:00
|
|
|
BlockKind::Coconut => false,
|
2019-08-16 11:38:59 +00:00
|
|
|
_ => true,
|
|
|
|
}
|
|
|
|
}
|
2019-09-25 21:17:43 +00:00
|
|
|
|
2020-04-18 20:26:43 +00:00
|
|
|
pub const MAX_HEIGHT: f32 = 3.0;
|
|
|
|
|
|
|
|
// TODO: Integrate this into `is_solid` by returning an `Option<f32>`
|
|
|
|
pub fn get_height(&self) -> f32 {
|
|
|
|
// Beware: the height *must* be <= `MAX_HEIGHT` or the collision system will not properly
|
|
|
|
// detect it!
|
|
|
|
match self {
|
2020-04-18 20:46:39 +00:00
|
|
|
BlockKind::Tomato => 1.65,
|
2020-04-18 20:26:43 +00:00
|
|
|
BlockKind::LargeCactus => 2.5,
|
|
|
|
_ => 1.0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-25 21:17:43 +00:00
|
|
|
pub fn is_collectible(&self) -> bool {
|
|
|
|
match self {
|
2019-10-17 20:59:36 +00:00
|
|
|
BlockKind::BlueFlower => false,
|
|
|
|
BlockKind::PinkFlower => false,
|
|
|
|
BlockKind::PurpleFlower => false,
|
|
|
|
BlockKind::RedFlower => false,
|
|
|
|
BlockKind::WhiteFlower => false,
|
|
|
|
BlockKind::YellowFlower => false,
|
|
|
|
BlockKind::Sunflower => false,
|
|
|
|
BlockKind::LongGrass => false,
|
|
|
|
BlockKind::MediumGrass => false,
|
|
|
|
BlockKind::ShortGrass => false,
|
2019-09-25 21:17:43 +00:00
|
|
|
BlockKind::Apple => true,
|
|
|
|
BlockKind::Mushroom => true,
|
|
|
|
BlockKind::Velorite => true,
|
2019-10-17 20:59:36 +00:00
|
|
|
BlockKind::VeloriteFrag => true,
|
2019-10-09 19:28:05 +00:00
|
|
|
BlockKind::Chest => true,
|
2020-04-13 23:13:03 +00:00
|
|
|
BlockKind::Coconut => true,
|
2019-09-25 21:17:43 +00:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
2019-08-14 21:28:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
|
|
#[repr(packed)]
|
2019-01-02 19:22:01 +00:00
|
|
|
pub struct Block {
|
2019-08-14 21:28:37 +00:00
|
|
|
kind: BlockKind,
|
2019-01-02 19:22:01 +00:00
|
|
|
color: [u8; 3],
|
|
|
|
}
|
2019-01-14 18:49:53 +00:00
|
|
|
|
2019-01-23 20:01:58 +00:00
|
|
|
impl Block {
|
2019-08-14 21:28:37 +00:00
|
|
|
pub fn new(kind: BlockKind, color: Rgb<u8>) -> Self {
|
2019-01-23 20:01:58 +00:00
|
|
|
Self {
|
|
|
|
kind,
|
|
|
|
color: color.into_array(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-14 21:28:37 +00:00
|
|
|
pub fn get_color(&self) -> Option<Rgb<u8>> {
|
|
|
|
if !self.is_air() {
|
2019-01-23 20:01:58 +00:00
|
|
|
Some(self.color.into())
|
2019-08-14 21:28:37 +00:00
|
|
|
} else {
|
|
|
|
None
|
2019-01-23 20:01:58 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-31 20:37:11 +00:00
|
|
|
|
2020-02-01 20:39:39 +00:00
|
|
|
pub fn kind(&self) -> BlockKind { self.kind }
|
2019-08-14 21:28:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Deref for Block {
|
|
|
|
type Target = BlockKind;
|
|
|
|
|
2020-02-01 20:39:39 +00:00
|
|
|
fn deref(&self) -> &Self::Target { &self.kind }
|
2019-01-23 20:01:58 +00:00
|
|
|
}
|
|
|
|
|
2019-01-14 18:49:53 +00:00
|
|
|
impl Vox for Block {
|
|
|
|
fn empty() -> Self {
|
|
|
|
Self {
|
2019-08-14 21:28:37 +00:00
|
|
|
kind: BlockKind::Air,
|
2019-01-14 18:49:53 +00:00
|
|
|
color: [0; 3],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-01 20:39:39 +00:00
|
|
|
fn is_empty(&self) -> bool { self.is_air() }
|
2019-08-14 21:28:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn block_size() {
|
|
|
|
assert_eq!(std::mem::size_of::<BlockKind>(), 1);
|
|
|
|
assert_eq!(std::mem::size_of::<Block>(), 4);
|
2019-01-14 18:49:53 +00:00
|
|
|
}
|
|
|
|
}
|