Skip to content

Commit

Permalink
Add "LampLight" env color variable and rename "BlockLight" to "LavaLi…
Browse files Browse the repository at this point in the history
…ght"
  • Loading branch information
Goodlyay committed May 16, 2024
1 parent bf23984 commit 003ad37
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 40 deletions.
11 changes: 6 additions & 5 deletions MCGalaxy/Blocks/BlockDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ public sealed class BlockDefinition {
/// </summary>
[ConfigInt(null, null, -1, -1, 15)] public int Brightness;
/// <summary>
/// Does this block use the sun environment color for light casting? (for fancy lighting option)
/// Does this block use the lamplight environment color for light casting? (for fancy lighting option)
/// If false, uses the lavalight environment color
/// </summary>
[ConfigBool] public bool UseSunBrightness;
[ConfigBool] public bool UseLampBrightness;

public BlockID GetBlock() { return Block.FromRaw(RawID); }
public void SetBlock(BlockID b) { RawID = Block.ToRaw(b); }
Expand All @@ -98,7 +99,7 @@ public sealed class BlockDefinition {
def.LeftTex = LeftTex; def.RightTex = RightTex;
def.FrontTex = FrontTex; def.BackTex = BackTex;
def.InventoryOrder = InventoryOrder;
def.Brightness = Brightness; def.UseSunBrightness = UseSunBrightness;
def.Brightness = Brightness; def.UseLampBrightness = UseLampBrightness;
return def;
}

Expand Down Expand Up @@ -292,9 +293,9 @@ public sealed class BlockDefinition {
/// <summary>
/// Does not validate that the range falls within 0-15
/// </summary>
public void SetBrightness(int brightness, bool sun) {
public void SetBrightness(int brightness, bool lamp) {
Brightness = brightness;
UseSunBrightness = sun;
UseLampBrightness = lamp;
if (Brightness > 0) { FullBright = true; } else { FullBright = false; }
}

Expand Down
18 changes: 9 additions & 9 deletions MCGalaxy/Commands/CPE/CustomBlockCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class BlockDefinitionsArgs
p.Message(" Order: " + def.InventoryOrder);
}
if (def.Brightness > 0) {
string word = def.UseSunBrightness ? "SunBrightness" : "Brightness";
string word = def.UseLampBrightness ? "LampBrightness" : "LavaBrightness";
p.Message(" {0}: {1}", word, def.Brightness);
}
}
Expand Down Expand Up @@ -556,17 +556,17 @@ class BlockDefinitionsArgs
order == def.RawID ? "default" : order.ToString());
return true;

