[PR #5188] [MERGED] Native mods: a block's fluids, read, filled and drained in millibuckets (API next) #6127

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5188
Author: @Qwerner88880
Created: 10/31/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @ludovic111

Base: main ← Head: hooks-fluid


📝 Commits (6)

  • c5f62fe Native mods: a block's fluids, read, filled and drained in millibuckets
  • 962288e Fluids: a cauldron never exceeds the ask, a shrunk tank table keeps its tanks, no overflow
  • b3e0f1d Merge main; the fluid hooks as an API fragment
  • b3c3bc2 Merge remote-tracking branch 'hr/main' into qw-5188
  • d346e90 Merge main (#5130's item handler beside the fluid handler)
  • 9314523 Fluid tanks: clamp a bad capacity instead of renumbering the tanks

📊 Changes

9 files changed (+622 additions, -5 deletions)

View changed files

📝 crates/horizon-client-render/src/block_entities.rs (+11 -1)
📝 crates/horizon-client-render/src/chunk/block_entity.rs (+15 -0)
📝 crates/horizon-client-render/src/containers.rs (+1 -1)
📝 crates/horizon-client/src/game/block_entity_ticks.rs (+2 -0)
📝 crates/horizon-client/src/game/machines.rs (+1 -0)
➕ crates/horizon-client/src/game/machines/native_fluids.rs (+524 -0)
📝 crates/horizon-client/src/game/machines/native_items.rs (+3 -2)
📝 crates/horizon-client/src/game/native_hooks.rs (+52 -1)
➕ tools/native-hook-fragments/fluids.json (+13 -0)

📄 Description

🤖 Opened by Qwerner88880's AI agent (ZCode, GLM-5.3), not by Qwerner88880 personally.

What and why

Fixes #5134. Part of #3911 (Mods) and #4953 (the fluid handler on blocks is the second of the three capabilities, after the item handler #5130). Its API number is asked for with a fragment, tools/native-hook-fragments/fluids.json, as #5161 directs — no edits to NATIVE_HOOKS_API, the histories, native-hooks.json or the docs' API ladder; a local stamp dry run gives it the next free number.

A native mod could put items into a block, read and take them through a side and move them (#5130) — nothing of the kind existed for fluids. This adds the volume layer (millibuckets; the game had no amount of fluid anywhere) and the handlers on it:

  • native_block_entity_fluids declares a mod block's tanks, exactly as native_block_entity_container (API 17) declares its slots: each tank's capacity in millibuckets, the tanks each face reaches, and the tanks a fill may reach and a drain may take. At most 16 tanks, capacities 1..=1 000 000, tank numbers past the count left out. The tanks' contents live in the block entity's saved compound under fluids — they survive restarts for free (the save already keeps the compound whole) and the block's own native_block_entity_tick reads them there.
  • native_fluid_tanks(dimension, pos, face) — the tanks a side reaches, with fluid, amount, capacity and whether each may be filled and drained through it. A cauldron reads as one tank of a bucket's capacity.
  • native_fluid_insert(pos, face, fluid, amount) — up to amount millibuckets of water or lava in, first into tanks holding the same fluid, then into empty ones, by the table's sides; answers what did not fit. Refuses on a client's copy, like native_insert_item.
  • native_fluid_extract(dimension, pos, face, amount) — drains up to amount through the side, one fluid only (the first that's there); answers the fluid and how much.

Cauldrons, the only fluid containers vanilla has, work through the same helpers: a level holds a third of a bucket (333/666/1000 mB — vanilla has no finer unit, so fills and drains move whole thirds), a lava cauldron only ever whole, and a powder snow cauldron holds none (powder snow is not a FluidKind). Water and lava are the fluids there are; a mod's own fluid types are the separate registration item in #4953.

A first pipe comes out of this: a machine's tick can drain its neighbour and fill the next block over — the live proof runs exactly that, between two cauldrons.

Kind

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

Vanilla reference

Horizon-only helpers on vanilla behaviour; checked against the game jar (server-game.jar, javap) where it cites vanilla:

  • A cauldron's levels and their interactions: LayeredCauldronBlock (a bucket fills 3 levels, a bottle 1, so a level is a third of a bucket); a lava cauldron has no level property.
  • CauldronInteractions (already ported in cauldron.rs): bucket and bottle exchanges, water only into water.
  • The millibucket unit and the tank model are NeoForge's IFluidHandler/FluidStack convention, as #4953's capabilities item names it.

Other projects' code

none

Tests

Unit: cauldron thirds (333/666/1000), the tank state's NBT round trip (missing entries read empty, a wrong tag reads empty, an empty tank saves as minecraft:empty).

Live, on this branch (HEAD c5f62fe73): a throwaway mixin bundle on a dedicated server with two horizon-ctl --offscreen clients (Alex and Steve) and a content mod's machine with two tanks (4000 mB fill-only from the top, 1000 mB fill-and-drain from the bottom), fresh temp folders, HORIZON_NO_AUDIO=1. RESULT: 37 checks, 0 failures (29 here plus the move section of #5203, which runs on this same branch base). Covers: each face reaching its own tanks; a fill stopping at capacity (5000 into 4000 leaves 1000); lava refused into a water tank; a drain taking exactly what was asked; the non-draining side giving none; a cauldron filled by exact thirds (333 → level 1, 332 → nothing, 667 more → level 3) and drained in thirds (500 asked, 667 taken); a level-one cauldron giving its whole third and emptying; a full lava cauldron taking nothing and draining whole; powder snow no fluid; another level, the world's edge, a dry block, a non-fluid and a zero drain all refusing; a machine piping a third of a bucket between two cauldrons through its own tick; the client's copy reading no tanks and refusing an insert; and both tanks' contents intact after a world restart.

Not verified live: single player's own window (the client-copy check covers the refusing side), hundreds of tanks (perf).

Self-check

pr_ready (tools/pr_ready.py --quick on DESKTOP-H7P5E7K, against origin/main at bd541458c, 1 min 24 s)

Check Result
Scope ⚠️ 9 files, +554 −4; 550 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 495 passed (52 s)
rustfmt ✅ (8 s)
clippy ✅ (1 s)
tests: horizon-client, horizon-client-render ✅ 2044 passed (18 s)
doc tests ✅ 0 passed (2 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)
exit=0

The tests ran with HORIZON_NO_AUDIO=1: without it, running this crate's tests right after horizon-client's in one cargo test sometimes hangs the render suite on this machine (the audio tests wait on a device the earlier suite leaves busy). The same suite passes in seconds alone or with audio off, on this branch and on #5131's. It looks like a pre-existing test-isolation flake on Windows, not this change.

🤖 Generated with ZCode (GLM-5.3)


🔄 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/5188 **Author:** [@Qwerner88880](https://github.com/Qwerner88880) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `hooks-fluid` --- ### 📝 Commits (6) - [`c5f62fe`](https://github.com/horizon-rust/horizon/commit/c5f62fe73c50763cce0d5b17325b866bbb1ad2cc) Native mods: a block's fluids, read, filled and drained in millibuckets - [`962288e`](https://github.com/horizon-rust/horizon/commit/962288e85fe8eb3d895a99e2f07f0b98d1863b1c) Fluids: a cauldron never exceeds the ask, a shrunk tank table keeps its tanks, no overflow - [`b3e0f1d`](https://github.com/horizon-rust/horizon/commit/b3e0f1d476720dcc5db433772fb4547e7d01e976) Merge main; the fluid hooks as an API fragment - [`b3c3bc2`](https://github.com/horizon-rust/horizon/commit/b3c3bc2843de3f2461d8e55ba37a98135319d1f5) Merge remote-tracking branch 'hr/main' into qw-5188 - [`d346e90`](https://github.com/horizon-rust/horizon/commit/d346e90232072b6baf75644164e929d853b4fc0c) Merge main (#5130's item handler beside the fluid handler) - [`9314523`](https://github.com/horizon-rust/horizon/commit/9314523024bf6753d653f163d50411aeb32b0215) Fluid tanks: clamp a bad capacity instead of renumbering the tanks ### 📊 Changes **9 files changed** (+622 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-render/src/block_entities.rs` (+11 -1) 📝 `crates/horizon-client-render/src/chunk/block_entity.rs` (+15 -0) 📝 `crates/horizon-client-render/src/containers.rs` (+1 -1) 📝 `crates/horizon-client/src/game/block_entity_ticks.rs` (+2 -0) 📝 `crates/horizon-client/src/game/machines.rs` (+1 -0) ➕ `crates/horizon-client/src/game/machines/native_fluids.rs` (+524 -0) 📝 `crates/horizon-client/src/game/machines/native_items.rs` (+3 -2) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+52 -1) ➕ `tools/native-hook-fragments/fluids.json` (+13 -0) </details> ### 📄 Description > 🤖 Opened by Qwerner88880's AI agent (ZCode, GLM-5.3), not by Qwerner88880 personally. ## What and why Fixes #5134. Part of #3911 (Mods) and #4953 (the fluid handler on blocks is the second of the three capabilities, after the item handler #5130). Its API number is asked for with a fragment, `tools/native-hook-fragments/fluids.json`, as #5161 directs — no edits to `NATIVE_HOOKS_API`, the histories, `native-hooks.json` or the docs' API ladder; a local stamp dry run gives it the next free number. A native mod could put items into a block, read and take them through a side and move them (#5130) — nothing of the kind existed for fluids. This adds the volume layer (millibuckets; the game had no amount of fluid anywhere) and the handlers on it: - **`native_block_entity_fluids`** declares a mod block's tanks, exactly as `native_block_entity_container` (API 17) declares its slots: each tank's capacity in millibuckets, the tanks each face reaches, and the tanks a fill may reach and a drain may take. At most 16 tanks, capacities 1..=1 000 000, tank numbers past the count left out. The tanks' **contents live in the block entity's saved compound under `fluids`** — they survive restarts for free (the save already keeps the compound whole) and the block's own `native_block_entity_tick` reads them there. - **`native_fluid_tanks(dimension, pos, face)`** — the tanks a side reaches, with fluid, amount, capacity and whether each may be filled and drained through it. A cauldron reads as one tank of a bucket's capacity. - **`native_fluid_insert(pos, face, fluid, amount)`** — up to `amount` millibuckets of water or lava in, first into tanks holding the same fluid, then into empty ones, by the table's sides; answers what did not fit. Refuses on a client's copy, like `native_insert_item`. - **`native_fluid_extract(dimension, pos, face, amount)`** — drains up to `amount` through the side, one fluid only (the first that's there); answers the fluid and how much. **Cauldrons**, the only fluid containers vanilla has, work through the same helpers: a level holds a third of a bucket (333/666/1000 mB — vanilla has no finer unit, so fills and drains move whole thirds), a lava cauldron only ever whole, and a powder snow cauldron holds none (powder snow is not a `FluidKind`). Water and lava are the fluids there are; a mod's own fluid types are the separate registration item in #4953. A first pipe comes out of this: a machine's tick can drain its neighbour and fill the next block over — the live proof runs exactly that, between two cauldrons. ## Kind - [x] feature: something new for players (listed under New in the release notes) - [ ] parity: Horizon now does what vanilla 26.3 does - [ ] bug: a crash or a breakage - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference Horizon-only helpers on vanilla behaviour; checked against the game jar (`server-game.jar`, `javap`) where it cites vanilla: - A cauldron's levels and their interactions: `LayeredCauldronBlock` (a bucket fills 3 levels, a bottle 1, so a level is a third of a bucket); a lava cauldron has no level property. - `CauldronInteractions` (already ported in `cauldron.rs`): bucket and bottle exchanges, water only into water. - The millibucket unit and the tank model are NeoForge's `IFluidHandler`/`FluidStack` convention, as #4953's capabilities item names it. ## Other projects' code none ## Tests **Unit:** cauldron thirds (333/666/1000), the tank state's NBT round trip (missing entries read empty, a wrong tag reads empty, an empty tank saves as `minecraft:empty`). **Live, on this branch (HEAD `c5f62fe73`):** a throwaway mixin bundle on a dedicated server with two `horizon-ctl --offscreen` clients (Alex and Steve) and a content mod's machine with two tanks (4000 mB fill-only from the top, 1000 mB fill-and-drain from the bottom), fresh temp folders, `HORIZON_NO_AUDIO=1`. RESULT: 37 checks, 0 failures (29 here plus the move section of #5203, which runs on this same branch base). Covers: each face reaching its own tanks; a fill stopping at capacity (5000 into 4000 leaves 1000); lava refused into a water tank; a drain taking exactly what was asked; the non-draining side giving none; a cauldron filled by exact thirds (333 → level 1, 332 → nothing, 667 more → level 3) and drained in thirds (500 asked, 667 taken); a level-one cauldron giving its whole third and emptying; a full lava cauldron taking nothing and draining whole; powder snow no fluid; another level, the world's edge, a dry block, a non-fluid and a zero drain all refusing; **a machine piping a third of a bucket between two cauldrons through its own tick**; the client's copy reading no tanks and refusing an insert; and both tanks' contents intact after a world restart. **Not verified live:** single player's own window (the client-copy check covers the refusing side), hundreds of tanks (perf). ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on DESKTOP-H7P5E7K, against origin/main at bd541458c, 1 min 24 s) | Check | Result | | --- | --- | | Scope | ⚠️ 9 files, +554 −4; 550 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 495 passed (52 s) | | rustfmt | ✅ (8 s) | | clippy | ✅ (1 s) | | tests: horizon-client, horizon-client-render | ✅ 2044 passed (18 s) | | doc tests | ✅ 0 passed (2 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) | exit=0 The tests ran with `HORIZON_NO_AUDIO=1`: without it, running this crate's tests right after horizon-client's in one `cargo test` sometimes hangs the render suite on this machine (the audio tests wait on a device the earlier suite leaves busy). The same suite passes in seconds alone or with audio off, on this branch and on #5131's. It looks like a pre-existing test-isolation flake on Windows, not this change. 🤖 Generated with ZCode (GLM-5.3) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:12:38 +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#6127
No description provided.