Merge pull request #2048 from rdbtCVS/fix/1490-sonic-boom-delivery
🤖 Agent: contrib-gate-17 verified this head (26.3 sources, integration tree build, clippy, tests, parity; details in the PR comment). Thanks @rdbtCVS!
This commit is contained in:
@@ -1087,6 +1087,9 @@ impl Game<'_> {
|
||||
self.ensure_item_particle_sprites();
|
||||
}
|
||||
let options = horizon_client::particles::ParticleOptions::simple(ty);
|
||||
if ty == horizon_client::particles::ParticleType::SonicBoom {
|
||||
self.lan_sonic_boom(&options, at);
|
||||
}
|
||||
// Count 0: one particle exactly there, at rest.
|
||||
if count == 0 {
|
||||
self.particles.add(&options, at, [0.0; 3]);
|
||||
|
||||
@@ -25,6 +25,33 @@ fn rgb(c: [f32; 4]) -> [f32; 3] {
|
||||
}
|
||||
|
||||
impl Game<'_> {
|
||||
/// `SonicBoom.tick` uses `ServerLevel.sendParticles` for each ray point.
|
||||
/// Keep the local event's rendering; connected players receive one at rest.
|
||||
pub(super) fn lan_sonic_boom(&self, options: &ParticleOptions, at: [f64; 3]) {
|
||||
let (Some(host), Some(particle)) = (&self.lan, self.network_particle(options, None)) else {
|
||||
return;
|
||||
};
|
||||
let packet = C::LevelParticles(play::LevelParticles {
|
||||
particle,
|
||||
override_limiter: false,
|
||||
always_show: false,
|
||||
pos: at,
|
||||
dist: [0.0; 3],
|
||||
max_speed: [0.0; 3],
|
||||
count: 0,
|
||||
randomization: 0,
|
||||
});
|
||||
for g in host.hub.guests.iter().filter(|g| host.hub.here(g)) {
|
||||
// ServerLevel compares the player's block centre, strictly within 32.
|
||||
let distance: f64 = (0..3)
|
||||
.map(|k| (g.position[k].floor() + 0.5 - at[k]).powi(2))
|
||||
.sum();
|
||||
if distance < 32.0 * 32.0 {
|
||||
g.send(&packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `ParticleTypes.STREAM_CODEC`'s value for `options`: the type's
|
||||
/// network id and the data it carries (`state` for the block particles).
|
||||
/// None while not serving, or for a particle whose data isn't sent from
|
||||
|
||||
@@ -6857,5 +6857,56 @@ CHECKS += ['replant']
|
||||
CHECK_FNS['replant'] = check_replant
|
||||
|
||||
|
||||
def check_sonic(host, guest, out):
|
||||
"""A real warden's ray reaches connected clients once, with normal damage.
|
||||
|
||||
Run with and without --server-thread to cover the window's local renderer too.
|
||||
The creative observer sees the same ray nearby and none outside sendParticles' range.
|
||||
"""
|
||||
x, y, z = (int(v // 1) for v in pos_of(host))
|
||||
result = {}
|
||||
guest('command', command='gamemode creative')
|
||||
host('command', command='difficulty normal')
|
||||
host('command', command='gamerule natural_health_regeneration false')
|
||||
try:
|
||||
host('command', command=f'fill {x - 3} {y - 1} {z - 3} {x + 85} {y - 1} {z + 14} minecraft:stone')
|
||||
host('command', command=f'fill {x - 3} {y} {z - 3} {x + 15} {y + 4} {z + 14} minecraft:air')
|
||||
host('command', command=f'fill {x - 2} {y} {z + 4} {x + 2} {y + 3} {z + 4} minecraft:stone')
|
||||
for near in (True, False):
|
||||
guest('command', command=f'tp @s {x + (3 if near else 80) + 0.5} {y} {z + 0.5}')
|
||||
host('command', command=f'tp @s {x + 0.5} {y} {z + 0.5} 0 0')
|
||||
host('command', command='gamemode survival')
|
||||
host('command', command='effect give @s minecraft:instant_health 1 5')
|
||||
host.wait(4)
|
||||
host('command', command=f'summon minecraft:warden {x + 0.5} {y} {z + 9.5} {{NoAI:1b,Tags:["sonic_test"]}}')
|
||||
host('command', command='attribute @e[tag=sonic_test,limit=1] minecraft:knockback_resistance base set 1')
|
||||
before = {side: made(g, 'sonic_boom') for side, g in (('host', host), ('guest', guest))}
|
||||
health = host('status')['player']['health']
|
||||
host('command', command='data merge entity @e[tag=sonic_test,limit=1] {NoAI:0b}')
|
||||
host('command', command='attribute @e[tag=sonic_test,limit=1] minecraft:movement_speed base set 0')
|
||||
host('command', command='damage @e[tag=sonic_test,limit=1] 1 minecraft:player_attack by @s')
|
||||
for _ in range(400):
|
||||
host.wait(2)
|
||||
if host('status')['player']['health'] < health:
|
||||
break
|
||||
host.wait(2) # let the observer process the same packet batch
|
||||
seen = {side: made(g, 'sonic_boom') - before[side] for side, g in (('host', host), ('guest', guest))}
|
||||
after = host('status')['player']['health']
|
||||
result['near' if near else 'far'] = {'particles': seen, 'health': [health, after]}
|
||||
host.shot(out, f'sonic-{"near" if near else "far"}')
|
||||
host('command', command='kill @e[tag=sonic_test]')
|
||||
assert after == health - 10, result
|
||||
assert seen['host'] == 15, result
|
||||
assert seen['guest'] == (15 if near else 0), result
|
||||
finally:
|
||||
host('command', command='kill @e[tag=sonic_test]')
|
||||
host('command', command='gamerule natural_health_regeneration true')
|
||||
return result
|
||||
|
||||
|
||||
CHECKS += ['sonic']
|
||||
CHECK_FNS['sonic'] = check_sonic
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user