From b77da60b00f52aac87e9f88d8e3bb692114ea6d8 Mon Sep 17 00:00:00 2001 From: Goodlyay Date: Fri, 17 May 2024 03:37:28 -0700 Subject: [PATCH] Fix blockdef brightness mistakes --- MCGalaxy/Blocks/BlockDefinitions.cs | 16 ++++++---------- MCGalaxy/Network/Packets/Packet.cs | 15 ++++++++++----- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/MCGalaxy/Blocks/BlockDefinitions.cs b/MCGalaxy/Blocks/BlockDefinitions.cs index 1f34b58b1..2af4822f5 100644 --- a/MCGalaxy/Blocks/BlockDefinitions.cs +++ b/MCGalaxy/Blocks/BlockDefinitions.cs @@ -67,7 +67,7 @@ namespace MCGalaxy { /// 0-15 value for how far this block casts light (for fancy lighting option). /// -1 means this property has not been set by the user before /// - [ConfigInt(null, null, -1, -1, 15)] public int Brightness; + [ConfigInt(null, null, -1, -1, 15)] public int Brightness = -1; /// /// Does this block use the lamplight environment color for light casting? (for fancy lighting option) /// If false, uses the lavalight environment color @@ -102,14 +102,6 @@ namespace MCGalaxy { def.Brightness = Brightness; def.UseLampBrightness = UseLampBrightness; return def; } - - /// - /// Called on this instance after it has been parsed from its json file - /// - void OnParsed() { - //Sync Brightness setting logically to max brightness if it has not been set before but this block is fullbright - if (Brightness == -1 && FullBright) Brightness = 15; - } static ConfigElement[] elems; public static BlockDefinition[] Load(string path) { @@ -124,7 +116,6 @@ namespace MCGalaxy { reader.OnMember = (obj, key, value) => { if (obj.Meta == null) obj.Meta = new BlockDefinition(); ConfigElement.Parse(elems, obj.Meta, key, (string)value); - ((BlockDefinition)obj.Meta).OnParsed(); }; JsonArray array = (JsonArray)reader.Parse(); @@ -146,6 +137,11 @@ namespace MCGalaxy { // In case user manually edited fallback in the json file def.FallBack = Math.Min(def.FallBack, Block.CPE_MAX_BLOCK); + + // Sync Brightness setting it has not been set before + if (def.Brightness == -1) { + if (def.FullBright) { def.Brightness = 15; } else { def.Brightness = 0; } + } } } catch (Exception ex) { Logger.LogError("Error Loading block defs from " + path, ex); diff --git a/MCGalaxy/Network/Packets/Packet.cs b/MCGalaxy/Network/Packets/Packet.cs index f7b0b1ae1..5d05ced05 100644 --- a/MCGalaxy/Network/Packets/Packet.cs +++ b/MCGalaxy/Network/Packets/Packet.cs @@ -748,12 +748,17 @@ namespace MCGalaxy.Network buffer[i++] = (byte)(def.BlocksLight ? 0 : 1); buffer[i++] = def.WalkSound; - // 0b_US--_LLLL where U = uses modern brightness, S = uses lamplight color, and L = brightness */ - byte brightness = (byte)Math.Max(0, Math.Min(def.Brightness, 15)); - brightness |= 1 << 7; // Insert "use modern brightness" flag (otherwise client will interpret it as either 0 or 15 lava brightness) - if (def.UseLampBrightness) brightness |= 1 << 6; // Insert "use lamplight color" flag + // Less than zero shouldn't happen, but just in case + if (def.Brightness <= 0) { + buffer[i++] = 0; + } else { + // 0b_US--_LLLL where U = uses modern brightness, S = uses lamplight color, and L = brightness */ + byte brightness = (byte)Math.Max(0, Math.Min(def.Brightness, 15)); + brightness |= 1 << 7; // Insert "use modern brightness" flag (otherwise client will interpret it as either 0 or 15 lava brightness) + if (def.UseLampBrightness) brightness |= 1 << 6; // Insert "use lamplight color" flag - buffer[i++] = brightness; + buffer[i++] = brightness; + } } static void MakeDefineBlockEnd(BlockDefinition def, ref int i, byte[] buffer) {