Merge pull request #1108 from ludovic111/fix/remote-player-abilities
🤖 Agent: merged after integration wave 1 on the desktop (main e730dc14 + #1108 #1114 #1131 #1157 #1158 #1162 = ae482a72): fmt, clippy -D warnings, workspace tests (one port-race flake in horizon-server panel, passes on rerun), release build, tools/parity.py --changed origin/main 299/302 then the 3 rerun: save_roundtrip pass, world_reopen pass x2 (one early-count flake), dedicated_server = known flake also failing on main (fixed by #1183/#1184).
This commit is contained in:
@@ -99,6 +99,10 @@ pub(super) struct Remote {
|
||||
last_input: u8,
|
||||
was_sprinting: bool,
|
||||
carried: Option<usize>,
|
||||
/// The last ClientboundPlayerAbilitiesPacket. Vanilla's LocalPlayer
|
||||
/// holds its abilities from the login on; here the player is made at
|
||||
/// the first teleport, which takes them then.
|
||||
abilities: Option<play::PlayerAbilities>,
|
||||
loaded_sent: bool,
|
||||
/// The view distance last sent in ClientInformation.
|
||||
sent_view: i8,
|
||||
@@ -313,6 +317,7 @@ impl Game<'_> {
|
||||
last_input: 0,
|
||||
was_sprinting: false,
|
||||
carried: None,
|
||||
abilities: None,
|
||||
loaded_sent: false,
|
||||
sent_view: view,
|
||||
predictions: HashMap::new(),
|
||||
@@ -1840,9 +1845,10 @@ impl Game<'_> {
|
||||
},
|
||||
C::PlayerAbilities(p) => {
|
||||
self.creative = p.flags & 8 != 0;
|
||||
if let Some(player) = &mut self.player {
|
||||
player.flying_speed = p.flying_speed;
|
||||
if let Some(r) = self.remote.as_mut() {
|
||||
r.abilities = Some(p);
|
||||
}
|
||||
self.apply_remote_abilities();
|
||||
}
|
||||
C::SetHeldSlot(p) => {
|
||||
self.selected = p.slot.clamp(0, 8) as usize;
|
||||
@@ -2485,6 +2491,7 @@ impl Game<'_> {
|
||||
self.previous_eye = 1.62;
|
||||
self.clock.reset();
|
||||
self.apply_remote_health();
|
||||
self.apply_remote_abilities();
|
||||
}
|
||||
}
|
||||
self.previous_position = position;
|
||||
@@ -2620,6 +2627,7 @@ impl Game<'_> {
|
||||
[player.velocity.x, player.velocity.y, player.velocity.z],
|
||||
[player.position.x, player.position.y, player.position.z],
|
||||
);
|
||||
let was_flying = player.flying;
|
||||
player.yaw = self.yaw;
|
||||
let dead = self.screen == Screen::Dead;
|
||||
// LivingEntity.isImmobile: a sleeper lies still in the bed.
|
||||
@@ -2642,6 +2650,9 @@ impl Game<'_> {
|
||||
}
|
||||
.controlled_simulation_tick(keys)?;
|
||||
}
|
||||
// LocalPlayer.onUpdateAbilities: flight turned on or off (a double
|
||||
// jump, a spectator, landing) is sent to the server.
|
||||
let flying = player.flying;
|
||||
let events = std::mem::take(&mut player.events);
|
||||
self.previous_eye = self.eye;
|
||||
self.eye += (player.dimensions.eye_height - self.eye) * 0.5;
|
||||
@@ -2676,9 +2687,29 @@ impl Game<'_> {
|
||||
if !dead {
|
||||
self.remote_tick_using();
|
||||
}
|
||||
if flying != was_flying {
|
||||
self.send(S::PlayerAbilities(play::PlayerAbilitiesRequest {
|
||||
flags: if flying { 2 } else { 0 },
|
||||
}));
|
||||
}
|
||||
self.remote_send_state(input);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// ClientPacketListener.handlePlayerAbilities: the player flies, may fly
|
||||
/// and is invulnerable as the server says (bits 2, 4 and 1).
|
||||
fn apply_remote_abilities(&mut self) {
|
||||
let (Some(player), Some(a)) = (
|
||||
self.player.as_mut(),
|
||||
self.remote.as_ref().and_then(|r| r.abilities.as_ref()),
|
||||
) else {
|
||||
return;
|
||||
};
|
||||
player.invulnerable = a.flags & 1 != 0;
|
||||
player.flying = a.flags & 2 != 0;
|
||||
player.may_fly = a.flags & 4 != 0;
|
||||
player.flying_speed = a.flying_speed;
|
||||
}
|
||||
/// The local player's share of every touching entity's
|
||||
/// `LivingEntity.pushEntities`: on a client `EntitySelector.pushableBy`
|
||||
/// lets entities push only the local player, so the server never sends
|
||||
|
||||
@@ -1872,6 +1872,7 @@ impl Hub {
|
||||
// (handlePlayerKnownMovement), PlayerInput once loaded.
|
||||
let acted = match &packet {
|
||||
S::AcceptTeleportation(_)
|
||||
| S::PlayerAbilities(_)
|
||||
| S::MovePlayerStatus(_)
|
||||
| S::MovePlayerRot(_)
|
||||
| S::PlayerLoaded(_)
|
||||
@@ -1909,6 +1910,11 @@ impl Hub {
|
||||
self.position_change(i, [p.x, p.y, p.z], rot, 0, ctx, events);
|
||||
}
|
||||
}
|
||||
// handlePlayerAbilities: the client flies only if it may.
|
||||
S::PlayerAbilities(p) => {
|
||||
let g = &mut self.guests[i];
|
||||
g.flying = p.flags & 2 != 0 && (g.creative() || g.spectator());
|
||||
}
|
||||
S::MovePlayerPos(p) => {
|
||||
self.move_player(i, Some([p.x, p.y, p.z]), None, p.flags, ctx, events);
|
||||
}
|
||||
@@ -2183,6 +2189,13 @@ impl Hub {
|
||||
return;
|
||||
};
|
||||
g.game_mode = mode;
|
||||
// GameType.updatePlayerAbilities: a spectator flies, survival and
|
||||
// adventure don't, creative keeps what it had.
|
||||
if g.spectator() {
|
||||
g.flying = true;
|
||||
} else if !g.creative() {
|
||||
g.flying = false;
|
||||
}
|
||||
let uuid = g.uuid;
|
||||
g.send(&C::GameEvent(play::GameEvent {
|
||||
event: game_event::CHANGE_GAME_MODE,
|
||||
|
||||
@@ -1674,6 +1674,8 @@ packet!(
|
||||
);
|
||||
packet!(ChangeDifficultyRequest { difficulty: i32 => VarInt });
|
||||
packet!(LockDifficulty { locked: bool => Bool });
|
||||
// ServerboundPlayerAbilitiesPacket: only whether the player flies (2).
|
||||
packet!(PlayerAbilitiesRequest { flags: i8 => Byte });
|
||||
packet!(SetGameRule { entries: Vec<GameRuleEntry> => List<GameRuleEntry> });
|
||||
packet!(ChunkBatchReceived { chunks_per_tick: f32 => Float });
|
||||
packet!(
|
||||
@@ -1786,6 +1788,7 @@ packet_enum!(Serverbound, crate::ids::play::serverbound {
|
||||
MovePlayerStatus(MovePlayerStatus) = MOVE_PLAYER_STATUS_ONLY,
|
||||
PickItemFromBlock(PickItemFromBlock) = PICK_ITEM_FROM_BLOCK,
|
||||
PingRequest(crate::packets::status::Ping) = PING_REQUEST,
|
||||
PlayerAbilities(PlayerAbilitiesRequest) = PLAYER_ABILITIES,
|
||||
PlayerAction(PlayerAction) = PLAYER_ACTION,
|
||||
PlayerCommand(PlayerCommand) = PLAYER_COMMAND,
|
||||
PlayerInput(PlayerInput) = PLAYER_INPUT,
|
||||
@@ -1805,6 +1808,17 @@ mod tests {
|
||||
use super::*;
|
||||
use crate::{chunk::BlockEntityInfo, packets::round_trip, text::literal};
|
||||
|
||||
#[test]
|
||||
fn serverbound_abilities_carry_only_flying() {
|
||||
// ServerboundPlayerAbilitiesPacket.write: one byte, 2 when flying.
|
||||
let flying = Serverbound::PlayerAbilities(PlayerAbilitiesRequest { flags: 2 });
|
||||
assert_eq!(
|
||||
flying.encode(),
|
||||
[crate::ids::play::serverbound::PLAYER_ABILITIES as u8, 2]
|
||||
);
|
||||
round_trip(flying, Serverbound::encode, Serverbound::decode);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn world_options_packets_match_vanilla_stream_codecs() {
|
||||
// mcsrc.dev 26.3: difficulty is a VarInt, locking is a Boolean,
|
||||
|
||||
+63
-3
@@ -92,6 +92,9 @@ address. The script then checks, from both sides, what a guest's game used to ge
|
||||
server's game time after the guest's game stalls for a few seconds (#848).
|
||||
- growth: far from the host, the chunks around the guest tick (#890): water placed there flows
|
||||
and wheat on farmland grows (random ticks), however the host runs its world.
|
||||
- flight: a player in creative double-taps jump and flies, stays up, and stops flying in survival:
|
||||
the guest, and on the server thread the host's window too, take what may fly from the
|
||||
server's abilities (ClientPacketListener.handlePlayerAbilities).
|
||||
- light: the guest's light matches the host's: around a torch placed near it, under a roof and
|
||||
once a block of the roof is removed under the sky, and in the last chunk it tracks next to
|
||||
glowstone in a chunk it doesn't (only the server's light updates bring that one).
|
||||
@@ -130,7 +133,7 @@ ROOT = Path(__file__).resolve().parents[1]
|
||||
GUEST_NAME = 'Guest'
|
||||
# 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', 'arrows', 'kills', 'hurt', 'respawn', 'containers', 'feedback', 'titles', 'chat', 'commands', 'recipes', 'machines', 'brewing', 'trials', 'clicks', 'sleep', 'predict', 'push', 'eat', 'eating', 'xp', 'objects', 'projectiles', 'worn', 'blast', 'barter', 'deflect', 'fireball', 'light', 'time', 'swings', 'cracks', 'plates', 'effects', 'portals', 'distance', 'growth']
|
||||
CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'arrows', 'kills', 'hurt', 'respawn', 'containers', 'feedback', 'titles', 'chat', 'commands', 'recipes', 'machines', 'brewing', 'trials', 'clicks', 'sleep', 'predict', 'push', 'eat', 'eating', 'xp', 'objects', 'projectiles', 'worn', 'blast', 'barter', 'deflect', 'fireball', 'light', 'time', 'swings', 'cracks', 'plates', 'effects', 'portals', 'distance', 'growth', 'flight']
|
||||
|
||||
|
||||
class Game:
|
||||
@@ -437,6 +440,20 @@ 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))
|
||||
hx, hy, hz = (int(v // 1) for v in pos_of(host))
|
||||
try:
|
||||
return portals(host, guest, out, x, y, z, hx, hy, hz)
|
||||
finally:
|
||||
# The guest comes home into its portal's frame (an obsidian ceiling three blocks up) and the
|
||||
# host onto its End portal at spawn: take both away so the next checks start in the open.
|
||||
home = 'execute in minecraft:overworld run'
|
||||
guest('command', command=f'{home} fill {x - 1} {y} {z + 3} {x + 2} {y + 3} {z + 3} minecraft:air')
|
||||
host('command', command=f'{home} setblock {hx} {hy} {hz} minecraft:air')
|
||||
guest('command', command=f'{home} tp @s {x + 0.5} {y} {z + 0.5}')
|
||||
guest.wait(20)
|
||||
|
||||
|
||||
def portals(host, guest, out, x, y, z, hx, hy, hz):
|
||||
nether_portal(guest, x, y, z + 3)
|
||||
guest.wait(5)
|
||||
guest('command', command=f'tp @s {x + 0.5} {y} {z + 3.5}')
|
||||
@@ -451,7 +468,6 @@ def check_portals(host, guest, out):
|
||||
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)
|
||||
@@ -1784,6 +1800,50 @@ def same_light(host, guest, lo, hi, what, ticks=100):
|
||||
f'{h["sky"][i]} block {h["block"][i]}, guest sky {g["sky"][i]} block {g["block"][i]}')
|
||||
|
||||
|
||||
def check_flight(host, guest, out):
|
||||
def double_jump(game):
|
||||
# LocalPlayer.aiStep: a second jump press within 7 ticks of the first toggles flight.
|
||||
for hold in (1, 4):
|
||||
game.raw('key', 'space', 'down')
|
||||
game.wait(hold)
|
||||
game.raw('key', 'space', 'up')
|
||||
game.wait(2)
|
||||
game.wait(10)
|
||||
return game('state')['player']
|
||||
|
||||
def set_mode(game, mode):
|
||||
# On a client of a server the mode and its abilities (may fly) come back with the server's
|
||||
# answer, later when the machine is busy: a double jump before them is two plain jumps.
|
||||
game('command', command=f'gamemode {mode}')
|
||||
for _ in range(100):
|
||||
if game('state').get('gamemode') == mode:
|
||||
break
|
||||
game.wait(1)
|
||||
game.wait(10)
|
||||
|
||||
players = [('guest', guest)] + ([('host', host)] if SERVER_THREAD else [])
|
||||
seen = {}
|
||||
try:
|
||||
for name, game in players:
|
||||
set_mode(game, 'creative')
|
||||
ground = game('state')['player']
|
||||
up = double_jump(game)
|
||||
game.wait(20)
|
||||
later = game('state')['player']
|
||||
set_mode(game, 'survival')
|
||||
fell = game('state')['player']
|
||||
seen[name] = {'flying': up['flying'], 'rose': round(up['position'][1] - ground['position'][1], 2),
|
||||
'stayed': round(later['position'][1] - up['position'][1], 2),
|
||||
'survival_flying': fell['flying']}
|
||||
finally:
|
||||
for _, game in players:
|
||||
game('command', command='gamemode survival')
|
||||
for name, s in seen.items():
|
||||
assert s['flying'] and s['rose'] > 1 and abs(s['stayed']) < 0.1, f'{name} does not fly in creative: {seen}'
|
||||
assert not s['survival_flying'], f'{name} still flies in survival: {seen}'
|
||||
return seen
|
||||
|
||||
|
||||
def check_growth(host, guest, out):
|
||||
"""Block ticks near a guest 1000 blocks from the host: only the guest's tickets tick them."""
|
||||
x0, y0, z0 = pos_of(guest)
|
||||
@@ -2086,7 +2146,7 @@ CHECK_FNS = {'tab': check_tab, 'self': check_self, 'armour': check_armour, 'name
|
||||
'xp': check_xp, 'objects': check_objects, 'projectiles': check_projectiles, 'blast': check_blast,
|
||||
'light': check_light, 'plates': check_plates,
|
||||
'swings': check_swings, 'cracks': check_cracks,
|
||||
'time': check_time, 'growth': check_growth, 'fireball': check_fireball, 'deflect': check_deflect, 'barter': check_barter, 'worn': check_worn, 'kills': check_kills, 'arrows': check_arrows, 'predict': check_predict}
|
||||
'time': check_time, 'growth': check_growth, 'flight': check_flight, 'fireball': check_fireball, 'deflect': check_deflect, 'barter': check_barter, 'worn': check_worn, 'kills': check_kills, 'arrows': check_arrows, 'predict': check_predict}
|
||||
|
||||
|
||||
def run(ctl, out, resources, checks):
|
||||
|
||||
Reference in New Issue
Block a user