LAN: pressure plates, tripwires and detector rails see the guests

Block triggers counted only the host's own player and the minecarts, so a
guest stepping on a plate did nothing. The guests in the level, not
spectators, now trigger them through Entity.checkInsideBlocks and are
counted by the plates' entity queries. On the server thread no block
ticks run at all yet (#890).

lan_e2e.py plates: a stone plate under the guest, on both sides.

Part of #848

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-18 14:14:48 +02:00
parent 2b6ae71fb7
commit 159a5dfa5f
3 changed files with 63 additions and 7 deletions
+18 -5
View File
@@ -460,6 +460,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])>,
@@ -673,7 +675,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(
@@ -682,10 +684,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) {
@@ -1868,6 +1877,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,
@@ -1885,6 +1895,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,
@@ -1963,8 +1974,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()
@@ -1983,7 +1995,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
View File
@@ -49,6 +49,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).
@@ -84,7 +86,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', 'titles', 'commands', 'recipes', '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', 'containers', 'feedback', 'titles', 'commands', 'recipes', 'trials', 'clicks', 'sleep', 'push', 'eat', 'xp', 'objects', 'projectiles', 'light', 'plates', 'effects', 'portals', 'distance']
class Game:
@@ -958,6 +960,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)
@@ -1278,7 +1301,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):