[GH-ISSUE #3966] Native mods: block entities for mod blocks (create, tick, save) #1161

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

Originally created by @Sylviromi on GitHub (Oct 29, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/3966

Originally assigned to: @Sylviromi on GitHub.

Part of #3911 (Mods). The first piece of the "ticking block entities with saved state" gap from #1854
(162 of ATM10's 307 code mods need it; machine mods such as GregTech start here).

Currently

  • BlockEntity is a closed enum of vanilla types. A block entity with a mod's id is kept as raw NBT in
    ChunkExtras and saved back unchanged, so nothing is lost, but nothing can create, tick or change it.
  • A placed block gets its block entity from BlockEntity::for_block, called from about 15 places in the
    game (placing, dispensers, commands, storage...).
  • #1189 did this on WebAssembly mods, which are being removed (#3351).

Proposal

  • Engine: a BlockEntity::Mod { id, nbt } variant, loaded and saved as its NBT. The game's for_block
    calls go through one Game method, so a mod sees every block it places.
  • Hook points (game/native_hooks.rs, raising NATIVE_HOOKS_API):
    • native_block_entity(block, &mut Option<(id, Compound)>): a mod block gets its block entity
      (EntityBlock.newBlockEntity).
    • native_block_entity_ticks(block, &mut bool): whether it ticks (EntityBlock.getTicker).
    • native_block_entity_tick(pos, id, &mut Compound): from tick_block_entities, on the server only.

Out of scope for now: inventories, menus, sending to the client, rendering. One small PR each, later as the guidelines has stated.

Checks

  • Without a mod nothing changes: block entities with a mod's id still round-trip byte for byte.
  • A unit test of place → tick → save → load with a test hook; hook_points_stay_hookable covers the
    new hooks.

Questions for @levzzz5154

  1. Is this the piece you want next, and in this shape?
  2. Should the tick hook stack on #3878 (server tick hooks), or stay independent?
  3. Should the mod's state stay a Compound, or do you want a typed handle?
Originally created by @Sylviromi on GitHub (Oct 29, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/3966 Originally assigned to: @Sylviromi on GitHub. Part of #3911 (Mods). The first piece of the "ticking block entities with saved state" gap from #1854 (162 of ATM10's 307 code mods need it; machine mods such as GregTech start here). ## Currently - `BlockEntity` is a closed enum of vanilla types. A block entity with a mod's id is kept as raw NBT in `ChunkExtras` and saved back unchanged, so nothing is lost, but nothing can create, tick or change it. - A placed block gets its block entity from `BlockEntity::for_block`, called from about 15 places in the game (placing, dispensers, commands, storage...). - #1189 did this on WebAssembly mods, which are being removed (#3351). ## Proposal - Engine: a `BlockEntity::Mod { id, nbt }` variant, loaded and saved as its NBT. The game's `for_block` calls go through one `Game` method, so a mod sees every block it places. - Hook points (`game/native_hooks.rs`, raising `NATIVE_HOOKS_API`): - `native_block_entity(block, &mut Option<(id, Compound)>)`: a mod block gets its block entity (`EntityBlock.newBlockEntity`). - `native_block_entity_ticks(block, &mut bool)`: whether it ticks (`EntityBlock.getTicker`). - `native_block_entity_tick(pos, id, &mut Compound)`: from `tick_block_entities`, on the server only. Out of scope for now: inventories, menus, sending to the client, rendering. One small PR each, later as the guidelines has stated. ## Checks - Without a mod nothing changes: block entities with a mod's id still round-trip byte for byte. - A unit test of place → tick → save → load with a test hook; `hook_points_stay_hookable` covers the new hooks. ## Questions for @levzzz5154 1. Is this the piece you want next, and in this shape? 2. Should the tick hook stack on #3878 (server tick hooks), or stay independent? 3. Should the mod's state stay a `Compound`, or do you want a typed handle?
Author
Owner

@Sylviromi commented on GitHub (Oct 29, 2026):

/claim

<!-- gh-comment-id:6508814322 --> @Sylviromi commented on GitHub (Oct 29, 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#1161
No description provided.