From 39f5c69bc3054d2f6426dadb7213fcd12972d3bb Mon Sep 17 00:00:00 2001 From: p2r3 Date: Sun, 14 Sep 2025 02:08:16 +0300 Subject: [PATCH] fix crash when overwriting terrain with a chest Closes #48 --- src/procedures.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/procedures.c b/src/procedures.c index faedde9..c0224f5 100644 --- a/src/procedures.c +++ b/src/procedures.c @@ -434,7 +434,21 @@ uint8_t makeBlockChange (short x, uint8_t y, short z, uint8_t block) { } #endif if (is_base_block) block_changes[i].block = 0xFF; - else block_changes[i].block = block; + else { + #ifdef ALLOW_CHESTS + // When placing chests, just unallocate the target block and fall + // through to the chest-specific routine below. + if (block == B_chest) { + block_changes[i].block = 0xFF; + if (first_gap > i) first_gap = i; + #ifndef DISK_SYNC_BLOCKS_ON_INTERVAL + writeBlockChangesToDisk(i, i); + #endif + break; + } + #endif + block_changes[i].block = block; + } #ifndef DISK_SYNC_BLOCKS_ON_INTERVAL writeBlockChangesToDisk(i, i); #endif