[PR #4964] [MERGED] Drop the block a moving piston carries when something destroys it #5977

Closed
opened 2026-11-03 05:16:21 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/4964
Author: @MSedgeMC
Created: 10/31/2026
Status: ✅ Merged
Merged: 10/31/2026
Merged by: @rdbtCVS

Base: main ← Head: fix/moving-piston-drops


📝 Commits (1)

  • c39db22 Drop the block a moving piston carries when something destroys it

📊 Changes

3 files changed (+76 additions, -0 deletions)

View changed files

📝 crates/horizon-world/src/level/pistons.rs (+19 -0)
📝 crates/horizon-world/src/level/tests.rs (+47 -0)
📝 crates/horizon-world/src/level/update.rs (+10 -0)

📄 Description

Fixes the MovingPistonBlock.getDrops row in the port ledger. (No issue.)

MovingPistonBlock.getDrops returns getBlockEntity(pos)'s getMovedState().getDrops(builder), and an empty list when the block entity is gone — read live from the level at the loot context's origin, not from the parameters it is handed.

The two destroy paths in vanilla differ, which is the part worth stating carefully:

  • A player breaking it drops nothing, because ServerPlayerGameMode.destroyBlock calls level.removeBlock before playerDestroy, and removing the block takes its block entity with it, so the live lookup finds nothing. Horizon already matched this and is untouched — a draft of this change that "fixed" it would have been a regression.
  • Level.destroyBlock(pos, drop) — /setblock … destroy, /fill … destroy, and the piston's own fragile-block destroys — draws the drops while the block entity is still alive, so vanilla drops the carried block's loot. Horizon dropped nothing there.

The fix resolves the state through the moving-piston list in Sim::drop_resources, before the existing DropResources event, so every destroy-with-drops path goes through one rule and the loot path itself is unchanged (the carried state's table, no held item, no player — exactly Block.dropResources from a non-player destroy). An orphan moving piston drops nothing, matching Collections.emptyList().

Proven: on a build box with the prepared data, cargo test -p horizon-world --lib a_broken_moving_piston → 1 passed and the whole --lib piston set → 24 passed. The new test destroys a moving piston carrying sand and an orphan one, and asserts exactly one drop with the sand state.

Not proven: nothing ran in a game, and there is no parity harness for piston loot. One known limit, marked with a shortcut: comment in the code: a carried block with spawnAfterBreak experience (coal ore and the like) now awards that experience, where vanilla spawns none because it calls spawnAfterBreak on the moving-piston state. Closing it needs the destroyed state carried alongside the loot state in the event, which is a bigger change than this PR.

MovingPistonBlock.useWithoutItem (right-clicking an orphan moving piston removes it) is the other half of the ledger row and is still unported; it belongs to the interaction path and is not touched here.


🔄 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/4964 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 10/31/2026 **Status:** ✅ Merged **Merged:** 10/31/2026 **Merged by:** [@rdbtCVS](https://github.com/rdbtCVS) **Base:** `main` ← **Head:** `fix/moving-piston-drops` --- ### 📝 Commits (1) - [`c39db22`](https://github.com/horizon-rust/horizon/commit/c39db2247cfd2625281a99dcdcf7e4da229aa92d) Drop the block a moving piston carries when something destroys it ### 📊 Changes **3 files changed** (+76 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-world/src/level/pistons.rs` (+19 -0) 📝 `crates/horizon-world/src/level/tests.rs` (+47 -0) 📝 `crates/horizon-world/src/level/update.rs` (+10 -0) </details> ### 📄 Description Fixes the `MovingPistonBlock.getDrops` row in the port ledger. (No issue.) `MovingPistonBlock.getDrops` returns `getBlockEntity(pos)`'s `getMovedState().getDrops(builder)`, and an empty list when the block entity is gone — read live from the level at the loot context's origin, not from the parameters it is handed. The two destroy paths in vanilla differ, which is the part worth stating carefully: - **A player breaking it drops nothing**, because `ServerPlayerGameMode.destroyBlock` calls `level.removeBlock` *before* `playerDestroy`, and removing the block takes its block entity with it, so the live lookup finds nothing. Horizon already matched this and is untouched — a draft of this change that "fixed" it would have been a regression. - **`Level.destroyBlock(pos, drop)`** — `/setblock … destroy`, `/fill … destroy`, and the piston's own fragile-block destroys — draws the drops while the block entity is still alive, so vanilla drops the carried block's loot. Horizon dropped nothing there. The fix resolves the state through the moving-piston list in `Sim::drop_resources`, before the existing `DropResources` event, so every destroy-with-drops path goes through one rule and the loot path itself is unchanged (the carried state's table, no held item, no player — exactly `Block.dropResources` from a non-player destroy). An orphan moving piston drops nothing, matching `Collections.emptyList()`. **Proven:** on a build box with the prepared data, `cargo test -p horizon-world --lib a_broken_moving_piston` → 1 passed and the whole `--lib piston` set → 24 passed. The new test destroys a moving piston carrying sand and an orphan one, and asserts exactly one drop with the sand state. **Not proven:** nothing ran in a game, and there is no parity harness for piston loot. One known limit, marked with a `shortcut:` comment in the code: a carried block with `spawnAfterBreak` experience (coal ore and the like) now awards that experience, where vanilla spawns none because it calls `spawnAfterBreak` on the moving-piston state. Closing it needs the destroyed state carried alongside the loot state in the event, which is a bigger change than this PR. `MovingPistonBlock.useWithoutItem` (right-clicking an orphan moving piston removes it) is the other half of the ledger row and is still unported; it belongs to the interaction path and is not touched here. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 05:16:21 +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#5977
No description provided.