LifeSourcesLight: Rework mod code

- Update Main.tileLighted (attempt to fix bug where lights wouldn't work in multiplayer until the config was reloaded)
- Organize and tidy code a bit
This commit is contained in:
Chev 2025-05-22 02:06:18 -07:00
parent 9b083b8357
commit 41a97f1ad5
Signed by: chev2
GPG key ID: 0B212D6AED495EC9
4 changed files with 30 additions and 24 deletions

View file

@ -4,21 +4,12 @@ namespace LifeSourcesLight
{
public class LifeSourcesLight : Mod
{
internal static bool _enableHeartCrystalLight;
public static bool EnableHeartCrystalLight
public override void PostSetupContent()
{
get { return _enableHeartCrystalLight; }
}
base.PostSetupContent();
internal static bool _enableLifeFruitLight;
public static bool EnableLifeFruitLight
{
get { return _enableLifeFruitLight; }
}
public override void Load()
{
base.Load();
// Update Main.tileLighted on post-load to ensure config is properly loaded
LifeSourcesLightModSystem.UpdateTileLighted();
}
}
}

View file

@ -6,20 +6,35 @@ namespace LifeSourcesLight
{
public class LifeSourcesLightModSystem : ModSystem
{
private LifeSourcesLightConfig _configInstance;
public LifeSourcesLightModSystem() : base()
{
_configInstance = ModContent.GetInstance<LifeSourcesLightConfig>();
internal static bool _enableLightHeartCrystal = true;
public static bool EnableLightHeartCrystal {
get { return _enableLightHeartCrystal; }
}
internal static bool _enableLightLifeFruit = true;
public static bool EnableLightLifeFruit {
get { return _enableLightLifeFruit; }
}
// We use the booleans above later in an if-check, and to my knowledge,
// that if-check runs every tick or every frame.
// It's more efficient than calling ModContent.GetInstance() every tick
// (as far as I'm aware)
public void ApplySettings()
{
LifeSourcesLight._enableHeartCrystalLight = _configInstance.EnableHeartCrystalLight;
LifeSourcesLight._enableLifeFruitLight = _configInstance.EnableLifeFruitLight;
LifeSourcesLightConfig configInstance = ModContent.GetInstance<LifeSourcesLightConfig>();
Main.tileLighted[TileID.Heart] = LifeSourcesLight._enableHeartCrystalLight;
Main.tileLighted[TileID.LifeFruit] = LifeSourcesLight._enableLifeFruitLight;
_enableLightHeartCrystal = configInstance.EnableHeartCrystalLight;
_enableLightLifeFruit = configInstance.EnableLifeFruitLight;
UpdateTileLighted();
}
// Modified Main.tileLighted for the heart crystal & life fruit
// Necessary in order to enable lighting calculations for both
public static void UpdateTileLighted() {
Main.tileLighted[TileID.Heart] = EnableLightHeartCrystal;
Main.tileLighted[TileID.LifeFruit] = EnableLightLifeFruit;
}
}
}

View file

@ -10,7 +10,7 @@ namespace LifeSourcesLight
public override void ModifyLight(int i, int j, int type, ref float r, ref float g, ref float b)
{
if (type == TileID.Heart && LifeSourcesLight.EnableHeartCrystalLight)
if (type == TileID.Heart && LifeSourcesLightModSystem.EnableLightHeartCrystal)
{
r = (255f / 255f) * LifeCrystalBrightCoefficient;
g = (38f / 255f) * LifeCrystalBrightCoefficient;

View file

@ -10,7 +10,7 @@ namespace LifeSourcesLight
public override void ModifyLight(int i, int j, int type, ref float r, ref float g, ref float b)
{
if (type == TileID.LifeFruit && LifeSourcesLight.EnableLifeFruitLight)
if (type == TileID.LifeFruit && LifeSourcesLightModSystem.EnableLightLifeFruit)
{
r = (221f / 255f) * LifeFruitBrightCoefficient;
g = (181f / 255f) * LifeFruitBrightCoefficient;