[PR #2564] [MERGED] Finish a use on the server's USE_ITEM_COMPLETE, and eat on the client too #4432

Closed
opened 2026-11-03 04:17:06 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/2564
Author: @Louistuis
Created: 10/26/2026
Status: ✅ Merged
Merged: 10/27/2026
Merged by: @ludovic111

Base: main ← Head: fix/eat-held-after-full


📝 Commits (2)

  • 64cd55c Finish a use on the server's USE_ITEM_COMPLETE, and eat on the client too
  • 7b11005 Merge remote-tracking branch 'origin/main' into HEAD

📊 Changes

6 files changed (+205 additions, -40 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+6 -0)
📝 crates/horizon-client/src/game/consume.rs (+10 -0)
📝 crates/horizon-client/src/game/lan_actions.rs (+35 -14)
📝 crates/horizon-client/src/game/potions.rs (+1 -0)
📝 crates/horizon-client/src/game/remote.rs (+88 -25)
📝 tools/lan_e2e.py (+65 -1)

📄 Description

🤖 Opened by Louis's AI agent (Claude Code), not by Louis personally.

What and why

Fixes #2471. On a server client (single player's window on its server thread, a LAN guest, a dedicated server's client), if you keep holding right click while eating, the eating animation carries on after the food bar is full.

The window ended a consumable's use on its own timer and never ate the food. Its FoodData kept the old value until the server's next ClientboundSetHealth, so with the button still held the next startUseItem saw a bar below 20 and began another bite. Vanilla's client never ends a use by itself:

  • LivingEntity.updateUsingItem completes the use only on the server (!level().isClientSide()).
  • ServerPlayer.completeUsingItem first sends the player ClientboundEntityEventPacket(9) (USE_ITEM_COMPLETE), then completes the use itself.
  • Player.handleEntityEvent(9) runs completeUsingItem on the client. There Consumable.onConsume calls its ConsumableListeners on both sides, so FoodProperties.onConsume → FoodData.eat fills the client's bar at once. Effects stay on the server.

This PR does the same:

  • Server. When a consumable, a potion or a spyglass use completes, the server sends event 9 to the player who was using it. The event goes out with their entity id, queued during the acting guest's turn like guest_packets. A nested turn saves and restores the queue (GuestSwap), so one guest's events never reach another.
  • Client. The use goes on until that event arrives. The client then shows the last crumbs and eats the food: the next ClientboundSetHealth replaces the value, as in vanilla. It also starts the item's use_cooldown, which ItemStack.use starts at once only for an item with no use time; for one held in use, finishUsingItem starts it.
  • Uses can't outlive the server's. Now that the server ends the use, the client needs vanilla's own checks for the cases where the two disagree:
    • MultiPlayerGameMode.useItem does nothing for an item that is cooling down. Without this, a held chorus fruit started a bite the server refused, and the bite never ended.
    • LivingEntity.updatingUsingItem stops when the hand no longer holds the item the use began with (ItemStack.isSameItem).
    • A respawn is a new player, with no use in progress.
    • Consumable.startConsuming starts no use for a consumable with no use time.
  • Cooldowns count down where vanilla counts them. With the client honouring a cooldown, a held chorus fruit retries the moment the client's entry ends, so the two clocks have to agree. Vanilla ticks ItemCooldowns in Player.tick, after LivingEntity.tick's use on the server and after Minecraft.handleKeybinds on the client. That leaves the client's retry at least a tick after the server's entry has ended. Horizon ticked them first on both sides: the server's entry lasted a tick longer and the client retried a tick sooner. The server refused that retry, and the bite never ended.
  • The spyglass's stop sound already reaches the guest from the server, so the client doesn't play it a second time.

Single player in frame (--in-frame) and the host's own player are unchanged: they complete the use where it runs.

Noticed while working on this, not changed here:

  • guest_cooldowns is flushed in leave_guest the same way guest_packets was, but it isn't saved across a nested turn.
  • The client doesn't predict its own living flags for the use.

Vanilla reference

Read with javap -c on the 26.3 client jar. tools/rea_vanilla.py timed out on this machine.

  • LivingEntity.updatingUsingItem, LivingEntity.updateUsingItem, LivingEntity.completeUsingItem
  • ServerPlayer.completeUsingItem (sends ClientboundEntityEventPacket(this, 9) first)
  • Player.handleEntityEvent (case 9 → completeUsingItem)
  • Consumable.startConsuming, Consumable.onConsume, FoodProperties.onConsume, FoodData.eat
  • ItemStack.use / ItemStack.finishUsingItem (applyAfterUseComponentSideEffects)
  • MultiPlayerGameMode.useItem (ItemCooldowns.isOnCooldown → PASS)
  • Player.tick (Avatar.tick, then ItemCooldowns.tick), Minecraft.tick (handleKeybinds before ClientLevel.tickEntities)
  • SpyglassItem.finishUsingItem / stopUsing

Harness. This adds a new lan_e2e check, eat_full, run against two real games:

  1. Drain the guest's food bar to 17 or less.
  2. Hold right click on melon slices until the bar is full, then keep holding.
  3. Check: food is 20, exactly as many slices were eaten as needed, and nothing is in use over the following ticks.
  4. Then hold right click on two chorus fruits across the cooldown, and check that both are eaten and that the use ends.

The test fails on main and passes with this change:

tools/lan_e2e.py, two real games on macOS (M3 Air). These runs were on main at aa0eb406; the branch has since been rebased onto a727f617 without conflicts:

Build Mode eat_full eat, eating, helduse, consume-release, respawn, shield
main server thread ❌ using: [{ticks 15}, {ticks 21}, {ticks 31}, None]: another bite with a full bar –
this PR server thread, run 1 ✅ fed 20, eaten 2/2, using [None×4]; chorus left 0 ✅ all
this PR server thread, run 2 ✅ fed 20, eaten 2/2, using [None×4]; chorus left 0 ✅ all
this PR --in-frame ✅ (two runs) ✅ all

Holding right click on three chorus fruits, sampled every 0.2 s (guest's use / server's use). Before the cooldown ordering change, the second bite started on the client but never on the server:

before:  2.80 s  client {ticks 4}   server None   ...  7.79 s  client {ticks 104}  server None
after:   2.93 s  client {ticks 5}   server {ticks 6}   → all three eaten, each after its 20-tick cooldown

Self-check

pr_ready (tools/pr_ready.py --quick --base upstream/main on MrLouis, against upstream/main at a727f617f, 3 min 33 s)

Check Result
Scope ✅ 6 files, +205 −40
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 320 passed (30 s)
rustfmt ✅ (4 s)
clippy ✅ (8 s)
tests: horizon-client ✅ 1337 passed (2 min 49 s)
doc tests ✅ 0 passed (3 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 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/2564 **Author:** [@Louistuis](https://github.com/Louistuis) **Created:** 10/26/2026 **Status:** ✅ Merged **Merged:** 10/27/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/eat-held-after-full` --- ### 📝 Commits (2) - [`64cd55c`](https://github.com/horizon-rust/horizon/commit/64cd55cf74d7ae27b67bc69b737a98f53274a59d) Finish a use on the server's USE_ITEM_COMPLETE, and eat on the client too - [`7b11005`](https://github.com/horizon-rust/horizon/commit/7b11005688b4cbecb29fc2197406fc69b4c0b64a) Merge remote-tracking branch 'origin/main' into HEAD ### 📊 Changes **6 files changed** (+205 additions, -40 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+6 -0) 📝 `crates/horizon-client/src/game/consume.rs` (+10 -0) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+35 -14) 📝 `crates/horizon-client/src/game/potions.rs` (+1 -0) 📝 `crates/horizon-client/src/game/remote.rs` (+88 -25) 📝 `tools/lan_e2e.py` (+65 -1) </details> ### 📄 Description > 🤖 Opened by Louis's AI agent (Claude Code), not by Louis personally. ## What and why Fixes #2471. On a server client (single player's window on its server thread, a LAN guest, a dedicated server's client), if you keep holding right click while eating, the eating animation carries on after the food bar is full. The window ended a consumable's use on its own timer and never ate the food. Its `FoodData` kept the old value until the server's next `ClientboundSetHealth`, so with the button still held the next `startUseItem` saw a bar below 20 and began another bite. Vanilla's client never ends a use by itself: - `LivingEntity.updateUsingItem` completes the use only on the server (`!level().isClientSide()`). - `ServerPlayer.completeUsingItem` first sends the player `ClientboundEntityEventPacket(9)` (`USE_ITEM_COMPLETE`), then completes the use itself. - `Player.handleEntityEvent(9)` runs `completeUsingItem` on the client. There `Consumable.onConsume` calls its `ConsumableListener`s on both sides, so `FoodProperties.onConsume` → `FoodData.eat` fills the client's bar at once. Effects stay on the server. This PR does the same: - **Server.** When a consumable, a potion or a spyglass use completes, the server sends event 9 to the player who was using it. The event goes out with their entity id, queued during the acting guest's turn like `guest_packets`. A nested turn saves and restores the queue (`GuestSwap`), so one guest's events never reach another. - **Client.** The use goes on until that event arrives. The client then shows the last crumbs and eats the food: the next `ClientboundSetHealth` replaces the value, as in vanilla. It also starts the item's `use_cooldown`, which `ItemStack.use` starts at once only for an item with no use time; for one held in use, `finishUsingItem` starts it. - **Uses can't outlive the server's.** Now that the server ends the use, the client needs vanilla's own checks for the cases where the two disagree: - `MultiPlayerGameMode.useItem` does nothing for an item that is cooling down. Without this, a held chorus fruit started a bite the server refused, and the bite never ended. - `LivingEntity.updatingUsingItem` stops when the hand no longer holds the item the use began with (`ItemStack.isSameItem`). - A respawn is a new player, with no use in progress. - `Consumable.startConsuming` starts no use for a consumable with no use time. - **Cooldowns count down where vanilla counts them.** With the client honouring a cooldown, a held chorus fruit retries the moment the client's entry ends, so the two clocks have to agree. Vanilla ticks `ItemCooldowns` in `Player.tick`, after `LivingEntity.tick`'s use on the server and after `Minecraft.handleKeybinds` on the client. That leaves the client's retry at least a tick after the server's entry has ended. Horizon ticked them first on both sides: the server's entry lasted a tick longer and the client retried a tick sooner. The server refused that retry, and the bite never ended. - The spyglass's stop sound already reaches the guest from the server, so the client doesn't play it a second time. Single player in frame (`--in-frame`) and the host's own player are unchanged: they complete the use where it runs. Noticed while working on this, not changed here: - `guest_cooldowns` is flushed in `leave_guest` the same way `guest_packets` was, but it isn't saved across a nested turn. - The client doesn't predict its own living flags for the use. ## Vanilla reference Read with `javap -c` on the 26.3 client jar. `tools/rea_vanilla.py` timed out on this machine. - `LivingEntity.updatingUsingItem`, `LivingEntity.updateUsingItem`, `LivingEntity.completeUsingItem` - `ServerPlayer.completeUsingItem` (sends `ClientboundEntityEventPacket(this, 9)` first) - `Player.handleEntityEvent` (case 9 → `completeUsingItem`) - `Consumable.startConsuming`, `Consumable.onConsume`, `FoodProperties.onConsume`, `FoodData.eat` - `ItemStack.use` / `ItemStack.finishUsingItem` (`applyAfterUseComponentSideEffects`) - `MultiPlayerGameMode.useItem` (`ItemCooldowns.isOnCooldown` → `PASS`) - `Player.tick` (`Avatar.tick`, then `ItemCooldowns.tick`), `Minecraft.tick` (`handleKeybinds` before `ClientLevel.tickEntities`) - `SpyglassItem.finishUsingItem` / `stopUsing` **Harness.** This adds a new `lan_e2e` check, `eat_full`, run against two real games: 1. Drain the guest's food bar to 17 or less. 2. Hold right click on melon slices until the bar is full, then keep holding. 3. Check: food is 20, exactly as many slices were eaten as needed, and nothing is in use over the following ticks. 4. Then hold right click on two chorus fruits across the cooldown, and check that both are eaten and that the use ends. The test fails on `main` and passes with this change: `tools/lan_e2e.py`, two real games on macOS (M3 Air). These runs were on `main` at `aa0eb406`; the branch has since been rebased onto `a727f617` without conflicts: | Build | Mode | `eat_full` | `eat`, `eating`, `helduse`, `consume-release`, `respawn`, `shield` | | --- | --- | --- | --- | | `main` | server thread | ❌ `using: [{ticks 15}, {ticks 21}, {ticks 31}, None]`: another bite with a full bar | – | | this PR | server thread, run 1 | ✅ `fed 20, eaten 2/2, using [None×4]`; chorus `left 0` | ✅ all | | this PR | server thread, run 2 | ✅ `fed 20, eaten 2/2, using [None×4]`; chorus `left 0` | ✅ all | | this PR | `--in-frame` | ✅ (two runs) | ✅ all | Holding right click on three chorus fruits, sampled every 0.2 s (guest's use / server's use). Before the cooldown ordering change, the second bite started on the client but never on the server: ``` before: 2.80 s client {ticks 4} server None ... 7.79 s client {ticks 104} server None after: 2.93 s client {ticks 5} server {ticks 6} → all three eaten, each after its 20-tick cooldown ``` ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base upstream/main` on MrLouis, against upstream/main at a727f617f, 3 min 33 s) | Check | Result | | --- | --- | | Scope | ✅ 6 files, +205 −40 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 320 passed (30 s) | | rustfmt | ✅ (4 s) | | clippy | ✅ (8 s) | | tests: horizon-client | ✅ 1337 passed (2 min 49 s) | | doc tests | ✅ 0 passed (3 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | 🤖 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-03 04:17:06 +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#4432
No description provided.