aboutsummaryrefslogtreecommitdiff
path: root/azalea-core
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2021-12-18 10:04:10 -0600
committermat <github@matdoes.dev>2021-12-18 10:04:10 -0600
commit8e3ba097b48543a85f2cf487d5db90add3f28bac (patch)
treeeb691675842ecaec0a8a561deb8cf5e2951c9d81 /azalea-core
parent498077e09f372ecd5c4f32f20363d7011f09e70a (diff)
downloadazalea-drasl-8e3ba097b48543a85f2cf487d5db90add3f28bac.tar.xz
start adding clientbound_login_packet
Diffstat (limited to 'azalea-core')
-rw-r--r--azalea-core/Cargo.toml1
-rw-r--r--azalea-core/src/game_type.rs60
-rw-r--r--azalea-core/src/lib.rs1
3 files changed, 62 insertions, 0 deletions
diff --git a/azalea-core/Cargo.toml b/azalea-core/Cargo.toml
index 1aa59fe9..b0139999 100644
--- a/azalea-core/Cargo.toml
+++ b/azalea-core/Cargo.toml
@@ -6,4 +6,5 @@ version = "0.1.0"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
+azalea-chat = {path = "../azalea-chat"}
uuid = "^0.8.2"
diff --git a/azalea-core/src/game_type.rs b/azalea-core/src/game_type.rs
new file mode 100644
index 00000000..b0ca6a2d
--- /dev/null
+++ b/azalea-core/src/game_type.rs
@@ -0,0 +1,60 @@
+use azalea_chat;
+
+#[derive(Hash, Clone, Debug)]
+pub enum GameType {
+ SURVIVAL,
+ CREATIVE,
+ ADVENTURE,
+ SPECTATOR,
+}
+
+impl GameType {
+ fn to_id(&self) -> u8 {
+ match self {
+ GameType::SURVIVAL => 0,
+ GameType::CREATIVE => 1,
+ GameType::ADVENTURE => 2,
+ GameType::SPECTATOR => 3,
+ }
+ }
+
+ fn from_id(id: u8) -> GameType {
+ match id {
+ 0 => GameType::SURVIVAL,
+ 1 => GameType::CREATIVE,
+ 2 => GameType::ADVENTURE,
+ 3 => GameType::SPECTATOR,
+ _ => panic!("Unknown game type id: {}", id),
+ }
+ }
+
+ fn short_name(&self) -> &'static str {
+ // TODO: these should be translated TranslatableComponent("selectWorld.gameMode." + string2)
+ match self {
+ GameType::SURVIVAL => "Survival",
+ GameType::CREATIVE => "Creative",
+ GameType::ADVENTURE => "Adventure",
+ GameType::SPECTATOR => "Spectator",
+ }
+ }
+
+ fn long_name(&self) -> &'static str {
+ // TODO: These should be translated TranslatableComponent("gameMode." + string2);
+ match self {
+ GameType::SURVIVAL => "Survival Mode",
+ GameType::CREATIVE => "Creative Mode",
+ GameType::ADVENTURE => "Adventure Mode",
+ GameType::SPECTATOR => "Spectator Mode",
+ }
+ }
+
+ fn from_name(name: &str) -> GameType {
+ match name {
+ "survival" => GameType::SURVIVAL,
+ "creative" => GameType::CREATIVE,
+ "adventure" => GameType::ADVENTURE,
+ "spectator" => GameType::SPECTATOR,
+ _ => panic!("Unknown game type name: {}", name),
+ }
+ }
+}
diff --git a/azalea-core/src/lib.rs b/azalea-core/src/lib.rs
index dbe08afb..887d1686 100644
--- a/azalea-core/src/lib.rs
+++ b/azalea-core/src/lib.rs
@@ -1,5 +1,6 @@
//! Random miscellaneous things like UUIDs that don't deserve their own crate.
+pub mod game_type;
pub mod resource_location;
pub mod serializable_uuid;