Merge remote-tracking branch 'origin/fix/lan-guest-pressure-plates' into integ/bl4
# Conflicts: # tools/lan_e2e.py
This commit is contained in:
@@ -463,6 +463,8 @@ struct GameLevel<'w> {
|
||||
raining: bool,
|
||||
thundering: bool,
|
||||
player_box: Option<([f64; 3], [f64; 3])>,
|
||||
/// The LAN guests in this level who trigger blocks (not spectators).
|
||||
guest_boxes: Vec<([f64; 3], [f64; 3])>,
|
||||
player_collision: Option<PlayerCollision>,
|
||||
/// Minecart boxes (detector rails).
|
||||
cart_boxes: Vec<([f64; 3], [f64; 3])>,
|
||||
@@ -676,7 +678,7 @@ impl LevelAccess for GameLevel<'_> {
|
||||
.unwrap_or(false)
|
||||
}
|
||||
/// Entities that trigger pressure plates, tripwires and detector rails:
|
||||
/// the player (a mob) and the minecarts.
|
||||
/// the players (the host and the LAN guests, mobs) and the minecarts.
|
||||
fn count_entities(&self, area: Aabb, query: EntityQuery) -> usize {
|
||||
let hit = |(lo, hi): &([f64; 3], [f64; 3])| {
|
||||
area.intersects(Aabb::new(
|
||||
@@ -685,10 +687,17 @@ impl LevelAccess for GameLevel<'_> {
|
||||
))
|
||||
};
|
||||
let carts = || self.cart_boxes.iter().filter(|b| hit(b)).count();
|
||||
let players = || {
|
||||
self.player_box
|
||||
.iter()
|
||||
.chain(&self.guest_boxes)
|
||||
.filter(|b| hit(b))
|
||||
.count()
|
||||
};
|
||||
match query {
|
||||
EntityQuery::Minecart => carts(),
|
||||
EntityQuery::Mobs => self.player_box.iter().filter(|b| hit(b)).count(),
|
||||
EntityQuery::Everything => self.player_box.iter().filter(|b| hit(b)).count() + carts(),
|
||||
EntityQuery::Mobs => players(),
|
||||
EntityQuery::Everything => players() + carts(),
|
||||
}
|
||||
}
|
||||
fn emit(&mut self, event: LevelEvent) {
|
||||
@@ -1999,6 +2008,7 @@ impl Game<'_> {
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
let guest_boxes = self.lan_block_trigger_boxes();
|
||||
let dimension = match self.dim {
|
||||
Dim::Overworld => LevelDimension::Overworld,
|
||||
Dim::Nether => LevelDimension::Nether,
|
||||
@@ -2016,6 +2026,7 @@ impl Game<'_> {
|
||||
raining: rain > 0.2,
|
||||
thundering: thunder > 0.9,
|
||||
player_box,
|
||||
guest_boxes,
|
||||
player_collision,
|
||||
biomes: self.res.biomes(),
|
||||
seed: self.level.seed,
|
||||
@@ -2094,8 +2105,9 @@ impl Game<'_> {
|
||||
ticking.push((x, z, sections));
|
||||
}
|
||||
// Entity.checkInsideBlocks for the plates, tripwires and detector rails
|
||||
// under the player and the minecarts.
|
||||
// under the players (the host and the LAN guests) and the minecarts.
|
||||
let mut inside = Vec::new();
|
||||
let guests = self.lan_block_trigger_boxes();
|
||||
let boxes = self
|
||||
.player
|
||||
.iter()
|
||||
@@ -2114,7 +2126,8 @@ impl Game<'_> {
|
||||
[p.x - 0.49, p.y, p.z - 0.49],
|
||||
[p.x + 0.49, p.y + 0.7, p.z + 0.49],
|
||||
)
|
||||
}));
|
||||
}))
|
||||
.chain(guests);
|
||||
for (lo, hi) in boxes {
|
||||
for x in (lo[0] + 1e-7).floor() as i32..=(hi[0] - 1e-7).floor() as i32 {
|
||||
for y in (lo[1] + 1e-7).floor() as i32..=(hi[1] - 1e-7).floor() as i32 {
|
||||
|
||||
@@ -131,6 +131,26 @@ impl Game<'_> {
|
||||
self.lan = Some(host);
|
||||
}
|
||||
|
||||
/// The guests' boxes for the blocks entities trigger (pressure plates,
|
||||
/// tripwires, detector rails): `Entity.checkInsideBlocks` and
|
||||
/// `Level.getEntities` see every player in the level, but not spectators
|
||||
/// (`Entity.isIgnoringBlockTriggers`).
|
||||
pub(super) fn lan_block_trigger_boxes(&self) -> Vec<([f64; 3], [f64; 3])> {
|
||||
let Some(host) = self.lan.as_ref() else {
|
||||
return Vec::new();
|
||||
};
|
||||
host.hub
|
||||
.guests
|
||||
.iter()
|
||||
.filter(|g| host.hub.here(g) && g.loaded && !g.dead && !g.spectator())
|
||||
.map(|g| {
|
||||
let [x, y, z] = g.position;
|
||||
let height = if g.sneaking { 1.5 } else { 1.8 };
|
||||
([x - 0.3, y, z - 0.3], [x + 0.3, y + height, z + 0.3])
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// The guests a projectile can hit, under their entity ids.
|
||||
pub(super) fn lan_projectile_targets(&self) -> Vec<(Who, Aabb)> {
|
||||
let Some(host) = self.lan.as_ref() else {
|
||||
|
||||
+25
-2
@@ -59,6 +59,8 @@ address. The script then checks, from both sides, what a guest's game used to ge
|
||||
guest as the host has them (kind, place, rotation, what they hold or wear, the variant).
|
||||
- projectiles: primed TNT (one falling), an end crystal and an arrow that lands reach the guest where
|
||||
the host has them; a falling block lands on both sides.
|
||||
- plates: a stone pressure plate the guest steps on is pressed on both sides, and comes up once
|
||||
the guest steps off (#848).
|
||||
- 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).
|
||||
@@ -94,7 +96,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', 'respawn', 'containers', 'feedback', 'titles', 'chat', 'commands', 'recipes', 'machines', 'brewing', 'trials', 'clicks', 'sleep', 'push', 'eat', 'xp', 'objects', 'projectiles', 'light', 'effects', 'portals', 'distance']
|
||||
CHECKS = ['tab', 'self', 'armour', 'nametags', 'walls', 'chest', 'crafting', 'sign', 'damage', 'mobs', 'hazards', 'pvp', 'respawn', 'containers', 'feedback', 'titles', 'chat', 'commands', 'recipes', 'machines', 'brewing', 'trials', 'clicks', 'sleep', 'push', 'eat', 'xp', 'objects', 'projectiles', 'light', 'plates', 'effects', 'portals', 'distance']
|
||||
|
||||
|
||||
class Game:
|
||||
@@ -1081,6 +1083,27 @@ def wait_state(game, pos, key, want, ticks):
|
||||
return state_of(game, pos, key)
|
||||
|
||||
|
||||
def check_plates(host, guest, out):
|
||||
guest('command', command='gamemode survival')
|
||||
x, y, z = (int(v // 1) for v in pos_of(guest))
|
||||
plate = (x + 2, y, z)
|
||||
guest('command', command=f'setblock {plate[0]} {plate[1]} {plate[2]} minecraft:stone_pressure_plate')
|
||||
guest.wait(10)
|
||||
guest('command', command=f'tp @s {plate[0] + 0.5} {plate[1]} {plate[2] + 0.5}')
|
||||
pressed = {'host': wait_state(host, plate, 'powered', 'true', 40),
|
||||
'guest': wait_state(guest, plate, 'powered', 'true', 40)}
|
||||
guest.shot(out, 'plate-pressed')
|
||||
guest('command', command=f'tp @s {x + 0.5} {y} {z + 0.5}')
|
||||
# PressurePlateBlock.getPressedTime: a stone plate checks again every 20 ticks.
|
||||
released = {'host': wait_state(host, plate, 'powered', 'false', 60),
|
||||
'guest': wait_state(guest, plate, 'powered', 'false', 60)}
|
||||
guest('command', command=f'setblock {plate[0]} {plate[1]} {plate[2]} minecraft:air')
|
||||
detail = {'pressed': pressed, 'released': released}
|
||||
assert pressed == {'host': 'true', 'guest': 'true'}, f'the plate under the guest: {detail}'
|
||||
assert released == {'host': 'false', 'guest': 'false'}, f'the plate after the guest left: {detail}'
|
||||
return detail
|
||||
|
||||
|
||||
def check_trials(host, guest, out):
|
||||
# The host watches as a spectator, whom neither block detects: only the guest can wake them.
|
||||
hx, hy, hz = pos_of(host)
|
||||
@@ -1404,7 +1427,7 @@ CHECK_FNS = {'tab': check_tab, 'self': check_self, 'armour': check_armour, 'name
|
||||
'effects': check_effects, 'portals': check_portals, 'distance': check_distance, 'clicks': check_clicks,
|
||||
'sleep': check_sleep, 'push': check_push, 'eat': check_eat,
|
||||
'xp': check_xp, 'objects': check_objects, 'projectiles': check_projectiles,
|
||||
'light': check_light}
|
||||
'light': check_light, 'plates': check_plates}
|
||||
|
||||
|
||||
def run(ctl, out, resources, checks):
|
||||
|
||||
Reference in New Issue
Block a user