Modern Apps git

← Modern-Apps.git

voxels: plant crops only once the block write lands

Commit
90883bb891fe2e32941e37c4985f75d8542960aa
Author
Vayun Mathur <[email protected]>
When
2026-08-05 18:26 UTC (4 months ago)
Parents
de63f6d

Diff

games/voxels/src/main/rust/src/engine.rs
diff --git a/games/voxels/src/main/rust/src/engine.rs b/games/voxels/src/main/rust/src/engine.rsindex abab10a5b6..2f3b6e6e28 100644--- a/games/voxels/src/main/rust/src/engine.rs+++ b/games/voxels/src/main/rust/src/engine.rs@@ -1916,8 +1916,14 @@ fn do_place(state: &mut EngineState, origin: Vec3, dir: Vec3) -> bool {             let (x, y, z) = hit.pos;             let (tx, ty, tz) = (x + hit.normal.0, y + hit.normal.1, z + hit.normal.2);             let on_farmland = state.chunks.get_block_world(x, y, z) == Block::Farmland as u8 && hit.normal.1 == 1;-            if on_farmland && state.chunks.get_block_world(tx, ty, tz) == 0 && state.inventory.consume_selected().is_some() {-                state.chunks.set_block_meta_world(tx, ty, tz, crop as u8, crate::world::block::crop_meta(0));+            // Plant only once the write is known to have landed, so an unloaded chunk can't eat the seed.+            if on_farmland && state.chunks.get_block_world(tx, ty, tz) == 0+                && state.chunks.set_block_meta_world(tx, ty, tz, crop as u8, crate::world::block::crop_meta(0))+            {+                if state.inventory.consume_selected().is_none() {+                    state.chunks.set_block_world(tx, ty, tz, 0);+                    return false;+                }                 mark_neighbors_dirty(state, tx, tz);                 return true;             }