Server: one level per dimension, so players can be in different dimensions
A server (the dedicated server and single player's server thread) now holds a level per dimension, like vanilla's `MinecraftServer.levels`. Each server tick runs every level with players in it, one at a time, by swapping its fields into place (game/levels.rs), so the world tick code runs unchanged. Before this, a portal did nothing while two or more players were online. - Levels: the parked levels keep the world, streaming, save, block ticks, entities, block entity state, raids, sculk and creaking scans. The Overworld stays loaded; another level is saved and closed after 300 ticks with nobody in it. Saving saves every level. - Hub: `tick` is split into `poll` (the network, once per tick), `tick_level` (the packets, chunks, block changes, containers and entities of the players in the level in place) and `end_tick` (latency). Each guest has a dimension; time, weather, sounds and events reach only the players in their level, and the clock and weather last sent are kept per level. - Travel: every player has their own portal state; a portal moves only that player into the destination's level (`ServerPlayer.teleport` packets as before). Respawning brings a player back to the Overworld's level. - Player data saves and loads each player's dimension, and a returning player is placed in their own level. - tools/lan_e2e.py --server-thread --check portals: the guest goes to the Nether while the host stays, then the host goes to the End while the guest is in the Nether, and both come back. The in-frame game keeps its one level that follows its player. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+73
-3
@@ -21,7 +21,10 @@ address. The script then checks, from both sides, what a guest's game used to ge
|
||||
- pvp: the guest and the host hit each other with a sword; with the pvp game rule off, nothing;
|
||||
- containers: the guest's ender chest holds the guest's items, not the host's, and a double chest
|
||||
opens as 9x6 with the right half first;
|
||||
- feedback: the guest's command feedback names the guest and shows the numbers.
|
||||
- feedback: the guest's command feedback names the guest and shows the numbers;
|
||||
- portals: (--server-thread) the server holds a level per dimension: the guest goes to the Nether
|
||||
through a portal while the host stays, then the host goes to the End while the guest is in
|
||||
the Nether, and both come back.
|
||||
|
||||
Each check is reported on its own (a failing one doesn't stop the others) and the screenshots of
|
||||
both sides go to --out (host-*.png, guest-*.png).
|
||||
@@ -29,6 +32,7 @@ both sides go to --out (host-*.png, guest-*.png).
|
||||
python3 tools/lan_e2e.py # build with the fast profile, run every check
|
||||
python3 tools/lan_e2e.py --bin-dir target/fast # prebuilt binaries
|
||||
python3 tools/lan_e2e.py --check chest --check tab
|
||||
python3 tools/lan_e2e.py --server-thread --check portals # the host's world on its server thread
|
||||
|
||||
Needs the prepared resources in .local/horizon-client and, on Linux, vscreen (the desktop); on
|
||||
macOS both games render offscreen. Games started here have no audio (HORIZON_NO_AUDIO=1).
|
||||
@@ -50,7 +54,9 @@ from agent_control_e2e import Cli, Failed, game_env # noqa: E402
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
GUEST_NAME = 'Guest'
|
||||
CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'containers', 'feedback', 'trials']
|
||||
# The host plays single player on its server thread (--server-thread).
|
||||
SERVER_THREAD = False
|
||||
CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'containers', 'feedback', 'trials', 'portals']
|
||||
|
||||
|
||||
class Game:
|
||||
@@ -288,6 +294,65 @@ def check_sign(host, guest, out):
|
||||
return placed
|
||||
|
||||
|
||||
def wait_dimension(game, dimension, ticks):
|
||||
"""Wait up to `ticks` for the game to be in `dimension` with its world loaded around it."""
|
||||
for _ in range(ticks // 20):
|
||||
state = game('state')
|
||||
if state.get('dimension') == dimension and state.get('player'):
|
||||
return state
|
||||
game.wait(20)
|
||||
return game('state')
|
||||
|
||||
|
||||
def nether_portal(game, x, y, z):
|
||||
"""A lit portal along x, two blocks wide and three tall, its inside starting at x y z."""
|
||||
game('command', command=f'fill {x - 1} {y - 1} {z} {x + 2} {y + 3} {z} minecraft:obsidian')
|
||||
game('command', command=f'fill {x} {y} {z} {x + 1} {y + 2} {z} minecraft:nether_portal[axis=x]')
|
||||
|
||||
|
||||
def check_portals(host, guest, out):
|
||||
if not SERVER_THREAD:
|
||||
return 'skipped (needs --server-thread)'
|
||||
x, y, z = (int(v // 1) for v in pos_of(guest))
|
||||
nether_portal(guest, x, y, z + 3)
|
||||
guest.wait(5)
|
||||
guest('command', command=f'tp @s {x + 0.5} {y} {z + 3.5}')
|
||||
# players_nether_portal_default_delay: 80 ticks in survival.
|
||||
there = wait_dimension(guest, 'minecraft:the_nether', 600)
|
||||
guest.wait(40)
|
||||
guest.shot(out, 'portals-nether')
|
||||
host_dim = host('state').get('dimension')
|
||||
assert there.get('dimension') == 'minecraft:the_nether', f'the guest is in {there.get("dimension")}'
|
||||
assert host_dim == 'minecraft:overworld', f'the host went to {host_dim} with the guest'
|
||||
arrived = [int(v // 1) for v in pos_of(guest)]
|
||||
below = guest.raw('block', arrived[0], arrived[1] - 1, arrived[2])
|
||||
assert below.get('loaded') and below.get('block') != 'minecraft:air', f'under the guest in the Nether: {below}'
|
||||
# The host takes an End portal while the guest is in the Nether: three levels at once.
|
||||
hx, hy, hz = (int(v // 1) for v in pos_of(host))
|
||||
host('command', command=f'setblock {hx} {hy} {hz} minecraft:end_portal')
|
||||
end = wait_dimension(host, 'minecraft:the_end', 600)
|
||||
host.wait(40)
|
||||
host.shot(out, 'portals-end')
|
||||
guest_dim = guest('state').get('dimension')
|
||||
assert end.get('dimension') == 'minecraft:the_end', f'the host is in {end.get("dimension")}'
|
||||
assert guest_dim == 'minecraft:the_nether', f'the guest left the Nether for {guest_dim}'
|
||||
# Both come back: the host through an exit portal, the guest out of its portal and in again.
|
||||
ex, ey, ez = (int(v // 1) for v in pos_of(host))
|
||||
host('command', command=f'setblock {ex + 2} {ey} {ez} minecraft:end_portal')
|
||||
host('command', command=f'tp @s {ex + 2.5} {ey} {ez + 0.5}')
|
||||
guest('command', command=f'tp @s {arrived[0] + 0.5} {arrived[1]} {arrived[2] - 2.5}')
|
||||
guest.wait(30)
|
||||
guest('command', command=f'tp @s {arrived[0] + 0.5} {arrived[1]} {arrived[2] + 0.5}')
|
||||
home = wait_dimension(host, 'minecraft:overworld', 600)
|
||||
back = wait_dimension(guest, 'minecraft:overworld', 600)
|
||||
guest.wait(40)
|
||||
host.shot(out, 'portals-back')
|
||||
guest.shot(out, 'portals-back')
|
||||
assert home.get('dimension') == 'minecraft:overworld', f'the host stayed in {home.get("dimension")}'
|
||||
assert back.get('dimension') == 'minecraft:overworld', f'the guest stayed in {back.get("dimension")}'
|
||||
return {'guest_nether': arrived, 'host_end': [ex, ey, ez], 'back': pos_of(guest)}
|
||||
|
||||
|
||||
def check_damage(host, guest, out):
|
||||
guest('command', command='gamemode survival')
|
||||
guest.wait(10)
|
||||
@@ -662,11 +727,13 @@ CHECK_FNS = {'tab': check_tab, 'self': check_self, 'armour': check_armour, 'name
|
||||
'chest': check_chest, 'crafting': check_crafting, 'sign': check_sign, 'damage': check_damage,
|
||||
'mobs': check_mobs, 'hazards': check_hazards, 'pvp': check_pvp,
|
||||
'containers': check_containers, 'feedback': check_feedback, 'trials': check_trials,
|
||||
'walls': check_walls}
|
||||
'walls': check_walls, 'portals': check_portals}
|
||||
|
||||
|
||||
def run(ctl, out, resources, checks):
|
||||
host, guest = Game('host', ctl, resources), Game('guest', ctl, resources)
|
||||
if SERVER_THREAD:
|
||||
host.d.env['HORIZON_SERVER_THREAD'] = '1'
|
||||
results = {}
|
||||
try:
|
||||
host('launch', wait=False, offscreen=sys.platform == 'darwin')
|
||||
@@ -712,7 +779,10 @@ def main():
|
||||
parser.add_argument('--bin-dir', help='prebuilt horizon-client and horizon-ctl (default: build with the fast profile)')
|
||||
parser.add_argument('--check', action='append', choices=CHECKS, help='run only these checks (repeatable)')
|
||||
parser.add_argument('--out', default=str(ROOT / '.local/lan-e2e'), help='screenshots and game logs go here')
|
||||
parser.add_argument('--server-thread', action='store_true', help="the host's world runs on its server thread")
|
||||
args = parser.parse_args()
|
||||
global SERVER_THREAD
|
||||
SERVER_THREAD = args.server_thread
|
||||
if args.bin_dir:
|
||||
bins = Path(args.bin_dir).resolve()
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user