1use crate::collectable::{CollectableType, Collectable};
2use crate::chunk::Chunk;
3
4use serde_derive::{Deserialize, Serialize};
5
6use core::fmt::{Formatter, Display, Result as FmtResult};
7use std::collections::HashMap;
8use core::default::Default;
9use core::cmp::PartialEq;
10use core::convert::Into;
11
12
13
14
15
16#[non_exhaustive]
17#[derive(Deserialize, PartialEq, Serialize, Clone, Debug, Copy, Hash, Eq)]
18#[serde(rename_all="snake_case")]
19#[repr(u8)]
20pub enum Block {
21 Air,
23 Grass,
25 Dirt,
27 Stone,
29 Wood,
31 Leaf,
33 Lava,
35 IronOre,
37 DeadlyOre,
39 Chest,
41 MidnightGrass,
43 MidnightSoil,
45 MidnightStone,
47 MidnightWood,
49 MidnightLeaf,
51 Bush,
53 MidnightBush,
55 RedFlower,
57 WhiteFlower,
59 BlueFlower,
61 TallGrass,
63 Sand,
65 Sandstone,
67 Cactus,
69 Snow,
71 Ice,
73 SnowyBush,
75 Glass,
77 SolenoidOre,
79 SnowyLeaf,
81 Pumpkin,
83 JackOLantern,
85 Barrier,
87 ChunkBorder
89}
90
91impl Block {
92 #[inline(always)] pub const fn as_str(&self) -> &'static str {
93 match self {
94 Self::MidnightGrass => "Midnight Grass",
95 Self::MidnightStone => "Midnight Stone",
96 Self::JackOLantern => "Jack o'Lantern",
97 Self::MidnightBush => "Midnight Bush",
98 Self::MidnightLeaf => "Midnight Leaf",
99 Self::MidnightSoil => "Midnight Soil",
100 Self::MidnightWood => "Midnight Wood",
101 Self::SolenoidOre => "Solenoid Ore",
102 Self::WhiteFlower => "White Flower",
103 Self::BlueFlower => "Blue Flower",
104 Self::DeadlyOre => "Deadly Ore",
105 Self::RedFlower => "Red Flower",
106 Self::Sandstone => "Sandstone",
107 Self::SnowyBush => "Snowy Bush",
108 Self::SnowyLeaf => "Snowy Leaf",
109 Self::TallGrass => "Tall Grass",
110 Self::Barrier => "Barrier",
111 Self::IronOre => "Iron Ore",
112 Self::Pumpkin => "Pumpkin",
113 Self::Cactus => "Cactus",
114 Self::Chest => "Chest",
115 Self::Glass => "Glass",
116 Self::Grass => "Grass",
117 Self::Stone => "Stone",
118 Self::Bush => "Bush",
119 Self::Dirt => "Dirt",
120 Self::Lava => "Lava",
121 Self::Leaf => "Leaf",
122 Self::Sand => "Sand",
123 Self::Snow => "Snow",
124 Self::Wood => "Wood",
125 Self::Air => "Air",
126 Self::Ice => "Ice",
127
128 _ => ""
129 }
130 }
131}
132
133impl Collectable for Block {
134 fn name(&self) -> &str { self.as_str() }
135 #[inline(always)] fn typ(&self) -> CollectableType { CollectableType::Block }
136}
137
138impl PartialEq<u8> for Block {
139 fn eq(&self, other:&u8) -> bool { *self as u8 == *other }
140}
141
142impl Default for Block {
143 #[inline(always)] fn default() -> Self { Self::Air }
144}
145
146impl Display for Block {
147 fn fmt(&self, f:&mut Formatter) -> FmtResult { f.write_str(self.as_str()) }
148}
149
150impl Into<u8> for Block {
151 fn into(self) -> u8 { self as u8 }
152}
153
154
155
156#[derive(PartialEq, Clone, Debug, Eq)]
158#[repr(transparent)]
159pub struct World(HashMap<(i64, i64, i64), Chunk>);
160
161impl World {
162 pub const HEIGHT:usize = 128;
164}
165
166
167
168
169
170impl PartialEq<Block> for u8 {
171 fn eq(&self, other:&Block) -> bool { *self == *other as u8 }
172}