Add default gamemode to configuration

This commit is contained in:
lukas0008 2024-08-04 21:29:10 +02:00
parent 42bc84b23c
commit 02337adbdf
3 changed files with 12 additions and 4 deletions

View File

@ -2,7 +2,7 @@ use std::path::Path;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::server::Difficulty; use crate::{entity::player::GameMode, server::Difficulty};
/// Current Config version of the Base Config /// Current Config version of the Base Config
const CURRENT_BASE_VERSION: &str = "1.0.0"; const CURRENT_BASE_VERSION: &str = "1.0.0";
@ -59,6 +59,8 @@ pub struct BasicConfiguration {
pub prevent_proxy_connections: bool, pub prevent_proxy_connections: bool,
/// The description send when Client performs a Status request, (e.g Multiplayer Screen) /// The description send when Client performs a Status request, (e.g Multiplayer Screen)
pub motd: String, pub motd: String,
/// default gamemode (e.g. Survival, Creative...)
pub default_gamemode: GameMode,
} }
impl Default for BasicConfiguration { impl Default for BasicConfiguration {
@ -80,6 +82,7 @@ impl Default for BasicConfiguration {
encryption: true, encryption: true,
prevent_proxy_connections: true, prevent_proxy_connections: true,
motd: "A Blazing fast Pumpkin Server!".to_string(), motd: "A Blazing fast Pumpkin Server!".to_string(),
default_gamemode: GameMode::Survival,
} }
} }
} }

View File

@ -1,4 +1,5 @@
use pumpkin_protocol::VarInt; use pumpkin_protocol::VarInt;
use serde::{Deserialize, Serialize};
use super::{Entity, EntityId}; use super::{Entity, EntityId};
@ -74,7 +75,7 @@ impl ChatMode {
} }
} }
#[derive(Clone, Copy)] #[derive(Clone, Copy, PartialEq, Serialize, Deserialize)]
pub enum GameMode { pub enum GameMode {
Undefined, Undefined,
Survival, Survival,

View File

@ -131,8 +131,12 @@ impl Server {
0, 0,
"minecraft:overworld".into(), "minecraft:overworld".into(),
0, // seed 0, // seed
GameMode::Survival.to_byte() as u8, match self.base_config.default_gamemode {
GameMode::Survival.to_byte(), GameMode::Undefined => GameMode::Survival,
game_mode => game_mode,
}
.to_byte() as u8,
self.base_config.default_gamemode.to_byte(),
false, false,
false, false,
false, // deth loc false, // deth loc