mirror of
https://github.com/zyllian/classics.git
synced 2025-05-10 07:26:40 -07:00
update spawn config to use yaw and orientation
This commit is contained in:
parent
5e8fe5a753
commit
87a2111751
2 changed files with 41 additions and 12 deletions
|
@ -21,7 +21,7 @@ pub struct ServerConfig {
|
||||||
/// the level's size
|
/// the level's size
|
||||||
pub level_size: ConfigCoordinates,
|
pub level_size: ConfigCoordinates,
|
||||||
/// the level's spawn point
|
/// the level's spawn point
|
||||||
pub spawn: Option<ConfigCoordinates>,
|
pub spawn: Option<ConfigCoordinatesWithOrientation>,
|
||||||
/// the method to generate the server's level with
|
/// the method to generate the server's level with
|
||||||
pub generation: LevelGeneration,
|
pub generation: LevelGeneration,
|
||||||
/// the server should auto save the world every X minutes, 0 to disable
|
/// the server should auto save the world every X minutes, 0 to disable
|
||||||
|
@ -65,6 +65,18 @@ pub struct ConfigCoordinates {
|
||||||
pub z: usize,
|
pub z: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// coordinates stored in config including orientation
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
|
pub struct ConfigCoordinatesWithOrientation {
|
||||||
|
/// the inner coordinates
|
||||||
|
#[serde(flatten)]
|
||||||
|
pub coords: ConfigCoordinates,
|
||||||
|
/// the orientation's yaw
|
||||||
|
pub yaw: u8,
|
||||||
|
/// the orientation's pitch
|
||||||
|
pub pitch: u8,
|
||||||
|
}
|
||||||
|
|
||||||
/// enum for the different kinds of server protection
|
/// enum for the different kinds of server protection
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
|
|
|
@ -176,11 +176,10 @@ async fn handle_stream_inner(
|
||||||
.copied()
|
.copied()
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
let player = Player {
|
let mut player = Player {
|
||||||
_addr: addr,
|
_addr: addr,
|
||||||
id: *own_id, // TODO: actually assign user ids
|
id: *own_id, // TODO: actually assign user ids
|
||||||
username,
|
username,
|
||||||
// TODO: properly assign spawn stuff
|
|
||||||
x: zero,
|
x: zero,
|
||||||
y: zero,
|
y: zero,
|
||||||
z: zero,
|
z: zero,
|
||||||
|
@ -203,23 +202,41 @@ async fn handle_stream_inner(
|
||||||
.extend(build_level_packets(&data.level).into_iter());
|
.extend(build_level_packets(&data.level).into_iter());
|
||||||
|
|
||||||
let username = player.username.clone();
|
let username = player.username.clone();
|
||||||
data.players.push(player);
|
|
||||||
|
|
||||||
let (spawn_x, spawn_y, spawn_z) =
|
let (spawn_x, spawn_y, spawn_z, spawn_yaw, spawn_pitch) =
|
||||||
if let Some(spawn) = &data.config.spawn {
|
if let Some(spawn) = &data.config.spawn {
|
||||||
(spawn.x, spawn.y, spawn.z)
|
(
|
||||||
|
spawn.coords.x,
|
||||||
|
spawn.coords.y,
|
||||||
|
spawn.coords.z,
|
||||||
|
spawn.yaw,
|
||||||
|
spawn.pitch,
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
(16, data.level.y_size / 2 + 2, 16)
|
(16, data.level.y_size / 2 + 2, 16, 0, 0)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let (spawn_x, spawn_y, spawn_z) = (
|
||||||
|
f16::from_f32(spawn_x as f32 + 0.5),
|
||||||
|
f16::from_f32(spawn_y as f32),
|
||||||
|
f16::from_f32(spawn_z as f32 + 0.5),
|
||||||
|
);
|
||||||
|
|
||||||
|
player.x = spawn_x;
|
||||||
|
player.y = spawn_y;
|
||||||
|
player.z = spawn_z;
|
||||||
|
player.yaw = spawn_yaw;
|
||||||
|
player.pitch = spawn_pitch;
|
||||||
|
data.players.push(player);
|
||||||
|
|
||||||
let spawn_packet = ServerPacket::SpawnPlayer {
|
let spawn_packet = ServerPacket::SpawnPlayer {
|
||||||
player_id: *own_id,
|
player_id: *own_id,
|
||||||
player_name: username.clone(),
|
player_name: username.clone(),
|
||||||
x: f16::from_f32(spawn_x as f32 + 0.5),
|
x: spawn_x,
|
||||||
y: f16::from_f32(spawn_y as f32),
|
y: spawn_y,
|
||||||
z: f16::from_f32(spawn_z as f32 + 0.5),
|
z: spawn_z,
|
||||||
yaw: 0,
|
yaw: spawn_yaw,
|
||||||
pitch: 0,
|
pitch: spawn_pitch,
|
||||||
};
|
};
|
||||||
let message_packet = ServerPacket::Message {
|
let message_packet = ServerPacket::Message {
|
||||||
player_id: *own_id,
|
player_id: *own_id,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue