mirror of
https://github.com/chev2/terraria-mods.git
synced 2026-04-26 12:41:41 +00:00
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:
parent
9b083b8357
commit
41a97f1ad5
4 changed files with 30 additions and 24 deletions
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue