Add env "lightingmode" config

This commit is contained in:
Goodlyay 2024-05-18 21:45:37 -07:00
parent 2f8aa7cd30
commit a970a7f007
8 changed files with 67 additions and 1 deletions

View File

@ -52,7 +52,7 @@ namespace MCGalaxy.Commands.CPE
if (!LevelInfo.Check(p, data.Rank, lvl, "set env settings of this level")) return;
}
string[] args = message.SplitSpaces();
string[] args = message.SplitSpaces(2);
string opt = args[0], value = args.Length > 1 ? args[1] : "";
if (!Handle(p, lvl, opt, value, cfg, area)) { Help(p); }
}

View File

@ -23,6 +23,7 @@ using MCGalaxy.DB;
using MCGalaxy.Games;
using MCGalaxy.Levels.IO;
using MCGalaxy.Maths;
using MCGalaxy.Network;
using BlockID = System.UInt16;
namespace MCGalaxy.Commands.Info
@ -159,6 +160,9 @@ namespace MCGalaxy.Commands.Info
p.Message("Fancy colors: &eLavaLight {0}, &eLampLight {1}",
Color(cfg.LavaLightColor), Color(cfg.LampLightColor));
}
if (cfg.LightingMode != Packet.LightingMode.None) {
p.Message("Lighting Mode: &b{0}{1}", cfg.LightingMode, cfg.LightingModeLocked ? "&c locked" : "");
}
p.Message("Water level: &b{0}&S, Bedrock offset: &b{1}&S, Clouds height: &b{2}&S, Max fog distance: &b{3}",
data.Get(EnvProp.EdgeLevel), data.Get(EnvProp.SidesOffset),
data.Get(EnvProp.CloudsLevel), data.Get(EnvProp.MaxFog));

View File

@ -21,6 +21,7 @@ using System.IO;
using MCGalaxy.Config;
using MCGalaxy.Games;
using MCGalaxy.Modules.Games.ZS;
using MCGalaxy.Network;
using BlockID = System.UInt16;
namespace MCGalaxy
@ -137,6 +138,11 @@ namespace MCGalaxy
[ConfigString("LampLightColor", "Env", "", true)]
public string LampLightColor = "";
[ConfigEnum("LightingMode", "Env", Packet.LightingMode.None, typeof(Packet.LightingMode))]
public Packet.LightingMode LightingMode;
[ConfigBool("LightingModeLocked", "Env", false)]
public bool LightingModeLocked = false;
public void ResetEnv() {
// TODO: Rewrite using ConfigElement somehow
Weather = ENV_USE_DEFAULT;
@ -163,6 +169,9 @@ namespace MCGalaxy
SkyboxColor = "";
LavaLightColor = "";
LampLightColor = "";
LightingMode = Packet.LightingMode.None;
LightingModeLocked = false;
}
internal const int ENV_COLOR_COUNT = 7;

View File

