Skip to content
This repository was archived by the owner on Jul 1, 2024. It is now read-only.

Commit dd312aa

Browse files
committed
ensure loaded chunks
1 parent a0e8696 commit dd312aa

File tree

6 files changed

+15
-11
lines changed

6 files changed

+15
-11
lines changed

minecraft-server/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ edition = "2021"
99
env_logger = "0.10.0"
1010
tokio = { version = "1.33.0", features = ["full"] }
1111
futures = "0.3.29"
12-
minecraft-protocol = { path="../minecraft-protocol" }
12+
minecraft-protocol = { path="../minecraft-protocol"}
1313
minecraft-positions = { path="../minecraft-positions" }
1414
minecraft-entities-derive = { path="../minecraft-entities-derive" }
1515
rand = "0.8.4"
@@ -21,4 +21,4 @@ tracing = { version = "0.1", features = ["attributes"] }
2121

2222
[features]
2323
default = []
24-
tracing = ["tracy-client", "tracing-tracy"]
24+
trace = ["tracy-client", "tracing-tracy" ]

minecraft-server/src/entities/player.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl Handler<Player> {
126126
}).await.flatten() else { return };
127127

128128
// Tell the world about the changes
129-
self.world.update_loaded_chunks(uuid, loaded_chunks_after).await;
129+
self.world.ensure_loaded_chunks(uuid, loaded_chunks_after).await;
130130

131131
// Send the chunks to the client
132132
let mut heightmaps = HashMap::new();

minecraft-server/src/player_handler/connect.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use super::*;
22

33

4-
#[cfg_attr(feature = "tracing", instrument(skip_all))]
5-
4+
#[cfg_attr(feature = "trace", instrument(skip_all))]
65
pub async fn handle_connection(
76
mut stream: TcpStream,
87
addr: SocketAddr,

minecraft-server/src/player_handler/handshake.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ pub async fn handshake(stream: &mut TcpStream, logged_in_player_info: LoggedInPl
315315
loaded_chunks.insert(ChunkColumnPosition { cx, cz });
316316
}
317317
}
318-
world.update_loaded_chunks(logged_in_player_info.uuid, loaded_chunks).await;
318+
world.ensure_loaded_chunks(logged_in_player_info.uuid, loaded_chunks).await;
319319

320320
let mut heightmaps = HashMap::new();
321321
heightmaps.insert(String::from("MOTION_BLOCKING"), NbtTag::LongArray(vec![0; 37]));

minecraft-server/src/world/loading_manager.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ pub(super) struct WorldLoadingManager {
77
}
88

99
impl WorldLoadingManager {
10-
#[cfg_attr(feature = "tracing", instrument(skip_all))]
11-
10+
#[cfg_attr(feature = "trace", instrument(skip_all))]
1211
pub(super) fn update_loaded_chunks(&mut self, uuid: UUID, loaded_chunks: HashSet<ChunkColumnPosition>) {
1312
let loaded_before = self.loaded_chunks.entry(uuid).or_default();
1413
for just_unloaded in loaded_before.difference(&loaded_chunks) {

minecraft-server/src/world/mod.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl World {
6363
self.change_senders.write().await.remove(&uuid);
6464
}
6565

66-
pub async fn update_loaded_chunks(&self, uuid: UUID, loaded_chunks: HashSet<ChunkColumnPosition>) {
66+
pub async fn ensure_loaded_chunks(&self, uuid: UUID, loaded_chunks: HashSet<ChunkColumnPosition>) {
6767
let mut loading_manager = self.loading_manager.write().await;
6868
let loaded_chunks_before = loading_manager.get_loaded_chunks();
6969
loading_manager.update_loaded_chunks(uuid, loaded_chunks);
@@ -160,6 +160,12 @@ impl World {
160160
}
161161
}
162162
}
163+
164+
#[cfg_attr(feature = "trace", instrument(skip(self)))]
165+
pub async fn get_network_chunk_column_data<'a>(&self, position: ChunkColumnPosition) -> Option<Vec<u8>> {
166+
self.map.get_network_chunk_column_data(position).await
167+
}
168+
163169
}
164170

165171
#[cfg(test)]
@@ -173,8 +179,8 @@ mod tests {
173179

174180
let mut receiver1 = world.add_loader(1).await;
175181
let mut receiver2 = world.add_loader(2).await;
176-
world.update_loaded_chunks(1, vec![ChunkColumnPosition{cx: 0, cz: 0}].into_iter().collect()).await;
177-
world.update_loaded_chunks(2, vec![ChunkColumnPosition{cx: 1, cz: 1}].into_iter().collect()).await;
182+
world.ensure_loaded_chunks(1, vec![ChunkColumnPosition{cx: 0, cz: 0}].into_iter().collect()).await;
183+
world.ensure_loaded_chunks(2, vec![ChunkColumnPosition{cx: 1, cz: 1}].into_iter().collect()).await;
178184

179185
world.set_block(BlockPosition{x: 1, y: 1, z: 1}, BlockWithState::Air).await;
180186
assert!(matches!(receiver1.try_recv(), Ok(WorldChange::Block(BlockPosition{x: 1, y: 1, z: 1}, BlockWithState::Air))));

0 commit comments

Comments
 (0)