[PR #466] [MERGED] LAN: mobs target and attack guests #2584

Closed
opened 2026-11-02 15:57:23 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/466
Author: @ludovic111
Created: 10/16/2026
Status: ✅ Merged
Merged: 10/16/2026
Merged by: @ludovic111

Base: main ← Head: fix/lan-mobs-target-guests


📝 Commits (2)

  • dac18e8 LAN: mobs target and attack guests
  • 327aa5a tools/lan_e2e.py: a world with commands, so the guest's commands run again

📊 Changes

8 files changed (+391 additions, -11 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+1 -0)
📝 crates/horizon-client/src/game/creatures.rs (+66 -6)
📝 crates/horizon-client/src/game/lan.rs (+3 -0)
📝 crates/horizon-client/src/game/lan_actions.rs (+4 -0)
➕ crates/horizon-client/src/game/lan_mobs.rs (+263 -0)
📝 crates/horizon-client/src/game/remote.rs (+6 -0)
📝 crates/horizon-client/src/lan/playerdata.rs (+2 -1)
📝 tools/lan_e2e.py (+46 -4)

📄 Description

Part of #435 (first item: mobs never target or attack guests).

What vanilla does

Target goals pick Level.getNearestPlayer under TargetingConditions (alive, not creative or spectator); HurtByTargetGoal answers whoever hurt the mob (getLastHurtByMob, forgotten after 100 ticks). The hit lands on that player, and hurtMarked sends the knockback to their client (ClientboundSetEntityMotionPacket).

What this changes

Horizon's mob code sees one player (MobWorld.player, Who::Player). With guests on (game/lan_mobs.rs):

  • each mob sees the nearest targetable player, host or guest (or the nearest non-spectator if nobody qualifies), and keeps a guest it targets or that hurt it in the last 100 ticks;
  • what its tick does to Who::Player (melee hits, typed damage, pushes, fire, iron-golem launches) runs with that guest swapped in (as_guest);
  • mobs' projectiles (arrows, fireballs, wind charges...) hit guests too, as that guest;
  • the guest's client applies knockback sent to its own entity (SetEntityMotion).
    No guests: nothing changes (the views list is empty and every path is skipped).

Left for later in #435: status effects from mobs (witch potions, poison, darkness, the elder guardian's curse) need guests' own effects, which Horizon doesn't model yet. Arrows the host shoots at a guest are PvP (next PR).

Also fixes tools/lan_e2e.py itself: since #372 (#407) a guest's commands need the world's Allow Commands as well as the LAN's, and the test opened a survival world without them, so every guest command (tp, gamemode, setblock) was refused and the checks built on them failed. It now creates the world with commands and puts everyone in survival.

How it was verified

  • Two real clients on this Mac (host + guest, offscreen, control socket): new mobs check in tools/lan_e2e.py. Host in creative, guest in survival, night: a zombie summoned 3 blocks away took the guest 20 → 5.3, a skeleton 7 blocks away kept shooting the guest down to 0 ("You Died!" on the guest's screen).
  • Every tools/lan_e2e.py check passes on this branch (tab, self, armour, nametags, chest, crafting, damage, mobs).
  • Unit tests for the player choice (game::lan_mobs::tests).
  • fmt, cargo clippy -p horizon-client --all-targets -- -D warnings. Parity harnesses: one tools/parity.py --changed origin/main run on the branch combining this series (results on the last PR).

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/466 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/16/2026 **Status:** ✅ Merged **Merged:** 10/16/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/lan-mobs-target-guests` --- ### 📝 Commits (2) - [`dac18e8`](https://github.com/horizon-rust/horizon/commit/dac18e8350600d38c4c6b95d987d4738b802185f) LAN: mobs target and attack guests - [`327aa5a`](https://github.com/horizon-rust/horizon/commit/327aa5af6e710b1aa0e3e10652ce0453943b6710) tools/lan_e2e.py: a world with commands, so the guest's commands run again ### 📊 Changes **8 files changed** (+391 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+1 -0) 📝 `crates/horizon-client/src/game/creatures.rs` (+66 -6) 📝 `crates/horizon-client/src/game/lan.rs` (+3 -0) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+4 -0) ➕ `crates/horizon-client/src/game/lan_mobs.rs` (+263 -0) 📝 `crates/horizon-client/src/game/remote.rs` (+6 -0) 📝 `crates/horizon-client/src/lan/playerdata.rs` (+2 -1) 📝 `tools/lan_e2e.py` (+46 -4) </details> ### 📄 Description Part of #435 (first item: mobs never target or attack guests). ## What vanilla does Target goals pick `Level.getNearestPlayer` under `TargetingConditions` (alive, not creative or spectator); `HurtByTargetGoal` answers whoever hurt the mob (`getLastHurtByMob`, forgotten after 100 ticks). The hit lands on that player, and `hurtMarked` sends the knockback to their client (`ClientboundSetEntityMotionPacket`). ## What this changes Horizon's mob code sees one player (`MobWorld.player`, `Who::Player`). With guests on (`game/lan_mobs.rs`): - each mob sees the nearest targetable player, host or guest (or the nearest non-spectator if nobody qualifies), and keeps a guest it targets or that hurt it in the last 100 ticks; - what its tick does to `Who::Player` (melee hits, typed damage, pushes, fire, iron-golem launches) runs with that guest swapped in (`as_guest`); - mobs' projectiles (arrows, fireballs, wind charges...) hit guests too, as that guest; - the guest's client applies knockback sent to its own entity (`SetEntityMotion`). No guests: nothing changes (the views list is empty and every path is skipped). Left for later in #435: status effects from mobs (witch potions, poison, darkness, the elder guardian's curse) need guests' own effects, which Horizon doesn't model yet. Arrows the host shoots at a guest are PvP (next PR). Also fixes `tools/lan_e2e.py` itself: since #372 (#407) a guest's commands need the world's Allow Commands as well as the LAN's, and the test opened a survival world without them, so every guest command (`tp`, `gamemode`, `setblock`) was refused and the checks built on them failed. It now creates the world with commands and puts everyone in survival. ## How it was verified - **Two real clients on this Mac** (host + guest, offscreen, control socket): new `mobs` check in `tools/lan_e2e.py`. Host in creative, guest in survival, night: a zombie summoned 3 blocks away took the guest 20 → 5.3, a skeleton 7 blocks away kept shooting the guest down to 0 ("You Died!" on the guest's screen). - Every `tools/lan_e2e.py` check passes on this branch (tab, self, armour, nametags, chest, crafting, damage, mobs). - Unit tests for the player choice (`game::lan_mobs::tests`). - fmt, `cargo clippy -p horizon-client --all-targets -- -D warnings`. Parity harnesses: one `tools/parity.py --changed origin/main` run on the branch combining this series (results on the last PR). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 15:57:23 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#2584
No description provided.