Add BlockLight EnvColor variable and fancy lighting blockdef values

This commit is contained in:
Goodlyay 2024-05-15 03:41:31 -07:00
parent a40648afce
commit bf23984370
6 changed files with 105 additions and 21 deletions

View File

@ -61,6 +61,17 @@ namespace MCGalaxy {
[ConfigInt(null, null, -1, -1)]
public int InventoryOrder = -1;
/// <summary>
/// 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;
/// <summary>
/// Does this block use the sun environment color for light casting? (for fancy lighting option)
/// </summary>
[ConfigBool] public bool UseSunBrightness;
public BlockID GetBlock() { return Block.FromRaw(RawID); }
public void SetBlock(BlockID b) { RawID = Block.ToRaw(b); }
@ -87,9 +98,18 @@ namespace MCGalaxy {
def.LeftTex = LeftTex; def.RightTex = RightTex;
def.FrontTex = FrontTex; def.BackTex = BackTex;
def.InventoryOrder = InventoryOrder;
def.Brightness = Brightness; def.UseSunBrightness = UseSunBrightness;
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) {
BlockDefinition[] defs = new BlockDefinition[Block.SUPPORTED_COUNT];
@ -103,6 +123,7 @@ 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();
@ -265,6 +286,17 @@ namespace MCGalaxy {
LeftTex = id; RightTex = id; FrontTex = id; BackTex = id;
}
public void SetFullBright(bool fullBright) {
SetBrightness(fullBright ? 15 : 0, false);
}
/// <summary>
/// Does not validate that the range falls within 0-15
/// </summary>
public void SetBrightness(int brightness, bool sun) {
Brightness = brightness;
UseSunBrightness = sun;
if (Brightness > 0) { FullBright = true; } else { FullBright = false; }
}
internal static void SendLevelCustomBlocks(Player pl) {
BlockDefinition[] defs = pl.level.CustomBlockDefs;

View File

@ -259,8 +259,11 @@ namespace MCGalaxy.Commands.CPE
} else {
p.Message(" Block is a cube from ({0}, {1}, {2}) to ({3}, {4}, {5})",
def.MinX, def.MinZ, def.MinY, def.MaxX, def.MaxZ, def.MaxY);
p.Message(" Texture IDs (left: {0}, right: {1}, front: {2}, back: {3}, top: {4}, bottom: {5})",
def.LeftTex, def.RightTex, def.FrontTex, def.BackTex, def.TopTex, def.BottomTex);
p.Message(" Texture IDs:");
p.Message(" left: {0}, right: {1}, front: {2}, back: {3}",
def.LeftTex, def.RightTex, def.FrontTex, def.BackTex);
p.Message(" top: {0}, bottom: {1}",
def.TopTex, def.BottomTex);
}
if (def.InventoryOrder < 0) {
@ -270,6 +273,10 @@ namespace MCGalaxy.Commands.CPE
} else {
p.Message(" Order: " + def.InventoryOrder);
}
if (def.Brightness > 0) {
string word = def.UseSunBrightness ? "SunBrightness" : "Brightness";
p.Message(" {0}: {1}", word, def.Brightness);
}
}
@ -384,8 +391,10 @@ namespace MCGalaxy.Commands.CPE
if (CommandParser.GetByte(p, value, "Walk sound", ref def.WalkSound, 0, 11))
step++;
} else if (step == 13) {
if (CommandParser.GetBool(p, value, ref def.FullBright))
if (CommandParser.GetBool(p, value, ref temp)) {
def.SetFullBright(temp);
step++;
}
} else if (step == 14) {
if (CommandParser.GetByte(p, value, "Block draw", ref def.BlockDraw, 0, 4))
step++;
@ -416,6 +425,9 @@ namespace MCGalaxy.Commands.CPE
SendStepHelp(p, args);
}
/// <summary>
/// Returns true if an edit actually occured
/// </summary>
static bool DoEdit(Player p, string[] parts, BlockDefinitionsArgs args, BlockID block) {
BlockDefinition def = args.defs[block], globalDef = BlockDefinition.GlobalDefs[block];
@ -483,7 +495,7 @@ namespace MCGalaxy.Commands.CPE
if (!CommandParser.GetBool(p, value, ref temp)) {
SendEditHelp(p, arg); return false;
}
def.FullBright = temp;
def.SetFullBright(temp);
break;
case "shape":
@ -543,6 +555,22 @@ namespace MCGalaxy.Commands.CPE
p.Message("Set inventory order for {0} to {1}", blockName,
order == def.RawID ? "default" : order.ToString());
return true;
case "brightness":
int brightness = 0;
if (!CommandParser.GetInt(p, value, "brightness", ref brightness, 0, 15)) {
SendEditHelp(p, arg); return false;
}
def.SetBrightness(brightness, false);
break;
case "sunbrightness":
int sunBrightness = 0;
if (!CommandParser.GetInt(p, value, "sunbrightness", ref sunBrightness, 0, 15)) {
SendEditHelp(p, arg); return false;
}
def.SetBrightness(sunBrightness, true);
break;
default:
p.Message("Unrecognised property: " + arg); return false;
}
@ -855,6 +883,14 @@ namespace MCGalaxy.Commands.CPE
"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.",
"You need Fancy Lighting to see differences between 1 and 15.",
"The block will glow using the \"blocklight\" env color" }
},
{ "sunbrightness", new string[] { "Type a number (0-15) for the sun-brightness of the block.",
"You need Fancy Lighting to see differences between 1 and 15.",
"The block will glow using the \"sun\" env color" }
},
};

