Send chunks to players connected to server
This commit is contained in:
+11
-6
@@ -45,6 +45,8 @@ export class Client {
|
||||
// whether the attack button is held on a block, breaking it advances every tick
|
||||
#attacking = false;
|
||||
#stopped = false;
|
||||
// the render distance the server was last told, it sends chunks for it
|
||||
#sent_view_distance: number;
|
||||
// called once when the connection drops, with why
|
||||
#on_disconnect: (message: string) => void;
|
||||
|
||||
@@ -52,11 +54,9 @@ export class Client {
|
||||
this.connection = connection;
|
||||
this.#on_disconnect = on_disconnect;
|
||||
|
||||
this.level = new ClientLevel(connection.seed);
|
||||
this.level = new ClientLevel(connection.server_blocks, this.options.render_distance);
|
||||
this.level.time = connection.time;
|
||||
for (const [x, y, z, id, state] of connection.initial_changes) {
|
||||
this.level.record_change(x, y, z, id, state);
|
||||
}
|
||||
this.#sent_view_distance = this.options.render_distance;
|
||||
|
||||
const spawn = connection.spawn;
|
||||
this.player = new LocalPlayer(this, connection.id, connection.name);
|
||||
@@ -128,7 +128,7 @@ export class Client {
|
||||
this.game_renderer.render(this, this.#pending_time / TICK_DELTA);
|
||||
}
|
||||
|
||||
// one step of the game: what the server sent, breaking, chunk loading, then every entity
|
||||
// one step of the game: what the server sent (chunks included), breaking, then every entity
|
||||
tick() {
|
||||
this.packet_listener.handle_packets();
|
||||
if (this.connection.closed) {
|
||||
@@ -141,7 +141,12 @@ export class Client {
|
||||
this.game_mode.continue_destroy_block(this.hit_result);
|
||||
}
|
||||
|
||||
this.level.update_loaded_chunks(this.player.x, this.player.z, this.options.render_distance);
|
||||
const view_distance = Math.round(this.options.render_distance);
|
||||
if (view_distance !== this.#sent_view_distance) {
|
||||
this.#sent_view_distance = view_distance;
|
||||
this.level.view_distance = view_distance;
|
||||
this.connection.send({ type: "view_distance", distance: view_distance });
|
||||
}
|
||||
this.level.tick();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user