[PR #6331] [MERGED] Native mods: fluid in an item, Capabilities.FluidHandler.ITEM #6805

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

📋 Pull Request Information

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

Base: main ← Head: mods/item-fluids


📝 Commits (2)

  • a87bf9d Native mods: fluid handler on items (Capabilities.FluidHandler.ITEM)
  • 96ca047 Merge remote-tracking branch 'hr/main' into mods/item-fluids

📊 Changes

4 files changed (+377 additions, -0 deletions)

View changed files

📝 crates/horizon-client/src/game.rs (+1 -0)
📝 crates/horizon-client/src/game/native_hooks.rs (+11 -0)
➕ crates/horizon-client/src/game/native_item_fluids.rs (+357 -0)
➕ tools/native-hook-fragments/item_fluid_tank.json (+8 -0)

📄 Description

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

What and why

Fixes #6278, part of #4953 ("Fluid handler on items (Capabilities.FluidHandler.ITEM)"). A tech mod's fluid containers are items (a bucket, a canister), and a mod had no way to ask what fluid a stack holds, nor to fill or empty it and get the changed container back.

One hook point and three helpers, in the shape of the block fluid handler (#5188: millibuckets, minecraft:water and minecraft:lava). API from a fragment (tools/native-hook-fragments/item_fluid_tank.json):

  • native_item_fluid_tank(item, capacity): a mod item (mod_id:name) is a fluid container; set its capacity (clamped to 1..=1 000 000). Asked at each call. What it holds is kept in the stack's minecraft:custom_data under horizon_fluid (Fluid, Amount), so it is saved and sent to Horizon clients (#5467), the rest of the stack's custom_data is kept, and an emptied container carries nothing, so it stacks with a plain one (also when the stack came from a server with its wire patch).
  • native_item_fluid(stack): fluid, amount and capacity of one item of the stack.
  • native_item_fluid_fill(stack, fluid, amount) and native_item_fluid_drain(stack, max): how much one item takes or gives, and the single item it becomes. The stack given is not changed: the caller shrinks it by one and hands out the result (NeoForge's ItemAccess acts on one item at a time, oneByOne). A mod container takes what fits of one fluid and gives what it holds up to max.
  • Vanilla's buckets are built in: minecraft:bucket is empty, water_bucket and lava_bucket are full, and (as BucketItem) a bucket takes or gives a whole bucket or nothing; the result is a fresh stack of the other item. Milk, powder snow and fish buckets hold no fluid Horizon models, so they are no containers.

They hold no world state and work on any side. Fluid on entities, mod fluids, and bucket use on blocks (native_fill_bucket) are separate.

Kind

  • feature: something new for players (mod authors)

Vanilla reference

BucketItem (getEmptySuccessItem, the full buckets), ItemUtils.createFilledResult: a bucket's result is a new stack of the other item, 1000 mB of one fluid. NeoForge's Capabilities.FluidHandler.ITEM is a ResourceHandler<FluidResource> over an ItemAccess (names and behaviour from its javadoc).

Other projects' code

None.

Proof in the real game

Engine from this branch plus a throwaway probe (a content mod testmod with an item canister of capacity 750, eprintln!s in native_tick; not in this PR). give @s testmod:canister[custom_data={horizon_fluid:{Fluid:"minecraft:water",Amount:250}}] 3, then the probe runs the helpers on the window's held stack. Server thread (horizon-ctl launch --world L --creative --offscreen --dev-mod …):

TESTHOOK [window] held=testmod:canister x3 read=Some(NativeItemFluid { fluid: Some("minecraft:water"), amount: 250, capacity: 750 })
TESTHOOK fill water 1000 -> Some((500, "testmod:canister", 1, Some(NativeItemFluid { fluid: Some("minecraft:water"), amount: 750, capacity: 750 })))
TESTHOOK fill lava 100 on held -> Some((0, Some(NativeItemFluid { fluid: Some("minecraft:water"), amount: 250, capacity: 750 })))
TESTHOOK drain 100 -> Some(("minecraft:water", 100, Some(NativeItemFluid { fluid: Some("minecraft:water"), amount: 150, capacity: 750 })))
TESTHOOK drain 10000 -> Some(("minecraft:water", 250, Some(NativeItemFluid { fluid: None, amount: 0, capacity: 750 }), true))
TESTHOOK bucket fill lava 1000 -> Some((1000, "minecraft:lava_bucket", 1))
TESTHOOK bucket fill lava 999 -> Some((0, "minecraft:bucket"))
TESTHOOK water_bucket read Some(NativeItemFluid { fluid: Some("minecraft:water"), amount: 1000, capacity: 1000 }) drain 999 None drain 1000 Some(("minecraft:water", 1000, "minecraft:bucket"))
TESTHOOK stone None

The true on the drain 10000 line is same_item_same_components of the emptied canister and a plain one. On a dedicated server with a client connected the same lines came from the client (the server's own probe saw no held stack, the helpers being stateless); that run was before the last fix (the wire patch dropped from the changed stack), which showed false there and true after, on the server thread. Not run: a mod container saved and reopened in an inventory (its custom_data saving is #5467's), stacks of containers inside a machine's slots.

Self-check

pr_ready (tools/pr_ready.py --quick --base hr/main on cachyos-x8664, against hr/main at dea6dea98, 2 min 14 s)

Check Result
Scope ✅ 4 files, +377 −0
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 586 passed (32 s)
rustfmt ✅ (6 s)
clippy ✅ (57 s)
tests: horizon-client ✅ 1812 passed (38 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

🤖 Generated with Claude Code


🔄 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/6331 **Author:** [@levzzz5154](https://github.com/levzzz5154) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@levzzz5154](https://github.com/levzzz5154) **Base:** `main` ← **Head:** `mods/item-fluids` --- ### 📝 Commits (2) - [`a87bf9d`](https://github.com/horizon-rust/horizon/commit/a87bf9d4caa7740e5ccc8b64a85eac713e7fc77f) Native mods: fluid handler on items (Capabilities.FluidHandler.ITEM) - [`96ca047`](https://github.com/horizon-rust/horizon/commit/96ca047ac717027059ed499adaee0de2cb007134) Merge remote-tracking branch 'hr/main' into mods/item-fluids ### 📊 Changes **4 files changed** (+377 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/game.rs` (+1 -0) 📝 `crates/horizon-client/src/game/native_hooks.rs` (+11 -0) ➕ `crates/horizon-client/src/game/native_item_fluids.rs` (+357 -0) ➕ `tools/native-hook-fragments/item_fluid_tank.json` (+8 -0) </details> ### 📄 Description > 🤖 Opened by levzzz5154's AI agent (Claude Code, Claude Sonnet 5.5), not by levzzz5154 personally. ## What and why Fixes #6278, part of #4953 ("Fluid handler on items (`Capabilities.FluidHandler.ITEM`)"). A tech mod's fluid containers are items (a bucket, a canister), and a mod had no way to ask what fluid a stack holds, nor to fill or empty it and get the changed container back. One hook point and three helpers, in the shape of the block fluid handler (#5188: millibuckets, `minecraft:water` and `minecraft:lava`). API from a fragment (`tools/native-hook-fragments/item_fluid_tank.json`): - `native_item_fluid_tank(item, capacity)`: a mod item (`mod_id:name`) is a fluid container; set its `capacity` (clamped to 1..=1 000 000). Asked at each call. What it holds is kept in the stack's `minecraft:custom_data` under `horizon_fluid` (`Fluid`, `Amount`), so it is saved and sent to Horizon clients (#5467), the rest of the stack's `custom_data` is kept, and an emptied container carries nothing, so it stacks with a plain one (also when the stack came from a server with its wire patch). - `native_item_fluid(stack)`: fluid, amount and capacity of one item of the stack. - `native_item_fluid_fill(stack, fluid, amount)` and `native_item_fluid_drain(stack, max)`: how much one item takes or gives, and the single item it becomes. The stack given is not changed: the caller shrinks it by one and hands out the result (NeoForge's `ItemAccess` acts on one item at a time, `oneByOne`). A mod container takes what fits of one fluid and gives what it holds up to `max`. - Vanilla's buckets are built in: `minecraft:bucket` is empty, `water_bucket` and `lava_bucket` are full, and (as `BucketItem`) a bucket takes or gives a whole bucket or nothing; the result is a fresh stack of the other item. Milk, powder snow and fish buckets hold no fluid Horizon models, so they are no containers. They hold no world state and work on any side. Fluid on entities, mod fluids, and bucket use on blocks (`native_fill_bucket`) are separate. ## Kind - [x] feature: something new for players (mod authors) ## Vanilla reference `BucketItem` (`getEmptySuccessItem`, the full buckets), `ItemUtils.createFilledResult`: a bucket's result is a new stack of the other item, 1000 mB of one fluid. NeoForge's `Capabilities.FluidHandler.ITEM` is a `ResourceHandler<FluidResource>` over an `ItemAccess` (names and behaviour from its javadoc). ## Other projects' code None. ## Proof in the real game Engine from this branch plus a throwaway probe (a content mod `testmod` with an item `canister` of capacity 750, `eprintln!`s in `native_tick`; not in this PR). `give @s testmod:canister[custom_data={horizon_fluid:{Fluid:"minecraft:water",Amount:250}}] 3`, then the probe runs the helpers on the window's held stack. Server thread (`horizon-ctl launch --world L --creative --offscreen --dev-mod …`): ``` TESTHOOK [window] held=testmod:canister x3 read=Some(NativeItemFluid { fluid: Some("minecraft:water"), amount: 250, capacity: 750 }) TESTHOOK fill water 1000 -> Some((500, "testmod:canister", 1, Some(NativeItemFluid { fluid: Some("minecraft:water"), amount: 750, capacity: 750 }))) TESTHOOK fill lava 100 on held -> Some((0, Some(NativeItemFluid { fluid: Some("minecraft:water"), amount: 250, capacity: 750 }))) TESTHOOK drain 100 -> Some(("minecraft:water", 100, Some(NativeItemFluid { fluid: Some("minecraft:water"), amount: 150, capacity: 750 }))) TESTHOOK drain 10000 -> Some(("minecraft:water", 250, Some(NativeItemFluid { fluid: None, amount: 0, capacity: 750 }), true)) TESTHOOK bucket fill lava 1000 -> Some((1000, "minecraft:lava_bucket", 1)) TESTHOOK bucket fill lava 999 -> Some((0, "minecraft:bucket")) TESTHOOK water_bucket read Some(NativeItemFluid { fluid: Some("minecraft:water"), amount: 1000, capacity: 1000 }) drain 999 None drain 1000 Some(("minecraft:water", 1000, "minecraft:bucket")) TESTHOOK stone None ``` The `true` on the `drain 10000` line is `same_item_same_components` of the emptied canister and a plain one. On a dedicated server with a client connected the same lines came from the client (the server's own probe saw no held stack, the helpers being stateless); that run was before the last fix (the wire patch dropped from the changed stack), which showed `false` there and `true` after, on the server thread. Not run: a mod container saved and reopened in an inventory (its `custom_data` saving is #5467's), stacks of containers inside a machine's slots. ## Self-check **pr_ready** (`tools/pr_ready.py --quick --base hr/main` on cachyos-x8664, against hr/main at dea6dea98, 2 min 14 s) | Check | Result | | --- | --- | | Scope | ✅ 4 files, +377 −0 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 586 passed (32 s) | | rustfmt | ✅ (6 s) | | clippy | ✅ (57 s) | | tests: horizon-client | ✅ 1812 passed (38 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 | 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:27:14 +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#6805
No description provided.