case "brightness":
case "lavabrightness":
int brightness = 0;
if (!CommandParser.GetInt(p, value, "brightness", ref brightness, 0, 15)) {
if (!CommandParser.GetInt(p, value, "lavabrightness", ref brightness, 0, 15)) {
SendEditHelp(p, arg); return false;
}
def.SetBrightness(brightness, false);
break;

case "sunbrightness":
case "lampbrightness":
int sunBrightness = 0;
if (!CommandParser.GetInt(p, value, "sunbrightness", ref sunBrightness, 0, 15)) {
if (!CommandParser.GetInt(p, value, "lampbrightness", ref sunBrightness, 0, 15)) {
SendEditHelp(p, arg); return false;
}
def.SetBrightness(sunBrightness, true);
Expand Down Expand Up @@ -883,13 +883,13 @@ class BlockDefinitionsArgs
"The default position of a block is its ID.",
"A position of 0 hides the block from the inventory." }
},
{ "brightness", new string[] { "Type a number (0-15) for the brightness of the block.",
{ "lavabrightness", new string[] { "Type a number (0-15) for the lava brightness of the block.",
"You need Fancy Lighting to see differences between 1 and 15.",
"The block will glow using the \"blocklight\" env color" }
"The block will glow using the \"lavalight\" env color" }
},
{ "sunbrightness", new string[] { "Type a number (0-15) for the sun-brightness of the block.",
{ "lampbrightness", new string[] { "Type a number (0-15) for the lamp brightness of the block.",
"You need Fancy Lighting to see differences between 1 and 15.",
"The block will glow using the \"sun\" env color" }
"The block will glow using the \"lamplight\" env color" }
},
};

Expand Down
3 changes: 3 additions & 0 deletions MCGalaxy/Levels/EnvPreset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@
namespace MCGalaxy {
internal sealed class EnvPreset {
public string Fog, Sky, Clouds, Sun, Shadow;
public string LavaLight = "", LampLight = "";

public EnvPreset(string raw) {
string[] args = raw.SplitSpaces();
Fog = args[0]; Sky = args[1]; Clouds = args[2]; Sun = args[3]; Shadow = args[4];
LavaLight = args.Length > 5 ? args[5] : "";
LampLight = args.Length > 6 ? args[6] : "";
}

public static Dictionary<string, string> Presets = new Dictionary<string, string>() {
Expand Down
31 changes: 18 additions & 13 deletions MCGalaxy/Levels/LevelConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,12 @@ public abstract class EnvConfig
/// <summary> Color of the skybox (Hex RGB color). Set to "" to use client defaults. </summary>
[ConfigString("SkyboxColor", "Env", "", true)]
public string SkyboxColor = "";
/// <summary> Color emitted by bright blocks (Hex RGB color). Set to "" to use client defaults. </summary>
[ConfigString("BlockLightColor", "Env", "", true)]
public string BlockLightColor = "";
/// <summary> Color emitted by bright natural blocks (Hex RGB color). Set to "" to use client defaults. </summary>
[ConfigString("LavaLightColor", "Env", "", true)]
public string LavaLightColor = "";
/// <summary> Color emitted by bright artificial blocks (Hex RGB color). Set to "" to use client defaults. </summary>
[ConfigString("LampLightColor", "Env", "", true)]
public string LampLightColor = "";

public void ResetEnv() {
// TODO: Rewrite using ConfigElement somehow
Expand All @@ -152,25 +155,27 @@ public abstract class EnvConfig
EdgeBlock = Block.Invalid;
ExpFog = ENV_USE_DEFAULT;

CloudColor = "";
FogColor = "";
SkyColor = "";
ShadowColor = "";
LightColor = "";
SkyboxColor = "";
BlockLightColor = "";
CloudColor = "";
FogColor = "";
SkyColor = "";
ShadowColor = "";
LightColor = "";
SkyboxColor = "";
LavaLightColor = "";
LampLightColor = "";
}

internal const int ENV_COLOR_COUNT = 6;
internal const int ENV_COLOR_COUNT = 7;
public string GetColor(int i) {
if (i == 0) return SkyColor;
if (i == 1) return CloudColor;
if (i == 2) return FogColor;
if (i == 3) return ShadowColor;
if (i == 4) return LightColor;
if (i == 5) return SkyboxColor;
if (i == 6) return BlockLightColor;

if (i == 6) return LavaLightColor;
if (i == 7) return LampLightColor;

return null;
}

Expand Down
26 changes: 16 additions & 10 deletions MCGalaxy/Levels/LevelEnv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ public static class EnvOptions {
new EnvOption("EdgeLevel", SetEdgeLevel, "&HSets the water height of the map"),
new EnvOption("SidesOffset", SetSidesOffset, "&HSets offset of bedrock from water (default -2)"),
new EnvOption("MaxFog", SetMaxFog, "&HSets maximum fog distance in the map (e.g. 16 for a horror map)"),
new EnvOption("Sky", SetSky, "&HSets color of the sky (default 99CCFF)"),
new EnvOption("Clouds", SetClouds, "&HSets color of the clouds (default FFFFFF)"),
new EnvOption("Fog", SetFog, "&HSets color of the fog (default FFFFFF)"),
new EnvOption("Sun", SetSun, "&HSets color of blocks in sunlight (default FFFFFF)"),
new EnvOption("Shadow", SetShadow, "&HSets color of blocks in darkness (default 9B9B9B)"),
new EnvOption("Skybox", SetSkybox, "&HSets color of the skybox (default FFFFFF)"),
new EnvOption("BlockLight", SetBlockLight, "&HSets color cast by bright blocks (default FFEBC6)"),
new EnvOption("Sky", SetSky, "&HSets color of the sky (default 99CCFF)"),
new EnvOption("Clouds", SetClouds, "&HSets color of the clouds (default FFFFFF)"),
new EnvOption("Fog", SetFog, "&HSets color of the fog (default FFFFFF)"),
new EnvOption("Sun", SetSun, "&HSets color of blocks in sunlight (default FFFFFF)"),
new EnvOption("Shadow", SetShadow, "&HSets color of blocks in darkness (default 9B9B9B)"),
new EnvOption("Skybox", SetSkybox, "&HSets color of the skybox (default FFFFFF)"),
new EnvOption("LavaLight", SetLavaLight, "&HSets color cast by bright natural blocks when fancy lighting is enabled (default FFEBC6)"),
new EnvOption("LampLight", SetLampLight, "&HSets color cast by bright artificial blocks when fancy lighting is enabled (default FFFFFF)"),
new EnvOption("CloudsSpeed", SetCloudsSpeed, "&HSets how fast clouds move (negative moves in opposite direction)"),
new EnvOption("WeatherSpeed", SetWeatherSpeed, "&HSets how fast rain/snow falls (negative falls upwards)"),
new EnvOption("WeatherFade", SetWeatherFade, "&HSets how quickly rain/snow fades out over distance"),
Expand All @@ -72,7 +73,9 @@ public static class EnvOptions {
if (opt.CaselessEq("CloudSpeed")) opt = "CloudsSpeed";
if (opt.CaselessEq("SkyboxHor")) opt = "SkyboxHorSpeed";
if (opt.CaselessEq("SkyboxVer")) opt = "SkyboxVerSpeed";

if (opt.CaselessEq("lavacolor")) opt = "LavaLight";
if (opt.CaselessEq("lampcolor")) opt = "LampLight";

foreach (EnvOption option in Options) {
if (option.Name.CaselessEq(opt)) return option;
}
Expand Down Expand Up @@ -118,8 +121,11 @@ public static class EnvOptions {
static void SetSkybox(Player p, string area, EnvConfig cfg, string value) {
SetColor(p, value, area, "skybox color", ref cfg.SkyboxColor);
}
static void SetBlockLight(Player p, string area, EnvConfig cfg, string value) {
SetColor(p, value, area, "block light color", ref cfg.BlockLightColor);
static void SetLavaLight(Player p, string area, EnvConfig cfg, string value) {
SetColor(p, value, area, "block lava light color", ref cfg.LavaLightColor);
}
static void SetLampLight(Player p, string area, EnvConfig cfg, string value) {
SetColor(p, value, area, "block lamp light color", ref cfg.LampLightColor);
}

static void SetCloudsSpeed(Player p, string area, EnvConfig cfg, string value) {
Expand Down
6 changes: 3 additions & 3 deletions MCGalaxy/Network/Packets/Packet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -748,10 +748,10 @@ public enum TeleportMoveMode { AbsoluteInstant, AbsoluteSmooth, RelativeSmooth,
buffer[i++] = (byte)(def.BlocksLight ? 0 : 1);
buffer[i++] = def.WalkSound;

// 0b_US--_LLLL where U = uses modern brightness, S = uses sun brightness, and L = brightness */
// 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 brightness)
if (def.UseSunBrightness) brightness |= 1 << 6; // Insert "use sun color" flag
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;
}
Expand Down

0 comments on commit 003ad37

Please sign in to comment.