[PR #1113] [MERGED] Draw and collide blocks while a piston moves them #3059

Closed
opened 2026-11-02 16:01:10 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/1113
Author: @ludovic111
Created: 10/21/2026
Status: ✅ Merged
Merged: 10/22/2026
Merged by: @ludovic111

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


📝 Commits (1)

  • 1cca55b Draw and collide blocks while a piston moves them

📊 Changes

8 files changed (+241 additions, -4 deletions)

View changed files

📝 crates/horizon-client/src/collisions.rs (+26 -3)
📝 crates/horizon-client/src/game.rs (+15 -0)
📝 crates/horizon-client/src/game/dispenser.rs (+5 -1)
➕ crates/horizon-client/src/game/moving_pistons.rs (+108 -0)
📝 crates/horizon-client/src/motion.rs (+62 -0)
📝 crates/horizon-client/src/world.rs (+4 -0)
📝 crates/horizon-world/src/block_collision.rs (+10 -0)
📝 crates/horizon-world/src/level/pistons.rs (+11 -0)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

Fixes #935 (reported on Discord by brabus): blocks moved by a piston vanished while they moved, and players could walk through them.

Cause

While a piston moves them, blocks are minecraft:moving_piston blocks with a PistonMovingBlockEntity. Horizon already simulated those block entities (Ticks::moving_pistons), but the client never read them:

  • Rendering. The chunk mesher draws nothing for moving_piston (its render shape is invisible). Vanilla draws the moved block with PistonHeadRenderer; Horizon had no equivalent. On a fast clock, the pistons and the blocks they push are moving most of the time, so they flickered out of existence.
  • Collision. SceneCollisions::moving_piston_shape returned None, so a moving block had no collision (vanilla: MovingPistonBlock.getCollisionShape → PistonMovingBlockEntity.getCollisionShape). horizon-world/src/piston_shape.rs already ported that shape, but nothing called it.

Fix

  • World::moving_pistons holds a copy of the level's moving-piston block entities, refreshed after every block tick (Game::sync_moving_pistons).

  • Collision: SceneCollisions::moving_piston_shape looks up the block entity and returns PistonBlockBindings::collision_shape, with no noclip direction because this is outside a push. The bindings are built once with the BlockCollisionRegistry.

  • Rendering: the new game/moving_pistons.rs ports PistonHeadRenderer.extractRenderState and submit:

    • the moved block is drawn at pos + direction × (extending ? progress − 1 : 1 − progress), interpolated with the partial tick (getXOff/getProgress), using the model seed of its source position;
    • a moving piston head gets short = progress <= 0.5 (vanilla's <= 4.0 test always passes);
    • a retracting piston draws its head (short = progress >= 0.5) and its extended base, which does not move.

    Moving blocks go through the same baked-model path and tint as falling blocks.

Proof

  • New test motion::tests::a_player_lands_on_a_block_a_piston_is_moving. A stone block halfway through an upward push (progress 0.5) is solid at y 3.5–4.5, so the player lands at y 4.5. Once the block entity is gone, the leftover moving_piston block has no shape and the player drops to 4.0. Without the fix the test fails (left: 4.0, right: 4.5).
  • Screenshot comparison on the Mac mini (Metal). A sticky piston pushes a gold block east, under /tick freeze and /tick step 1. "Before" is main plus the unrelated combat fixes of this batch; "after" is this branch. The 12 frames and a side-by-side image are in ~/code/horizon-parity/shots/pr-935-moving-pistons/ (piston-compare.png).
    • Extending, 1 tick in: before, only the redstone block and the piston base are visible (the head and the gold block are gone); after, the head and the gold block are drawn half-way.
    • Retracting, 1 tick in: before, the whole piston and the gold block are invisible (only the sky shows); after, the extended base, the short head and the gold block are drawn mid-retraction.
    • Final states are identical in both builds (gold block back at x=1 after the retraction).
  • cargo fmt --all -- --check: ok
  • set -o pipefail; cargo clippy -p horizon-client -p horizon-world --all-targets -- -D warnings: exit 0
  • cargo test -p horizon-client -p horizon-world: all passed (horizon-client lib 958 passed, 14 ignored; horizon-world lib 151 passed; every integration test and doc-test ok)
  • tools/parity.py --changed origin/main: running on the Mac mini; the result follows in a comment

Not in this PR (added to FEATURES.md LATER)

  • Entity pushing. Moving blocks don't push or carry entities yet: PistonMovingBlockEntity.moveCollidedEntities, moveStuckEntities (honey), fixEntityWithinPistonBase, slime bounce, and Entity.limitPistonMovement for MoverType.PISTON, which still errors in motion.rs. A block extending into a player still ends up inside them, as before.
  • Guests (of a Horizon host or of a vanilla server) create no moving-piston block entities. A Horizon host doesn't send pistons' ClientboundBlockEventPacket, and the guest ignores it for pistons (PistonBaseBlock.triggerEvent doesn't run client-side). So on a guest, moving blocks are still neither drawn nor solid.

🤖 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/1113 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/21/2026 **Status:** ✅ Merged **Merged:** 10/22/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/moving-piston-collision` --- ### 📝 Commits (1) - [`1cca55b`](https://github.com/horizon-rust/horizon/commit/1cca55b66724484fa27fdb8f0d5b357be963db91) Draw and collide blocks while a piston moves them ### 📊 Changes **8 files changed** (+241 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client/src/collisions.rs` (+26 -3) 📝 `crates/horizon-client/src/game.rs` (+15 -0) 📝 `crates/horizon-client/src/game/dispenser.rs` (+5 -1) ➕ `crates/horizon-client/src/game/moving_pistons.rs` (+108 -0) 📝 `crates/horizon-client/src/motion.rs` (+62 -0) 📝 `crates/horizon-client/src/world.rs` (+4 -0) 📝 `crates/horizon-world/src/block_collision.rs` (+10 -0) 📝 `crates/horizon-world/src/level/pistons.rs` (+11 -0) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. Fixes #935 (reported on Discord by **brabus**): blocks moved by a piston vanished while they moved, and players could walk through them. ## Cause While a piston moves them, blocks are `minecraft:moving_piston` blocks with a `PistonMovingBlockEntity`. Horizon already simulated those block entities (`Ticks::moving_pistons`), but the client never read them: - **Rendering.** The chunk mesher draws nothing for `moving_piston` (its render shape is invisible). Vanilla draws the moved block with `PistonHeadRenderer`; Horizon had no equivalent. On a fast clock, the pistons and the blocks they push are moving most of the time, so they flickered out of existence. - **Collision.** `SceneCollisions::moving_piston_shape` returned `None`, so a moving block had no collision (vanilla: `MovingPistonBlock.getCollisionShape` → `PistonMovingBlockEntity.getCollisionShape`). `horizon-world/src/piston_shape.rs` already ported that shape, but nothing called it. ## Fix - `World::moving_pistons` holds a copy of the level's moving-piston block entities, refreshed after every block tick (`Game::sync_moving_pistons`). - **Collision:** `SceneCollisions::moving_piston_shape` looks up the block entity and returns `PistonBlockBindings::collision_shape`, with no noclip direction because this is outside a push. The bindings are built once with the `BlockCollisionRegistry`. - **Rendering:** the new `game/moving_pistons.rs` ports `PistonHeadRenderer.extractRenderState` and `submit`: - the moved block is drawn at `pos + direction × (extending ? progress − 1 : 1 − progress)`, interpolated with the partial tick (`getXOff`/`getProgress`), using the model seed of its source position; - a moving piston head gets `short = progress <= 0.5` (vanilla's `<= 4.0` test always passes); - a retracting piston draws its head (`short = progress >= 0.5`) and its extended base, which does not move. Moving blocks go through the same baked-model path and tint as falling blocks. ## Proof - New test `motion::tests::a_player_lands_on_a_block_a_piston_is_moving`. A stone block halfway through an upward push (progress 0.5) is solid at y 3.5–4.5, so the player lands at y 4.5. Once the block entity is gone, the leftover `moving_piston` block has no shape and the player drops to 4.0. Without the fix the test fails (`left: 4.0, right: 4.5`). - **Screenshot comparison** on the Mac mini (Metal). A sticky piston pushes a gold block east, under `/tick freeze` and `/tick step 1`. "Before" is main plus the unrelated combat fixes of this batch; "after" is this branch. The 12 frames and a side-by-side image are in `~/code/horizon-parity/shots/pr-935-moving-pistons/` (`piston-compare.png`). - Extending, 1 tick in: before, only the redstone block and the piston base are visible (the head and the gold block are gone); after, the head and the gold block are drawn half-way. - Retracting, 1 tick in: before, the whole piston and the gold block are invisible (only the sky shows); after, the extended base, the short head and the gold block are drawn mid-retraction. - Final states are identical in both builds (gold block back at x=1 after the retraction). - `cargo fmt --all -- --check`: ok - `set -o pipefail; cargo clippy -p horizon-client -p horizon-world --all-targets -- -D warnings`: exit 0 - `cargo test -p horizon-client -p horizon-world`: all passed (horizon-client lib 958 passed, 14 ignored; horizon-world lib 151 passed; every integration test and doc-test ok) - `tools/parity.py --changed origin/main`: running on the Mac mini; the result follows in a comment ## Not in this PR (added to FEATURES.md LATER) - **Entity pushing.** Moving blocks don't push or carry entities yet: `PistonMovingBlockEntity.moveCollidedEntities`, `moveStuckEntities` (honey), `fixEntityWithinPistonBase`, slime bounce, and `Entity.limitPistonMovement` for `MoverType.PISTON`, which still errors in `motion.rs`. A block extending into a player still ends up inside them, as before. - **Guests** (of a Horizon host or of a vanilla server) create no moving-piston block entities. A Horizon host doesn't send pistons' `ClientboundBlockEventPacket`, and the guest ignores it for pistons (`PistonBaseBlock.triggerEvent` doesn't run client-side). So on a guest, moving blocks are still neither drawn nor solid. 🤖 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-02 16:01:10 +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#3059
No description provided.