dedicated_server: settle the generated world in game ticks, without random ticks

The world was saved 20 wall-clock seconds after force-loading the area, so
on a busy machine chunks were still generating or their fluids flowing,
and random ticks changed blocks while the client was being sent its
chunks: which chunks differed varied from run to run. Wait until every
force-loaded chunk is loaded and 600 game ticks have passed, with
random_tick_speed 0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-13 03:40:50 +02:00
parent 6aa875c6c2
commit 71e677ed6a
+36 -1
View File
@@ -163,6 +163,36 @@ class Server:
self.log.close()
def settle(server, ticks=600, timeout=600):
"""Waits until every force-loaded chunk is loaded, then for `ticks` game
ticks, so their fluids have finished flowing however slow the machine."""
deadline = time.time() + timeout
offsets = range(-80, 81, 16)
for poll in range(1_000_000):
start = len(server.lines)
for dx in offsets:
for dz in offsets:
server.console(f'execute unless loaded ~{dx} ~ ~{dz} run say unloaded')
server.console(f'say poll {poll}')
server.wait_for(rf'\[Server\] poll {poll}$', timeout=max(1, deadline - time.time()))
if not any(l.endswith('[Server] unloaded') for l in server.lines[start:]):
break
time.sleep(2)
def game_time():
start = len(server.lines)
server.console('time query gametime')
while time.time() < deadline:
for line in server.lines[start:]:
if m := re.search(r'The time is (\d+)', line):
return int(m.group(1))
time.sleep(0.2)
raise AssertionError(f'{server.log_path.name}: no game time in {timeout} s')
until = game_time() + ticks
while game_time() < until:
time.sleep(2)
def legacy_ping(port):
"""The reply to a 1.6 client's 0xFE 0x01 0xFA MC|PingHost query (LegacyQueryHandler)."""
host = 'localhost'
@@ -330,9 +360,14 @@ def main():
# Vanilla keeps no spawn chunks: force-load the area the client is
# sent and its neighbours (the console stands at the world spawn) so
# both servers load full chunks instead of finishing proto-chunks.
# Random ticks change blocks while the client is being sent its
# chunks, more of them the busier the machine: none, so both servers
# send the world as it was saved.
server.console('gamerule random_tick_speed 0')
server.wait_for(r'random_tick_speed', timeout=30)
server.console('forceload add ~-80 ~-80 ~80 ~80')
server.wait_for(r'chunks in the Overworld are now force loaded|forceloaded|force loaded', timeout=60)
time.sleep(20)
settle(server)
server.console('forceload remove all')
server.console('save-all flush')
server.wait_for(r'Saved the game', timeout=120)