[PR #7645] A destroyed bundle spills the stacks it held #7733

Open
opened 2026-11-03 07:23:20 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7645
Author: @MSedgeMC
Created: 11/2/2026
Status: 🔄 Open

Base: main ← Head: fix/bundle-destroyed-spills


📝 Commits (3)

  • 6af75cb fix: a destroyed bundle spills the stacks it held
  • 5359e99 test: a bundle's contents leave it when its item entity dies
  • 8338dcf port_map: BundleItem.onDestroyed points at the item death spill

📊 Changes

4 files changed (+214 additions, -5 deletions)

View changed files

📝 crates/horizon-client/src/entities.rs (+172 -4)
📝 crates/horizon-client/src/game.rs (+23 -0)
📝 crates/horizon-items/src/bundle.rs (+18 -0)
📝 tools/port_map/game2-008.tsv (+1 -1)

📄 Description

Vanilla

ItemEntity.hurtServer(DamageSource, float) takes the damage off health and, at zero or below, calls ItemStack.onDestroyed(this) and then discard(). For a bundle, ItemStack.onDestroyed reaches BundleItem.onDestroyed(ItemEntity), which reads the stack's BUNDLE_CONTENTS, writes BundleContents.EMPTY back and hands the old contents to ItemUtils.onContainerDestroyed. That adds one new ItemEntity(level, entity.getX(), entity.getY(), entity.getZ(), stack) to the level per stack: the destroyed entity's exact position, no pickup delay, and the constructor's nextDouble() * 0.2 - 0.1 nudge per axis.

So a bundle dropped in lava, in fire or on a cactus spills everything it held where it lay, and the bundle itself is gone empty.

What Horizon got wrong

Horizon's port of that health step, entities.rs::ItemEntity::environment_tick, took the same four damage amounts (lava 4, cactus 1, fire contact, burning every 20 ticks) straight off ItemEntity::health, and tick_dropped_items removed the entity the moment alive came back false. Nothing ran the item's onDestroyed, so the contents were deleted with the bundle — the ledger row tools/port_map/game2-008.tsv:45 said missing ("nothing spills a destroyed item entity's contents"), and it now points at the port.

The damage now goes through ItemEntity::hurt, the port of hurtServer's health step: it returns None while the item lives and the stacks the emptied item let go when it dies. ItemEnvironmentTick.spilled carries them out of environment_tick, and Game::spawn_destroyed_contents adds each one as an item entity at the dead item's position with the constructor's nudge and no pickup delay, exactly as onContainerDestroyed does.

Tests

entities::item_destroyed_tests::a_destroyed_bundle_spills_its_contents needs no prepared data: it drives ItemEntity::hurt — the function environment_tick calls for every damage the game does to a dropped item — with a bundle holding 3 stone and 1 diamond. entities::destroyed_bundle_environment_tests::lava_that_destroys_a_bundle_spills_its_contents runs the same thing through environment_tick at a lava block on the prepared resources (.local/horizon-client/26.3, skipped without them, like the fire-environment tests beside it): 5 health against 4 a tick leaves 1 alive on the first tick and the spill on the second.

Fails without the fix, through the path the game calls: with the bundle::destroyed call taken out of ItemEntity::hurt (the only thing that changed in that function), cargo test -q -p horizon-client-lib --lib item_destroyed_tests fails on the spill assertion:

assertion `left == right` failed
  left: []
 right: [("minecraft:stone", 3), ("minecraft:diamond", 1)]

Both tests call the same ItemEntity method the tick calls (ItemEntity::hurt, four call sites in environment_tick; environment_tick's spilled field is what tick_dropped_items reads) — not a helper written for the test.

Not proven: the spawn half (Game::spawn_destroyed_contents) has no unit test, because a Game needs a window, audio and prepared resources; it was checked by reading it against ItemUtils.onContainerDestroyed, not by a run.

cargo clippy -q -p horizon-items -p horizon-client-lib -p horizon-client --lib is silent and cargo fmt --all -- --check is clean. cargo test -q -p horizon-client-lib --lib entities passes (50 passed, 1 ignored).


🔄 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/7645 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/bundle-destroyed-spills` --- ### 📝 Commits (3) - [`6af75cb`](https://github.com/horizon-rust/horizon/commit/6af75cb8d11bcee8f46122bfc3a2bd84d49f3490) fix: a destroyed bundle spills the stacks it held - [`5359e99`](https://github.com/horizon-rust/horizon/commit/5359e998d63cb787d2f5d738205688509a4a998d) test: a bundle's contents leave it when its item entity dies - [`8338dcf`](https://github.com/horizon-rust/horizon/commit/8338dcf7b13d10b7deb644d4b8c6bfc8e3f1047a) port_map: BundleItem.onDestroyed points at the item death spill ### 📊 Changes **4 files changed** (+214 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/entities.rs` (+172 -4) 📝 `crates/horizon-client/src/game.rs` (+23 -0) 📝 `crates/horizon-items/src/bundle.rs` (+18 -0) 📝 `tools/port_map/game2-008.tsv` (+1 -1) </details> ### 📄 Description ## Vanilla `ItemEntity.hurtServer(DamageSource, float)` takes the damage off `health` and, at zero or below, calls `ItemStack.onDestroyed(this)` and then `discard()`. For a bundle, `ItemStack.onDestroyed` reaches `BundleItem.onDestroyed(ItemEntity)`, which reads the stack's `BUNDLE_CONTENTS`, writes `BundleContents.EMPTY` back and hands the old contents to `ItemUtils.onContainerDestroyed`. That adds one `new ItemEntity(level, entity.getX(), entity.getY(), entity.getZ(), stack)` to the level per stack: the destroyed entity's exact position, no pickup delay, and the constructor's `nextDouble() * 0.2 - 0.1` nudge per axis. So a bundle dropped in lava, in fire or on a cactus spills everything it held where it lay, and the bundle itself is gone empty. ## What Horizon got wrong Horizon's port of that health step, `entities.rs::ItemEntity::environment_tick`, took the same four damage amounts (lava 4, cactus 1, fire contact, burning every 20 ticks) straight off `ItemEntity::health`, and `tick_dropped_items` removed the entity the moment `alive` came back false. Nothing ran the item's `onDestroyed`, so the contents were deleted with the bundle — the ledger row `tools/port_map/game2-008.tsv:45` said `missing` ("nothing spills a destroyed item entity's contents"), and it now points at the port. The damage now goes through `ItemEntity::hurt`, the port of `hurtServer`'s health step: it returns `None` while the item lives and the stacks the emptied item let go when it dies. `ItemEnvironmentTick.spilled` carries them out of `environment_tick`, and `Game::spawn_destroyed_contents` adds each one as an item entity at the dead item's position with the constructor's nudge and no pickup delay, exactly as `onContainerDestroyed` does. ## Tests `entities::item_destroyed_tests::a_destroyed_bundle_spills_its_contents` needs no prepared data: it drives `ItemEntity::hurt` — the function `environment_tick` calls for every damage the game does to a dropped item — with a bundle holding 3 stone and 1 diamond. `entities::destroyed_bundle_environment_tests::lava_that_destroys_a_bundle_spills_its_contents` runs the same thing through `environment_tick` at a lava block on the prepared resources (`.local/horizon-client/26.3`, skipped without them, like the fire-environment tests beside it): 5 health against 4 a tick leaves 1 alive on the first tick and the spill on the second. **Fails without the fix, through the path the game calls:** with the `bundle::destroyed` call taken out of `ItemEntity::hurt` (the only thing that changed in that function), `cargo test -q -p horizon-client-lib --lib item_destroyed_tests` fails on the spill assertion: ``` assertion `left == right` failed left: [] right: [("minecraft:stone", 3), ("minecraft:diamond", 1)] ``` Both tests call the same `ItemEntity` method the tick calls (`ItemEntity::hurt`, four call sites in `environment_tick`; `environment_tick`'s `spilled` field is what `tick_dropped_items` reads) — not a helper written for the test. **Not proven:** the spawn half (`Game::spawn_destroyed_contents`) has no unit test, because a `Game` needs a window, audio and prepared resources; it was checked by reading it against `ItemUtils.onContainerDestroyed`, not by a run. `cargo clippy -q -p horizon-items -p horizon-client-lib -p horizon-client --lib` is silent and `cargo fmt --all -- --check` is clean. `cargo test -q -p horizon-client-lib --lib entities` passes (50 passed, 1 ignored). --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#7733
No description provided.