mirror of
https://github.com/italicsjenga/valence.git
synced 2025-01-11 15:21:31 +11:00
Fix client respawning
This commit is contained in:
parent
04ce5366c8
commit
a6bb67ecfe
|
@ -118,7 +118,7 @@ impl Config for Game {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
client.set_world(world_id);
|
client.spawn(world_id);
|
||||||
client.set_game_mode(GameMode::Survival);
|
client.set_game_mode(GameMode::Survival);
|
||||||
client.teleport(spawn_pos, 0.0, 0.0);
|
client.teleport(spawn_pos, 0.0, 0.0);
|
||||||
|
|
||||||
|
|
|
@ -93,7 +93,7 @@ impl Config for Game {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
client.set_world(world_id);
|
client.spawn(world_id);
|
||||||
client.set_game_mode(GameMode::Creative);
|
client.set_game_mode(GameMode::Creative);
|
||||||
client.teleport([0.0, 200.0, 0.0], 0.0, 0.0);
|
client.teleport([0.0, 200.0, 0.0], 0.0, 0.0);
|
||||||
|
|
||||||
|
|
|
@ -97,7 +97,7 @@ impl Config for Game {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
client.set_world(world_id);
|
client.spawn(world_id);
|
||||||
client.set_game_mode(GameMode::Creative);
|
client.set_game_mode(GameMode::Creative);
|
||||||
client.set_max_view_distance(32);
|
client.set_max_view_distance(32);
|
||||||
client.teleport([0.0, 200.0, 0.0], 0.0, 0.0);
|
client.teleport([0.0, 200.0, 0.0], 0.0, 0.0);
|
||||||
|
|
|
@ -103,8 +103,8 @@ pub struct Client {
|
||||||
uuid: Uuid,
|
uuid: Uuid,
|
||||||
username: String,
|
username: String,
|
||||||
textures: Option<SignedPlayerTextures>,
|
textures: Option<SignedPlayerTextures>,
|
||||||
new_world: WorldId,
|
world: WorldId,
|
||||||
old_world: WorldId,
|
spawn: bool,
|
||||||
on_ground: bool,
|
on_ground: bool,
|
||||||
new_position: Vec3<f64>,
|
new_position: Vec3<f64>,
|
||||||
old_position: Vec3<f64>,
|
old_position: Vec3<f64>,
|
||||||
|
@ -162,8 +162,8 @@ impl Client {
|
||||||
uuid: ncd.uuid,
|
uuid: ncd.uuid,
|
||||||
username: ncd.username,
|
username: ncd.username,
|
||||||
textures: ncd.textures,
|
textures: ncd.textures,
|
||||||
new_world: WorldId::default(),
|
world: WorldId::default(),
|
||||||
old_world: WorldId::default(),
|
spawn: false,
|
||||||
on_ground: false,
|
on_ground: false,
|
||||||
new_position: Vec3::default(),
|
new_position: Vec3::default(),
|
||||||
old_position: Vec3::default(),
|
old_position: Vec3::default(),
|
||||||
|
@ -209,11 +209,12 @@ impl Client {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn world(&self) -> WorldId {
|
pub fn world(&self) -> WorldId {
|
||||||
self.new_world
|
self.world
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_world(&mut self, world: WorldId) {
|
pub fn spawn(&mut self, world: WorldId) {
|
||||||
self.new_world = world;
|
self.world = world;
|
||||||
|
self.spawn = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Sends a system message to the player.
|
/// Sends a system message to the player.
|
||||||
|
@ -578,7 +579,7 @@ impl Client {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let world = match worlds.get(self.new_world) {
|
let world = match worlds.get(self.world) {
|
||||||
Some(world) => world,
|
Some(world) => world,
|
||||||
None => {
|
None => {
|
||||||
log::warn!(
|
log::warn!(
|
||||||
|
@ -600,15 +601,19 @@ impl Client {
|
||||||
.player_list()
|
.player_list()
|
||||||
.initial_packets(|pkt| self.send_packet(pkt));
|
.initial_packets(|pkt| self.send_packet(pkt));
|
||||||
|
|
||||||
|
let mut dimension_names: Vec<_> = shared
|
||||||
|
.dimensions()
|
||||||
|
.map(|(id, _)| ident!("{LIBRARY_NAMESPACE}:dimension_{}", id.0))
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
dimension_names.push(ident!("{LIBRARY_NAMESPACE}:dummy_dimension"));
|
||||||
|
|
||||||
self.send_packet(Login {
|
self.send_packet(Login {
|
||||||
entity_id: 0, // EntityId 0 is reserved for clients.
|
entity_id: 0, // EntityId 0 is reserved for clients.
|
||||||
is_hardcore: false, // TODO
|
is_hardcore: false, // TODO
|
||||||
gamemode: self.new_game_mode,
|
gamemode: self.new_game_mode,
|
||||||
previous_gamemode: self.old_game_mode,
|
previous_gamemode: self.old_game_mode,
|
||||||
dimension_names: shared
|
dimension_names,
|
||||||
.dimensions()
|
|
||||||
.map(|(id, _)| ident!("{LIBRARY_NAMESPACE}:dimension_{}", id.0))
|
|
||||||
.collect(),
|
|
||||||
registry_codec: Nbt(make_dimension_codec(shared)),
|
registry_codec: Nbt(make_dimension_codec(shared)),
|
||||||
dimension_type_name: ident!(
|
dimension_type_name: ident!(
|
||||||
"{LIBRARY_NAMESPACE}:dimension_type_{}",
|
"{LIBRARY_NAMESPACE}:dimension_type_{}",
|
||||||
|
@ -633,24 +638,24 @@ impl Client {
|
||||||
|
|
||||||
self.teleport(self.position(), self.yaw(), self.pitch());
|
self.teleport(self.position(), self.yaw(), self.pitch());
|
||||||
} else {
|
} else {
|
||||||
if self.new_world != self.old_world {
|
if self.spawn {
|
||||||
self.loaded_entities.clear();
|
self.loaded_entities.clear();
|
||||||
self.loaded_chunks.clear();
|
self.loaded_chunks.clear();
|
||||||
|
|
||||||
// TODO: clear player list.
|
// TODO: clear player list.
|
||||||
|
|
||||||
// // Client bug workaround: send the client to a dummy dimension first.
|
// Client bug workaround: send the client to a dummy dimension first.
|
||||||
// self.send_packet(Respawn {
|
self.send_packet(Respawn {
|
||||||
// dimension_type_name: ident!("{LIBRARY_NAMESPACE}:dimension_type_0"),
|
dimension_type_name: ident!("{LIBRARY_NAMESPACE}:dimension_type_0"),
|
||||||
// dimension_name: ident!("{LIBRARY_NAMESPACE}:dummy_dimension"),
|
dimension_name: ident!("{LIBRARY_NAMESPACE}:dummy_dimension"),
|
||||||
// hashed_seed: 0,
|
hashed_seed: 0,
|
||||||
// game_mode: self.game_mode(),
|
game_mode: self.game_mode(),
|
||||||
// previous_game_mode: self.game_mode(),
|
previous_game_mode: self.game_mode(),
|
||||||
// is_debug: false,
|
is_debug: false,
|
||||||
// is_flat: false,
|
is_flat: false,
|
||||||
// copy_metadata: true,
|
copy_metadata: true,
|
||||||
// last_death_location: None,
|
last_death_location: None,
|
||||||
// });
|
});
|
||||||
|
|
||||||
self.send_packet(Respawn {
|
self.send_packet(Respawn {
|
||||||
dimension_type_name: ident!(
|
dimension_type_name: ident!(
|
||||||
|
@ -960,7 +965,7 @@ impl Client {
|
||||||
);
|
);
|
||||||
|
|
||||||
self.old_position = self.new_position;
|
self.old_position = self.new_position;
|
||||||
self.old_world = self.new_world;
|
self.spawn = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue