Moved GameMode into pumpkin-core
This commit is contained in:
parent
6740e717f7
commit
2fbf450ed3
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1936,6 +1936,8 @@ dependencies = [
|
|||||||
"colored",
|
"colored",
|
||||||
"fastnbt",
|
"fastnbt",
|
||||||
"md5",
|
"md5",
|
||||||
|
"num-derive",
|
||||||
|
"num-traits",
|
||||||
"serde",
|
"serde",
|
||||||
"uuid",
|
"uuid",
|
||||||
]
|
]
|
||||||
|
|||||||
@ -9,3 +9,6 @@ fastnbt = { git = "https://github.com/owengage/fastnbt.git" }
|
|||||||
uuid.workspace = true
|
uuid.workspace = true
|
||||||
colored = "2"
|
colored = "2"
|
||||||
md5 = "0.7.0"
|
md5 = "0.7.0"
|
||||||
|
|
||||||
|
num-traits = "0.2.19"
|
||||||
|
num-derive = { version = "0.4.2" }
|
||||||
|
|||||||
30
pumpkin-core/src/gamemode.rs
Normal file
30
pumpkin-core/src/gamemode.rs
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
|
use num_derive::{FromPrimitive, ToPrimitive};
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
#[derive(Debug, PartialEq, Eq)]
|
||||||
|
pub struct ParseGameModeError;
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, FromPrimitive, ToPrimitive)]
|
||||||
|
pub enum GameMode {
|
||||||
|
Undefined = -1,
|
||||||
|
Survival,
|
||||||
|
Creative,
|
||||||
|
Adventure,
|
||||||
|
Spectator,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FromStr for GameMode {
|
||||||
|
type Err = ParseGameModeError;
|
||||||
|
|
||||||
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
|
match s {
|
||||||
|
"survival" => Ok(Self::Survival),
|
||||||
|
"creative" => Ok(Self::Creative),
|
||||||
|
"adventure" => Ok(Self::Adventure),
|
||||||
|
"spectator" => Ok(Self::Spectator),
|
||||||
|
_ => Err(ParseGameModeError),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,2 +1,5 @@
|
|||||||
|
pub mod gamemode;
|
||||||
pub mod random;
|
pub mod random;
|
||||||
pub mod text;
|
pub mod text;
|
||||||
|
|
||||||
|
pub use gamemode::GameMode;
|
||||||
|
|||||||
@ -3,12 +3,12 @@ use std::f32::consts::PI;
|
|||||||
use crate::{
|
use crate::{
|
||||||
commands::{handle_command, CommandSender},
|
commands::{handle_command, CommandSender},
|
||||||
config::ADVANCED_CONFIG,
|
config::ADVANCED_CONFIG,
|
||||||
entity::player::{ChatMode, GameMode, Hand, Player},
|
entity::player::{ChatMode, Hand, Player},
|
||||||
server::Server,
|
server::Server,
|
||||||
util::math::wrap_degrees,
|
util::math::wrap_degrees,
|
||||||
};
|
};
|
||||||
use num_traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
use pumpkin_core::text::TextComponent;
|
use pumpkin_core::{text::TextComponent, GameMode};
|
||||||
use pumpkin_entity::EntityId;
|
use pumpkin_entity::EntityId;
|
||||||
use pumpkin_inventory::WindowType;
|
use pumpkin_inventory::WindowType;
|
||||||
use pumpkin_protocol::server::play::{SCloseContainer, SSetPlayerGround, SUseItem};
|
use pumpkin_protocol::server::play::{SCloseContainer, SSetPlayerGround, SUseItem};
|
||||||
|
|||||||
@ -2,6 +2,7 @@ use std::str::FromStr;
|
|||||||
|
|
||||||
use num_traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
use pumpkin_core::text::TextComponent;
|
use pumpkin_core::text::TextComponent;
|
||||||
|
use pumpkin_core::GameMode;
|
||||||
|
|
||||||
use crate::commands::arg_player::{consume_arg_player, parse_arg_player};
|
use crate::commands::arg_player::{consume_arg_player, parse_arg_player};
|
||||||
|
|
||||||
@ -13,7 +14,6 @@ use crate::commands::tree::{CommandTree, ConsumedArgs, RawArgs};
|
|||||||
use crate::commands::tree_builder::{argument, require};
|
use crate::commands::tree_builder::{argument, require};
|
||||||
use crate::commands::CommandSender;
|
use crate::commands::CommandSender;
|
||||||
use crate::commands::CommandSender::Player;
|
use crate::commands::CommandSender::Player;
|
||||||
use crate::entity::player::GameMode;
|
|
||||||
|
|
||||||
const NAMES: [&str; 1] = ["gamemode"];
|
const NAMES: [&str; 1] = ["gamemode"];
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
use log::warn;
|
use log::warn;
|
||||||
|
use pumpkin_core::GameMode;
|
||||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
@ -8,7 +9,7 @@ use std::{
|
|||||||
sync::LazyLock,
|
sync::LazyLock,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{entity::player::GameMode, server::Difficulty};
|
use crate::server::Difficulty;
|
||||||
|
|
||||||
pub mod auth;
|
pub mod auth;
|
||||||
pub mod proxy;
|
pub mod proxy;
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
use std::{str::FromStr, sync::Arc};
|
use std::sync::Arc;
|
||||||
|
|
||||||
use num_derive::{FromPrimitive, ToPrimitive};
|
use num_derive::FromPrimitive;
|
||||||
use num_traits::ToPrimitive;
|
use num_traits::ToPrimitive;
|
||||||
use pumpkin_core::text::TextComponent;
|
use pumpkin_core::{text::TextComponent, GameMode};
|
||||||
use pumpkin_entity::{entity_type::EntityType, pose::EntityPose, Entity, EntityId};
|
use pumpkin_entity::{entity_type::EntityType, pose::EntityPose, Entity, EntityId};
|
||||||
use pumpkin_inventory::player::PlayerInventory;
|
use pumpkin_inventory::player::PlayerInventory;
|
||||||
use pumpkin_protocol::{
|
use pumpkin_protocol::{
|
||||||
@ -21,7 +21,6 @@ use pumpkin_protocol::{
|
|||||||
ConnectionState, RawPacket, ServerPacket, VarInt,
|
ConnectionState, RawPacket, ServerPacket, VarInt,
|
||||||
};
|
};
|
||||||
use pumpkin_world::vector3::Vector3;
|
use pumpkin_world::vector3::Vector3;
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
client::{authentication::GameProfile, Client},
|
client::{authentication::GameProfile, Client},
|
||||||
@ -454,29 +453,3 @@ pub enum ChatMode {
|
|||||||
CommandsOnly,
|
CommandsOnly,
|
||||||
Hidden,
|
Hidden,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize, FromPrimitive, ToPrimitive)]
|
|
||||||
pub enum GameMode {
|
|
||||||
Undefined = -1,
|
|
||||||
Survival,
|
|
||||||
Creative,
|
|
||||||
Adventure,
|
|
||||||
Spectator,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq)]
|
|
||||||
pub struct ParseGameModeError;
|
|
||||||
|
|
||||||
impl FromStr for GameMode {
|
|
||||||
type Err = ParseGameModeError;
|
|
||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
|
||||||
match s {
|
|
||||||
"survival" => Ok(Self::Survival),
|
|
||||||
"creative" => Ok(Self::Creative),
|
|
||||||
"adventure" => Ok(Self::Adventure),
|
|
||||||
"spectator" => Ok(Self::Spectator),
|
|
||||||
_ => Err(ParseGameModeError),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@ -11,6 +11,7 @@ use std::{
|
|||||||
use base64::{engine::general_purpose, Engine};
|
use base64::{engine::general_purpose, Engine};
|
||||||
use image::GenericImageView;
|
use image::GenericImageView;
|
||||||
use mio::Token;
|
use mio::Token;
|
||||||
|
use pumpkin_core::GameMode;
|
||||||
use pumpkin_entity::EntityId;
|
use pumpkin_entity::EntityId;
|
||||||
use pumpkin_plugin::PluginLoader;
|
use pumpkin_plugin::PluginLoader;
|
||||||
use pumpkin_protocol::{
|
use pumpkin_protocol::{
|
||||||
@ -26,7 +27,7 @@ use serde::{Deserialize, Serialize};
|
|||||||
use crate::{
|
use crate::{
|
||||||
client::Client,
|
client::Client,
|
||||||
config::{BasicConfiguration, BASIC_CONFIG},
|
config::{BasicConfiguration, BASIC_CONFIG},
|
||||||
entity::player::{GameMode, Player},
|
entity::player::Player,
|
||||||
world::World,
|
world::World,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user