mirror of
https://github.com/zyllian/classics.git
synced 2025-05-10 04:46: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
|
||||
pub level_size: ConfigCoordinates,
|
||||
/// the level's spawn point
|
||||
pub spawn: Option<ConfigCoordinates>,
|
||||
pub spawn: Option<ConfigCoordinatesWithOrientation>,
|
||||
/// the method to generate the server's level with
|
||||
pub generation: LevelGeneration,
|
||||
/// the server should auto save the world every X minutes, 0 to disable
|
||||
|
@ -65,6 +65,18 @@ pub struct ConfigCoordinates {
|
|||
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
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
|
|
|
@ -176,11 +176,10 @@ async fn handle_stream_inner(
|
|||
.copied()
|
||||
.unwrap_or_default();
|
||||
|
||||
let player = Player {
|
||||
let mut player = Player {
|
||||
_addr: addr,
|
||||
id: *own_id, // TODO: actually assign user ids
|
||||
username,
|
||||
// TODO: properly assign spawn stuff
|
||||
x: zero,
|
||||
y: zero,
|
||||
z: zero,
|
||||
|
@ -203,23 +202,41 @@ async fn handle_stream_inner(
|
|||
.extend(build_level_packets(&data.level).into_iter());
|
||||
|
||||
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 {
|
||||
(spawn.x, spawn.y, spawn.z)
|
||||
(
|
||||
spawn.coords.x,
|
||||
spawn.coords.y,
|
||||
spawn.coords.z,
|
||||
spawn.yaw,
|
||||
spawn.pitch,
|
||||
)
|
||||
} 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 {
|
||||
player_id: *own_id,
|
||||
player_name: username.clone(),
|
||||
x: f16::from_f32(spawn_x as f32 + 0.5),
|
||||
y: f16::from_f32(spawn_y as f32),
|
||||
z: f16::from_f32(spawn_z as f32 + 0.5),
|
||||
yaw: 0,
|
||||
pitch: 0,
|
||||
x: spawn_x,
|
||||
y: spawn_y,
|
||||
z: spawn_z,
|
||||
yaw: spawn_yaw,
|
||||
pitch: spawn_pitch,
|
||||
};
|
||||
let message_packet = ServerPacket::Message {
|
||||
player_id: *own_id,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue