[PR #7347] Status effects: purge expired effects immediately without lingering at duration 0 #7539

Open
opened 2026-11-03 07:19:20 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7347
Author: @echo-ilovech3ss
Created: 11/2/2026
Status: 🔄 Open

Base: main ← Head: fix/status-effect-expired-pruning


📝 Commits (1)

  • 1632096 Status effects: purge expired effects immediately matching vanilla

📊 Changes

6 files changed (+92 additions, -32 deletions)

View changed files

📝 crates/horizon-client/src/effects.rs (+63 -6)
📝 crates/horizon-client/src/entity_nbt.rs (+21 -19)
📝 crates/horizon-client/src/game/agent.rs (+1 -1)
📝 crates/horizon-client/src/game/potions.rs (+2 -4)
📝 crates/horizon-client/src/lan/hub.rs (+1 -1)
📝 crates/horizon-client/src/mobs.rs (+4 -1)

📄 Description

What and Why

Fixes #7253.

When a status effect's remaining duration reached 0 ticks, it lingered in the active effects list for additional ticks with duration: 0 before being purged (in client-predicted effect loops, it could persist indefinitely at duration 0).

In vanilla Minecraft: Java Edition 26.3 (LivingEntity.tickEffects()), when an active MobEffectInstance decrements to duration <= 0, it is removed during that exact tick and an entity query never returns an active status effect instance whose duration is 0 or negative.

Root Cause

  1. client_tick_effects iterated through self.potions.effects.list calling e.tick_client(), which decremented duration from 1 to 0 via tick_down(), but never pruned expired effects using retain_mut. On subsequent ticks, !(self.infinite() || self.duration > 0) caused tick_client() to no-op, leaving the effect in self.potions.effects.list at duration: 0 indefinitely.
  2. PlayerEffects::get, modifiers(), saved(), add(), and from_saved() did not filter expired non-infinite effects (duration <= 0), allowing active effect queries (effects_json, agent control state, NBT saves) to report expired effects with duration 0.
  3. Mob effect querying and NBT serialization now consistently ignore expired non-infinite effects (ticks == 0).

Changes

  • crates/horizon-client/src/effects.rs:
    • Made EffectInstance::tick_client return bool indicating whether the effect remains active (self.is_active()).
    • Added pub fn infinite(&self) -> bool and pub fn is_active(&self) -> bool.
    • Guarded PlayerEffects::get, add, from_saved, saved, and modifiers to ignore non-infinite expired effects.
    • Added unit tests expired_status_effects_are_purged_and_never_queried and client_effects_tick_purges_expired.
  • crates/horizon-client/src/game/potions.rs:
    • client_tick_effects: uses self.potions.effects.list.retain_mut(|e| e.tick_client()).
    • effects_json: filters active effects only.
  • crates/horizon-client/src/game/agent.rs:
    • state: filters active effects only.
  • crates/horizon-client/src/lan/hub.rs:
    • sync_effects: filters active effects so expired effects cleanly trigger removal packets.
  • crates/horizon-client/src/mobs.rs & crates/horizon-client/src/entity_nbt.rs:
    • Mob effect lookup and NBT serialization ignore expired effects.

Checks

  • cargo test -p horizon-client --lib effects: 20 passed.
  • cargo test -p horizon-client --lib potions: 3 passed.
  • cargo test -p horizon-client --lib entity_nbt: 12 passed.

🔄 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/7347 **Author:** [@echo-ilovech3ss](https://github.com/echo-ilovech3ss) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/status-effect-expired-pruning` --- ### 📝 Commits (1) - [`1632096`](https://github.com/horizon-rust/horizon/commit/163209616a5284ae95bcce92c02f8172947f8d70) Status effects: purge expired effects immediately matching vanilla ### 📊 Changes **6 files changed** (+92 additions, -32 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/effects.rs` (+63 -6) 📝 `crates/horizon-client/src/entity_nbt.rs` (+21 -19) 📝 `crates/horizon-client/src/game/agent.rs` (+1 -1) 📝 `crates/horizon-client/src/game/potions.rs` (+2 -4) 📝 `crates/horizon-client/src/lan/hub.rs` (+1 -1) 📝 `crates/horizon-client/src/mobs.rs` (+4 -1) </details> ### 📄 Description ### What and Why Fixes #7253. When a status effect's remaining duration reached 0 ticks, it lingered in the active effects list for additional ticks with `duration: 0` before being purged (in client-predicted effect loops, it could persist indefinitely at duration 0). In vanilla Minecraft: Java Edition 26.3 (`LivingEntity.tickEffects()`), when an active `MobEffectInstance` decrements to `duration <= 0`, it is removed during that exact tick and an entity query never returns an active status effect instance whose duration is 0 or negative. ### Root Cause 1. `client_tick_effects` iterated through `self.potions.effects.list` calling `e.tick_client()`, which decremented `duration` from 1 to 0 via `tick_down()`, but never pruned expired effects using `retain_mut`. On subsequent ticks, `!(self.infinite() || self.duration > 0)` caused `tick_client()` to no-op, leaving the effect in `self.potions.effects.list` at `duration: 0` indefinitely. 2. `PlayerEffects::get`, `modifiers()`, `saved()`, `add()`, and `from_saved()` did not filter expired non-infinite effects (`duration <= 0`), allowing active effect queries (`effects_json`, agent control `state`, NBT saves) to report expired effects with duration 0. 3. Mob effect querying and NBT serialization now consistently ignore expired non-infinite effects (`ticks == 0`). ### Changes - `crates/horizon-client/src/effects.rs`: - Made `EffectInstance::tick_client` return `bool` indicating whether the effect remains active (`self.is_active()`). - Added `pub fn infinite(&self) -> bool` and `pub fn is_active(&self) -> bool`. - Guarded `PlayerEffects::get`, `add`, `from_saved`, `saved`, and `modifiers` to ignore non-infinite expired effects. - Added unit tests `expired_status_effects_are_purged_and_never_queried` and `client_effects_tick_purges_expired`. - `crates/horizon-client/src/game/potions.rs`: - `client_tick_effects`: uses `self.potions.effects.list.retain_mut(|e| e.tick_client())`. - `effects_json`: filters active effects only. - `crates/horizon-client/src/game/agent.rs`: - `state`: filters active effects only. - `crates/horizon-client/src/lan/hub.rs`: - `sync_effects`: filters active effects so expired effects cleanly trigger removal packets. - `crates/horizon-client/src/mobs.rs` & `crates/horizon-client/src/entity_nbt.rs`: - Mob effect lookup and NBT serialization ignore expired effects. ### Checks - `cargo test -p horizon-client --lib effects`: 20 passed. - `cargo test -p horizon-client --lib potions`: 3 passed. - `cargo test -p horizon-client --lib entity_nbt`: 12 passed. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#7539
No description provided.