[PR #7197] [MERGED] Native mods: a dropped item reaching its lifetime, which mods may extend (native_item_expire) #7404

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7197
Author: @arismoko
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: v2/ses_01M6DYB8QYSC38EEXTNNJRQ8T4-drops


📝 Commits (10+)

  • 22dd5f9 Add native item expiration hook
  • 12b38c9 Match replacement hook generator contract
  • 9fe4c74 Let every mod extend an expiring item
  • 75c640c Preserve extended item lifetime in signed age
  • 039cf9a Fix extended item lifetime behavior
  • 45ffb1d Regenerate the mod API
  • 6be9ab6 Use a listen contract for item expiry extensions
  • 3dd5956 Fix signed age in item merge test fixture
  • 1ed50d2 Set tick phase explicitly in resting item test
  • 3794f5e Merge upstream main into item expiry hooks

📊 Changes

7 files changed (+102 additions, -21 deletions)

View changed files

📝 crates/horizon-client/src/entities.rs (+19 -10)
📝 crates/horizon-client/src/entity_nbt.rs (+5 -3)
📝 crates/horizon-client/src/game.rs (+13 -5)
📝 crates/horizon-client/src/game/machines.rs (+3 -3)
📝 crates/horizon-client/src/game/native_hooks.rs (+13 -0)
📝 crates/horizon-client/src/mod_api/generated.rs (+33 -0)
➕ tools/native-hook-fragments/item_expire.json (+16 -0)

📄 Description

🤖 Opened by Aria's agent swarm, Dyna, not by Aria.

Adds native_item_expire, which fires on the server when a dropped item reaches the end of its lifetime. Its counterpart is NeoForge's ItemExpireEvent, a server event that can't be cancelled; a mod extends the item's life instead.

Part of #4953.

What it does

  • The hook. It fires where vanilla's ItemEntity.tick discards an item whose age has reached 6000 on the server. It doesn't fire on a LAN or server guest. Its contract is listen, and every mod gets extra_life, which starts at 0. A mod may set it or add to it, and the dispatch writes it back, so the result is a running total. A positive total keeps the item that much longer; zero or less lets it expire as before. The item's age is set back by the extension, which is capped at 32766 ticks so the age stays above vanilla's -32768.

  • The item age is signed. An extended item has a negative age, so ItemEntity.age changes from u32 to i32, as vanilla's int age is. That also brings in vanilla's behaviour for a saved Age of -32768:

    • the item never ages (INFINITE_LIFETIME);
    • it never merges (isMergable);
    • it saves back unchanged.

    Before this change, loading clamped the age to 0.

  • Resting items use tickCount. A resting item moves on 1 tick in 4 by tickCount + id, and the lava hurt sound plays every 10 ticks by tickCount. Horizon used age for both, as a shortcut, and a negative age would have broken that. Both now use the entity's tick count, as vanilla does. The machines path that follows a resting item's move uses it too. The honey-slide test's fixture now sets the tick count to match.

  • Merging. The item catalog lookup only runs when an item actually merges.

Overlap with #7005

#7005's item_despawn fires at the same place, but it can't extend an item's life. Is that hook meant to be a separate event, or should one of the two give way? Happy to fold either into the other.

Tests

  • The existing merge tests now run with a signed age. The resting-item tests now use the tick count, as vanilla does.
  • cargo run -p xtask -- mod-api regenerated generated.rs. The native-hook stamp tests pass on this head.

Tested in game

The route was a throwaway branch of horizon-machine-sample's trait-API example, which adds 200 ticks to an item on expiry.

  • Server thread: the test ran on a merge of this head with the living-hooks PR (31f835842d), not this branch alone. A diamond summoned one tick before its expiry was still there after the first check. It disappeared at the next expiry check, which added nothing.
  • Dedicated server, with a connected client: an earlier merge of the two branches (771e2307fb), from before upstream main was merged in, passed the same test. The hook fired at both checks.

pr_ready

pr_ready (tools/pr_ready.py --quick --base 693aa8482f7d577c944d847e15fb5d1b33a9a94a on 5cb5a44b1c95, against 693aa8482f at 693aa8482, 7 min 36 s)

Check Result
Scope ✅ 7 files, +102 −21
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 612 passed (41 s)
rustfmt ✅ (10 s)
clippy ✅ (1 s)
tests: horizon-client, horizon-client-lib ✅ 2106 passed (6 min 13 s)
doc tests ✅ 0 passed (4 s)
content root tests ➖ content root untouched
mod API up to date ✅ (24 s)
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ 375 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, anvil_turtle_egg, armor_stand_frost, armor_stand_turtle_egg, arrow, arrow_wind_charge, attribute_health, attribute_map_queries, attribute and 363 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 Generated with Dyna.


🔄 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/7197 **Author:** [@arismoko](https://github.com/arismoko) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `v2/ses_01M6DYB8QYSC38EEXTNNJRQ8T4-drops` --- ### 📝 Commits (10+) - [`22dd5f9`](https://github.com/horizon-rust/horizon/commit/22dd5f9a80251d170fcf5a101fa0286916803d0a) Add native item expiration hook - [`12b38c9`](https://github.com/horizon-rust/horizon/commit/12b38c91f71ebf4ab0a225bfd5eef3a6ec6b530b) Match replacement hook generator contract - [`9fe4c74`](https://github.com/horizon-rust/horizon/commit/9fe4c746bb4512fbda4f54af7ac829a09e7856cb) Let every mod extend an expiring item - [`75c640c`](https://github.com/horizon-rust/horizon/commit/75c640c9a63691929fff5322667d5e30e7ce828b) Preserve extended item lifetime in signed age - [`039cf9a`](https://github.com/horizon-rust/horizon/commit/039cf9ab29c57bbb1b0f9b415e9eaa461d944551) Fix extended item lifetime behavior - [`45ffb1d`](https://github.com/horizon-rust/horizon/commit/45ffb1d479d61f0a2ad6d307f578b8640fbaf77f) Regenerate the mod API - [`6be9ab6`](https://github.com/horizon-rust/horizon/commit/6be9ab6017782055fd03d7d58a7118df4df279f0) Use a listen contract for item expiry extensions - [`3dd5956`](https://github.com/horizon-rust/horizon/commit/3dd5956f106d246173dd617309c146bf518a6b27) Fix signed age in item merge test fixture - [`1ed50d2`](https://github.com/horizon-rust/horizon/commit/1ed50d2e5b1b524cf5f06ffb5dd916844fa4b437) Set tick phase explicitly in resting item test - [`3794f5e`](https://github.com/horizon-rust/horizon/commit/3794f5e635b536064f344064dfa9002e5cc9505b) Merge upstream main into item expiry hooks ### 📊 Changes **7 files changed** (+102 additions, -21 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/entities.rs` (+19 -10) 📝 `crates/horizon-client/src/entity_nbt.rs` (+5 -3) 📝 `crates/horizon-client/src/game.rs` (+13 -5) 📝 `crates/horizon-client/src/game/machines.rs` (+3 -3) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+13 -0) 📝 `crates/horizon-client/src/mod_api/generated.rs` (+33 -0) ➕ `tools/native-hook-fragments/item_expire.json` (+16 -0) </details> ### 📄 Description > 🤖 Opened by Aria's agent swarm, Dyna, not by Aria. Adds `native_item_expire`, which fires on the server when a dropped item reaches the end of its lifetime. Its counterpart is NeoForge's `ItemExpireEvent`, a server event that can't be cancelled; a mod extends the item's life instead. Part of #4953. ## What it does - **The hook.** It fires where vanilla's `ItemEntity.tick` discards an item whose `age` has reached 6000 on the server. It doesn't fire on a LAN or server guest. Its contract is `listen`, and every mod gets `extra_life`, which starts at 0. A mod may set it or add to it, and the dispatch writes it back, so the result is a running total. A positive total keeps the item that much longer; zero or less lets it expire as before. The item's age is set back by the extension, which is capped at 32766 ticks so the age stays above vanilla's `-32768`. - **The item age is signed.** An extended item has a negative age, so `ItemEntity.age` changes from `u32` to `i32`, as vanilla's `int age` is. That also brings in vanilla's behaviour for a saved `Age` of `-32768`: - the item never ages (`INFINITE_LIFETIME`); - it never merges (`isMergable`); - it saves back unchanged. Before this change, loading clamped the age to 0. - **Resting items use `tickCount`.** A resting item moves on 1 tick in 4 by `tickCount + id`, and the lava hurt sound plays every 10 ticks by `tickCount`. Horizon used `age` for both, as a shortcut, and a negative age would have broken that. Both now use the entity's tick count, as vanilla does. The machines path that follows a resting item's move uses it too. The honey-slide test's fixture now sets the tick count to match. - **Merging.** The item catalog lookup only runs when an item actually merges. ## Overlap with #7005 #7005's `item_despawn` fires at the same place, but it can't extend an item's life. Is that hook meant to be a separate event, or should one of the two give way? Happy to fold either into the other. ## Tests - The existing merge tests now run with a signed age. The resting-item tests now use the tick count, as vanilla does. - `cargo run -p xtask -- mod-api` regenerated `generated.rs`. The native-hook stamp tests pass on this head. ## Tested in game The route was a throwaway branch of [horizon-machine-sample](https://github.com/arismoko/horizon-machine-sample)'s trait-API example, which adds 200 ticks to an item on expiry. - **Server thread:** the test ran on a merge of this head with the living-hooks PR (31f835842d), not this branch alone. A diamond summoned one tick before its expiry was still there after the first check. It disappeared at the next expiry check, which added nothing. - **Dedicated server, with a connected client:** an earlier merge of the two branches (771e2307fb), from before upstream main was merged in, passed the same test. The hook fired at both checks. ## pr_ready **pr_ready** (`tools/pr_ready.py --quick --base 693aa8482f7d577c944d847e15fb5d1b33a9a94a` on 5cb5a44b1c95, against 693aa8482f7d577c944d847e15fb5d1b33a9a94a at 693aa8482, 7 min 36 s) | Check | Result | | --- | --- | | Scope | ✅ 7 files, +102 −21 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 612 passed (41 s) | | rustfmt | ✅ (10 s) | | clippy | ✅ (1 s) | | tests: horizon-client, horizon-client-lib | ✅ 2106 passed (6 min 13 s) | | doc tests | ✅ 0 passed (4 s) | | content root tests | ➖ content root untouched | | mod API up to date | ✅ (24 s) | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ 375 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, anvil_turtle_egg, armor_stand_frost, armor_stand_turtle_egg, arrow, arrow_wind_charge, attribute_health, attribute_map_queries, attribute and 363 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | 🤖 Generated with Dyna. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:39:02 +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#7404
No description provided.