Merge remote-tracking branch 'pr/726' into bm2/combined
# Conflicts: # crates/horizon-client/src/game/remote.rs # tools/lan_e2e.py
This commit is contained in:
@@ -999,6 +999,7 @@ fn main() -> horizon_client::Result<()> {
|
||||
hero: false,
|
||||
uuid: PLAYER_UUID,
|
||||
allies: Default::default(),
|
||||
remote: false,
|
||||
}
|
||||
});
|
||||
let mut scratch = LegacyRandom::new(0);
|
||||
|
||||
@@ -196,6 +196,7 @@ impl Game<'_> {
|
||||
hero: self.potions.effects.get("hero_of_the_village").is_some(),
|
||||
uuid: self.level.player_uuid.unwrap_or_default(),
|
||||
allies: std::sync::Arc::new(self.player_allies()),
|
||||
remote: false,
|
||||
})
|
||||
}
|
||||
/// Biome facts at a position for finalizeSpawn and variant rules.
|
||||
|
||||
@@ -107,6 +107,7 @@ impl Game<'_> {
|
||||
v.velocity = Vec3::new(moved[0], moved[1], moved[2]);
|
||||
v.uuid = horizon_client::lan::playerdata::uuid_ints(uuid);
|
||||
v.allies = Default::default();
|
||||
v.remote = true;
|
||||
views.push((conn, v));
|
||||
}
|
||||
}
|
||||
@@ -274,6 +275,7 @@ mod tests {
|
||||
hero: false,
|
||||
uuid: [0; 4],
|
||||
allies: Default::default(),
|
||||
remote: false,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,12 +15,13 @@ use horizon_client::{
|
||||
hud::{HudBatch, rgba},
|
||||
items::ItemStack,
|
||||
menu::Input,
|
||||
mobs::{Mob, MobType},
|
||||
mobs::{Mob, MobType, Who},
|
||||
motion::{MotionWorld, PlayerMotion},
|
||||
net::{Event, Session},
|
||||
save::SaveDir,
|
||||
sprint::Keys,
|
||||
streaming::{ChunkGenerator, Proto, Streaming},
|
||||
tab_list::SPECTATOR,
|
||||
world::World,
|
||||
};
|
||||
use horizon_core::{
|
||||
@@ -2225,6 +2226,7 @@ impl Game<'_> {
|
||||
// Player.tick's sleep counter (the darkening and the wake-up fade).
|
||||
self.sleep_timer = super::tick_sleep_timer(self.sleep_timer, self.sleeping.is_some());
|
||||
let ghast_collisions = self.happy_ghast_player_collisions();
|
||||
let pushed = self.remote_pushes();
|
||||
let Some(player) = self.player.as_mut() else {
|
||||
return Ok(());
|
||||
};
|
||||
@@ -2284,6 +2286,7 @@ impl Game<'_> {
|
||||
);
|
||||
player.velocity = Vec3::ZERO;
|
||||
} else if !dead {
|
||||
player.velocity = player.velocity.add_vector(pushed);
|
||||
MotionWorld {
|
||||
entities: &ghast_collisions,
|
||||
player,
|
||||
@@ -2336,6 +2339,70 @@ impl Game<'_> {
|
||||
self.send(S::ClientTickEnd(Empty));
|
||||
Ok(())
|
||||
}
|
||||
/// 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
|
||||
/// these pushes. `doPush(player)` is `player.push(entity)`.
|
||||
fn remote_pushes(&self) -> Vec3 {
|
||||
let (Some(p), Some(r)) = (self.player.as_ref(), self.remote.as_ref()) else {
|
||||
return Vec3::ZERO;
|
||||
};
|
||||
// LivingEntity.isPushable: alive, no spectator, off ladders.
|
||||
let feet = [
|
||||
p.position.x.floor() as i32,
|
||||
p.position.y.floor() as i32,
|
||||
p.position.z.floor() as i32,
|
||||
];
|
||||
if self.screen == Screen::Dead
|
||||
|| p.spectator
|
||||
|| self.block_in_tag("minecraft:climbable", &self.block_name(feet))
|
||||
{
|
||||
return Vec3::ZERO;
|
||||
}
|
||||
let bounds = p.bounds();
|
||||
let teams = self.mob_teams();
|
||||
let mut push = Vec3::ZERO;
|
||||
for m in &self.mobs {
|
||||
let spectator = r
|
||||
.level_players
|
||||
.get(&(m.id as i32))
|
||||
.and_then(|uuid| r.tab_players.get(uuid))
|
||||
.is_some_and(|t| t.game_mode == SPECTATOR);
|
||||
// Bats never push; a spectator has no physics; passengers of the
|
||||
// same vehicle never push each other.
|
||||
if !m.alive()
|
||||
|| spectator
|
||||
|| m.species() == horizon_client::mobs::Species::Bat
|
||||
|| self
|
||||
.riding
|
||||
.is_some_and(|v| v == m.id || m.extra.mount == Some(v))
|
||||
|| !m.bounds().intersects(bounds)
|
||||
|| !horizon_client::scoreboard::pushable_by(
|
||||
teams.of(Who::Mob(m.id)),
|
||||
teams.of(Who::Player),
|
||||
true,
|
||||
)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// Entity.push(Entity), `this` the player.
|
||||
let (mut xa, mut za) = (m.position.x - p.position.x, m.position.z - p.position.z);
|
||||
let mut dd = xa.abs().max(za.abs());
|
||||
if dd < f64::from(0.01_f32) {
|
||||
continue;
|
||||
}
|
||||
dd = dd.sqrt();
|
||||
xa /= dd;
|
||||
za /= dd;
|
||||
let pow = (1.0 / dd).min(1.0);
|
||||
xa *= pow;
|
||||
za *= pow;
|
||||
xa *= f64::from(0.05_f32);
|
||||
za *= f64::from(0.05_f32);
|
||||
push = Vec3::new(push.x - xa, push.y, push.z - za);
|
||||
}
|
||||
push
|
||||
}
|
||||
/// ClientLevel.tickEntities; a frozen level only ticks the players
|
||||
/// (`TickRateManager.isEntityFrozen`).
|
||||
fn tick_remote_entities(&mut self, running: bool) {
|
||||
|
||||
@@ -324,7 +324,7 @@ impl Game<'_> {
|
||||
)
|
||||
.unwrap_or_else(|_| VoxelShape::empty())
|
||||
}
|
||||
fn block_in_tag(&self, tag: &str, block: &str) -> bool {
|
||||
pub(super) fn block_in_tag(&self, tag: &str, block: &str) -> bool {
|
||||
self.res
|
||||
.items
|
||||
.block_tags
|
||||
|
||||
@@ -1400,6 +1400,9 @@ pub struct PlayerView {
|
||||
/// The mobs on the player's team (`isAlliedTo`): combat targeting
|
||||
/// leaves the player alone.
|
||||
pub allies: std::sync::Arc<std::collections::HashSet<u32>>,
|
||||
/// A LAN guest: its own client moves it, and touching mobs push it there
|
||||
/// (`EntitySelector.pushableBy` on the client).
|
||||
pub remote: bool,
|
||||
}
|
||||
pub struct MobWorld<'a> {
|
||||
pub world: &'a World,
|
||||
|
||||
@@ -822,10 +822,14 @@ fn push_entities(m: &mut Mob, w: &MobWorld, events: &mut Vec<MobEvent>) {
|
||||
za *= pow;
|
||||
xa *= f64::from(0.05_f32);
|
||||
za *= f64::from(0.05_f32);
|
||||
events.push(MobEvent::Push {
|
||||
target: who,
|
||||
velocity: [-xa, 0.0, -za],
|
||||
});
|
||||
// A guest's server-side push never reaches its client (ServerPlayer
|
||||
// motion is synced only when hurt): its client pushes it itself.
|
||||
if who != Who::Player || w.player.as_ref().is_none_or(|p| !p.remote) {
|
||||
events.push(MobEvent::Push {
|
||||
target: who,
|
||||
velocity: [-xa, 0.0, -za],
|
||||
});
|
||||
}
|
||||
if self_pushable {
|
||||
m.velocity = Vec3::new(m.velocity.x + xa, m.velocity.y, m.velocity.z + za);
|
||||
}
|
||||
|
||||
+21
-2
@@ -36,6 +36,8 @@ address. The script then checks, from both sides, what a guest's game used to ge
|
||||
its crafting grid and gathers a stack with a double click; the server has each.
|
||||
- sleep: at night the guest lies down in its own bed (not the host); alone it stays night, it
|
||||
gets up with Escape, and once the host sleeps too the night ends and both wake.
|
||||
- push: a cow standing in the guest pushes it just clear of the cow (the guest's own client
|
||||
pushes it, as in vanilla), not ever faster across the ground.
|
||||
|
||||
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).
|
||||
@@ -67,7 +69,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', 'containers', 'feedback', 'commands', 'recipes', 'trials', 'clicks', 'sleep', 'effects', 'portals']
|
||||
CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'containers', 'feedback', 'commands', 'recipes', 'trials', 'clicks', 'sleep', 'push', 'effects', 'portals']
|
||||
|
||||
|
||||
class Game:
|
||||
@@ -959,6 +961,23 @@ def check_sleep(host, guest, out):
|
||||
assert 13000 < night < 23000, f'one of two players asleep ended the night: {detail}'
|
||||
assert up is None, f'Escape did not get the guest up: {detail}'
|
||||
assert after['guest'] is None and after['host'] is None and after['time'] < 1000, f'no morning: {detail}'
|
||||
def check_push(host, guest, out):
|
||||
guest('command', command='gamemode survival')
|
||||
x, y, z = (int(v // 1) + 0.5 for v in pos_of(guest))
|
||||
guest('command', command=f'tp @s {x} {y - 0.5} {z}')
|
||||
guest.wait(20)
|
||||
x, y, z = pos_of(guest)
|
||||
# A cow that doesn't walk, 0.3 east of the guest: the two boxes overlap until their centres are
|
||||
# 0.75 apart, so the push stops a fraction of a block away.
|
||||
guest('command', command=f'summon minecraft:cow {x + 0.3:.2f} {y:.2f} {z:.2f} {{NoAI:1b}}')
|
||||
guest.wait(60)
|
||||
nx, _, nz = pos_of(guest)
|
||||
guest.shot(out, 'push')
|
||||
guest('command', command='kill @e[type=minecraft:cow]')
|
||||
moved = ((nx - x) ** 2 + (nz - z) ** 2) ** 0.5
|
||||
detail = {'from': [round(x, 3), round(z, 3)], 'to': [round(nx, 3), round(nz, 3)], 'moved': round(moved, 3)}
|
||||
assert nx < x, f'the cow did not push the guest west: {detail}'
|
||||
assert moved < 1.5, f'the cow pushed the guest too far: {detail}'
|
||||
return detail
|
||||
|
||||
|
||||
@@ -968,7 +987,7 @@ CHECK_FNS = {'tab': check_tab, 'self': check_self, 'armour': check_armour, 'name
|
||||
'containers': check_containers, 'feedback': check_feedback, 'commands': check_commands,
|
||||
'recipes': check_recipes, 'trials': check_trials, 'walls': check_walls,
|
||||
'effects': check_effects, 'portals': check_portals, 'clicks': check_clicks,
|
||||
'sleep': check_sleep}
|
||||
'sleep': check_sleep, 'push': check_push}
|
||||
|
||||
|
||||
def run(ctl, out, resources, checks):
|
||||
|
||||
Reference in New Issue
Block a user