Skip to content

Commit

Permalink
Fix blockdef brightness mistakes
Browse files Browse the repository at this point in the history
  • Loading branch information
Goodlyay committed May 17, 2024
1 parent 003ad37 commit b77da60
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
16 changes: 6 additions & 10 deletions MCGalaxy/Blocks/BlockDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public sealed class BlockDefinition {
/// 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
/// </summary>
[ConfigInt(null, null, -1, -1, 15)] public int Brightness;
[ConfigInt(null, null, -1, -1, 15)] public int Brightness = -1;
/// <summary>
/// Does this block use the lamplight environment color for light casting? (for fancy lighting option)
/// If false, uses the lavalight environment color
Expand Down Expand Up @@ -102,14 +102,6 @@ public BlockDefinition Copy() {
def.Brightness = Brightness; def.UseLampBrightness = UseLampBrightness;
return def;
}

/// <summary>
/// Called on this instance after it has been parsed from its json file
/// </summary>
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) {
Expand All @@ -124,7 +116,6 @@ public static BlockDefinition[] Load(string path) {
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();
Expand All @@ -146,6 +137,11 @@ public static BlockDefinition[] Load(string path) {

// 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);
Expand Down
15 changes: 10 additions & 5 deletions MCGalaxy/Network/Packets/Packet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -748,12 +748,17 @@ static void MakeDefineBlockStart(BlockDefinition def, byte[] buffer, ref int i,
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) {
Expand Down

0 comments on commit b77da60

Please sign in to comment.