[PR #3401] [MERGED] Pistons: moving blocks keep their colour, survive saves and leave no black ghost #4955

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/3401
Author: @JacobRWebb
Created: 10/28/2026
Status: ✅ Merged
Merged: 10/29/2026
Merged by: @ludovic111

Base: main ← Head: JacobRWebb/sticky-piston-texture-color


📝 Commits (6)

  • 4a094be Pistons: moving blocks keep their tint, survive saves and leave no black ghost
  • fab9c37 Moving pistons save facing as a byte, as Direction.LEGACY_ID_CODEC does
  • a72f06c Test the moving piston's saved fields against vanilla's
  • ee90b3b Moving blocks take their light from the cells their faces look at
  • edd11b6 Merge remote-tracking branch 'origin/main' into upd/3401
  • 1a01f5e Merge main into the branch

📊 Changes

10 files changed (+400 additions, -41 deletions)

View changed files

📝 crates/horizon-client-core/src/block_entity_nbt.rs (+22 -1)
📝 crates/horizon-client-render/src/mesher.rs (+50 -0)
📝 crates/horizon-client-render/src/mesher/lighting.rs (+59 -3)
📝 crates/horizon-client-render/src/mesher/particle_tests.rs (+37 -0)
📝 crates/horizon-client/src/game.rs (+15 -1)
📝 crates/horizon-client/src/game/minecarts.rs (+26 -8)
📝 crates/horizon-client/src/game/moving_pistons.rs (+73 -26)
📝 crates/horizon-client/src/game/persist.rs (+100 -2)
📝 crates/horizon-client/src/game/remote.rs (+11 -0)
📝 crates/horizon-world/src/level/ticks.rs (+7 -0)

📄 Description

🤖 Opened by JacobRWebb's AI agent (Claude Code), not by JacobRWebb personally. JacobRWebb found the bugs, tested every fix in game and confirmed them.

What and why

Fixes #3310
Fixes #3002

With a sticky piston moving a block back and forth, players saw five things:

  1. Moving grass blocks turned gray. The top and the side overlay lost their biome colour while the block moved.
  2. Blocks in motion vanished on save (#3310). Leaving and rejoining mid-move deleted the moving blocks and the moving piston, and left an invisible block you could not place into.
  3. A black ghost followed moved blocks (#3002). A pulled block left a black, z-fighting copy behind it, the piston looked wrong once retracted, and the head and arm stuttered on a single pulse.
  4. The piston disappeared for a frame when it fired or settled.
  5. The moved block and the piston base flashed black for a frame as a move finished.

1. Gray moving blocks: per-face block tints. moving_block_vertices tinted the whole model with particle_sprite's colour, the terrain particle tint. terrain_particle_tint returns None for grass blocks on purpose (vanilla's dirt crumbs are untinted, #1034), so a moving grass block was drawn white. One colour over the whole model was also wrong for blocks with untinted faces.

  • MeshTables::block_tints (mesher.rs): each tint index's colour at a position, through the same Mesher::tint the chunk mesh uses.
  • tinted_block_model_vertices (game/minecarts.rs, beside block_model_vertices, which now calls it with no tint): multiplies each face by the tint of its tint_index. Moving pistons draw with it.

2. Moving blocks lost on save (#3310). Moving pistons live only in Ticks::moving_pistons, never in chunk.block_entities, so saves never wrote them. A reload found a bare minecraft:moving_piston with no block entity.

  • attach_save_data writes each moving piston in the chunk as a minecraft:piston block entity, field for field as vanilla does.
  • register_chunk_ticks loads them back into the level through the new Ticks::load_moving_piston, for a moving_piston block only. Worlds vanilla saved with blocks mid-move load too.
  • Unloading a chunk drops its moving pistons from the level after the chunk is saved.
  • block_entity_nbt::canonical wrote facing as an int; it is a byte in vanilla.

3. Black ghost and stutter (#3002). In the default server-thread mode the window is a client of the in-process server. Its moveBlocks makes its own moving pistons, and the server then sends the block each one placed. Vanilla removes the client's block entity when that block changes. Horizon's client kept it and animated it for up to five more deathTicks, drawn over the placed block in the chunk mesh and lit from a cell that is now opaque (light 0): a black, z-fighting copy.

  • remote.rs set_block: a server update that turns a moving_piston into another block removes the client's moving piston there.

4. One frame with no piston. moving_piston_fallback covers the gap until the chunk mesh shows a finished piston's block, but it was cleared after exactly one tick. Remeshing can take longer, which left frames with nothing drawn (hidden before by the stale five-tick copy). Drawn for a whole tick when the mesh was already up, it also z-fought.

  • sync_moving_pistons keeps a fallback entry until its section's mesh is up (not dirty, not meshing, not waiting for upload), the test cull_entity_vertices already uses, and draws it only while that holds.

5. Black flash as a move ends (#3002). Moving blocks were lit with the light stored at the moving piston's own cell. A finished piston's block is still drawn over the chunk mesh until that mesh shows it, and by then the placed block stands in that cell: an opaque cell, light 0. The pushed or pulled block and the piston base flashed black for that frame. Vanilla never reads that cell. createMovingBlock places a lone block at the cell it moves from, and tesselateFlat lights each face from the neighbour it looks at.

  • MeshTables::flat_light (mesher.rs), built on lighting::flat_position and packed_coords (mesher/lighting.rs): the chunk mesher's own flat-light rules for one quad, including emission. The mesher's flat path uses the same helpers, so its output is unchanged.
  • tinted_block_model_vertices takes the light per quad. block_model_vertices passes its old constant, so minecarts and the other callers are unchanged.
  • A moving block is lit per face around the cell it moves from (the retracting base around its own cell). A finished one is lit at the cell it was placed in, as the block it stands in for.

Rapid lever clicks that leave the block out are vanilla: a sticky piston given a pulse shorter than its 2-tick extension spits its block.

Vanilla reference

Read from the pinned 26.3 client jar with tools/rea_vanilla.py (REA 6.4.0) and javap -c -p:

  • PistonMovingBlockEntity.saveAdditional / loadAdditional: blockState (BlockState.CODEC), facing (Direction.LEGACY_ID_CODEC, Codec.BYTE of get3DDataValue), progress written from progressO and read into both progress and progressO, extending, source.
  • LevelChunk.setBlockState: on client and server alike, the old state's block entity is removed when hasBlockEntity() and !shouldChangedStateKeepBlockEntity(new), so a moving_piston turning into another block drops its PistonMovingBlockEntity.
  • PistonMovingBlockEntity.tick: on a client, a finished entity waits while deathTicks < 5. That is the wait the stale animation ran out.
  • ModelBlockRenderer.putQuadWithTint / getTintColor: each quad's tintIndex picks a BlockTintSource, coloured by colorInWorld, not by colorAsTerrainParticle, which the old particle tint used.
  • PistonHeadRenderer.extractRenderState → createMovingBlock(pos, …): the moved block's position is getBlockPos().relative(getMovementDirection().getOpposite()), the cell it moves from, and the retracting base's is the piston's own cell. MovingBlockRenderState is a world holding only that block, with the level's light engine.
  • MovingBlockFeatureRenderer.buildGroup → ModelBlockRenderer.tesselateBlock → tesselateFlat: a quad with a cull face is lit by getLightCoords at the neighbour it faces. BlockModelLighter.prepareQuadFlat lights one without: the neighbour when the quad is flush with the block's side, else the block's own cell.

Harnesses: none new; piston_push, piston_movement, piston_shape and block_entity_storage pass (see Self-check). The saved fields are pinned by block_entity_nbt::tests::moving_piston_fields_match_vanilla, from the bytecode above. save_roundtrip covers chunk saves but runs only where a virtual screen is available, so CI and the maintainers' hosts run it. The tint is covered by mesher::particle_tests::block_tints_match_the_chunk_mesh_for_grass_blocks (prepared 26.3 resources).

Self-check

pr_ready (tools/pr_ready.py --quick on Jacob, against origin/main at 81f339814, 2 min 47 s)

Check Result
Scope ✅ 10 files, +398 −34
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ❌ 405 run, FAILED (failures=1, skipped=2) (35 s)
rustfmt ✅ (6 s)
clippy ✅ (9 s)
tests: horizon-client, horizon-client-core, horizon-world ❌ 1110 passed, 1 failed (1 min 44 s)
doc tests ✅ 0 passed (6 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 ➖ 346 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo and 334 more
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

The two ❌ are Windows-only and in code this branch does not touch (git diff --stat origin/main...HEAD lists none of them):

  • save::tests::session_lock_is_exclusive: Windows byte-range locks (os error 33) refuse the test's read of a locked file.
  • Python test_port_publish: expects / in a path and gets \.

--quick because tools/parity.py doesn't run on Windows (signal.SIGHUP, fcntl, resource, os.killpg). Through a locally patched copy of the runner, not part of this PR, the piston and block-entity harnesses pass on this branch with JDK 25:

PASS piston_push 13s
PASS piston_movement 14s
PASS block_entity_storage 14s
PASS piston_shape 24s
4 passed, 0 failed

In game (Windows, RTX 4080 SUPER, server-thread mode), JacobRWebb tested each fix:

  • a sticky piston moving a grass block back and forth keeps its colour;
  • after save and quit mid-move, then rejoin, the blocks finish their move;
  • single and rapid pulses show no black ghost, no head or arm stutter, no missing frame and no black flash.

Screenshots

Before (left, without this branch) and after (right, this branch). The recording predates fix 5: the one-frame black flash still visible on the right around 0.75 s and 2.75 s is what fix 5 removes.

2026-10-28 16-22-30

Notes for review

  • Overlap with #2986 (enderman carried block): it adds a similar block_model_vertices_tinted(…, tint: u32, …) in minecarts.rs. This one takes a per-index closure, since some blocks have two tint sources. Whichever merges second should fold the two together.
  • #3186 (crate split) moves mesher.rs to horizon-client-render. block_tints moves with it on rebase.
  • Saves are on the risky list, so this waits for a local proof.
  • Follow-up, not here: moving blocks are flat-lit per face. With smooth lighting on, vanilla tesselates them with tesselateAmbientOcclusion, as the chunk mesh does, so a block still brightens slightly when it lands.

🤖 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/3401 **Author:** [@JacobRWebb](https://github.com/JacobRWebb) **Created:** 10/28/2026 **Status:** ✅ Merged **Merged:** 10/29/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `JacobRWebb/sticky-piston-texture-color` --- ### 📝 Commits (6) - [`4a094be`](https://github.com/horizon-rust/horizon/commit/4a094bee901d70ddef044c1ad05684b3e193508d) Pistons: moving blocks keep their tint, survive saves and leave no black ghost - [`fab9c37`](https://github.com/horizon-rust/horizon/commit/fab9c374130f3916a050017723af0c7ca59dd096) Moving pistons save facing as a byte, as Direction.LEGACY_ID_CODEC does - [`a72f06c`](https://github.com/horizon-rust/horizon/commit/a72f06cfabfbeda80f2e0fe7b6cf1eaf4b6f66b6) Test the moving piston's saved fields against vanilla's - [`ee90b3b`](https://github.com/horizon-rust/horizon/commit/ee90b3b34bb2556aee37e5f3901db5da2114b77f) Moving blocks take their light from the cells their faces look at - [`edd11b6`](https://github.com/horizon-rust/horizon/commit/edd11b610303ab72f1894cd43fac71f78e2a94a4) Merge remote-tracking branch 'origin/main' into upd/3401 - [`1a01f5e`](https://github.com/horizon-rust/horizon/commit/1a01f5ef5966c763a446cbcf4c17aff52578f0ab) Merge main into the branch ### 📊 Changes **10 files changed** (+400 additions, -41 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-client-core/src/block_entity_nbt.rs` (+22 -1) 📝 `crates/horizon-client-render/src/mesher.rs` (+50 -0) 📝 `crates/horizon-client-render/src/mesher/lighting.rs` (+59 -3) 📝 `crates/horizon-client-render/src/mesher/particle_tests.rs` (+37 -0) 📝 `crates/horizon-client/src/game.rs` (+15 -1) 📝 `crates/horizon-client/src/game/minecarts.rs` (+26 -8) 📝 `crates/horizon-client/src/game/moving_pistons.rs` (+73 -26) 📝 `crates/horizon-client/src/game/persist.rs` (+100 -2) 📝 `crates/horizon-client/src/game/remote.rs` (+11 -0) 📝 `crates/horizon-world/src/level/ticks.rs` (+7 -0) </details> ### 📄 Description > 🤖 Opened by JacobRWebb's AI agent (Claude Code), not by JacobRWebb personally. JacobRWebb found the bugs, tested every fix in game and confirmed them. ## What and why Fixes #3310 Fixes #3002 With a sticky piston moving a block back and forth, players saw five things: 1. **Moving grass blocks turned gray.** The top and the side overlay lost their biome colour while the block moved. 2. **Blocks in motion vanished on save (#3310).** Leaving and rejoining mid-move deleted the moving blocks and the moving piston, and left an invisible block you could not place into. 3. **A black ghost followed moved blocks (#3002).** A pulled block left a black, z-fighting copy behind it, the piston looked wrong once retracted, and the head and arm stuttered on a single pulse. 4. **The piston disappeared for a frame** when it fired or settled. 5. **The moved block and the piston base flashed black** for a frame as a move finished. **1. Gray moving blocks: per-face block tints.** `moving_block_vertices` tinted the whole model with `particle_sprite`'s colour, the *terrain particle* tint. `terrain_particle_tint` returns `None` for grass blocks on purpose (vanilla's dirt crumbs are untinted, #1034), so a moving grass block was drawn white. One colour over the whole model was also wrong for blocks with untinted faces. - `MeshTables::block_tints` (`mesher.rs`): each tint index's colour at a position, through the same `Mesher::tint` the chunk mesh uses. - `tinted_block_model_vertices` (`game/minecarts.rs`, beside `block_model_vertices`, which now calls it with no tint): multiplies each face by the tint of its `tint_index`. Moving pistons draw with it. **2. Moving blocks lost on save (#3310).** Moving pistons live only in `Ticks::moving_pistons`, never in `chunk.block_entities`, so saves never wrote them. A reload found a bare `minecraft:moving_piston` with no block entity. - `attach_save_data` writes each moving piston in the chunk as a `minecraft:piston` block entity, field for field as vanilla does. - `register_chunk_ticks` loads them back into the level through the new `Ticks::load_moving_piston`, for a `moving_piston` block only. Worlds vanilla saved with blocks mid-move load too. - Unloading a chunk drops its moving pistons from the level after the chunk is saved. - `block_entity_nbt::canonical` wrote `facing` as an int; it is a byte in vanilla. **3. Black ghost and stutter (#3002).** In the default server-thread mode the window is a client of the in-process server. Its `moveBlocks` makes its own moving pistons, and the server then sends the block each one placed. Vanilla removes the client's block entity when that block changes. Horizon's client kept it and animated it for up to five more `deathTicks`, drawn over the placed block in the chunk mesh and lit from a cell that is now opaque (light 0): a black, z-fighting copy. - `remote.rs` `set_block`: a server update that turns a `moving_piston` into another block removes the client's moving piston there. **4. One frame with no piston.** `moving_piston_fallback` covers the gap until the chunk mesh shows a finished piston's block, but it was cleared after exactly one tick. Remeshing can take longer, which left frames with nothing drawn (hidden before by the stale five-tick copy). Drawn for a whole tick when the mesh was already up, it also z-fought. - `sync_moving_pistons` keeps a fallback entry until its section's mesh is up (not dirty, not meshing, not waiting for upload), the test `cull_entity_vertices` already uses, and draws it only while that holds. **5. Black flash as a move ends (#3002).** Moving blocks were lit with the light stored at the moving piston's own cell. A finished piston's block is still drawn over the chunk mesh until that mesh shows it, and by then the placed block stands in that cell: an opaque cell, light 0. The pushed or pulled block and the piston base flashed black for that frame. Vanilla never reads that cell. `createMovingBlock` places a lone block at the cell it moves from, and `tesselateFlat` lights each face from the neighbour it looks at. - `MeshTables::flat_light` (`mesher.rs`), built on `lighting::flat_position` and `packed_coords` (`mesher/lighting.rs`): the chunk mesher's own flat-light rules for one quad, including emission. The mesher's flat path uses the same helpers, so its output is unchanged. - `tinted_block_model_vertices` takes the light per quad. `block_model_vertices` passes its old constant, so minecarts and the other callers are unchanged. - A moving block is lit per face around the cell it moves from (the retracting base around its own cell). A finished one is lit at the cell it was placed in, as the block it stands in for. Rapid lever clicks that leave the block out are vanilla: a sticky piston given a pulse shorter than its 2-tick extension spits its block. ## Vanilla reference Read from the pinned 26.3 client jar with `tools/rea_vanilla.py` (REA 6.4.0) and `javap -c -p`: - `PistonMovingBlockEntity.saveAdditional` / `loadAdditional`: `blockState` (`BlockState.CODEC`), `facing` (`Direction.LEGACY_ID_CODEC`, `Codec.BYTE` of `get3DDataValue`), `progress` written from `progressO` and read into both `progress` and `progressO`, `extending`, `source`. - `LevelChunk.setBlockState`: on client and server alike, the old state's block entity is removed when `hasBlockEntity()` and `!shouldChangedStateKeepBlockEntity(new)`, so a `moving_piston` turning into another block drops its `PistonMovingBlockEntity`. - `PistonMovingBlockEntity.tick`: on a client, a finished entity waits while `deathTicks < 5`. That is the wait the stale animation ran out. - `ModelBlockRenderer.putQuadWithTint` / `getTintColor`: each quad's `tintIndex` picks a `BlockTintSource`, coloured by `colorInWorld`, not by `colorAsTerrainParticle`, which the old particle tint used. - `PistonHeadRenderer.extractRenderState` → `createMovingBlock(pos, …)`: the moved block's position is `getBlockPos().relative(getMovementDirection().getOpposite())`, the cell it moves from, and the retracting base's is the piston's own cell. `MovingBlockRenderState` is a world holding only that block, with the level's light engine. - `MovingBlockFeatureRenderer.buildGroup` → `ModelBlockRenderer.tesselateBlock` → `tesselateFlat`: a quad with a cull face is lit by `getLightCoords` at the neighbour it faces. `BlockModelLighter.prepareQuadFlat` lights one without: the neighbour when the quad is flush with the block's side, else the block's own cell. Harnesses: none new; `piston_push`, `piston_movement`, `piston_shape` and `block_entity_storage` pass (see Self-check). The saved fields are pinned by `block_entity_nbt::tests::moving_piston_fields_match_vanilla`, from the bytecode above. `save_roundtrip` covers chunk saves but runs only where a virtual screen is available, so CI and the maintainers' hosts run it. The tint is covered by `mesher::particle_tests::block_tints_match_the_chunk_mesh_for_grass_blocks` (prepared 26.3 resources). ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on Jacob, against origin/main at 81f339814, 2 min 47 s) | Check | Result | | --- | --- | | Scope | ✅ 10 files, +398 −34 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ❌ 405 run, FAILED (failures=1, skipped=2) (35 s) | | rustfmt | ✅ (6 s) | | clippy | ✅ (9 s) | | tests: horizon-client, horizon-client-core, horizon-world | ❌ 1110 passed, 1 failed (1 min 44 s) | | doc tests | ✅ 0 passed (6 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 | ➖ 346 affected, to run in CI (--quick): active_effect_tick, active_effects, ambient_sound, anchor, arrow, attribute_health, attribute_map_queries, attribute, attribute_updates, audio_attributes, auto_jump, bamboo and 334 more | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | The two ❌ are Windows-only and in code this branch does not touch (`git diff --stat origin/main...HEAD` lists none of them): - `save::tests::session_lock_is_exclusive`: Windows byte-range locks (`os error 33`) refuse the test's read of a locked file. - Python `test_port_publish`: expects `/` in a path and gets `\`. `--quick` because `tools/parity.py` doesn't run on Windows (`signal.SIGHUP`, `fcntl`, `resource`, `os.killpg`). Through a locally patched copy of the runner, not part of this PR, the piston and block-entity harnesses pass on this branch with JDK 25: ``` PASS piston_push 13s PASS piston_movement 14s PASS block_entity_storage 14s PASS piston_shape 24s 4 passed, 0 failed ``` In game (Windows, RTX 4080 SUPER, server-thread mode), JacobRWebb tested each fix: - a sticky piston moving a grass block back and forth keeps its colour; - after save and quit mid-move, then rejoin, the blocks finish their move; - single and rapid pulses show no black ghost, no head or arm stutter, no missing frame and no black flash. ## Screenshots Before (left, without this branch) and after (right, this branch). The recording predates fix 5: the one-frame black flash still visible on the right around 0.75 s and 2.75 s is what fix 5 removes. <img width="960" height="540" alt="2026-10-28 16-22-30" src="https://github.com/user-attachments/assets/60b2ee73-a887-40a2-87f6-7439b07ca487" /> ## Notes for review - **Overlap with #2986** (enderman carried block): it adds a similar `block_model_vertices_tinted(…, tint: u32, …)` in `minecarts.rs`. This one takes a per-index closure, since some blocks have two tint sources. Whichever merges second should fold the two together. - **#3186** (crate split) moves `mesher.rs` to `horizon-client-render`. `block_tints` moves with it on rebase. - **Saves are on the risky list**, so this waits for a local proof. - **Follow-up, not here:** moving blocks are flat-lit per face. With smooth lighting on, vanilla tesselates them with `tesselateAmbientOcclusion`, as the chunk mesh does, so a block still brightens slightly when it lands. 🤖 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 05:09: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#4955
No description provided.