@ -18,6 +18,7 @@
using System;
using System.Collections.Generic;
using MCGalaxy.Commands;
using MCGalaxy.Network;
using BlockID = System.UInt16;
namespace MCGalaxy {
@ -50,6 +51,8 @@ namespace MCGalaxy {
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("LightingMode", SetLightingMode, "&HSets the lighting mode, which can be Classic or Fancy. " +
"Add \"locked\" on the end to lock the mode. For example: &Tlightingmode classic locked"),
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"),
@ -75,6 +78,7 @@ namespace MCGalaxy {
if (opt.CaselessEq("SkyboxVer")) opt = "SkyboxVerSpeed";
if (opt.CaselessEq("lavacolor")) opt = "LavaLight";
if (opt.CaselessEq("lampcolor")) opt = "LampLight";
if (opt.CaselessEq("lighting")) opt = "LightingMode";
foreach (EnvOption option in Options) {
if (option.Name.CaselessEq(opt)) return option;
@ -127,6 +131,16 @@ namespace MCGalaxy {
static void SetLampLight(Player p, string area, EnvConfig cfg, string value) {
SetColor(p, value, area, "block lamp light color", ref cfg.LampLightColor);
}
static void SetLightingMode(Player p, string area, EnvConfig cfg, string value) {
string[] args = value.SplitSpaces(2);
string lightingMode = args[0];
bool locked = args.Length > 1 && args[1].CaselessEq("locked");
if (!SetEnum(p, lightingMode, area, "lighting mode", Packet.LightingMode.None, ref cfg.LightingMode)) return;
cfg.LightingModeLocked = locked;
if (locked) p.Message("Lighting mode for {0}&S was %clocked%S. Players will not be able to change lighting mode while inside.", area);
if (!p.Supports(CpeExt.LightingMode)) p.Message("&WNote: Your client does not support lighting modes, so you will see no changes.");
}
static void SetCloudsSpeed(Player p, string area, EnvConfig cfg, string value) {
SetFloat(p, value, area, 256, "clouds speed", ref cfg.CloudsSpeed, -0xFFFFFF, 0xFFFFFF);
@ -240,5 +254,17 @@ namespace MCGalaxy {
target = Utils.Hex(rgb.R, rgb.G, rgb.B);
}
}
static bool SetEnum<T>(Player p, string input, string area, string variable, T resetValue, ref T target) where T : struct {
if (IsResetString(input)) {
p.Message("Reset {0} for {1} &Sto normal", variable, area);
target = resetValue;
return true;
} else {
if (!CommandParser.GetEnum(p, input, variable, ref target)) return false;
p.Message("Set {0} for {1} &Sto {2}", variable, area, target.ToString());
return true;
}
}
}
}

View File

@ -92,6 +92,7 @@ namespace MCGalaxy
public const string CustomModels = "CustomModels";
public const string PluginMessages = "PluginMessages";
public const string ExtEntityTeleport = "ExtEntityTeleport";
public const string LightingMode = "LightingMode";
}
public sealed class CpeExtension
@ -151,6 +152,7 @@ namespace MCGalaxy
new CpeExtension(CpeExt.CustomModels, "Allows defining custom models for entities", 2),
new CpeExtension(CpeExt.PluginMessages, "Allows sending and receiving plugin messages from clients"),
new CpeExtension(CpeExt.ExtEntityTeleport, "Allows sending more precisely controlled teleports"),
new CpeExtension(CpeExt.LightingMode, "Allows changing how the client lights worlds"),
#if TEN_BIT_BLOCKS
new CpeExtension(CpeExt.ExtBlocks, "Allows using block IDs over 255 in block definitions"),
#endif

View File

@ -78,5 +78,6 @@ namespace MCGalaxy.Network {
public const byte CpeUndefineModel = 52;
public const byte CpePluginMessage = 53;
public const byte CpeEntityTeleportExt = 54;
public const byte CpeLightingMode = 55;
}
}

View File

@ -681,6 +681,15 @@ namespace MCGalaxy.Network
buffer[4 + offset] = rot.HeadX;
return buffer;
}
public enum LightingMode { None, Classic, Fancy }
public static byte[] SetLightingMode(LightingMode mode, bool locked) {
byte[] buffer = new byte[3];
buffer[0] = Opcode.CpeLightingMode;
buffer[1] = (byte)mode;
buffer[2] = (byte)(locked ? 1 : 0);
return buffer;
}
#endregion

View File

@ -316,6 +316,21 @@ namespace MCGalaxy
Send(Packet.EnvMapProperty(i, value));
}
}
if (Supports(CpeExt.LightingMode)) {
EnvConfig cfg;
if (zone != null && zone.Config.LightingMode != Packet.LightingMode.None) {
// Zone takes most precedence if it has a setting
cfg = zone.Config;
} else {
if (level.Config.LightingMode == Packet.LightingMode.None) {
// If level has no setting, use global
cfg = Server.Config;
} else {
cfg = level.Config;
}
}
Send(Packet.SetLightingMode(cfg.LightingMode, cfg.LightingModeLocked));
}
int weather = CurrentEnvProp(EnvProp.Weather, zone);
Session.SendSetWeather((byte)weather);