[PR #4440] [MERGED] Functions: tick before the levels' entities so a fresh drop still has Age 0 #5620

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4440
Author: @masa-masa-0314
Created: 10/30/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @ludovic111

Base: main ← Head: fix/function-tick-order


📝 Commits (5)

  • 9c23d27 Functions: tick before the levels' entities, and drop Age: 0 a tick early
  • 0ddc638 Merge remote-tracking branch 'origin/main' into pr-4440
  • d22bb9e Skip only items added this tick in tick_items, not every fresh one
  • d788399 Predicates: a server's player matches input.sneak and its game mode
  • 5182748 Merge remote-tracking branch 'origin/main' into a3-pr-4440

📊 Changes

4 files changed (+79 additions, -10 deletions)

View changed files

📝 crates/horizon-client/src/advancements.rs (+24 -8)
📝 crates/horizon-client/src/game.rs (+24 -1)
📝 crates/horizon-client/src/game/advancements.rs (+23 -0)
📝 crates/horizon-client/src/game/functions.rs (+8 -1)

📄 Description

🤖 Opened by masa-masa-0314's AI agent (ZCode), not by masa-masa-0314 personally.

What and why

A data pack that hooks a block break through the tick functions never fired, on this tree or on
upstream/main. Vanilla's order is what makes that pattern work:

  • MinecraftServer.tickChildren runs commandFunctions before any ServerLevel.tick.
  • EntityTickList.ensureActiveIsNotIterated hands an entity added while the list is being iterated
    its first tick on the next tick, so the drop a broken block made still reports Age: 0 when
    the tick function polls for it (@n[type=item,nbt={Age:0s},distance=..5]).

Horizon ran tick_functions() inside tick_mobs, i.e. after the level's items, and ticked a fresh
item on the tick it spawned, so the age had already counted up. The functions now run at the top of
the tick, before the levels — with the world's saved data (load_scoreboard: scoreboard, command
storage, stopwatches) read first, since a load tag's data modify storage has to land after the
save is restored and not before. An item entity added this tick first ticks the next one.

type_specific/player had the same shape of problem: PlayerPredicate.matches starts with
instanceof ServerPlayer, which Horizon's view-side branch did not check (every mob passed when the
predicate named neither a game mode nor a look target), and the 26.3 input field
(InputPredicate) was ignored, so a predicate asking for the sneak input was always true. It is now
input.sneak = Input.shift() — the held key, the source BlockItem.place's sneaking already
reads — with the other inputs left unconstrained until they have a source.

The function runner also logs a function that failed to instantiate or run, as
ServerFunctionManager.execute does.

Vanilla reference

  • net.minecraft.server.MinecraftServer#tickChildren (the commandFunctions step).
  • net.minecraft.world.level.entity.EntityTickList#ensureActiveIsNotIterated.
  • net.minecraft.world.entity.item.ItemEntity#tick (age++).
  • net.minecraft.advancements.predicates.entity.PlayerPredicate#matches and
    net.minecraft.advancements.predicates.InputPredicate#matches.
  • net.minecraft.server.ServerFunctionManager#execute (the failure log).

Not changed: function lines already run at permission level 2 on upstream/main
(Functions::command_level), which is what vanilla's game-loop source uses.

Self-check

rustfmt: pass
clippy -p horizon-client --lib --bins -D warnings: pass

cargo check -p horizon-client --lib --tests fails on this tree in files this change does not
touch: game/creatures.rs defines mod tests twice (5442 and 5514) and end_gateway.rs:190's
in_water takes a Vec3 where the trait now passes an Aabb. Both reproduce on a clean
upstream/main checkout, so the test target could not be run here; the verification below is the
headless client.

Verified with the Vein Miner 1.3.6 data pack as the world's only pack (a plain creative world, no
cheats beyond it):

/execute as @a at @s run execute if block ~ ~-1 ~2 minecraft:air run say VM-ORE1-MINED
  -> [Player] VM-ORE1-MINED
/execute as @a at @s run execute if block ~ ~-1 ~3 minecraft:air run say VM-ORE2-MINED
  -> [Player] VM-ORE2-MINED
/execute if predicate veinminer:sneaking run say SNEAK-PRED-TRUE
  -> (nothing: the player is not sneaking, as it should be)

The two ores are the vein the pack's tick function is asked to mine; before this change neither was
taken and the sneak predicate reported true while standing still.

Screenshots

None: the behaviour is command output, captured headlessly above.

🤖 Generated with ZCode


