[GH-ISSUE #6249] Native mods: entities ticking, EntityTickEvent.Pre and .Post #2033

Closed
opened 2026-11-02 15:51:30 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @levzzz5154 on GitHub (Nov 1, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6249

Originally assigned to: @levzzz5154 on GitHub.

🤖 Filed by levzzz5154's AI agent (Claude Code, Claude Sonnet 5.5), not by levzzz5154 personally.

Part of #4953 ("Entity: tick, mount, size, projectile impact").

A native mod that makes machines out of entities (a conveyor that carries item entities, a field that freezes mobs, radiation that acts on every mob each tick) has no point that runs for each entity as it ticks, and none to stop an entity's tick. native_server_tick and native_level_tick_pre/_post speak of the level, native_inventory_tick of inventories, the player tick hook of the player.

Vanilla and NeoForge 26.3:

  • Vanilla ticks an entity in ServerLevel.tickNonPassenger (commonTick and tick), then its passengers in tickPassenger, for each entity of entityTickList in an entity-ticking chunk.
  • NeoForge posts EntityTickEvent.Pre around commonTick/tick in tickNonPassenger: cancellable, and when canceled the tick is skipped and EntityTickEvent.Post is not posted. Post follows the tick.

Horizon ticks each family of entities in its own loop, and the mob and item loops hold their entity lists (taken out of Game), so a hook with &mut Game can't run between one entity's tick and the next. So the firing point is the family's tick, with a Pre for each entity that will tick before the family's loop and a Post for each that did tick after it:

  • native_entity_tick_pre(dimension, entity, kind, canceled) (EntityTickEvent.Pre): set canceled and the entity doesn't tick this tick (no AI or physics for a mob, no movement, ageing or merging for an item, no motion for a cart or boat), and its Post isn't told.
  • native_entity_tick_post(dimension, entity, kind) (EntityTickEvent.Post): after the family has ticked every entity Pre let through; an entity that died or was removed in its tick is told too.

Families in this step: mobs (every Mob: animals, monsters, villagers, players' pets...), item entities, minecarts and boats (all but the one a player rides, which ticks with the player). Later steps, listed here: projectiles, experience orbs, primed TNT, falling blocks, armor stands, End crystals, the ender dragon, and the entity a player rides. Server-side only (the single player server thread and a dedicated server); the deprecated in-frame path and clients never fire it. The calls allocate nothing per tick on a server (the lists they use are kept between ticks; a boat's type name is the exception) and cost two empty calls per ticking entity; a client does none of it. API from a fragment.

Originally created by @levzzz5154 on GitHub (Nov 1, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/6249 Originally assigned to: @levzzz5154 on GitHub. > 🤖 Filed by levzzz5154's AI agent (Claude Code, Claude Sonnet 5.5), not by levzzz5154 personally. Part of #4953 ("Entity: tick, mount, size, projectile impact"). A native mod that makes machines out of entities (a conveyor that carries item entities, a field that freezes mobs, radiation that acts on every mob each tick) has no point that runs for each entity as it ticks, and none to stop an entity's tick. `native_server_tick` and `native_level_tick_pre`/`_post` speak of the level, `native_inventory_tick` of inventories, the player tick hook of the player. Vanilla and NeoForge 26.3: - Vanilla ticks an entity in `ServerLevel.tickNonPassenger` (`commonTick` and `tick`), then its passengers in `tickPassenger`, for each entity of `entityTickList` in an entity-ticking chunk. - NeoForge posts `EntityTickEvent.Pre` around `commonTick`/`tick` in `tickNonPassenger`: cancellable, and when canceled the tick is skipped and `EntityTickEvent.Post` is not posted. `Post` follows the tick. Horizon ticks each family of entities in its own loop, and the mob and item loops hold their entity lists (taken out of `Game`), so a hook with `&mut Game` can't run between one entity's tick and the next. So the firing point is the family's tick, with a Pre for each entity that will tick before the family's loop and a Post for each that did tick after it: - `native_entity_tick_pre(dimension, entity, kind, canceled)` (`EntityTickEvent.Pre`): set `canceled` and the entity doesn't tick this tick (no AI or physics for a mob, no movement, ageing or merging for an item, no motion for a cart or boat), and its Post isn't told. - `native_entity_tick_post(dimension, entity, kind)` (`EntityTickEvent.Post`): after the family has ticked every entity Pre let through; an entity that died or was removed in its tick is told too. Families in this step: mobs (every `Mob`: animals, monsters, villagers, players' pets...), item entities, minecarts and boats (all but the one a player rides, which ticks with the player). Later steps, listed here: projectiles, experience orbs, primed TNT, falling blocks, armor stands, End crystals, the ender dragon, and the entity a player rides. Server-side only (the single player server thread and a dedicated server); the deprecated in-frame path and clients never fire it. The calls allocate nothing per tick on a server (the lists they use are kept between ticks; a boat's type name is the exception) and cost two empty calls per ticking entity; a client does none of it. API from a fragment.
Author
Owner

@levzzz5154 commented on GitHub (Nov 1, 2026):

/claim

<!-- gh-comment-id:6562064227 --> @levzzz5154 commented on GitHub (Nov 1, 2026): /claim
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#2033
No description provided.