[PR #5649] [MERGED] feat(mods): native mods use items over time (duration, animation, can eat, start and finish) #6416

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5649
Author: @reservedbytes
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @levzzz5154

Base: main ← Head: feat/native-item-use-over-time


📝 Commits (3)

  • e26bd0f feat(mods): native mods use items over time (duration, animation, can eat, start and finish)
  • 69722df Merge main into feat/native-item-use-over-time
  • b91ef70 fix(mods): a use's client countdowns follow its started duration

📊 Changes

14 files changed (+401 additions, -69 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+55 -38)
📝 crates/horizon-client/src/game/crossbow.rs (+2 -4)
📝 crates/horizon-client/src/game/end.rs (+1 -3)
📝 crates/horizon-client/src/game/fov.rs (+1 -2)
📝 crates/horizon-client/src/game/item_draw.rs (+5 -2)
➕ crates/horizon-client/src/game/item_use.rs (+218 -0)
📝 crates/horizon-client/src/game/lan_actions.rs (+6 -0)
📝 crates/horizon-client/src/game/native_hooks.rs (+75 -0)
📝 crates/horizon-client/src/game/potions.rs (+1 -3)
📝 crates/horizon-client/src/game/remote.rs (+22 -10)
📝 crates/horizon-client/src/game/shield.rs (+2 -2)
📝 crates/horizon-client/src/game/spear.rs (+1 -2)
📝 crates/horizon-client/src/game/trident.rs (+1 -3)
➕ tools/native-hook-fragments/item_use_over_time.json (+11 -0)

📄 Description

What and why

Part of #5523

A native mod's item could not be used over time: no bow-like hold, no food of its own time
Vanilla asks Item.getUseDuration and getUseAnimation
startUsingItem starts the use, and completeUsingItem ends it with finishUsingItem's result
This adds five hook points for that, on the server thread, LAN and the in-frame path alike

native_use_duration(stack, &mut duration) is Item.getUseDuration, arriving with vanilla's answer
It takes no user, since it is asked each frame an item in use is drawn
A mod's own item (outside minecraft:) with no consumable, blocks_attacks or kinetic weapon that answers above 0 is used over time on a right click
That stands in for the item's own Item.use calling startUsingItem, after a block item's useOn had its turn
Its use counts down to the answered time on the server, then completes (USE_ITEM_COMPLETE, the use cooldown, the finish hook)
The player's own client starts and keeps it too, so letting go sends RELEASE_USE_ITEM as for a bow
A consumable's time follows the answer as well, so a mod food can take its own eat time
native_use_animation(stack, &mut animation) is Item.getUseAnimation for the first person hand: eat and drink bring it to the mouth, bow draws, trident raises, brush sweeps
native_can_eat(stack, &mut can_eat) is Player.canEat where Consumable.canConsume asks it, so a mod can refuse food or let a full player eat
native_living_entity_use_item_start(stack, entity, hand, &mut duration, &mut canceled) fires in startUsingItem for every item
It fires on both sides, as vanilla's startUsingItem runs on both: where the world runs, and on a server's client for the uses it predicts, so a cancel or a changed duration doesn't drift
A mod should answer the same on both, and change the world only where this Game runs the world, not on a server's client
No helper tells the two apart yet: native_window is also true in-frame and on an in-frame LAN host
native_living_entity_use_item_finish(stack, entity, hand, 0, &mut result) fires after finishUsingItem of consumables, potions and mods' items, server-side, and may replace what the hand holds
Its duration is always 0, as the use ran its time
entity is a mob's Entity.getId, None for a player as in native_apply_effect_tick, so mobs can fire both later without a new version
Only players fire them so far
hand is the hand in use, main or off (first_person::Hand, vanilla's InteractionHand)

Every use start now goes through one start_using_item, the client's predictions included
It keeps the duration the use started with, as useItemRemaining does
A guest's turn swaps that duration with the rest of its use state
A use that the server's flags start on the client (synced_local_use) doesn't go through it, as vanilla's onSyncedDataUpdated doesn't call startUsingItem
Two hooks follow NeoForge's LivingEntityUseItemEvent.Start and .Finish and take their names in snake case (#4402)
Their getters are the entity, the item, the hand and the duration, with setDuration on the base event, and the result stack for Finish
The other three have no NeoForge event and keep Horizon names
They go in as the item_use_over_time fragment, "API next"
The stamp tool copies only a hook's name, version and target into native-hooks.json (tools/stamp_native_hooks.py:53), so their neoforge, side and cancellable fields are left out for now

Without a mod, Horizon's own uses go on as before, with two changes that follow vanilla
A consumable of no time (consume_seconds 0) is eaten at once, as Consumable.startConsuming does, instead of a use that ended on the next tick
A data-driven consumable with the bow, trident or brush animation now gets that pose in the first person hand, where it was held still
The empty hooks cost nothing: a fast build of the game has no native_use_duration, native_use_animation, native_can_eat or native_living_entity_use_item_* symbol left, while their callers are there
The mod-item check stops at the minecraft: namespace before calling any hook
Tests: a started use finishes on its last tick (vanilla's --useItemRemaining == 0, so no time or one cut below what was used waits for the release), a food of no time is eaten at once, and the pose each animation picks
There is no seam for a Game in a test, so the start, countdown and finish are tested through the step functions they share

Left as is: a use tick and a release (onUseTick, releaseUsing, LivingEntityUseItemEvent.Tick and .Stop) come in a second PR
Left as is: bows, crossbows, tridents, spyglasses, brushes, bundles, goat horns and potions keep Horizon's own use times, so a changed duration counts only for the other consumables and mods' items
Left as is: the finish hook doesn't fire yet when a spyglass, horn, bundle or brush runs its time
Left as is: other players see a mod's use pose only as the generic one, and a third person arm pose follows no animation
Left as is: the crossbow, spear, spyglass, horn and block animations draw the hand still when a mod names them for its own item
Left as is: a cake's canEat doesn't ask native_can_eat, and mobs using items don't fire the hooks

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

world/entity/LivingEntity.java:3515-3530 (startUsingItem)
world/entity/LivingEntity.java:3488-3493 (updateUsingItem: onUseTick, then completeUsingItem when the time runs out)
world/entity/LivingEntity.java:3533-3550 (onSyncedDataUpdated: a use the server's flags start, without startUsingItem)
world/entity/LivingEntity.java:3583-3600 (completeUsingItem: finishUsingItem's result in the hand)
server/level/ServerPlayer.java:1661-1666 (entity event 9 to the player's client first)
world/item/Item.java:205-227, :230-233, :317-335 (use, finishUsingItem, getUseAnimation, getUseDuration)
world/item/BowItem.java:85, CrossbowItem.java:242, TridentItem.java:57, SpyglassItem.java:20, BrushItem.java:53, BundleItem.java:233, InstrumentItem.java:55 (their own use times)
world/item/component/Consumable.java:62-75, :95-98 (startConsuming, eaten at once with no time; canConsume)
world/entity/player/Player.java:1580-1582 (canEat)

Other projects' code

none

Self-check

Check Result
Scope ✅ 14 files, +388 −67
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 510 passed (1 min 1 s)
rustfmt ✅ (10 s)
clippy ✅ (2 min 13 s)
tests: horizon-client ✅ 1580 passed (5 min 41 s)
doc tests ✅ 0 passed (1 s)
content root tests ➖ content root untouched
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)

🔄 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/5649 **Author:** [@reservedbytes](https://github.com/reservedbytes) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `feat/native-item-use-over-time` --- ### 📝 Commits (3) - [`e26bd0f`](https://github.com/horizon-rust/horizon/commit/e26bd0fe58f0cb465b60f7bc5712fb5a08ca5507) feat(mods): native mods use items over time (duration, animation, can eat, start and finish) - [`69722df`](https://github.com/horizon-rust/horizon/commit/69722dfc5ec6e6c729a867266125cb956b13955d) Merge main into feat/native-item-use-over-time - [`b91ef70`](https://github.com/horizon-rust/horizon/commit/b91ef7030175f9ded34a0912872f72c309d7bdbd) fix(mods): a use's client countdowns follow its started duration ### 📊 Changes **14 files changed** (+401 additions, -69 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+55 -38) 📝 `crates/horizon-client/src/game/crossbow.rs` (+2 -4) 📝 `crates/horizon-client/src/game/end.rs` (+1 -3) 📝 `crates/horizon-client/src/game/fov.rs` (+1 -2) 📝 `crates/horizon-client/src/game/item_draw.rs` (+5 -2) ➕ `crates/horizon-client/src/game/item_use.rs` (+218 -0) 📝 `crates/horizon-client/src/game/lan_actions.rs` (+6 -0) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+75 -0) 📝 `crates/horizon-client/src/game/potions.rs` (+1 -3) 📝 `crates/horizon-client/src/game/remote.rs` (+22 -10) 📝 `crates/horizon-client/src/game/shield.rs` (+2 -2) 📝 `crates/horizon-client/src/game/spear.rs` (+1 -2) 📝 `crates/horizon-client/src/game/trident.rs` (+1 -3) ➕ `tools/native-hook-fragments/item_use_over_time.json` (+11 -0) </details> ### 📄 Description ## What and why Part of #5523 A native mod's item could not be used over time: no bow-like hold, no food of its own time Vanilla asks `Item.getUseDuration` and `getUseAnimation` `startUsingItem` starts the use, and `completeUsingItem` ends it with `finishUsingItem`'s result This adds five hook points for that, on the server thread, LAN and the in-frame path alike `native_use_duration(stack, &mut duration)` is `Item.getUseDuration`, arriving with vanilla's answer It takes no user, since it is asked each frame an item in use is drawn A mod's own item (outside `minecraft:`) with no `consumable`, `blocks_attacks` or kinetic weapon that answers above 0 is used over time on a right click That stands in for the item's own `Item.use` calling `startUsingItem`, after a block item's `useOn` had its turn Its use counts down to the answered time on the server, then completes (`USE_ITEM_COMPLETE`, the use cooldown, the finish hook) The player's own client starts and keeps it too, so letting go sends `RELEASE_USE_ITEM` as for a bow A consumable's time follows the answer as well, so a mod food can take its own eat time `native_use_animation(stack, &mut animation)` is `Item.getUseAnimation` for the first person hand: eat and drink bring it to the mouth, bow draws, trident raises, brush sweeps `native_can_eat(stack, &mut can_eat)` is `Player.canEat` where `Consumable.canConsume` asks it, so a mod can refuse food or let a full player eat `native_living_entity_use_item_start(stack, entity, hand, &mut duration, &mut canceled)` fires in `startUsingItem` for every item It fires on both sides, as vanilla's `startUsingItem` runs on both: where the world runs, and on a server's client for the uses it predicts, so a cancel or a changed duration doesn't drift A mod should answer the same on both, and change the world only where this `Game` runs the world, not on a server's client No helper tells the two apart yet: `native_window` is also true in-frame and on an in-frame LAN host `native_living_entity_use_item_finish(stack, entity, hand, 0, &mut result)` fires after `finishUsingItem` of consumables, potions and mods' items, server-side, and may replace what the hand holds Its duration is always 0, as the use ran its time `entity` is a mob's `Entity.getId`, None for a player as in `native_apply_effect_tick`, so mobs can fire both later without a new version Only players fire them so far `hand` is the hand in use, main or off (`first_person::Hand`, vanilla's `InteractionHand`) Every use start now goes through one `start_using_item`, the client's predictions included It keeps the duration the use started with, as `useItemRemaining` does A guest's turn swaps that duration with the rest of its use state A use that the server's flags start on the client (`synced_local_use`) doesn't go through it, as vanilla's `onSyncedDataUpdated` doesn't call `startUsingItem` Two hooks follow NeoForge's `LivingEntityUseItemEvent.Start` and `.Finish` and take their names in snake case (#4402) Their getters are the entity, the item, the hand and the duration, with `setDuration` on the base event, and the result stack for `Finish` The other three have no NeoForge event and keep Horizon names They go in as the `item_use_over_time` fragment, "API next" The stamp tool copies only a hook's name, version and target into `native-hooks.json` (`tools/stamp_native_hooks.py:53`), so their `neoforge`, `side` and `cancellable` fields are left out for now Without a mod, Horizon's own uses go on as before, with two changes that follow vanilla A consumable of no time (`consume_seconds` 0) is eaten at once, as `Consumable.startConsuming` does, instead of a use that ended on the next tick A data-driven consumable with the `bow`, `trident` or `brush` animation now gets that pose in the first person hand, where it was held still The empty hooks cost nothing: a fast build of the game has no `native_use_duration`, `native_use_animation`, `native_can_eat` or `native_living_entity_use_item_*` symbol left, while their callers are there The mod-item check stops at the `minecraft:` namespace before calling any hook Tests: a started use finishes on its last tick (vanilla's `--useItemRemaining == 0`, so no time or one cut below what was used waits for the release), a food of no time is eaten at once, and the pose each animation picks There is no seam for a `Game` in a test, so the start, countdown and finish are tested through the step functions they share Left as is: a use tick and a release (`onUseTick`, `releaseUsing`, `LivingEntityUseItemEvent.Tick` and `.Stop`) come in a second PR Left as is: bows, crossbows, tridents, spyglasses, brushes, bundles, goat horns and potions keep Horizon's own use times, so a changed duration counts only for the other consumables and mods' items Left as is: the finish hook doesn't fire yet when a spyglass, horn, bundle or brush runs its time Left as is: other players see a mod's use pose only as the generic one, and a third person arm pose follows no animation Left as is: the crossbow, spear, spyglass, horn and block animations draw the hand still when a mod names them for its own item Left as is: a cake's `canEat` doesn't ask `native_can_eat`, and mobs using items don't fire the hooks ## Kind - [ ] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [ ] perf: faster, or less memory - [x] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference `world/entity/LivingEntity.java:3515-3530` (`startUsingItem`) `world/entity/LivingEntity.java:3488-3493` (`updateUsingItem`: `onUseTick`, then `completeUsingItem` when the time runs out) `world/entity/LivingEntity.java:3533-3550` (`onSyncedDataUpdated`: a use the server's flags start, without `startUsingItem`) `world/entity/LivingEntity.java:3583-3600` (`completeUsingItem`: `finishUsingItem`'s result in the hand) `server/level/ServerPlayer.java:1661-1666` (entity event 9 to the player's client first) `world/item/Item.java:205-227`, `:230-233`, `:317-335` (`use`, `finishUsingItem`, `getUseAnimation`, `getUseDuration`) `world/item/BowItem.java:85`, `CrossbowItem.java:242`, `TridentItem.java:57`, `SpyglassItem.java:20`, `BrushItem.java:53`, `BundleItem.java:233`, `InstrumentItem.java:55` (their own use times) `world/item/component/Consumable.java:62-75`, `:95-98` (`startConsuming`, eaten at once with no time; `canConsume`) `world/entity/player/Player.java:1580-1582` (`canEat`) ## Other projects' code none ## Self-check | Check | Result | | --- | --- | | Scope | ✅ 14 files, +388 −67 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 510 passed (1 min 1 s) | | rustfmt | ✅ (10 s) | | clippy | ✅ (2 min 13 s) | | tests: horizon-client | ✅ 1580 passed (5 min 41 s) | | doc tests | ✅ 0 passed (1 s) | | content root tests | ➖ content root untouched | | 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) | --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:20:13 +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#6416
No description provided.