🔄 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/4440 **Author:** [@masa-masa-0314](https://github.com/masa-masa-0314) **Created:** 10/30/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/function-tick-order` --- ### 📝 Commits (5) - [`9c23d27`](https://github.com/horizon-rust/horizon/commit/9c23d276666a5940aa363b6e7fe0fd3fdf9d68e0) Functions: tick before the levels' entities, and drop `Age: 0` a tick early - [`0ddc638`](https://github.com/horizon-rust/horizon/commit/0ddc638be06a5795f5626b4c0a9342b98582aec0) Merge remote-tracking branch 'origin/main' into pr-4440 - [`d22bb9e`](https://github.com/horizon-rust/horizon/commit/d22bb9e177c575c5cadc36aa71ae13fb5c7eb9fb) Skip only items added this tick in tick_items, not every fresh one - [`d788399`](https://github.com/horizon-rust/horizon/commit/d7883994ebf7f686ef5cd35c04c689aa9e9873df) Predicates: a server's player matches input.sneak and its game mode - [`5182748`](https://github.com/horizon-rust/horizon/commit/51827488ed49a10fbd95886e9a01c6ad9bf509d7) Merge remote-tracking branch 'origin/main' into a3-pr-4440 ### 📊 Changes **4 files changed** (+79 additions, -10 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/advancements.rs` (+24 -8) 📝 `crates/horizon-client/src/game.rs` (+24 -1) 📝 `crates/horizon-client/src/game/advancements.rs` (+23 -0) 📝 `crates/horizon-client/src/game/functions.rs` (+8 -1) </details> ### 📄 Description > 🤖 Opened by masa-masa-0314's AI agent (ZCode), not by masa-masa-0314 personally. ## What and why A data pack that hooks a block break through the tick functions never fired, on this tree or on `upstream/main`. Vanilla's order is what makes that pattern work: - `MinecraftServer.tickChildren` runs `commandFunctions` **before** any `ServerLevel.tick`. - `EntityTickList.ensureActiveIsNotIterated` hands an entity added while the list is being iterated its first tick on the **next** tick, so the drop a broken block made still reports `Age: 0` when the tick function polls for it (`@n[type=item,nbt={Age:0s},distance=..5]`). Horizon ran `tick_functions()` inside `tick_mobs`, i.e. after the level's items, and ticked a fresh item on the tick it spawned, so the age had already counted up. The functions now run at the top of the tick, before the levels — with the world's saved data (`load_scoreboard`: scoreboard, command storage, stopwatches) read first, since a load tag's `data modify storage` has to land after the save is restored and not before. An item entity added this tick first ticks the next one. `type_specific/player` had the same shape of problem: `PlayerPredicate.matches` starts with `instanceof ServerPlayer`, which Horizon's view-side branch did not check (every mob passed when the predicate named neither a game mode nor a look target), and the 26.3 `input` field (`InputPredicate`) was ignored, so a predicate asking for the sneak input was always true. It is now `input.sneak` = `Input.shift()` — the held key, the source `BlockItem.place`'s `sneaking` already reads — with the other inputs left unconstrained until they have a source. The function runner also logs a function that failed to instantiate or run, as `ServerFunctionManager.execute` does. ## Vanilla reference - `net.minecraft.server.MinecraftServer#tickChildren` (the `commandFunctions` step). - `net.minecraft.world.level.entity.EntityTickList#ensureActiveIsNotIterated`. - `net.minecraft.world.entity.item.ItemEntity#tick` (`age++`). - `net.minecraft.advancements.predicates.entity.PlayerPredicate#matches` and `net.minecraft.advancements.predicates.InputPredicate#matches`. - `net.minecraft.server.ServerFunctionManager#execute` (the failure log). Not changed: function lines already run at permission level 2 on `upstream/main` (`Functions::command_level`), which is what vanilla's game-loop source uses. ## Self-check ``` rustfmt: pass clippy -p horizon-client --lib --bins -D warnings: pass ``` `cargo check -p horizon-client --lib --tests` fails on this tree in files this change does not touch: `game/creatures.rs` defines `mod tests` twice (5442 and 5514) and `end_gateway.rs:190`'s `in_water` takes a `Vec3` where the trait now passes an `Aabb`. Both reproduce on a clean `upstream/main` checkout, so the test target could not be run here; the verification below is the headless client. Verified with the Vein Miner 1.3.6 data pack as the world's only pack (a plain creative world, no cheats beyond it): ``` /execute as @a at @s run execute if block ~ ~-1 ~2 minecraft:air run say VM-ORE1-MINED -> [Player] VM-ORE1-MINED /execute as @a at @s run execute if block ~ ~-1 ~3 minecraft:air run say VM-ORE2-MINED -> [Player] VM-ORE2-MINED /execute if predicate veinminer:sneaking run say SNEAK-PRED-TRUE -> (nothing: the player is not sneaking, as it should be) ``` The two ores are the vein the pack's tick function is asked to mine; before this change neither was taken and the sneak predicate reported true while standing still. ## Screenshots None: the behaviour is command output, captured headlessly above. 🤖 Generated with ZCode --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:13:51 +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#5620
No description provided.