From dd45c90b4c7f98f929993f33eaefb180a6e14a48 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 21 Oct 2023 11:42:42 +1100 Subject: [PATCH] Fix custom blocks with no fog in .cw files mistakenly still being loaded with fog density The easiest way to reproduce this was to use noclip to move inside a solid custom block, and then notice the horizon has become black fog To solve this problem for both current and past client versions: - when the read FogDensity value is 0, the in-memory fog density value is set to 0 - when writing FogDensity values to disc, 0xFF instead of 0 is written to indicate 'no fog' (since older client versions convert FogDensity values of 0xFF to 0 in-memory) --- src/Formats.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Formats.c b/src/Formats.c index bc0504492..898223065 100644 --- a/src/Formats.c +++ b/src/Formats.c @@ -836,8 +836,8 @@ static void Cw_Callback_5(struct NbtTag* tag) { if (!arr) return; Blocks.FogDensity[id] = (arr[0] + 1) / 128.0f; - /* Fix for older ClassicalSharp versions which saved wrong fog density value */ - if (arr[0] == 0xFF) Blocks.FogDensity[id] = 0.0f; + /* Backwards compatibility with apps that use 0xFF to indicate no fog */ + if (arr[0] == 0 || arr[0] == 0xFF) Blocks.FogDensity[id] = 0.0f; Blocks.FogCol[id] = PackedCol_Make(arr[1], arr[2], arr[3], 255); return; } @@ -1548,7 +1548,7 @@ static cc_result Cw_WriteBockDef(struct Stream* stream, int b) { cur = Nbt_WriteArray(cur, "Fog", 4); fog = (cc_uint8)(128 * Blocks.FogDensity[b] - 1); col = Blocks.FogCol[b]; - cur[0] = Blocks.FogDensity[b] ? fog : 0; + cur[0] = Blocks.FogDensity[b] ? fog : 0xFF; /* write 0xFF instead of 0 for backwards compatibility */ cur[1] = PackedCol_R(col); cur[2] = PackedCol_G(col); cur[3] = PackedCol_B(col); cur += 4;