View File

@ -130,7 +130,10 @@ namespace MCGalaxy
/// <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 = "";
public void ResetEnv() {
// TODO: Rewrite using ConfigElement somehow
Weather = ENV_USE_DEFAULT;
@ -149,14 +152,16 @@ namespace MCGalaxy
EdgeBlock = Block.Invalid;
ExpFog = ENV_USE_DEFAULT;
CloudColor = "";
FogColor = "";
SkyColor = "";
ShadowColor = "";
LightColor = "";
SkyboxColor = "";
CloudColor = "";
FogColor = "";
SkyColor = "";
ShadowColor = "";
LightColor = "";
SkyboxColor = "";
BlockLightColor = "";
}
internal const int ENV_COLOR_COUNT = 6;
public string GetColor(int i) {
if (i == 0) return SkyColor;
if (i == 1) return CloudColor;
@ -164,6 +169,7 @@ namespace MCGalaxy
if (i == 3) return ShadowColor;
if (i == 4) return LightColor;
if (i == 5) return SkyboxColor;
if (i == 6) return BlockLightColor;
return null;
}

View File

@ -42,12 +42,13 @@ namespace MCGalaxy {
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("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("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"),
@ -117,7 +118,10 @@ namespace MCGalaxy {
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 SetCloudsSpeed(Player p, string area, EnvConfig cfg, string value) {
SetFloat(p, value, area, 256, "clouds speed", ref cfg.CloudsSpeed, -0xFFFFFF, 0xFFFFFF);
}

View File

@ -747,7 +747,13 @@ namespace MCGalaxy.Network
buffer[i++] = (byte)(def.BlocksLight ? 0 : 1);
buffer[i++] = def.WalkSound;
buffer[i++] = (byte)(def.FullBright ? 1 : 0);
// 0b_US--_LLLL where U = uses modern brightness, S = uses sun brightness, 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
buffer[i++] = brightness;
}
static void MakeDefineBlockEnd(BlockDefinition def, ref int i, byte[] buffer) {

View File

@ -299,7 +299,7 @@ namespace MCGalaxy
public void SendCurrentEnv() {
Zone zone = ZoneIn;
for (int i = 0; i <= 5; i++) {
for (int i = 0; i <= EnvConfig.ENV_COLOR_COUNT; i++) {
string col = Server.Config.GetColor(i);
if (level.Config.GetColor(i) != "") {
col = level.Config.GetColor(i);