|
|
|
@ -15,7 +15,10 @@ use valence::entity::player::PlayerEntityBundle;
|
|
|
|
|
use valence::packet::WritePacket;
|
|
|
|
|
use valence::prelude::*;
|
|
|
|
|
|
|
|
|
|
use valence_protocol::packet::s2c::play::synchronize_tags::Tag;
|
|
|
|
|
use valence_protocol::packet::s2c::play::synchronize_tags::TagGroup;
|
|
|
|
|
use valence_protocol::packet::s2c::play::ChunkRenderDistanceCenterS2c;
|
|
|
|
|
use valence_protocol::packet::s2c::play::SynchronizeTagsS2c;
|
|
|
|
|
use valence_protocol::var_int::VarInt;
|
|
|
|
|
use valence_protocol::Encode;
|
|
|
|
|
|
|
|
|
@ -90,6 +93,7 @@ fn init_clients(
|
|
|
|
|
for (_pos, entity, uuid, mut client, mut game_mode, username, mut has_respawn_screen) in
|
|
|
|
|
&mut new_clients
|
|
|
|
|
{
|
|
|
|
|
// initialize client
|
|
|
|
|
has_respawn_screen.0 = true;
|
|
|
|
|
*game_mode = GameMode::Creative;
|
|
|
|
|
commands.entity(entity).insert(PlayerEntityBundle {
|
|
|
|
@ -103,17 +107,34 @@ fn init_clients(
|
|
|
|
|
..Default::default()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// send packet that magically fixes chunks
|
|
|
|
|
// TODO: make this configurable as different maps will have different chunks we need to force load
|
|
|
|
|
client.write_packet(&ChunkRenderDistanceCenterS2c {
|
|
|
|
|
chunk_x: VarInt(-14),
|
|
|
|
|
chunk_z: VarInt(17),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// send block tags packet
|
|
|
|
|
client.write_packet(&SynchronizeTagsS2c {
|
|
|
|
|
tags: vec![TagGroup {
|
|
|
|
|
kind: ident!("block").into(),
|
|
|
|
|
tags: vec![Tag {
|
|
|
|
|
name: ident!("climbable").into(),
|
|
|
|
|
entries: vec![VarInt(316), VarInt(195)],
|
|
|
|
|
}],
|
|
|
|
|
}],
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// send server brand
|
|
|
|
|
let mut buf = Vec::new();
|
|
|
|
|
"Valence".encode(&mut buf).unwrap();
|
|
|
|
|
client.send_custom_payload(ident!("brand"), &buf);
|
|
|
|
|
|
|
|
|
|
// add player to count
|
|
|
|
|
PLAYER_COUNT.fetch_add(1, Ordering::SeqCst);
|
|
|
|
|
|
|
|
|
|
tracing::info!("{username} joined the game");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -124,7 +145,7 @@ pub fn despawn_disconnected_clients(
|
|
|
|
|
for entity in disconnected_clients.iter() {
|
|
|
|
|
if let Some(mut entity) = commands.get_entity(entity) {
|
|
|
|
|
entity.insert(Despawned);
|
|
|
|
|
PLAYER_COUNT.fetch_sub(1, Ordering::SeqCst);
|
|
|
|
|
}
|
|
|
|
|
PLAYER_COUNT.fetch_sub(1, Ordering::SeqCst);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|