From 580b14a09ab5dbff811b8cb5c04944d3ba19be79 Mon Sep 17 00:00:00 2001 From: Lion8cake <69915693+Lion8cake@users.noreply.github.com> Date: Thu, 29 Aug 2024 01:34:48 +1000 Subject: [PATCH 01/12] Liquid Edits Rewrite (#52) Technically a half reimplementation of the BiomeLava mod. --- CalPlayer/CalamityPlayer.cs | 4 + CalPlayer/CalamityPlayerMiscEffects.cs | 8 +- CalamityMod.cs | 37 +- Dusts/WaterSplash/AstralSplash.cs | 9 + Dusts/WaterSplash/AstralSplash.png | Bin 0 -> 245 bytes Dusts/WaterSplash/CragsLavaSplash.cs | 178 +++ Dusts/WaterSplash/CragsLavaSplash.png | Bin 0 -> 275 bytes Dusts/WaterSplash/MiddleAbyssSplash.cs | 9 + Dusts/WaterSplash/MiddleAbyssSplash.png | Bin 0 -> 246 bytes Dusts/WaterSplash/SplashDust.cs | 20 + Dusts/WaterSplash/SulphuricDepthsSplash.cs | 9 + Dusts/WaterSplash/SulphuricDepthsSplash.png | Bin 0 -> 245 bytes Dusts/WaterSplash/SulphuricSplash.cs | 9 + Dusts/WaterSplash/SulphuricSplash.png | Bin 0 -> 245 bytes Dusts/WaterSplash/SunkenSeaSplash.cs | 9 + Dusts/WaterSplash/SunkenSeaSplash.png | Bin 0 -> 241 bytes Dusts/WaterSplash/UpperAbyssSplash.cs | 9 + Dusts/WaterSplash/UpperAbyssSplash.png | Bin 0 -> 245 bytes Dusts/WaterSplash/VoidSplash.cs | 9 + Dusts/WaterSplash/VoidSplash.png | Bin 0 -> 246 bytes Gores/AstralWaterDroplet.cs | 167 --- Gores/WaterDroplet/AstralWaterDroplet.cs | 6 + .../{ => WaterDroplet}/AstralWaterDroplet.png | Bin Gores/WaterDroplet/CragsLavaDroplet.cs | 11 + Gores/WaterDroplet/CragsLavaDroplet.png | Bin 0 -> 972 bytes Gores/WaterDroplet/LiquidDropletGore.cs | 201 +++ Gores/WaterDroplet/MiddleAbyssWaterDroplet.cs | 6 + .../WaterDroplet/MiddleAbyssWaterDroplet.png | Bin 0 -> 939 bytes .../SulphuricDepthsWaterDroplet.cs | 6 + .../SulphuricDepthsWaterDroplet.png | Bin 0 -> 945 bytes Gores/WaterDroplet/SulphuricWaterDroplet.cs | 6 + Gores/WaterDroplet/SulphuricWaterDroplet.png | Bin 0 -> 948 bytes Gores/WaterDroplet/SunkenSeaWaterDroplet.cs | 6 + Gores/WaterDroplet/SunkenSeaWaterDroplet.png | Bin 0 -> 966 bytes Gores/WaterDroplet/UpperAbyssWaterDroplet.cs | 6 + Gores/WaterDroplet/UpperAbyssWaterDroplet.png | Bin 0 -> 942 bytes Gores/WaterDroplet/VoidWaterDroplet.cs | 6 + Gores/WaterDroplet/VoidWaterDroplet.png | Bin 0 -> 939 bytes ILEditing/ILChangesLoading.cs | 45 +- ILEditing/ILHelperMethods.cs | 89 +- ILEditing/MechanicILChanges.cs | 768 ++++++----- ModSupport/WeakReferenceSupport.cs | 48 + Systems/CalamityModWaterStyle.cs | 57 + Systems/LavaRendering.cs | 1159 +++++++++++++++++ Systems/ModLavaStyle.cs | 262 ++++ Utilities/MiscUtils.cs | 1 + Utilities/TileUtils.cs | 37 +- Waters/AstralWater.cs | 15 +- Waters/AstralWaterflow.cs | 8 - Waters/BasaltGullyWater.cs | 71 +- Waters/CragsLava.cs | 38 + Waters/CragsLavaStyle.cs | 31 - Waters/CustomLavaManagement.cs | 92 -- Waters/CustomLavaStyle.cs | 51 - Waters/LiquidTileType.cs | 9 - Waters/MiddleAbyssWater.cs | 34 +- Waters/MiddleAbyssWaterflow.cs | 8 - Waters/PissWater.cs | 29 +- Waters/PissWaterflow.cs | 8 - Waters/SulphuricDepthsWater.cs | 52 +- Waters/SulphuricDepthsWaterflow.cs | 8 - Waters/SulphuricWater.cs | 101 +- Waters/SulphuricWaterflow.cs | 8 - Waters/UpperAbyssWater.cs | 34 +- Waters/UpperAbyssWaterflow.cs | 8 - Waters/VoidWater.cs | 34 +- Waters/VoidWaterflow.cs | 8 - 67 files changed, 2882 insertions(+), 962 deletions(-) create mode 100644 Dusts/WaterSplash/AstralSplash.cs create mode 100644 Dusts/WaterSplash/AstralSplash.png create mode 100644 Dusts/WaterSplash/CragsLavaSplash.cs create mode 100644 Dusts/WaterSplash/CragsLavaSplash.png create mode 100644 Dusts/WaterSplash/MiddleAbyssSplash.cs create mode 100644 Dusts/WaterSplash/MiddleAbyssSplash.png create mode 100644 Dusts/WaterSplash/SplashDust.cs create mode 100644 Dusts/WaterSplash/SulphuricDepthsSplash.cs create mode 100644 Dusts/WaterSplash/SulphuricDepthsSplash.png create mode 100644 Dusts/WaterSplash/SulphuricSplash.cs create mode 100644 Dusts/WaterSplash/SulphuricSplash.png create mode 100644 Dusts/WaterSplash/SunkenSeaSplash.cs create mode 100644 Dusts/WaterSplash/SunkenSeaSplash.png create mode 100644 Dusts/WaterSplash/UpperAbyssSplash.cs create mode 100644 Dusts/WaterSplash/UpperAbyssSplash.png create mode 100644 Dusts/WaterSplash/VoidSplash.cs create mode 100644 Dusts/WaterSplash/VoidSplash.png delete mode 100644 Gores/AstralWaterDroplet.cs create mode 100644 Gores/WaterDroplet/AstralWaterDroplet.cs rename Gores/{ => WaterDroplet}/AstralWaterDroplet.png (100%) create mode 100644 Gores/WaterDroplet/CragsLavaDroplet.cs create mode 100644 Gores/WaterDroplet/CragsLavaDroplet.png create mode 100644 Gores/WaterDroplet/LiquidDropletGore.cs create mode 100644 Gores/WaterDroplet/MiddleAbyssWaterDroplet.cs create mode 100644 Gores/WaterDroplet/MiddleAbyssWaterDroplet.png create mode 100644 Gores/WaterDroplet/SulphuricDepthsWaterDroplet.cs create mode 100644 Gores/WaterDroplet/SulphuricDepthsWaterDroplet.png create mode 100644 Gores/WaterDroplet/SulphuricWaterDroplet.cs create mode 100644 Gores/WaterDroplet/SulphuricWaterDroplet.png create mode 100644 Gores/WaterDroplet/SunkenSeaWaterDroplet.cs create mode 100644 Gores/WaterDroplet/SunkenSeaWaterDroplet.png create mode 100644 Gores/WaterDroplet/UpperAbyssWaterDroplet.cs create mode 100644 Gores/WaterDroplet/UpperAbyssWaterDroplet.png create mode 100644 Gores/WaterDroplet/VoidWaterDroplet.cs create mode 100644 Gores/WaterDroplet/VoidWaterDroplet.png create mode 100644 Systems/CalamityModWaterStyle.cs create mode 100644 Systems/LavaRendering.cs create mode 100644 Systems/ModLavaStyle.cs delete mode 100644 Waters/AstralWaterflow.cs create mode 100644 Waters/CragsLava.cs delete mode 100644 Waters/CragsLavaStyle.cs delete mode 100644 Waters/CustomLavaManagement.cs delete mode 100644 Waters/CustomLavaStyle.cs delete mode 100644 Waters/LiquidTileType.cs delete mode 100644 Waters/MiddleAbyssWaterflow.cs delete mode 100644 Waters/PissWaterflow.cs delete mode 100644 Waters/SulphuricDepthsWaterflow.cs delete mode 100644 Waters/SulphuricWaterflow.cs delete mode 100644 Waters/UpperAbyssWaterflow.cs delete mode 100644 Waters/VoidWaterflow.cs diff --git a/CalPlayer/CalamityPlayer.cs b/CalPlayer/CalamityPlayer.cs index 4feba2595f..8b88bd0563 100644 --- a/CalPlayer/CalamityPlayer.cs +++ b/CalPlayer/CalamityPlayer.cs @@ -45,11 +45,15 @@ using CalamityMod.Projectiles.Ranged; using CalamityMod.Projectiles.Rogue; using CalamityMod.Projectiles.Summon; using CalamityMod.Projectiles.Typeless; +using CalamityMod.Systems; +using CalamityMod.Waters; using CalamityMod.World; using Microsoft.Xna.Framework; using Terraria; using Terraria.Audio; using Terraria.DataStructures; +using Terraria.GameContent; +using Terraria.GameContent.Liquid; using Terraria.GameInput; using Terraria.Graphics.Shaders; using Terraria.ID; diff --git a/CalPlayer/CalamityPlayerMiscEffects.cs b/CalPlayer/CalamityPlayerMiscEffects.cs index 205a777c76..8cad606584 100644 --- a/CalPlayer/CalamityPlayerMiscEffects.cs +++ b/CalPlayer/CalamityPlayerMiscEffects.cs @@ -1021,13 +1021,7 @@ namespace CalamityMod.CalPlayer } } - // Extra DoT in the lava of the crags. Negated by Flame-licked Shell. - if (Player.lavaWet) - { - if (ZoneCalamity && !flameLickedShell) - Player.AddBuff(ModContent.BuffType(), 2, false); - } - else + if (!Player.lavaWet) { if (Player.lavaImmune) { diff --git a/CalamityMod.cs b/CalamityMod.cs index 76f456afca..f61064ace2 100644 --- a/CalamityMod.cs +++ b/CalamityMod.cs @@ -51,6 +51,7 @@ using CalamityMod.Projectiles; using CalamityMod.Projectiles.BaseProjectiles; using CalamityMod.Schematics; using CalamityMod.Skies; +using CalamityMod.Systems; using CalamityMod.UI; using CalamityMod.UI.CalamitasEnchants; using CalamityMod.UI.DraedonsArsenal; @@ -62,6 +63,7 @@ using ReLogic.Content; using Terraria; using Terraria.GameContent; using Terraria.GameContent.Dyes; +using Terraria.GameContent.Liquid; using Terraria.Graphics.Effects; using Terraria.Graphics.Shaders; using Terraria.ID; @@ -111,8 +113,20 @@ namespace CalamityMod // Destroyer glowmasks public static Asset[] DestroyerGlowmasks = new Asset[3]; - // Probe glowmask - public static Asset ProbeGlowmask; + // Holds the Texture Arrays for all the lava textures. + // These are used for the lava styles. They are seperate from Textureasset.Instance._liquidTexture as they will conflict with ModWaterStyle + // Can hold up to 255 lava styles (more than enough) (excluding the normal lava texture which is liquidTexture 1) + public struct LavaTextures + { + public static Asset[] liquid = new Asset[1]; + public static Asset[] slope = new Asset[1]; + public static Asset[] block = new Asset[1]; + public static Asset[] fall = new Asset[1]; + } + + public static int LavaStyle; + + public static float[] lavaAlpha = new float[1]; // Wall of Flesh glowmasks public static Asset WallOfFleshEyeGlowmask; @@ -158,6 +172,7 @@ namespace CalamityMod // Please keep this in alphabetical order so it's easy to read internal Mod ancientsAwakened = null; + internal Mod biomeLava = null; internal Mod bossChecklist = null; internal Mod coloredDamageTypes = null; internal Mod crouchMod = null; @@ -192,6 +207,8 @@ namespace CalamityMod ancientsAwakened = null; ModLoader.TryGetMod("AAMod", out ancientsAwakened); + biomeLava = null; + ModLoader.TryGetMod("BiomeLava", out biomeLava); bossChecklist = null; ModLoader.TryGetMod("BossChecklist", out bossChecklist); coloredDamageTypes = null; @@ -265,7 +282,11 @@ namespace CalamityMod SetupVanillaDR(); SetupBossKillTimes(); SchematicManager.Load(); - CustomLavaManagement.Load(); + + //lava + LavaRendering.instance = new LavaRendering(); + WeakReferenceSupport.LavaStytleToBiomeLava(); + Attunement.Load(); BalancingChangesManager.Load(); BaseIdleHoldoutProjectile.LoadAll(); @@ -300,8 +321,12 @@ namespace CalamityMod DestroyerGlowmasks[1] = ModContent.Request("CalamityMod/ExtraTextures/VanillaBossGlowmasks/DestroyerBodyGlow", AssetRequestMode.AsyncLoad); DestroyerGlowmasks[2] = ModContent.Request("CalamityMod/ExtraTextures/VanillaBossGlowmasks/DestroyerTailGlow", AssetRequestMode.AsyncLoad); - // Probe glowmask - ProbeGlowmask = ModContent.Request("CalamityMod/ExtraTextures/VanillaBossGlowmasks/ProbeGlow", AssetRequestMode.AsyncLoad); + // Lava Texture + LavaTextures.liquid[0] = LiquidRenderer.Instance._liquidTextures[1]; + LavaTextures.slope[0] = TextureAssets.LiquidSlope[1]; + LavaTextures.block[0] = TextureAssets.Liquid[1]; + var waterfallTexture = (Asset[])typeof(WaterfallManager).GetField("waterfallTexture", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(Main.instance.waterfallManager); + LavaTextures.fall[0] = waterfallTexture[1]; // Wall of Flesh glowmasks WallOfFleshEyeGlowmask = ModContent.Request("CalamityMod/ExtraTextures/VanillaBossGlowmasks/WallOfFleshEyeTelegraphGlow", AssetRequestMode.AsyncLoad); @@ -424,6 +449,7 @@ namespace CalamityMod vcmm = null; ancientsAwakened = null; + biomeLava = null; bossChecklist = null; coloredDamageTypes = null; crouchMod = null; @@ -461,7 +487,6 @@ namespace CalamityMod InvasionProgressUIManager.UnloadGUIs(); BossRushEvent.Unload(); SchematicManager.Unload(); - CustomLavaManagement.Unload(); CooldownRegistry.Unload(); PlayerDashManager.Unload(); diff --git a/Dusts/WaterSplash/AstralSplash.cs b/Dusts/WaterSplash/AstralSplash.cs new file mode 100644 index 0000000000..6fcb24f6c3 --- /dev/null +++ b/Dusts/WaterSplash/AstralSplash.cs @@ -0,0 +1,9 @@ +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Dusts.WaterSplash +{ + public class AstralSplash : SplashDust + { + } +} diff --git a/Dusts/WaterSplash/AstralSplash.png b/Dusts/WaterSplash/AstralSplash.png new file mode 100644 index 0000000000000000000000000000000000000000..839409589de316fa0ddb15e103c118f5fdf29ae9 GIT binary patch literal 245 zcmeAS@N?(olHy`uVBq!ia0vp^AhsL_8;}$&?Kc2YjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1quc!7fi1#}EtuWCiXczf%9RCu)eZ8aQS)H3+&K z@R=wq${xtmAGe?7a<{oJ>*;2Oi)xD)R_!QcV7&AD#XJW-DFFq$0~eWRhla8F+_x8435KoHOx`4wXO#n8#o+1c=d#Wzp$PyYv`sGn literal 0 HcmV?d00001 diff --git a/Dusts/WaterSplash/CragsLavaSplash.cs b/Dusts/WaterSplash/CragsLavaSplash.cs new file mode 100644 index 0000000000..907f65c969 --- /dev/null +++ b/Dusts/WaterSplash/CragsLavaSplash.cs @@ -0,0 +1,178 @@ +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics.PackedVector; +using System; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Dusts.WaterSplash +{ + public class CragsLavaSplash : ModDust + { + public override void OnSpawn(Dust dust) + { + dust.velocity *= 0.1f; + dust.velocity.Y = -0.5f; + } + + public override bool Update(Dust dust) + { + if (dust.scale > 10f) + { + dust.active = false; + } + Dust.lavaBubbles++; + dust.position += dust.velocity; + if (!dust.noGravity) + { + dust.velocity.Y += 0.1f; + } + if (dust.noGravity) + { + dust.scale += 0.03f; + if (dust.scale < 1f) + { + dust.velocity.Y += 0.075f; + } + dust.velocity.X *= 1.08f; + if (dust.velocity.X > 0f) + { + dust.rotation += 0.01f; + } + else + { + dust.rotation -= 0.01f; + } + float num109 = dust.scale * 0.6f; + if (num109 > 1f) + { + num109 = 1f; + } + Lighting.AddLight((int)(dust.position.X / 16f), (int)(dust.position.Y / 16f + 1f), num109 * (2.5f / 4), num109 * (1.1f / 4), num109 * (0.1f / 4)); + } + else + { + if (!Collision.WetCollision(new Vector2(dust.position.X, dust.position.Y - 8f), 4, 4)) + { + dust.scale = 0f; + } + else + { + dust.alpha += Main.rand.Next(2); + if (dust.alpha > 255) + { + dust.scale = 0f; + } + dust.velocity.Y = -0.5f; + dust.alpha++; + dust.scale -= 0.01f; + dust.velocity.Y = -0.2f; + dust.velocity.X += (float)Main.rand.Next(-10, 10) * 0.002f; + if ((double)dust.velocity.X < -0.25) + { + dust.velocity.X = -0.25f; + } + if ((double)dust.velocity.X > 0.25) + { + dust.velocity.X = 0.25f; + } + } + float num3 = dust.scale * 0.3f + 0.4f; + if (num3 > 1f) + { + num3 = 1f; + } + Lighting.AddLight((int)(dust.position.X / 16f), (int)(dust.position.Y / 16f), num3 * (2.5f / 4), num3 * (1.1f / 4), num3 * (0.1f / 4)); + } + dust.rotation += dust.velocity.X * 0.5f; + if (dust.fadeIn > 0f && dust.fadeIn < 100f) + { + dust.scale += 0.03f; + if (dust.scale > dust.fadeIn) + { + dust.fadeIn = 0f; + } + } + dust.scale -= 0.01f; + if (dust.noGravity) + { + dust.velocity *= 0.92f; + if (dust.fadeIn == 0f) + { + dust.scale -= 0.04f; + } + } + if (dust.position.Y > Main.screenPosition.Y + (float)Main.screenHeight) + { + dust.active = false; + } + float num17 = 0.1f; + if ((double)Dust.dCount == 0.5) + { + dust.scale -= 0.001f; + } + if ((double)Dust.dCount == 0.6) + { + dust.scale -= 0.0025f; + } + if ((double)Dust.dCount == 0.7) + { + dust.scale -= 0.005f; + } + if ((double)Dust.dCount == 0.8) + { + dust.scale -= 0.01f; + } + if ((double)Dust.dCount == 0.9) + { + dust.scale -= 0.02f; + } + if ((double)Dust.dCount == 0.5) + { + num17 = 0.11f; + } + if ((double)Dust.dCount == 0.6) + { + num17 = 0.13f; + } + if ((double)Dust.dCount == 0.7) + { + num17 = 0.16f; + } + if ((double)Dust.dCount == 0.8) + { + num17 = 0.22f; + } + if ((double)Dust.dCount == 0.9) + { + num17 = 0.25f; + } + if (dust.scale < num17) + { + dust.active = false; + } + return false; + } + + public override Color? GetAlpha(Dust dust, Color lightColor) + { + float num = (float)(255 - dust.alpha) / 255f; + int num4; + int num3; + int num2; + num = (num + 3f) / 4f; + num4 = (int)((int)lightColor.R * num); + num3 = (int)((int)lightColor.G * num); + num2 = (int)((int)lightColor.B * num); + int num6 = lightColor.A - dust.alpha; + if (num6 < 0) + { + num6 = 0; + } + if (num6 > 255) + { + num6 = 255; + } + return new Color(num4, num3, num2, num6); + } + } +} diff --git a/Dusts/WaterSplash/CragsLavaSplash.png b/Dusts/WaterSplash/CragsLavaSplash.png new file mode 100644 index 0000000000000000000000000000000000000000..dbe3be3c6521acbe9775d793b32377ed8913c8cb GIT binary patch literal 275 zcmeAS@N?(olHy`uVBq!ia0vp^AhsL_8;}$&?Kc2YjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1quc!4;k^jv*HQ$qLecX4=2D=WyOxaDZhgCzG27 zuNkL{@$20UKkN11F<#c`%uFzKnccytQTCXDsp3P!f%koCBK{k~t{i;Y`HhFWqhaQe zlq9Z25;Iz^9Q=~c#p9`V}@F9tJKg_o~{A S*yBJqGkCiCxvXW?|m| literal 0 HcmV?d00001 diff --git a/Dusts/WaterSplash/MiddleAbyssSplash.cs b/Dusts/WaterSplash/MiddleAbyssSplash.cs new file mode 100644 index 0000000000..319e596446 --- /dev/null +++ b/Dusts/WaterSplash/MiddleAbyssSplash.cs @@ -0,0 +1,9 @@ +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Dusts.WaterSplash +{ + public class MiddleAbyssSplash : SplashDust + { + } +} diff --git a/Dusts/WaterSplash/MiddleAbyssSplash.png b/Dusts/WaterSplash/MiddleAbyssSplash.png new file mode 100644 index 0000000000000000000000000000000000000000..b368be985f32cf9e98dc60970db5a51da2b7bdd8 GIT binary patch literal 246 zcmeAS@N?(olHy`uVBq!ia0vp^AhsL_8;}$&?Kc2YjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1quc!ER3%#}EtuWCiYsERBEci5lXp29B9c4T3HQ zd>%f3$QH;WzrTj{^6~sT?5CRK7UPMWb0o2ui0QqHNQ zFjHxvGS?!BxR^@bW&T!X4Nn~#GK2#eLho2KFubcR@mFBy4)`=a6^$s#6FJ+) lE?9ZcS=5|QA|Zi+!EcNCovJ<8{eZ4w@O1TaS?83{1OSnNPXYh{ literal 0 HcmV?d00001 diff --git a/Dusts/WaterSplash/SunkenSeaSplash.cs b/Dusts/WaterSplash/SunkenSeaSplash.cs new file mode 100644 index 0000000000..3c0e44605e --- /dev/null +++ b/Dusts/WaterSplash/SunkenSeaSplash.cs @@ -0,0 +1,9 @@ +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Dusts.WaterSplash +{ + public class SunkenSeaSplash : SplashDust + { + } +} diff --git a/Dusts/WaterSplash/SunkenSeaSplash.png b/Dusts/WaterSplash/SunkenSeaSplash.png new file mode 100644 index 0000000000000000000000000000000000000000..4872767ad68c3b3d8eea2faf1231c3eee743684a GIT binary patch literal 241 zcmeAS@N?(olHy`uVBq!ia0vp^AhsL_8;}$&?Kc2YjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1quc!8T79#}EtuWCiXQXXF0Lw=9eiIl!`%lgUkh z(fH}4m0BH17p!Zged4`%Sx+}JTvS`cuxdvk1LK|FFXlP$NeL*}9k|Fm+tH29=jGb_ z{L2#6gmaag6i=uK)O})Uy2$V`ujSH}&tDfXitGJhPu6KT@}O}R(|PR;FH8&?*ac@E hbmleZlSoKlV6c)gNeNyb@D}JI22WQ%mvv4FO#rA^Oz;2z literal 0 HcmV?d00001 diff --git a/Dusts/WaterSplash/UpperAbyssSplash.cs b/Dusts/WaterSplash/UpperAbyssSplash.cs new file mode 100644 index 0000000000..715e5467b6 --- /dev/null +++ b/Dusts/WaterSplash/UpperAbyssSplash.cs @@ -0,0 +1,9 @@ +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Dusts.WaterSplash +{ + public class UpperAbyssSplash : SplashDust + { + } +} diff --git a/Dusts/WaterSplash/UpperAbyssSplash.png b/Dusts/WaterSplash/UpperAbyssSplash.png new file mode 100644 index 0000000000000000000000000000000000000000..09400057b85ffca08f366382000d31bf717193ad GIT binary patch literal 245 zcmeAS@N?(olHy`uVBq!ia0vp^AhsL_8;}$&?Kc2YjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1quc!7fi1#}EtuWCiXGF7E%>6E(zH4IDF@8U$Sq z_#{r6#1hE!f1WM-<@#xQ?5CRd=xWr=SM|U}vu6+LbAkz)6?tje&Q@WWvxaDSOZrH=reJ=iP n?FR)V{fZTjjxjRx@GumvGF-90@cK=ls~9|8{an^LB{Ts5XAx5v literal 0 HcmV?d00001 diff --git a/Dusts/WaterSplash/VoidSplash.cs b/Dusts/WaterSplash/VoidSplash.cs new file mode 100644 index 0000000000..0e046fa962 --- /dev/null +++ b/Dusts/WaterSplash/VoidSplash.cs @@ -0,0 +1,9 @@ +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod.Dusts.WaterSplash +{ + public class VoidSplash : SplashDust + { + } +} diff --git a/Dusts/WaterSplash/VoidSplash.png b/Dusts/WaterSplash/VoidSplash.png new file mode 100644 index 0000000000000000000000000000000000000000..3177c26e7c41530ecc11eb2f3cabdd6bffb34d80 GIT binary patch literal 246 zcmeAS@N?(olHy`uVBq!ia0vp^AhsL_8;}$&?Kc2YjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1quc!ER3%#}EtuWCd=Hf)jt)6E(zH4IDF@8U$Sq z_&gK{V+-W5zju%IvV5Hl)9Gf0i)xD)R_!QcV7&AD#XJW-DFFq$0~eX29Rg&1_V3ut z>vPyg?Uu_9rwN`4e;)qzHE?4;vRlwA`26)|Ru2#Be_+!mh}jqfCseYE&DEdxuAN=5 i@}RS*IiEyA0s}+6q3#|vyGoFM7(8A5T-G@yGywn(97;w2 literal 0 HcmV?d00001 diff --git a/Gores/AstralWaterDroplet.cs b/Gores/AstralWaterDroplet.cs deleted file mode 100644 index 0022de1b56..0000000000 --- a/Gores/AstralWaterDroplet.cs +++ /dev/null @@ -1,167 +0,0 @@ -using Microsoft.Xna.Framework; -using Terraria; -using Terraria.Audio; -using Terraria.DataStructures; -using Terraria.GameContent; -using Terraria.GameContent.Shaders; -using Terraria.Graphics.Effects; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Gores -{ - public class AstralWaterDroplet : ModGore - { - public override void SetStaticDefaults() - { - ChildSafety.SafeGore[Type] = true; - } - - public override void OnSpawn(Gore gore, IEntitySource source) - { - gore.numFrames = 15; - gore.behindTiles = true; - gore.timeLeft = Gore.goreTime * 3; - } - - public override bool Update(Gore gore) - { - if ((double)gore.position.Y < Main.worldSurface * 16.0 + 8.0) - { - gore.alpha = 0; - } - else - { - gore.alpha = 100; - } - int goreFrameDelay = 4; - gore.frameCounter++; - if (gore.frame <= 4) - { - int goreXPos = (int)(gore.position.X / 16f); - int goreYPos = (int)(gore.position.Y / 16f) - 1; - if (WorldGen.InWorld(goreXPos, goreYPos, 0) && !Main.tile[goreXPos, goreYPos].HasTile) - { - gore.active = false; - } - if (gore.frame == 0) - { - goreFrameDelay = 24 + Main.rand.Next(256); - } - if (gore.frame == 1) - { - goreFrameDelay = 24 + Main.rand.Next(256); - } - if (gore.frame == 2) - { - goreFrameDelay = 24 + Main.rand.Next(256); - } - if (gore.frame == 3) - { - goreFrameDelay = 24 + Main.rand.Next(96); - } - if (gore.frame == 5) - { - goreFrameDelay = 16 + Main.rand.Next(64); - } - if ((int)gore.frameCounter >= goreFrameDelay) - { - gore.frameCounter = 0; - gore.frame += 1; - if (gore.frame == 5 && Main.netMode != NetmodeID.Server) - { - int astralWater = Gore.NewGore(new EntitySource_Misc("0"), gore.position, gore.velocity, gore.type, 1f); - Main.gore[astralWater].frame = 9; - Main.gore[astralWater].velocity *= 0f; - } - } - } - else if (gore.frame <= 6) - { - goreFrameDelay = 8; - if ((int)gore.frameCounter >= goreFrameDelay) - { - gore.frameCounter = 0; - gore.frame += 1; - if (gore.frame == 7) - { - gore.active = false; - } - } - } - else if (gore.frame <= 9) - { - goreFrameDelay = 6; - gore.velocity.Y += 0.2f; - if ((double)gore.velocity.Y < 0.5) - { - gore.velocity.Y = 0.5f; - } - if (gore.velocity.Y > 12f) - { - gore.velocity.Y = 12f; - } - if ((int)gore.frameCounter >= goreFrameDelay) - { - gore.frameCounter = 0; - gore.frame += 1; - } - if (gore.frame > 9) - { - gore.frame = 7; - } - } - else - { - gore.velocity.Y += 0.1f; - if ((int)gore.frameCounter >= goreFrameDelay) - { - gore.frameCounter = 0; - gore.frame += 1; - } - gore.velocity *= 0f; - if (gore.frame > 14) - { - gore.active = false; - } - } - - Vector2 goreVelCheck = gore.velocity; - gore.velocity = Collision.TileCollision(gore.position, gore.velocity, 16, 14, false, false, 1); - if (gore.velocity != goreVelCheck) - { - if (gore.frame < 10) - { - gore.frame = 10; - gore.frameCounter = 0; - if (gore.type != 716 && gore.type != 717 && gore.type != 943) - { - SoundEngine.PlaySound(SoundID.Drip, gore.position + Vector2.One * 8); - } - } - } - else if (Collision.WetCollision(gore.position + gore.velocity, 16, 14)) - { - if (gore.frame < 10) - { - gore.frame = 10; - gore.frameCounter = 0; - if (gore.type != 716 && gore.type != 717 && gore.type != 943) - { - SoundEngine.PlaySound(SoundID.Drip, gore.position + Vector2.One * 8); - } - ((WaterShaderData)Filters.Scene["WaterDistortion"].GetShader()).QueueRipple(gore.position + new Vector2(8f, 8f), 1f, RippleShape.Square, 0f); - } - int goreTileX = (int)(gore.position.X + 8f) / 16; - int goreTileY = (int)(gore.position.Y + 14f) / 16; - if (Main.tile[goreTileX, goreTileY] != null && Main.tile[goreTileX, goreTileY].LiquidAmount > 0) - { - gore.velocity *= 0f; - gore.position.Y = (float)(goreTileY * 16 - (int)(Main.tile[goreTileX, goreTileY].LiquidAmount / 16)); - } - } - - return true; - } - } -} diff --git a/Gores/WaterDroplet/AstralWaterDroplet.cs b/Gores/WaterDroplet/AstralWaterDroplet.cs new file mode 100644 index 0000000000..0add03de05 --- /dev/null +++ b/Gores/WaterDroplet/AstralWaterDroplet.cs @@ -0,0 +1,6 @@ +namespace CalamityMod.Gores.WaterDroplet +{ + public class AstralWaterDroplet : LiquidDropletGore + { + } +} diff --git a/Gores/AstralWaterDroplet.png b/Gores/WaterDroplet/AstralWaterDroplet.png similarity index 100% rename from Gores/AstralWaterDroplet.png rename to Gores/WaterDroplet/AstralWaterDroplet.png diff --git a/Gores/WaterDroplet/CragsLavaDroplet.cs b/Gores/WaterDroplet/CragsLavaDroplet.cs new file mode 100644 index 0000000000..3841f789d3 --- /dev/null +++ b/Gores/WaterDroplet/CragsLavaDroplet.cs @@ -0,0 +1,11 @@ +using Microsoft.Xna.Framework; + +namespace CalamityMod.Gores.WaterDroplet +{ + public class CragsLavaDroplet : LiquidDropletGore + { + public override bool lavaDroplet => true; + + public override Vector3 lavaColor => new Vector3(2.5f, 1.1f, 0.1f); + } +} diff --git a/Gores/WaterDroplet/CragsLavaDroplet.png b/Gores/WaterDroplet/CragsLavaDroplet.png new file mode 100644 index 0000000000000000000000000000000000000000..5a62700a83a1a65835a35a29cd3f183d1c34cf5b GIT binary patch literal 972 zcmV;-12g=IP)Px&g-Jv~RCr$PT)UOjKoFGp!~o7^0U6*B1`aV`VVp$_ID~;i29U)$5Cd?_JKfd1 zw>9)t&!}fV+Fobh?zT#;n(6AE9%<)4Uq0`qX_|Jwe%`&gU-OHXi|w;_@8`SsISk0{ zf-qd%ig+cEW-&QRjx+<>BIl8VqcEur1G1dP3Gh3zg=KFJe;AOaci$o>q-HERN{%!G z+G5M|hy_g5+o-Q$_x!`h{W=?Tb_4Nv{QdTISqa?!_`dfOSNeQhHELl%I1>Qz`RSXt zk4_cy$1os0motkbM}>hc3tQ_jH*Z&m1Zlgwl1{*!NBX8rQL<2Fd+79 zzPehzLN;m6BJgZA5POzuktr@jT7&b9qCYQ9GH`3 z0~A_b(LdapmOWA)N~uLibOW)lb<4;wpyO+HYqLd;T6lsyel_BiSQ%^KKw63JEiPHJ zm3$n2)P8@uUhe(tj()hj8tC++zgx5U(l!J%tYGh+kX%=*n3I)13iNIubs#IJ%xh|y z?v|0%?2ArEIs6A0{;*rmn}MuVklN1Rowi?JQ8}7W;3V6v&2rpO3k!C76a&QFMfX?u3 zjDUcqBT4Xab2t!$%*rOL*{qnwqt!s%O!4M5F675OouLQ%{}ve{nz`gCInoShi*fVF z>OiQ@MCH+HAim=ll|5$>e3lAX3h;-=&fGvqM^%;jaA$7;GX5W_Jen5UKDdR!j27(Z&Q9;Qc{vE(Q@ u(hO*eOPWX4^CQh0zF|Omd literal 0 HcmV?d00001 diff --git a/Gores/WaterDroplet/LiquidDropletGore.cs b/Gores/WaterDroplet/LiquidDropletGore.cs new file mode 100644 index 0000000000..f99d0b6c4b --- /dev/null +++ b/Gores/WaterDroplet/LiquidDropletGore.cs @@ -0,0 +1,201 @@ +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.Audio; +using Terraria.DataStructures; +using Terraria.GameContent; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Gores.WaterDroplet +{ + public abstract class LiquidDropletGore : ModGore + { + public virtual bool lavaDroplet => false; + + public virtual Vector3 lavaColor => new Vector3(0, 0, 0); + + public override void SetStaticDefaults() + { + ChildSafety.SafeGore[Type] = true; + } + + public override void OnSpawn(Gore gore, IEntitySource source) + { + gore.numFrames = 15; + gore.behindTiles = true; + gore.timeLeft = Gore.goreTime * 3; + } + + public override bool Update(Gore gore) + { + gore.alpha = gore.position.Y < (Main.worldSurface * 16.0) + 8.0 + ? 0 + : 100; + + int frameDuration = 4; + gore.frameCounter += 1; + if (gore.frame <= 4) + { + int tileX = (int)(gore.position.X / 16f); + int tileY = (int)(gore.position.Y / 16f) - 1; + if (WorldGen.InWorld(tileX, tileY) && !Main.tile[tileX, tileY].HasTile) + { + gore.active = false; + } + + if (gore.frame == 0 || gore.frame == 1 || gore.frame == 2) + { + frameDuration = 24 + Main.rand.Next(256); + } + + if (gore.frame == 3) + { + frameDuration = 24 + Main.rand.Next(96); + } + + if (gore.frameCounter >= frameDuration) + { + gore.frameCounter = 0; + gore.frame += 1; + if (gore.frame == 5) + { + int droplet = Gore.NewGore(new EntitySource_Misc("0"), gore.position, gore.velocity, gore.type); + Main.gore[droplet].frame = 9; + Main.gore[droplet].velocity *= 0f; + } + } + } + else if (gore.frame <= 6) + { + frameDuration = 8; + if (gore.frameCounter >= frameDuration) + { + gore.frameCounter = 0; + gore.frame += 1; + if (gore.frame == 7) + { + gore.active = false; + } + } + } + else if (gore.frame <= 9) + { + frameDuration = 6; + gore.velocity.Y += 0.2f; + if (gore.velocity.Y < 0.5f) + { + gore.velocity.Y = 0.5f; + } + + if (gore.velocity.Y > 12f) + { + gore.velocity.Y = 12f; + } + + if (gore.frameCounter >= frameDuration) + { + gore.frameCounter = 0; + gore.frame += 1; + } + + if (gore.frame > 9) + { + gore.frame = 7; + } + } + else + { + gore.velocity.Y += 0.1f; + if (gore.frameCounter >= frameDuration) + { + gore.frameCounter = 0; + gore.frame += 1; + } + + gore.velocity *= 0f; + if (gore.frame > 14) + { + gore.active = false; + } + } + + if (lavaDroplet) + { + float num24 = 1f; + float num25 = 1f; + float num26 = 1f; + float num27 = 0.6f; + num27 *= gore.frame switch + { + 0 => 0.1f, + 1 => 0.2f, + 2 => 0.3f, + 3 => 0.4f, + 4 => 0.5f, + 5 => 0.4f, + 6 => 0.2f, + 7 => 0.5f, + 8 => 0.5f, + 9 => 0.5f, + 10 => 0.5f, + 11 => 0.4f, + 12 => 0.3f, + 13 => 0.2f, + 14 => 0.1f, + _ => 0.0f, + }; + num24 = (lavaColor.X / 4) * num27; //R + num25 = (lavaColor.Y / 4) * num27; //G + num26 = (lavaColor.Z / 4) * num27; //B + Lighting.AddLight(gore.position + new Vector2(8f, 8f), num24, num25, num26); + } + + Vector2 oldVelocity = gore.velocity; + gore.velocity = Collision.TileCollision(gore.position, gore.velocity, 16, 14); + if (gore.velocity != oldVelocity) + { + if (gore.frame < 10) + { + gore.frame = 10; + gore.frameCounter = 0; + if (!lavaDroplet) + { + SoundEngine.PlaySound(SoundID.Drip, gore.position + new Vector2(8, 8)); + } + } + } + else if (Collision.WetCollision(gore.position + gore.velocity, 16, 14)) + { + if (gore.frame < 10) + { + gore.frame = 10; + gore.frameCounter = 0; + if (!lavaDroplet) + { + SoundEngine.PlaySound(SoundID.Drip, gore.position + new Vector2(8, 8)); + } + } + + int tileX = (int)(gore.position.X + 8f) / 16; + int tileY = (int)(gore.position.Y + 14f) / 16; + if (Main.tile[tileX, tileY] != null && Main.tile[tileX, tileY].LiquidAmount > 0) + { + gore.velocity *= 0f; + gore.position.Y = (tileY * 16) - (Main.tile[tileX, tileY].LiquidAmount / 16); + } + } + + gore.position += gore.velocity; + return false; + } + + public override Color? GetAlpha(Gore gore, Color lightColor) + { + if (lavaDroplet) + { + return new Color(255, 255, 255, 200); + } + return null; + } + } +} diff --git a/Gores/WaterDroplet/MiddleAbyssWaterDroplet.cs b/Gores/WaterDroplet/MiddleAbyssWaterDroplet.cs new file mode 100644 index 0000000000..73728d4332 --- /dev/null +++ b/Gores/WaterDroplet/MiddleAbyssWaterDroplet.cs @@ -0,0 +1,6 @@ +namespace CalamityMod.Gores.WaterDroplet +{ + public class MiddleAbyssWaterDroplet : LiquidDropletGore + { + } +} diff --git a/Gores/WaterDroplet/MiddleAbyssWaterDroplet.png b/Gores/WaterDroplet/MiddleAbyssWaterDroplet.png new file mode 100644 index 0000000000000000000000000000000000000000..235b55d951b1b65e308de210fae2ce0459fc2a42 GIT binary patch literal 939 zcmV;c162HpP)Px&Wl2OqRCr$Po3U;bF%X7#Ya$Rr5u%_#NHK)6s{dfF({Lk2H&lj&>-AvOoefx2J`{n+eK7G8{zW?}XzWtuV zfZQ&C;o?@rCxMv7-t7J`Af|V1kpan!B}d5- zGr$&y97kHfsNR#Ic-NBsnS!9I~+0c5`*IiJ+rjCa1;il zJ$rKUX!%RBNp%(x&$@xMXE_&{;)Y1=;M}9ppG`vs28^Te>ui!-5qqq&!+@-;VtFF= zxLTtpFYeKAHLW>|=*-&;)SZqpuWh1WKp8>la~fpRn5gpVP)w;z{{L$uXV0H4Ya{wo zEhAw-;)wu~C#c!sK$Jb)9(4nW@cA0wZgz2X!dwjt=8;r zVH3^n2Fl33i|kr1+>@GC;A0g3TCS2KW-K}C;3!OL!-1qxlmyJ~*K?9;AU$=^^Eda3 zRv1vOANdzq!nRh00r4=++0nQhc?AyBQ8!Sxu<3%mS!%6i9|GKP6b_`<(waT$1`1mk zKVTp|rkBd=$uM+Xe#T_Qt{!hpQmjUIIaS+%6Qs#3xT|onRpl)k3FBLVXUYG_4zmj!+5BS~+D^51X8HfsVQqXejEF4Il zZ0%a5HMf#Qx`A|k%@On0LgzVCvkA}yq8sUYj(%cj%7buBQF3(T9C`DZrb*vdR%Px&YDq*vRCr$Po3U;bF%X7#3nZFIP^Ctckx*VIMP7g!8XkZKYF>bX*FljeqtvND zqCuhnWziVz>`lJ0JrLjBTywhH*?-5s$N!AI_I&pK<*#X)rXROo@4noh$EQyh+b^#^ z%y-{&7?9fqFkIY<_#_asm>eZX%m7C(*1G%@y#+5_x}+<8ecz_n!hqyS z0w}*fU%tIJRLqNEKpe}NMUtb!z#$7;Z8uk!ezgyXBfGUc7LPZYOU&~c;#Ed0J9UO&8Z8(rLijsiY{d!JP4Wy?I zdj95K(Fy~~^&|fxOW4+`Fd!bLIXfDcBd@?=I_d`M7B*e5H%qOx>_dPXj>3WTT3WM5 z-9TXr;|C0+=d|*hR<`g>O*hcEdgS#C_2__syh~)rQ5cX{yV0X=Agh*iSGCqcRI}7t zf#~)qvj~^RVObFlB48^8DNWyqle^Zyd9d%#%_zSIQk7_!9`k7 T?RPN%0000Px&Y)M2xRCr$Po3U;bF%X7#X^>C~M1%4K6jUi9YTkmUpr=cho~Pg~s1XGf1y2ys zL@5vw4WKL-FuI`*ZU2$zuEA z<;8saJ%<6gT>!(yt%y$oF^kDja>NXe8?F0dZuvmdE1pMzcw)t)>fOENpeN(vCa+y zva*WhiP+<6jh?)?N59py<}9K!Z!=JLI?BAZiGl%T1f|bukWFKv%Bw>$r84>duZ=u^ z_j*|y(VuD=2?G*O1du#I%?<~m?BVvP8%QLV-aep5VL&`6))vPoBVlBR0cEch2KGR+ z$E#|!W_JslXm&SHM)u#xuI0i#sc8j1M)9xZDmh}tlA{ie!lX7FNE$^+!0diKC#eR~ zQwKeNbFXNH0p`%$gADxQ8$oPOS-FCYayyx zYOO$Ydz4v(%j2*tlA6tAd!<#|;pq1QClE8WM;v+6kTe?WBPy^E$UB*d2eP=J7ry$w z^2$eZQ4J*9@E_d#Seom7-!FS_WdHvh1|+N#piFYKC!1ai1JYB_N6$`IBUSd-R_Fe1 zAQp_>7JDQkwN1>XF=GRBqzA1QI$aX#b4aCW-9U7NN@&)~DT8{Wkk+9tH;|RT^z2CM zkiKsY1Ja=uwjH(`h^Cx$y~Gh2()EGI8VkkU7TGjrFgdypjzqiZl&WR7$s)}_RG5>3 zmSbn(K=Nd3*D9^Kl`PT?r0Z*rm_HUe&zYJ{fF=;#NY``p6GKxTgky@5qa)|Yo6j^& z`o6MSL-`DW#DEHQN)G?-6tp8`cABJSGjqvNa>NXPx&e@R3^RCr$Pn?X+9Kn#WxsaIf67u_Nj4oi49Id?9w67HT3Ghx^oId4y-SM>NMUtYc$ zD)z-NAP(k*#VJR2BNe83a>Ps~NAJne+V)s{tTdan+8SH|5(BSimUfpo3Io!f?an?; z|B`CbTt&pQZXoShu0@8Fk@u7lewNQ7XN`F(+tA(ZaahByohHc@vBy3;49Kb~mM3D5 zyES_8V$EL#WDRX~715Pl(erz@d=`So>Q6j?kl=wKB=6+5h6*+!(h~ zLids+Cz$=KyIQT;+PL7zlO3Iodhqbg^xt&uxuadUVe&iAFo;j=$I@~=g_0*ABK4b&}c zx?x`}wbr%|0ahG^1L@_|YLB{s!ZyZF7)WL(>^N)~P%5NfA-!CoLWTi(_u9~-Fd(mX zqetC9Rxj!9YIV|fx5w7ByFJP(!tHTb6-muzvb{p4?J)bjzzM`m9T7*~G9-h>H7zZQ z5y-oki3hT{pclUSzH+ombI}Ym%*XJrpZ`q5rDL(>-S&K@bePZok8wakJ9uV!QqNi# z&W~7Ky)Kr z&+I3LhWrqYDN2t1caFUEO!K7fE4wvV&k$%fphlgFLs7^uAV;WVSKCQa)-@(DIZBS0 o0k$|?9BuD}CbO~MB8;QI5rZ*W53^4g00000NkvXXu0mjf0CeZZQvd(} literal 0 HcmV?d00001 diff --git a/Gores/WaterDroplet/UpperAbyssWaterDroplet.cs b/Gores/WaterDroplet/UpperAbyssWaterDroplet.cs new file mode 100644 index 0000000000..52d68f19ea --- /dev/null +++ b/Gores/WaterDroplet/UpperAbyssWaterDroplet.cs @@ -0,0 +1,6 @@ +namespace CalamityMod.Gores.WaterDroplet +{ + public class UpperAbyssWaterDroplet : LiquidDropletGore + { + } +} diff --git a/Gores/WaterDroplet/UpperAbyssWaterDroplet.png b/Gores/WaterDroplet/UpperAbyssWaterDroplet.png new file mode 100644 index 0000000000000000000000000000000000000000..1b6552138efad6107cb3ecb2334bcbf8d03b26e7 GIT binary patch literal 942 zcmV;f15x~mP)Px&XGugsRCr$Po8OHTF$~6M;0{CsNbqze&;$+ehUfz6sz9O(bZ<0pOgDfgnx@mwU$4L1pYM+!F1A13UCh_t za~P1@1u$IPiufcDvzQzuN6Y|QWE?p-3X|F}Aj@fafLxbsVcDDA9|pwqt}QYknX%+3 zIbsIb;*jG=3mDbgQeTVRm&^C-I$P*$2GafU;QaM66S#l%VRcDY`ue_2uZ020lLSzH ze|z)x)=)7oh5>ObXBJ703Im5MY_;87UHa8NAdc+T@>o3HXf|oJ)zktc242rB?JgXJ z0cp?fJ$34K-#mMi%fAtq;_!b(df^nAp--((fD;XNv?=J*4be|R#ve* z5qn&%(UTYV=(n2IoJDlzZ3gO2N14|)Q81v4p!7KnvT00Id37kJR3`ubwUI~9Uo2}Q z`co|| z>~3Kb&F%)u$o?DIwOqI-HLbwMDE_rvB}dFya@4_5nAC;?NuwwUnBA}EB-KEA>Y(Ru z?iH;tpjISlENq1FiEkrd-trduF zk1~sJc^sBSQnQ(Cue54A9Q|J41Y)N4h$C+rl15{FL0SW5_D3cuR$)?xBfbZ4H3-@=Eg$jIa9L<&;+6z>3WWSVra^Pa7ee-&a;^ zD4!va7*L^3$>HCff_8+=PLtGZW-d8Oj+gg-e$!zSl2#cdX1Fkh%RA<9| Q00000NkvXXu0mjf048d~(f|Me literal 0 HcmV?d00001 diff --git a/Gores/WaterDroplet/VoidWaterDroplet.cs b/Gores/WaterDroplet/VoidWaterDroplet.cs new file mode 100644 index 0000000000..daf1abf2d7 --- /dev/null +++ b/Gores/WaterDroplet/VoidWaterDroplet.cs @@ -0,0 +1,6 @@ +namespace CalamityMod.Gores.WaterDroplet +{ + public class VoidWaterDroplet : LiquidDropletGore + { + } +} diff --git a/Gores/WaterDroplet/VoidWaterDroplet.png b/Gores/WaterDroplet/VoidWaterDroplet.png new file mode 100644 index 0000000000000000000000000000000000000000..caa2b6f97a5139da1c6d6d4d26c01a561a5e6c0a GIT binary patch literal 939 zcmV;c162HpP)Px&Wl2OqRCr$Po3U;bF%X7#yOcp`A|cU$loWZ1v^)uq#FNnS5)>ej1_>!ml$7Z} zSu{pFdy{W$55#vj*PQNl_TTaE@jqj)J)gh6{xwb0^mupk^yU7XoV{IaZ-0KCpT6fX zAh!!(xVRPZNg!r1IZBS00k+6Ea&QzTwP8S()A9hhF4@AeH@iO!i0NHhWI!@w$x(8| z46wx^$B`B=s<)-S7Q2VXAL}|>=xhek{c(BqVVMcse*d((q$_=W-=^2XfaFO6D8Ijc z`S@(8m>0uVuBu9mTLl(B$Zmur3Sn zXQ!_&mcJyMRA&+KtQ$ysmUEFQZiv(l&OI9a*)(Kez&IMe&L+tfvBx?)49LnVmM3D5 zt2KJ^;vW50)0(r0&b-Y)-RUUv+9nDHlo6CZr$IK2i7KxS#gxkA|GzeJdh%vj8_}O? z83_XtPXv%WLCp>aqU_=Js2fNmm)<_0M`1ubDApFoC?jEHhXG};6$bV|v&XAywPtq< zn`m}7P)7FO$gbtWJ*jC0K1T7c4oi97q~PNxYTll7?8)#fT@_L4PbihE~B{JkF49Kh9=utP2RZF_7T5BPyS!%67bbFLp zgv;ZwERvedWP7Dm+u`W<0w)kNwMQIz(~vY8>mw?#5Xd{3i3hT{pclUSzVgaPb5RW> z+wdRmzb(!6zVDa4H?seK4g(U_2~Z|E+LKMMg#qa)==r<%tC1@EYpZjAHxLWPZi_vV zk=iC^)0nY=Inskx3!N?r^*N-{v~D0eLM1e7<&;6aQAq1hmmA2+UwU?=bx7YghXLtO z3)>Fc4MbB;x?bXl4C(s7V~vI4d5dfsGngE`1V^IXbV}8-+hmbuAS%pBLCdkTa3FcI zwQH5u+)5Vd2GaF4N6a4!o##x=CO{L2Zlvou`iY?_55h4;$>zhbFVJ+afHEegpG7MOra&vMm4r N002ovPDHLkV1ghiv4sEt literal 0 HcmV?d00001 diff --git a/ILEditing/ILChangesLoading.cs b/ILEditing/ILChangesLoading.cs index 3ed952106c..54225d3926 100644 --- a/ILEditing/ILChangesLoading.cs +++ b/ILEditing/ILChangesLoading.cs @@ -44,12 +44,6 @@ namespace CalamityMod.ILEditing On_Main.DrawCursor += UseCoolFireCursorEffect; On_Main.SortDrawCacheWorms += DrawFusableParticles; On_Main.DrawInfernoRings += DrawForegroundParticles; - On_TileDrawing.DrawPartialLiquid += DrawCustomLava; - On_WaterfallManager.DrawWaterfall_int_int_int_float_Vector2_Rectangle_Color_SpriteEffects += DrawCustomLavafalls; - On_Main.RenderWater += CacheLavaStyle; - IL_LiquidRenderer.DrawNormalLiquids += ChangeWaterQuadColors; - IL_Main.oldDrawWater += DrawCustomLava3; - On_TileLightScanner.GetTileLight += MakeSulphSeaWaterBetter; On_TileDrawing.PreDrawTiles += ClearForegroundStuff; On_TileDrawing.Draw += ClearTilePings; On_CommonCode.ModifyItemDropFromNPC += ColorBlightedGel; @@ -94,6 +88,45 @@ namespace CalamityMod.ILEditing // Mana Burn (Chaos Stone) and Chalice of the Blood God IL_Player.ApplyLifeAndOrMana += ManaSicknessAndChaliceBufferHeal; + //LavaStyles + if (CalamityMod.Instance.biomeLava == null) + { + //Rendering/Drawing + IL_Main.DoDraw += DoDrawLavas; + IL_Main.RenderWater += RenderLavas; + IL_Main.RenderBackground += RenderLavaBackgrounds; + IL_Main.DrawCapture += DrawLavatoCapture; + IL_TileDrawing.Draw += AddTileLiquidDrawing; + + //Blocking + IL_LiquidRenderer.DrawNormalLiquids += BlockLavaDrawing; + On_TileDrawing.DrawTile_LiquidBehindTile += BlockLavaDrawingForSlopes; + On_TileDrawing.DrawPartialLiquid += BlockLavaDrawingForSlopes2; + On_WaterfallManager.DrawWaterfall_int_int_int_float_Vector2_Rectangle_Color_SpriteEffects += LavafallRemover; + IL_Main.oldDrawWater += BlockRetroLightingLava; + + //Replacing + IL_LiquidRenderer.InternalPrepareDraw += LavaBubbleReplacer; + IL_TileDrawing.EmitLiquidDrops += LavaDropletReplacer; + IL_NPC.Collision_WaterCollision += SplashEntityLava; + IL_Projectile.Update += SplashEntityLava; + IL_Item.MoveInWorld += SplashEntityLava; + IL_Player.Update += SplashEntityLava; + IL_Player.Update += PlayerDebuffEdit; + + //Other + On_WaterfallManager.Draw += LavaFallRedrawer; + On_WaterfallManager.StylizeColor += WaterfallGlowmaskEditor; + + //Waterfall light + On_WaterfallManager.AddLight += LavafallLightEditor; + } + + // Liquid Lighting and alpha (Liquid Viusuals) + On_TileLightScanner.ApplyLiquidLight += LiquidEmitLight; + IL_LiquidRenderer.DrawNormalLiquids += LiquidDrawColors; //Liquid Light + IL_TileDrawing.DrawTile_LiquidBehindTile += LiquidSlopeDrawColors; + // Custom grappling On_Player.GrappleMovement += CustomGrappleMovementCheck; On_Player.UpdatePettingAnimal += CustomGrapplePreDefaultMovement; diff --git a/ILEditing/ILHelperMethods.cs b/ILEditing/ILHelperMethods.cs index 01f2379f0e..fe90e30043 100644 --- a/ILEditing/ILHelperMethods.cs +++ b/ILEditing/ILHelperMethods.cs @@ -64,77 +64,8 @@ namespace CalamityMod.ILEditing SoundEngine.PlaySound(SoundID.DoorClosed, new Vector2(doorX * 16, doorY * 16)); return true; } - - private static Texture2D SelectLavaTexture(Texture2D initialTexture, LiquidTileType type) - { - // Use the initial texture if it isn't lava. - if (initialTexture != CustomLavaManagement.LavaTexture && - initialTexture != CustomLavaManagement.LavaBlockTexture && - initialTexture != CustomLavaManagement.LavaSlopeTexture) - return initialTexture; - if (cachedLavaStyle == default) - return initialTexture; - - switch (type) - { - case LiquidTileType.Block: - return cachedLavaStyle.BlockTexture; - case LiquidTileType.Waterflow: - return cachedLavaStyle.LavaTexture; - case LiquidTileType.Slope: - return cachedLavaStyle.SlopeTexture; - } - - return initialTexture; - } - - private static VertexColors SelectLavaQuadColor(Texture2D initialTexture, ref VertexColors initialColor, bool forceTrue = false) - { - // We should handle the 'forceTrue' flag at this level to prevent us from checking the same thing four times. - if (!forceTrue) - { - if (initialTexture != CustomLavaManagement.LavaTexture && - initialTexture != CustomLavaManagement.LavaBlockTexture && - initialTexture != CustomLavaManagement.LavaSlopeTexture) - return initialColor; - } - - // No lava style to draw? Then skip. - if (cachedLavaStyle == default) - return initialColor; - - cachedLavaStyle.SelectLightColor(ref initialColor.TopLeftColor); - cachedLavaStyle.SelectLightColor(ref initialColor.TopRightColor); - cachedLavaStyle.SelectLightColor(ref initialColor.BottomLeftColor); - cachedLavaStyle.SelectLightColor(ref initialColor.BottomRightColor); - return initialColor; - } - - private static Color SelectLavaColor(Texture2D initialTexture, Color initialLightColor, bool forceTrue = false) - { - // Use the initial color if it isn't lava. - if (!forceTrue) - { - if (initialTexture != CustomLavaManagement.LavaTexture && - initialTexture != CustomLavaManagement.LavaBlockTexture && - initialTexture != CustomLavaManagement.LavaSlopeTexture) - return initialLightColor; - } - - foreach (CustomLavaStyle lavaStyle in CustomLavaManagement.CustomLavaStyles) - { - if (lavaStyle.ChooseLavaStyle()) - { - lavaStyle.SelectLightColor(ref initialLightColor); - return initialLightColor; - } - } - - return initialLightColor; - } - - private static void SelectSulphuricWaterColor(int x, int y, ref VertexColors initialColor) + public static void SelectSulphuricWaterColor(int x, int y, ref VertexColors initialColor, bool isSlope) { if (SulphuricWaterSafeZoneSystem.NearbySafeTiles.Count >= 1) { @@ -177,10 +108,20 @@ namespace CalamityMod.ILEditing } } - initialColor.TopLeftColor *= 0.4f; - initialColor.TopRightColor *= 0.4f; - initialColor.BottomLeftColor *= 0.4f; - initialColor.BottomRightColor *= 0.4f; + if (isSlope) + { + initialColor.TopLeftColor *= 1f / 3; + initialColor.TopRightColor *= 1f / 3; + initialColor.BottomLeftColor *= 1f / 3; + initialColor.BottomRightColor *= 1f / 3; + } + else + { + initialColor.TopLeftColor *= 0.4f; + initialColor.TopRightColor *= 0.4f; + initialColor.BottomLeftColor *= 0.4f; + initialColor.BottomRightColor *= 0.4f; + } } public static void DumpToLog(ILContext il) => CalamityMod.Instance.Logger.Debug(il.ToString()); diff --git a/ILEditing/MechanicILChanges.cs b/ILEditing/MechanicILChanges.cs index 231b0affeb..15b1400c6d 100644 --- a/ILEditing/MechanicILChanges.cs +++ b/ILEditing/MechanicILChanges.cs @@ -1,6 +1,8 @@ using System; +using System.Diagnostics; using System.Linq; using System.Reflection; +using System.Runtime.CompilerServices; using CalamityMod.Balancing; using CalamityMod.Buffs.DamageOverTime; using CalamityMod.CalPlayer; @@ -43,6 +45,7 @@ using Terraria.GameContent.Liquid; using Terraria.GameContent.UI.Elements; using Terraria.GameInput; using Terraria.Graphics; +using Terraria.Graphics.Capture; using Terraria.Graphics.Light; using Terraria.Graphics.Shaders; using Terraria.ID; @@ -51,6 +54,7 @@ using Terraria.Localization; using Terraria.ModLoader; using Terraria.ModLoader.IO; using Terraria.UI.Gamepad; +using static Terraria.WaterfallManager; namespace CalamityMod.ILEditing { @@ -62,14 +66,12 @@ namespace CalamityMod.ILEditing private static int aLabDoorClosed = -1; private static int exoDoorOpen = -1; private static int exoDoorClosed = -1; - // Cached for use in ChangeWaterQuadColors. - private static CustomLavaStyle cachedLavaStyle = default; // Holds the vanilla game function which spawns town NPCs, wrapped in a delegate for reflection purposes. // This function is (optionally) invoked manually in an IL edit to enable NPCs to spawn at night. private static Action VanillaSpawnTownNPCs; - private static readonly MethodInfo textureGetValueMethod = typeof(Asset).GetMethod("get_Value", BindingFlags.Public | BindingFlags.Instance); + //private static readonly MethodInfo textureGetValueMethod = typeof(Asset).GetMethod("get_Value", BindingFlags.Public | BindingFlags.Instance); public static event Func ExtraColorChangeConditions; @@ -828,366 +830,498 @@ namespace CalamityMod.ILEditing } #endregion - #region Custom Lava Visuals + #region Lava Style Edits + //Nine Layers of Hell brought to you by LIONEIGHTCAKE!! + //All new liquid rendering for lava can be found in Systems/LavaRendering.cs - private static void CacheLavaStyle(Terraria.On_Main.orig_RenderWater orig, Main self) - { - // Immediately cache the lava drawing style. - // This will pay off in SPADES when we go to draw the tiles. - foreach (CustomLavaStyle style in CustomLavaManagement.CustomLavaStyles) - { - if (style.ChooseLavaStyle()) - { - cachedLavaStyle = style; - orig(self); - return; - } - } + //To save on time, a LOT of the edits are from the BiomeLava mod (owned by myself, lion8cake). Obv every edit has been changed to reflect + //Calamity's style of IL edits and to remove any unnessesary edits not relivant to calamity. In the loading of the detours and edits + //BiomeLava is a check for whether they load or not. If BiomeLava is active all ModLavaStyles will be turned into ModCalls for BiomeLava. - cachedLavaStyle = default; - orig(self); - } - - private static void DrawCustomLava(Terraria.GameContent.Drawing.On_TileDrawing.orig_DrawPartialLiquid orig, TileDrawing self, bool behindBlocks, Tile tileCache, ref Vector2 position, ref Rectangle liquidSize, int liquidType, ref VertexColors colors) - { - if (liquidType != 1) - { - orig(self, behindBlocks, tileCache, ref position, ref liquidSize, liquidType, ref colors); - return; - } - - int slope = (int)tileCache.Slope; - colors = SelectLavaQuadColor(TextureAssets.LiquidSlope[liquidType].Value, ref colors, true); - if (!TileID.Sets.BlocksWaterDrawingBehindSelf[tileCache.TileType] || behindBlocks || slope == 0) - { - Texture2D liquidTexture = SelectLavaTexture(liquidType == 1 ? CustomLavaManagement.LavaBlockTexture : TextureAssets.Liquid[liquidType].Value, LiquidTileType.Block); - Main.tileBatch.Draw(liquidTexture, position, liquidSize, colors, default(Vector2), 1f, SpriteEffects.None); - return; - } - - Texture2D slopeTexture = SelectLavaTexture(liquidType == 1 ? CustomLavaManagement.LavaSlopeTexture : TextureAssets.LiquidSlope[liquidType].Value, LiquidTileType.Slope); - liquidSize.X += 18 * (slope - 1); - switch (slope) - { - case 1: - Main.tileBatch.Draw(slopeTexture, position, liquidSize, colors, Vector2.Zero, 1f, SpriteEffects.None); - break; - case 2: - Main.tileBatch.Draw(slopeTexture, position, liquidSize, colors, Vector2.Zero, 1f, SpriteEffects.None); - break; - case 3: - Main.tileBatch.Draw(slopeTexture, position, liquidSize, colors, Vector2.Zero, 1f, SpriteEffects.None); - break; - case 4: - Main.tileBatch.Draw(slopeTexture, position, liquidSize, colors, Vector2.Zero, 1f, SpriteEffects.None); - break; - } - } - - private static void ChangeWaterQuadColors(ILContext il) + #region Lava Rendering + private void DoDrawLavas(ILContext il) { ILCursor cursor = new ILCursor(il); - - if (!cursor.TryGotoNext(c => c.MatchLdfld("_liquidTextures"))) + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdsfld
("drawToScreen"), i => i.MatchBrfalse(out _), i => i.MatchLdarg0(), i => i.MatchLdcI4(1), i => i.MatchCall
("DrawWaters"))) { - LogFailure("Custom Lava Drawing", "Could not locate the liquid texture array load."); + LogFailure("DoDraw Lava", "Could not locate the drawing of Background Waters"); return; } - - // Move to the end of the get_Value() call and then use the resulting texture to check if a new one should replace it. - // Adding to the index directly would seem like a simple, direct way of achieving this since the operation is incredibly light, but - // it also unsafe due to the potential for NOP operations to appear. - if (!cursor.TryGotoNext(MoveType.After, c => c.MatchCallvirt(textureGetValueMethod))) + cursor.EmitDelegate(() => { + LavaRendering.instance.DrawLavas(isBackground: true); + }); + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdsfld
("drawToScreen"), i => i.MatchBrfalse(out _), i => i.MatchLdarg0(), i => i.MatchLdcI4(0), i => i.MatchCall
("DrawWaters"))) { - LogFailure("Custom Lava Drawing", "Could not locate the liquid texture Value call."); + LogFailure("DoDraw Lava", "Could not locate the drawing of Waters"); return; } - cursor.EmitDelegate>(initialTexture => SelectLavaTexture(initialTexture, LiquidTileType.Waterflow)); - - if (!cursor.TryGotoNext(MoveType.After, c => c.MatchLdloc(9))) - { - LogFailure("Custom Lava Drawing", "Could not locate the liquid light color."); - return; - } - - // Pass the texture in so that the method can ensure it is not messing around with non-lava textures. - cursor.Emit(OpCodes.Ldarg_0); - cursor.Emit(OpCodes.Ldfld, typeof(LiquidRenderer).GetField("_liquidTextures")); - cursor.Emit(OpCodes.Ldloc, 8); - cursor.Emit(OpCodes.Ldelem_Ref); - cursor.Emit(OpCodes.Ldloc, 8); - cursor.Emit(OpCodes.Ldloc, 3); - cursor.Emit(OpCodes.Ldloc, 4); - - // Caching these values can save a LOT of overhead at runtime. - ModWaterStyle basaltWater = ModContent.GetInstance(); - ModWaterStyle burrowsWater = ModContent.GetInstance(); - ModWaterStyle polypWater = ModContent.GetInstance(); - ModWaterStyle reefsWater = ModContent.GetInstance(); - ModWaterStyle shoresWater = ModContent.GetInstance(); - ModWaterStyle sulphuricWater = ModContent.GetInstance(); - ModWaterStyle sulphuricDepthsWater = ModContent.GetInstance(); - ModWaterStyle upperAbyssWater = ModContent.GetInstance(); - ModWaterStyle middleAbyssWater = ModContent.GetInstance(); - ModWaterStyle voidWater = ModContent.GetInstance(); - - cursor.EmitDelegate>((initialColor, initialTexture, liquidType, x, y) => - { - // Don't bother changing the color if the cached drawing style is null. - if (cachedLavaStyle != default) - { - initialColor = SelectLavaQuadColor(initialTexture, ref initialColor, liquidType == 1); - } - if (liquidType == burrowsWater.Slot || - liquidType == basaltWater.Slot || - liquidType == polypWater.Slot || - liquidType == shoresWater.Slot || - liquidType == reefsWater.Slot || - liquidType == sulphuricWater.Slot || - liquidType == sulphuricDepthsWater.Slot || - liquidType == upperAbyssWater.Slot || - liquidType == middleAbyssWater.Slot || - liquidType == voidWater.Slot) - { - SelectSulphuricWaterColor(x, y, ref initialColor); - } - - // Apply any extra color conditions. - initialColor = ExtraColorChangeConditions?.Invoke(initialColor, liquidType, new(x, y)) ?? initialColor; - - return initialColor; + cursor.EmitDelegate(() => { + LavaRendering.instance.DrawLavas(); }); } - private static void DrawCustomLava3(ILContext il) + private void RenderLavas(ILContext il) { ILCursor cursor = new ILCursor(il); - - // Locate the local index for the liquid color and tile coordinates. - int xCoordLocalIndex = 0; - int yCoordLocalIndex = 0; - int liquidColorLocalIndex = 0; - MethodInfo lightingGetColorMethod = typeof(Lighting).GetMethod("GetColor", new Type[] { typeof(int), typeof(int) }); - if (!cursor.TryGotoNext(MoveType.Before, c => c.MatchCallOrCallvirt(lightingGetColorMethod))) + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdarg0(), i => i.MatchLdcI4(0), i => i.MatchCall
("DrawWaters"))) { - LogFailure("Custom Lava Drawing", "Could not lighting GetColor call."); + LogFailure("Render Lava", "Could not locate the drawing of Waters"); return; } - if (!cursor.TryGotoPrev(c => c.MatchLdloc(out xCoordLocalIndex))) - { - LogFailure("Custom Lava Drawing", "Could not X coordinate local variable index."); - return; - } - if (!cursor.TryGotoPrev(c => c.MatchLdloc(out yCoordLocalIndex))) - { - LogFailure("Custom Lava Drawing", "Could not Y coordinate local variable index."); - return; - } - if (!cursor.TryGotoNext(c => c.MatchStloc(out liquidColorLocalIndex))) - { - LogFailure("Custom Lava Drawing", "Could not lighting GetColor local variable index."); - return; - } - - // Shortly after the liquid color local is the liquid type integer. Locate it. - int liquidTypeLocalIndex = 0; - if (!cursor.TryGotoNext(MoveType.Before, c => c.MatchLdcI4(0))) - { - LogFailure("Custom Lava Drawing", "Could not default value for the liquid type."); - return; - } - if (!cursor.TryGotoNext(c => c.MatchStloc(out liquidTypeLocalIndex))) - { - LogFailure("Custom Lava Drawing", "Could not liquid type local variable index."); - return; - } - - // Select the lava color. - if (!cursor.TryGotoNext(MoveType.After, c => c.MatchCallOrCallvirt("get_NotRetro"))) - { - LogFailure("Custom Lava Drawing", "Could not locate the retro style check."); - return; - } - - // Pass the texture in so that the method can ensure it is not messing around with non-lava textures. - cursor.Emit(OpCodes.Ldloc, liquidColorLocalIndex); - cursor.Emit(OpCodes.Ldsfld, typeof(TextureAssets).GetField("Liquid")); - cursor.Emit(OpCodes.Ldloc, liquidTypeLocalIndex); - cursor.Emit(OpCodes.Ldelem_Ref); - cursor.Emit(OpCodes.Call, textureGetValueMethod); - cursor.Emit(OpCodes.Ldloc, xCoordLocalIndex); - cursor.Emit(OpCodes.Ldloc, yCoordLocalIndex); - cursor.EmitDelegate>((initialColor, initialTexture, x, y) => - { - Color c = SelectLavaColor(initialTexture, initialColor); - - if (ExtraColorChangeConditions is not null) - c = ExtraColorChangeConditions(new(c), Main.waterStyle, new(x, y)).TopLeftColor; - - return c; + cursor.EmitDelegate(() => { + LavaRendering.instance.DrawLavas(); }); - cursor.Emit(OpCodes.Stloc, liquidColorLocalIndex); - - // Go back to the start and change textures as necessary. - cursor.Index = 0; - - while (cursor.TryGotoNext(c => c.MatchLdsfld(typeof(TextureAssets).GetField("Liquid")))) - { - // Move to the end of the get_Value() call and then use the resulting texture to check if a new one should replace it. - // Adding to the index directly would seem like a simple, direct way of achieving this since the operation is incredibly light, but - // it is unsafe due to the potential for NOP operations to appear. - if (!cursor.TryGotoNext(MoveType.After, c => c.MatchCallvirt(textureGetValueMethod))) - { - LogFailure("Custom Lava Drawing", "Could not locate the liquid texture Value call."); - return; - } - - cursor.EmitDelegate>(initialTexture => SelectLavaTexture(initialTexture, LiquidTileType.Block)); - } } - private static void DrawCustomLavafalls(Terraria.On_WaterfallManager.orig_DrawWaterfall_int_int_int_float_Vector2_Rectangle_Color_SpriteEffects orig, WaterfallManager self, int waterfallType, int x, int y, float opacity, Vector2 position, Rectangle sourceRect, Color color, SpriteEffects effects) + private void RenderLavaBackgrounds(ILContext il) { - waterfallType = CustomLavaManagement.SelectLavafallStyle(waterfallType); - color = CustomLavaManagement.SelectLavafallColor(waterfallType, color); + ILCursor cursor = new ILCursor(il); + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdarg0(), i => i.MatchLdcI4(1), i => i.MatchCall
("DrawWaters"))) + { + LogFailure("Render Lava Backgroumds", "Could not locate the drawing of Background Waters"); + return; + } + cursor.EmitDelegate(() => { + LavaRendering.instance.DrawLavas(isBackground: true); + }); + } - orig(self, waterfallType, x, y, opacity, position, sourceRect, color, effects); + private void DrawLavatoCapture(ILContext il) + { + ILCursor cursor = new ILCursor(il); + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdsfld
("liquidAlpha"), i => i.MatchCall(out _), i => i.MatchStloc2())) + { + LogFailure("Draw lavas to captures", "Could not locate the saving of water alphas"); + return; + } + cursor.EmitDelegate(() => { + LavaRendering.alphaSave = CalamityMod.lavaAlpha.ToArray(); + }); + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdcI4(0), i => i.MatchStloc(34), i => i.MatchBr(out _), i => i.MatchLdloc(34), i => i.MatchLdcI4(1), i => i.MatchBeq(out _))) + { + LogFailure("Draw lavas to captures", "Could not locate the resetting of water alphas"); + return; + } + cursor.EmitLdloc(8); + cursor.EmitDelegate((CaptureBiome biome) => { + for (int i = 0; i < 1; i++) + { + CalamityMod.lavaAlpha[i] = ((i == CalamityMod.LavaStyle) ? 1f : 0f); + } + }); + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdarg0(), i => i.MatchLdcI4(1), i => i.MatchLdsfld
("waterStyle"), i => i.MatchLdcR4(1), i => i.MatchLdcI4(1), i => i.MatchCall
("DrawLiquid"))) + { + LogFailure("Draw lavas to captures", "Could not locate the background of liquid capture drawing"); + return; + } + cursor.EmitDelegate(() => { + LavaRendering.instance.DrawLiquid(bg: true, CalamityMod.LavaStyle); + }); + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdarg0(), i => i.MatchLdcI4(1), i => i.MatchLdsfld
("bloodMoon"), i => i.MatchBrtrue(out _), i => i.MatchLdloc(8), i => i.MatchLdfld("WaterStyle"), i => i.MatchBr(out _), i => i.MatchLdcI4(9), i => i.MatchLdcR4(1), i => i.MatchLdcI4(1), i => i.MatchCall
("DrawLiquid"))) + { + LogFailure("Draw lavas to captures", "Could not locate the second background of liquid capture drawing"); + return; + } + cursor.EmitDelegate(() => { + LavaRendering.instance.DrawLiquid(bg: true, CalamityMod.LavaStyle); + }); + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdarg0(), i => i.MatchLdcI4(0), i => i.MatchLdsfld
("waterStyle"), i => i.MatchLdcR4(1), i => i.MatchLdcI4(1), i => i.MatchCall
("DrawLiquid"))) + { + LogFailure("Draw lavas to captures", "Could not locate the liquid capture drawing"); + return; + } + cursor.EmitDelegate(() => { + LavaRendering.instance.DrawLiquid(bg: false, CalamityMod.LavaStyle); + }); + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdarg0(), i => i.MatchLdcI4(0), i => i.MatchLdloc(8), i => i.MatchLdfld("WaterStyle"), i => i.MatchLdcR4(1), i => i.MatchLdcI4(1), i => i.MatchCall
("DrawLiquid"))) + { + LogFailure("Draw lavas to captures", "Could not locate the second liquid capture drawing"); + return; + } + cursor.EmitDelegate(() => { + LavaRendering.instance.DrawLiquid(bg: false, CalamityMod.LavaStyle); + }); + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdloc2(), i => i.MatchStsfld
("liquidAlpha"))) + { + LogFailure("Draw lavas to captures", "Could not locate water style value returner"); + return; + } + cursor.EmitDelegate(() => { + CalamityMod.lavaAlpha = LavaRendering.alphaSave; + }); + } + + private void AddTileLiquidDrawing(ILContext il) + { + ILCursor cursor = new ILCursor(il); + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdarg0(), i => i.MatchLdarg1(), i => i.MatchLdcI4(0), i => i.MatchLdarg(out _), i => i.MatchLdloc1(), i => i.MatchLdloc2(), i => i.MatchLdloc(12), i => i.MatchLdloc(13), i => i.MatchLdloc(14), i => i.MatchCall("DrawTile_LiquidBehindTile"))) + { + LogFailure("Tile Lava Drawing", "Could not locate the drawing of Liquid Behind Tile drawing"); + return; + } + cursor.EmitLdloc1(); + cursor.EmitLdloc2(); + cursor.EmitLdloc(12); + cursor.EmitLdloc(13); + cursor.EmitLdloc(14); + cursor.EmitDelegate((Microsoft.Xna.Framework.Vector2 unscaledPosition, Microsoft.Xna.Framework.Vector2 vector, int j, int i, Terraria.Tile tile) => { + LavaRendering.instance.DrawTile_LiquidBehindTile(solidLayer: false, inFrontOfPlayers: false, -1, unscaledPosition, vector, j, i, tile); + }); + } + #endregion + + #region Lava Blocking + private void BlockLavaDrawing(ILContext il) + { + //This edit to DrawNormalLiquids makes lavas in normal and white lighting draw with an alpha and with new textures + //If the parameter for the waterstyle is more than the max waterstyles then its subtracted by the max water style count and thats the lava style ID + ILCursor cursor = new ILCursor(il); + + //Continue if statement, basically + //if the liquid being drawn is lava and the water style is greater than the max water styles or if the liquid is water and less than the max water styles then the draw code is ran + //otherwise the loop/s are continued for the next liquid + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchStloc(4), i => i.MatchBr(out _), i => i.MatchLdloc(2), i => i.MatchLdfld(typeof(LiquidRenderer).GetNestedType("LiquidDrawCache", BindingFlags.NonPublic), "IsVisible"))) + { + LogFailure("Liquid Renderer Drawing", "Could not locate the IsVisible boolean check"); + return; + } + cursor.EmitLdarg3(); + cursor.EmitLdloc2(); //Initiated Liquid Draw Cache (needed for the Type parameter) + cursor.EmitLdfld(typeof(LiquidRenderer).GetNestedType("LiquidDrawCache", BindingFlags.NonPublic).GetRuntimeField("Type")); + cursor.EmitDelegate>((IsVisible, style, type) => IsVisible && ((type == 1 && style >= LavaRendering.instance.WaterStyleMaxCount + 1) || (type != 1 && style <= LavaRendering.instance.WaterStyleMaxCount))); + + //Lava alpha color, if the liquid drawn is lava, multiply num by the water alpha + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdloc(2), i => i.MatchLdfld(typeof(LiquidRenderer).GetNestedType("LiquidDrawCache", BindingFlags.NonPublic).GetRuntimeField("Type")), i => i.MatchStloc(8))) + { + LogFailure("Liquid Renderer Drawing", "Could not locate creation of the local variable num2 (the liquid type holder variable)"); + return; + } + cursor.EmitLdloc(8); + cursor.EmitLdloca(7); + cursor.EmitLdarg(4); + cursor.EmitDelegate((int num2, ref float num, float globalAlpha) => + { + if (num2 == LiquidID.Lava) + { + num *= globalAlpha; + } + }); + + //Conditionally replace the liquid texture whether the liquid is lava or water + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchCallvirt(typeof(Asset).GetMethod("get_Value", BindingFlags.Public | BindingFlags.Instance)))) + { + LogFailure("Liquid Renderer Drawing", "Could not locate the Texture2D array of liquids"); + return; + } + cursor.EmitLdarg3(); + cursor.EmitLdloc2(); //Initiated Liquid Draw Cache (needed for the Type parameter) + cursor.EmitLdfld(typeof(LiquidRenderer).GetNestedType("LiquidDrawCache", BindingFlags.NonPublic).GetRuntimeField("Type")); + cursor.EmitDelegate>((initialTexture, style, type) => (style >= LavaRendering.instance.WaterStyleMaxCount + 1 && type == LiquidID.Lava) ? CalamityMod.LavaTextures.liquid[style - LavaRendering.instance.WaterStyleMaxCount - 1].Value : initialTexture); + } + + private void BlockLavaDrawingForSlopes(On_TileDrawing.orig_DrawTile_LiquidBehindTile orig, TileDrawing self, bool solidLayer, bool inFrontOfPlayers, int waterStyleOverride, Vector2 screenPosition, Vector2 screenOffset, int tileX, int tileY, Tile tileCache) + { + Tile tile = Main.tile[tileX + 1, tileY]; + Tile tile2 = Main.tile[tileX - 1, tileY]; + Tile tile3 = Main.tile[tileX, tileY - 1]; + Tile tile4 = Main.tile[tileX, tileY + 1]; + if (tileCache.LiquidType == LiquidID.Lava || tile.LiquidType == LiquidID.Lava || tile2.LiquidType == LiquidID.Lava || tile3.LiquidType == LiquidID.Lava || tile4.LiquidType == LiquidID.Lava) + { + return; + } + orig.Invoke(self, solidLayer, inFrontOfPlayers, waterStyleOverride, screenPosition, screenOffset, tileX, tileY, tileCache); + } + + private void BlockLavaDrawingForSlopes2(On_TileDrawing.orig_DrawPartialLiquid orig, TileDrawing self, bool behindBlocks, Tile tileCache, ref Vector2 position, ref Rectangle liquidSize, int liquidType, ref VertexColors colors) + { + if (liquidType == 1) + { + return; + } + orig.Invoke(self, behindBlocks, tileCache, ref position, ref liquidSize, liquidType, ref colors); + } + + private void LavafallRemover(On_WaterfallManager.orig_DrawWaterfall_int_int_int_float_Vector2_Rectangle_Color_SpriteEffects orig, WaterfallManager self, int waterfallType, int x, int y, float opacity, Vector2 position, Rectangle sourceRect, Color color, SpriteEffects effects) + { + if (waterfallType == 1) + { + return; + } + orig.Invoke(self, waterfallType, x, y, opacity, position, sourceRect, color, effects); + } + + private void BlockRetroLightingLava(ILContext il) + { + ILCursor cursor = new ILCursor(il); + ILLabel target = cursor.DefineLabel(); + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchCgt(), i => i.MatchLdarg1(), i => i.MatchOr(), i => i.MatchBrfalse(out target))) + { + LogFailure("old Drawing Waters", "Could not locate the if statement that contains the check for liquid types, amounts and wether the liquid has a bg (arg1) or not"); + return; + } + if (target == null) + { + LogFailure("old Drawing Waters", "The BrFalse returned null, the boolean check getting was unsuccessful"); + return; + } + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdindU1(), i => i.MatchSub(), i => i.MatchConvR4(), i => i.MatchStloc(14))) + { + LogFailure("old Drawing Waters", "Could not locate the num3 local variable creation to put the if check after"); + return; + } + cursor.EmitLdloc(12); + cursor.EmitLdloc(11); + cursor.EmitDelegate((int i, int j) => { + return Main.tile[i, j].LiquidType == LiquidID.Lava; + }); + cursor.EmitBrtrue(target); + } + #endregion + + #region Lava Replacing + private void LavaBubbleReplacer(ILContext il) + { + ILCursor cursor = new ILCursor(il); + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdcI4(16), i => i.MatchLdcI4(16), i => i.MatchLdcI4(35))) + { + LogFailure("Ambient lava bubble replacer", "Could not locate the bubble newdust parameters"); + return; + } + cursor.EmitDelegate>(type => LavaRendering.dustLava()); + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdcI4(16), i => i.MatchLdcI4(8), i => i.MatchLdcI4(35))) + { + LogFailure("Ambient lava bubble replacer", "Could not locate the surface bubble newdust parameters"); + return; + } + cursor.EmitDelegate>(type2 => LavaRendering.dustLava()); + } + + private void LavaDropletReplacer(ILContext il) + { + ILCursor cursor = new ILCursor(il); + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdarg(out _), i => i.MatchLdcI4(374), i => i.MatchBneUn(out _), i => i.MatchLdcI4(716))) + { + LogFailure("Ambient lava droplet replacer", "Could not locate the lava droplet newgore parameters"); + return; + } + cursor.EmitDelegate>(type => LavaRendering.goreLava()); + } + + private void SplashEntityLava(ILContext il) + { + ILCursor cursor = new ILCursor(il); + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdfld("width"), i => i.MatchLdcI4(12), i => i.MatchAdd(), i => i.MatchLdcI4(24), i => i.MatchLdcI4(35))) + { + LogFailure("Entity Lava Splashing (Item, Projectile, NPC, Player)", "Could not locate the first lava bubble splashing"); + return; + } + cursor.EmitDelegate>(type => LavaRendering.dustLava()); + if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdfld("width"), i => i.MatchLdcI4(12), i => i.MatchAdd(), i => i.MatchLdcI4(24), i => i.MatchLdcI4(35))) + { + LogFailure("Entity Lava Splashing (Item, Projectile, NPC, Player)", "Could not locate the second lava bubble splashing"); + return; + } + cursor.EmitDelegate>(type2 => LavaRendering.dustLava()); + } + + private void PlayerDebuffEdit(ILContext il) + { + //Injects code directly at the position where the OnFire debuff is handled + ILCursor cursor = new ILCursor(il); + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchLdarg0(), i => i.MatchLdcI4(24), i => i.MatchLdloc(161), i => i.MatchLdcI4(1), i => i.MatchLdcI4(0), i => i.MatchCall("AddBuff"))) + { + LogFailure("Player Update Lava Debuff", "Could not locate the infliction of the On Fire! debuff inside the Player Update code"); + return; + } + cursor.EmitLdarg0(); + cursor.EmitLdloc(161); + cursor.EmitDelegate((Player player, int onFiretime) => + { + LavaStylesLoader.InflictDebuff(player, CalamityMod.LavaStyle, onFiretime); + }); } #endregion - #region Water Visuals - private static void MakeSulphSeaWaterBetter(Terraria.Graphics.Light.On_TileLightScanner.orig_GetTileLight orig, TileLightScanner self, int x, int y, out Vector3 outputColor) + #region Other + private Color WaterfallGlowmaskEditor(On_WaterfallManager.orig_StylizeColor orig, float alpha, int maxSteps, int waterfallType, int y, int s, Tile tileCache, Color aColor) { - orig(self, x, y, out outputColor); - if (outputColor == Vector3.One || outputColor == new Vector3(0.25f, 0.25f, 0.25f) || outputColor == new Vector3(0.5f, 0.5f, 0.5f)) - return; - - Tile tile = CalamityUtils.ParanoidTileRetrieval(x, y); - if (tile.LiquidAmount <= 0 || tile.HasTile || tile.Get().LiquidType != LiquidID.Water || (Main.waterStyle != SulphuricWater.Type && - Main.waterStyle != SulphuricDepthsWater.Type && Main.waterStyle != SunkenSeaBurrowsWater.Type && Main.waterStyle != SunkenSeaPolypWater.Type && - Main.waterStyle != SunkenSeaReefsWater.Type && Main.waterStyle != SunkenSeaShoresWater.Type && Main.waterStyle != BasaltGullyWater.Type)) - return; - - Tile above = CalamityUtils.ParanoidTileRetrieval(x, y - 1); - if (!Main.gamePaused && !above.HasTile && above.LiquidAmount <= 0 && Main.rand.NextBool(9) && Main.waterStyle == SulphuricWater.Type) + if (CalamityMod.LavaStyle != 0 && !LavaStylesLoader.Get(CalamityMod.LavaStyle).LavafallGlowmask()) { - MediumMistParticle acidFoam = new(new(x * 16f + Main.rand.NextFloat(16f), y * 16f + 8f), -Vector2.UnitY.RotatedByRandom(0.67f) * Main.rand.NextFloat(1f, 2.4f), Color.LightSeaGreen, Color.White, 0.16f, 128f, 0.02f); - GeneralParticleHandler.SpawnParticle(acidFoam); + return aColor; } - - if (tile.TileType != (ushort)ModContent.TileType()) + else { - if (Main.waterStyle == SulphuricWater.Type && Main.dayTime && !Main.raining) - { - float brightness = MathHelper.Clamp(0.2f - (y / 680), 0f, 0.2f); - if (y > 580) - brightness *= 1f - (y - 580) / 100f; + return orig.Invoke(alpha, maxSteps, waterfallType, y, s, tileCache, aColor); + } + } - float waveScale1 = Main.GameUpdateCount * 0.014f; - float waveScale2 = Main.GameUpdateCount * 0.1f; - int scalar = x + (-y / 2); - float wave1 = waveScale1 * -50 + scalar * 15; - float wave2 = waveScale2 * -10 + scalar * 14; - float wave3 = waveScale1 * -100 + scalar * 13; - float wave4 = waveScale2 * 10 + scalar * 25; - float wave5 = waveScale1 * -70 + scalar * 5; - float wave1angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave1)); - float wave2angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave2)); - float wave3angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave3)); - float wave4angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave4)); - float wave5angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave5)); - outputColor = Vector3.Lerp(outputColor, Color.LightSeaGreen.ToVector3(), 0.41f + wave1angle + wave2angle + wave3angle + wave4angle + wave5angle); - outputColor *= brightness; + private void LavaFallRedrawer(On_WaterfallManager.orig_Draw orig, WaterfallManager self, SpriteBatch spriteBatch) + { + orig.Invoke(self, spriteBatch); + LavaRendering.instance.InitialDrawLavafall(self); + } + #endregion + + #endregion + + #region Liquid Visuals + //Contains all liquid light and liquid alpha (seethrough-ability) + private void LiquidEmitLight(On_TileLightScanner.orig_ApplyLiquidLight orig, TileLightScanner self, Tile tile, ref Vector3 lightColor) + { + orig.Invoke(self, tile, ref lightColor); + if (tile.LiquidAmount > 0 && !tile.HasTile) + { + if (tile.LiquidType == LiquidID.Water) + { + float R = 0f; + float G = 0f; + float B = 0f; + CalamityWaterLoader.ModifyLightSetup(tile.X(), tile.Y(), Main.waterStyle, ref R, ref G, ref B); + if (lightColor.X < R) + { + lightColor.X = R; + } + if (lightColor.Y < G) + { + lightColor.Y = G; + } + if (lightColor.Z < B) + { + lightColor.Z = B; + } } - - if (Main.waterStyle == SulphuricWater.Type && !Main.dayTime && !Main.raining) + else if (tile.LiquidType == LiquidID.Lava && CalamityMod.Instance.biomeLava == null) { - float brightness = MathHelper.Clamp(0.17f - (y / 680), 0f, 0.17f); - if (y > 580) - brightness *= 1f - (y - 580) / 100f; - - float waveScale1 = Main.GameUpdateCount * 0.014f; - float waveScale2 = Main.GameUpdateCount * 0.1f; - int scalar = x + (-y / 2); - float wave1 = waveScale1 * -50 + scalar * 15; - float wave2 = waveScale2 * -10 + scalar * 14; - float wave3 = waveScale1 * -100 + scalar * 13; - float wave4 = waveScale2 * 10 + scalar * 25; - float wave5 = waveScale1 * -70 + scalar * 5; - float wave1angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave1)); - float wave2angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave2)); - float wave3angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave3)); - float wave4angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave4)); - float wave5angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave5)); - outputColor = Vector3.Lerp(outputColor, Color.LightSeaGreen.ToVector3(), 0.41f + wave1angle + wave2angle + wave3angle + wave4angle + wave5angle); - outputColor *= brightness; - } - - if (Main.waterStyle == SulphuricWater.Type && Main.raining) - { - float brightness = MathHelper.Clamp(1f - (y / 680), 0f, 1f); - if (y > 580) - brightness *= 1f - (y - 580) / 100f; - - outputColor = Vector3.Lerp(outputColor, Color.LightSeaGreen.ToVector3(), 0.41f); - outputColor *= brightness; - } - - if (Main.waterStyle == SulphuricDepthsWater.Type) - outputColor = Vector3.Lerp(outputColor, Color.MediumSeaGreen.ToVector3(), 0.18f); - - if (Main.waterStyle == SunkenSeaBurrowsWater.Type || Main.waterStyle == SunkenSeaPolypWater.Type || Main.waterStyle == SunkenSeaReefsWater.Type || - Main.waterStyle == SunkenSeaShoresWater.Type || Main.waterStyle == BasaltGullyWater.Type) - { - //default to white - Color waterGlowColor = Color.White; - - //set the glow colors for each sunken sea biome water style - if (Main.waterStyle == SunkenSeaShoresWater.Type) + Vector3 lavaLight = new Vector3(0.55f, 0.33f, 0.11f); + float R = CalamityMod.LavaStyle == 0 ? lavaLight.X : 0f; + float G = CalamityMod.LavaStyle == 0 ? lavaLight.Y : 0f; + float B = CalamityMod.LavaStyle == 0 ? lavaLight.Z : 0f; + LavaStylesLoader.ModifyLightSetup(tile.X(), tile.Y(), CalamityMod.LavaStyle, ref R, ref G, ref B); + for (int j = 0; j < LavaStylesLoader.TotalCount; j++) { - waterGlowColor = new Color(233, 170, 184); + if (CalamityMod.lavaAlpha[j] > 0f && j != CalamityMod.LavaStyle) + { + float r = j == 0 ? lavaLight.X : 0f; + float g = j == 0 ? lavaLight.Y : 0f; + float b = j == 0 ? lavaLight.Z : 0f; + LavaStylesLoader.ModifyLightSetup(tile.X(), tile.Y(), j, ref r, ref g, ref b); + float r2 = CalamityMod.LavaStyle == 0 ? lavaLight.X : 0f; + float g2 = CalamityMod.LavaStyle == 0 ? lavaLight.Y : 0f; + float b2 = CalamityMod.LavaStyle == 0 ? lavaLight.Z : 0f; + LavaStylesLoader.ModifyLightSetup(tile.X(), tile.Y(), CalamityMod.LavaStyle, ref r2, ref g2, ref b2); + R = Single.Lerp(r, r2, CalamityMod.lavaAlpha[CalamityMod.LavaStyle]); + G = Single.Lerp(g, g2, CalamityMod.lavaAlpha[CalamityMod.LavaStyle]); + B = Single.Lerp(b, b2, CalamityMod.lavaAlpha[CalamityMod.LavaStyle]); + } } - if (Main.waterStyle == SunkenSeaPolypWater.Type) + if (!(R == 0 && G == 0 && B == 0)) { - waterGlowColor = new Color(213, 185, 178); + float colorManipulator = (float)(270 - Main.mouseTextColor) / 900f; + R += colorManipulator; + G += colorManipulator; + B += colorManipulator; } - if (Main.waterStyle == SunkenSeaReefsWater.Type) + if (lightColor.X < R) { - waterGlowColor = new Color(140, 222, 239); + lightColor.X = R; } - if (Main.waterStyle == SunkenSeaBurrowsWater.Type) + if (lightColor.Y < G) { - waterGlowColor = new Color(76, 211, 231); + lightColor.Y = G; } - if (Main.waterStyle == BasaltGullyWater.Type) + if (lightColor.Z < B) { - waterGlowColor = new Color(144, 174, 200); + lightColor.Z = B; } - - float brightness = MathHelper.Clamp(0.07f, 0f, 0.07f); - float waveScale1 = Main.GameUpdateCount * 0.028f; - float waveScale2 = Main.GameUpdateCount * 0.1f; - int yScale = -y / 2; - int xScale = x / 15; - float wave1 = Main.GameUpdateCount * 0.024f * -50 + ((-x / 30) + (y / 30)) * 25; - float wave2 = waveScale2 * -10 + ((-xScale) + yScale) * 45; - float wave3 = waveScale1 * -100 + ((x / 7) + (y / 50)) * 25; - float wave4 = Main.GameUpdateCount * 0.15f * 10 + ((x / 3) + yScale) * 45; - float wave5 = waveScale1 * -70 + ((-x / 25) + (-y / 25)) * 20; - float wave6 = waveScale2 * -10 + (xScale + yScale) * 45; - float bigwave = Main.GameUpdateCount * 0.01f * -70 + ((-x / 2) + (-y / 40)) * 5; - float wave1angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave1)); - float wave2angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave2)); - float wave3angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave3)); - float wave4angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave4)); - float wave5angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave5)); - float wave6angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave6)); - float bigwaveangle = 0.55f + 0.80f * (float)Math.Sin(MathHelper.ToRadians(bigwave)); - outputColor = Vector3.Lerp(outputColor, Color.DarkSlateGray.ToVector3(), 0.07f + wave1angle + wave2angle + wave3angle + wave4angle + wave5angle + wave6angle + bigwaveangle); - outputColor *= brightness * 6f; } } } + + private void LavafallLightEditor(On_WaterfallManager.orig_AddLight orig, int waterfallType, int x, int y) + { + if (waterfallType == 1) + { + float r = 0.55f; + float g = 0.33f; + float b = 0.11f; + LavaStylesLoader.ModifyLightSetup(x, y, CalamityMod.LavaStyle, ref r, ref g, ref b); + if (!(r == 0 && g == 0 && b == 0)) + { + float r8; + float num3 = (r8 = (r + (float)(270 - Main.mouseTextColor) / 900f) * 0.4f); + float g8 = num3 * g; + float b8 = num3 * b; + Lighting.AddLight(x, y, r8, g8, b8); + } + return; + } + orig.Invoke(waterfallType, x, y); + } + + private static void LiquidDrawColors(ILContext il) + { + ILCursor cursor = new ILCursor(il); + if (!cursor.TryGotoNext(MoveType.Before, c => c.MatchLdarg2(), c => c.MatchLdloc3(), c => c.MatchLdloc(4), c => c.MatchCall
("DrawTileInWater"))) + { + LogFailure("Liquid Draw Colors", "Could not locate the liquid vertex colors for drawing"); + return; + } + + cursor.Emit(OpCodes.Ldloc_3); + cursor.Emit(OpCodes.Ldloc, 4); + cursor.Emit(OpCodes.Ldloc_2); + cursor.Emit(OpCodes.Ldfld, typeof(LiquidRenderer).GetNestedType("LiquidDrawCache", BindingFlags.NonPublic).GetRuntimeField("Type")); + cursor.Emit(OpCodes.Ldloca, 9); + + cursor.EmitDelegate((int x, int y, int liquidType, ref VertexColors initialColor) => + { + if (liquidType == LiquidID.Water) + { + CalamityWaterLoader.DrawColorSetup(x, y, Main.waterStyle, ref initialColor); + } + else if (liquidType == LiquidID.Lava && CalamityMod.Instance.biomeLava == null) + { + LavaStylesLoader.DrawColorSetup(x, y, CalamityMod.LavaStyle, ref initialColor); + } + }); + } + + private static void LiquidSlopeDrawColors(ILContext il) + { + ILCursor cursor = new ILCursor(il); + + if (!cursor.TryGotoNext(MoveType.Before, c => c.MatchLdcI4(0), c => c.MatchStloc(19), c => c.MatchLdloc(11), c => c.MatchBrfalse(out _))) + { + LogFailure("Liquid Slope Draw Colors", "Could not locate the liquid slope vertex colors for drawing"); + return; + } + + cursor.Emit(OpCodes.Ldarg, 6); + cursor.Emit(OpCodes.Ldarg, 7); + cursor.Emit(OpCodes.Ldloca, 14); + cursor.Emit(OpCodes.Ldloc, 11); + cursor.Emit(OpCodes.Ldloc, 10); + + cursor.EmitDelegate((int x, int y, ref VertexColors initialColor, bool flag6, int num2) => + { + if (flag6) + { + int totalCount = (int)typeof(Loader).GetProperty("TotalCount", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).GetValue(LoaderManager.Get()); + for (int i = 0; i < totalCount; i++) + { + Tile tile = Main.tile[x, y]; + if (i == Main.waterStyle && tile.LiquidType == LiquidID.Water) + { + CalamityWaterLoader.DrawColorSetup(x, y, Main.waterStyle, ref initialColor, true); + } + else if ((tile.LiquidType == LiquidID.Lava || i == 1) && CalamityMod.Instance.biomeLava == null) + { + LavaStylesLoader.DrawColorSetup(x, y, CalamityMod.LavaStyle, ref initialColor); + } + } + } + }); + } #endregion #region Statue Additions diff --git a/ModSupport/WeakReferenceSupport.cs b/ModSupport/WeakReferenceSupport.cs index 1ec0ce7533..b4d09eebcc 100644 --- a/ModSupport/WeakReferenceSupport.cs +++ b/ModSupport/WeakReferenceSupport.cs @@ -206,6 +206,54 @@ namespace CalamityMod } } + #region BiomeLava + public static void LavaStytleToBiomeLava() + { + CalamityMod calamity = GetInstance(); + Mod biomelava = calamity.biomeLava; + if (biomelava == null) + return; + + foreach (ModLavaStyle item in LavaStylesLoader.Content) + { + int type = item.Slot; + ModLavaStyle lavaStyle = LavaStylesLoader.Get(type); + if (lavaStyle != null) + { + Func GetSplashDust = lavaStyle.GetSplashDust; + Func GetDropletGore = lavaStyle.GetDropletGore; + Func ModifyLightFunc = ModifyLight; + Func IsLavaActive = lavaStyle.IsLavaActive; + Func lavafallGlowmask = lavaStyle.LavafallGlowmask; + Func InflictDebuffFunc = InflictDebuff; + Func yes = InflictsOnFire; + + Vector3 ModifyLight(int x, int y, float r, float g, float b) + { + lavaStyle.ModifyLight(x, y, ref r, ref g, ref b); + return new Vector3(r, g, b); + } + + Action InflictDebuff(Player player, NPC npc, int onfireDuration) + { + if (player != null && npc == null) + { + lavaStyle.InflictDebuff(player, onfireDuration); + } + return null; + } + + bool InflictsOnFire() + { + return true; + } + + biomelava.Call("ModLavaStyle", calamity, lavaStyle.Name, lavaStyle.Texture, lavaStyle.BlockTexture, lavaStyle.SlopeTexture, lavaStyle.WaterfallTexture, GetSplashDust, GetDropletGore, ModifyLightFunc, IsLavaActive, lavafallGlowmask, InflictDebuffFunc, yes); + } + } + } + #endregion + #region WikiThis // This is a separate function because it only runs clientside public static void WikiThisSupport() diff --git a/Systems/CalamityModWaterStyle.cs b/Systems/CalamityModWaterStyle.cs new file mode 100644 index 0000000000..66c3d6766f --- /dev/null +++ b/Systems/CalamityModWaterStyle.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using Terraria; +using Terraria.Graphics; +using Terraria.ModLoader; + +namespace CalamityMod.Systems +{ + public abstract class CalamityModWaterStyle : ModWaterStyle + { + /// + /// Allows water styles to manipulate what color the liquid is drawn to, this can allow waters to be see-throughable to see backgrounds (surface and underground backgrounds not walls) + /// + /// X position of the water + /// Y position of the water + /// The vertexColor of the water color, this is both used to get the current color and to set the color of the water + public virtual void DrawColor(int x, int y, ref VertexColors liquidColor, bool isSlope) + { + } + + /// + /// Allows you to determine how much light this water emits.
+ /// It can also let you light up the block in front of this water.
+ /// See for vanilla tile light values to use as a reference.
+ ///
+ /// The x position in tile coordinates. + /// The y position in tile coordinates. + /// The red component of light, usually a value between 0 and 1 + /// The green component of light, usually a value between 0 and 1 + /// The blue component of light, usually a value between 0 and 1 + public virtual void ModifyLight(int i, int j, ref float r, ref float g, ref float b) + { + } + } + + internal static class CalamityWaterLoader + { + internal static void ModifyLightSetup(int i, int j, int type, ref float r, ref float g, ref float b) + { + CalamityModWaterStyle styles = (CalamityModWaterStyle)LoaderManager.Get().Get(type); + if (styles != null) + { + styles?.ModifyLight(i, j, ref r, ref g, ref b); + } + } + + internal static void DrawColorSetup(int x, int y, int type, ref VertexColors liquidColor, bool isSlope = false) + { + CalamityModWaterStyle styles = (CalamityModWaterStyle)LoaderManager.Get().Get(type); + if (styles != null) + { + styles?.DrawColor(x, y, ref liquidColor, isSlope); + } + } + } +} diff --git a/Systems/LavaRendering.cs b/Systems/LavaRendering.cs new file mode 100644 index 0000000000..8dc526e169 --- /dev/null +++ b/Systems/LavaRendering.cs @@ -0,0 +1,1159 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using Terraria; +using Terraria.GameContent.Liquid; +using Terraria.Graphics; +using Terraria.ID; +using Terraria.ModLoader; +using static Terraria.WaterfallManager; + +namespace CalamityMod.Systems +{ + public class LavaRendering : ModSystem + { + //Welcome to Calamity's lava rendering. Prepare your eyes + public static LavaRendering instance; + + public int WaterStyleMaxCount = ModContent.GetContent().Count() + LoaderManager.Get().VanillaCount; + + internal static float[] alphaSave; + + public override void Load() + { + LavaRendering.alphaSave = new float[CalamityMod.lavaAlpha.Length]; + } + + public void DrawLavas(bool isBackground = false) + { + Main.drewLava = false; + if (!isBackground) + { + CalamityMod.LavaStyle = 0; + LavaStylesLoader.IsLavaActive(); + for (int i = 0; i < 1; i++) + { + if (CalamityMod.LavaStyle != i) + { + CalamityMod.lavaAlpha[i] = Math.Max(CalamityMod.lavaAlpha[i] - 0.2f, 0f); + } + else + { + CalamityMod.lavaAlpha[i] = Math.Min(CalamityMod.lavaAlpha[i] + 0.2f, 1f); + } + } + LavaStylesLoader.UpdateLiquidAlphas(); + } + bool flag = false; + for (int j = 0; j < LavaStylesLoader.TotalCount; j++) + { + if (CalamityMod.lavaAlpha[j] > 0f && j != CalamityMod.LavaStyle) + { + DrawLiquid(isBackground, j, isBackground ? 1f : CalamityMod.lavaAlpha[j], drawSinglePassLiquids: false); + flag = true; + } + } + DrawLiquid(isBackground, CalamityMod.LavaStyle, flag ? CalamityMod.lavaAlpha[CalamityMod.LavaStyle] : 1f); + } + + protected internal void DrawLiquid(bool bg = false, int lavaStyle = 0, float Alpha = 1f, bool drawSinglePassLiquids = true) + { + if (!Lighting.NotRetro) + { + oldDrawLava(bg, lavaStyle, Alpha); + return; + } + Stopwatch stopwatch = new Stopwatch(); + stopwatch.Start(); + Vector2 drawOffset = (Vector2)(Main.drawToScreen ? Vector2.Zero : new Vector2((float)Main.offScreenRange, (float)Main.offScreenRange)) - Main.screenPosition; + if (bg) + { + DrawLiquidBehindTiles(lavaStyle); + } + LiquidRenderer.Instance.DrawNormalLiquids(Main.spriteBatch, drawOffset, lavaStyle + ModContent.GetContent().Count() + LoaderManager.Get().VanillaCount + 1, Alpha, bg); + if (!bg) + { + TimeLogger.DrawTime(4, stopwatch.Elapsed.TotalMilliseconds); + } + } + + public void oldDrawLava(bool bg = false, int Style = 0, float Alpha = 1f) + { + float num = 0f; + float num12 = 99999f; + float num23 = 99999f; + int num27 = -1; + int num28 = -1; + Vector2 vector = new((float)Main.offScreenRange, (float)Main.offScreenRange); + if (Main.drawToScreen) + { + vector = Vector2.Zero; + } + _ = new Color[4]; + int num29 = (int)(255f * (1f - Main.gfxQuality) + 40f * Main.gfxQuality); + _ = Main.gfxQuality; + _ = Main.gfxQuality; + int num30 = (int)((Main.screenPosition.X - vector.X) / 16f - 1f); + int num31 = (int)((Main.screenPosition.X + (float)Main.screenWidth + vector.X) / 16f) + 2; + int num32 = (int)((Main.screenPosition.Y - vector.Y) / 16f - 1f); + int num2 = (int)((Main.screenPosition.Y + (float)Main.screenHeight + vector.Y) / 16f) + 5; + if (num30 < 5) + { + num30 = 5; + } + if (num31 > Main.maxTilesX - 5) + { + num31 = Main.maxTilesX - 5; + } + if (num32 < 5) + { + num32 = 5; + } + if (num2 > Main.maxTilesY - 5) + { + num2 = Main.maxTilesY - 5; + } + Vector2 vector2; + Rectangle value; + Color newColor; + for (int i = num32; i < num2 + 4; i++) + { + for (int j = num30 - 2; j < num31 + 2; j++) + { + if (Main.tile[j, i].LiquidAmount <= 0 || (Main.tile[j, i].HasUnactuatedTile && Main.tileSolid[Main.tile[j, i].TileType] && !Main.tileSolidTop[Main.tile[j, i].TileType]) || !(Lighting.Brightness(j, i) > 0f || bg) || Main.tile[j, i].LiquidType != LiquidID.Lava) + { + continue; + } + Color color = Lighting.GetColor(j, i); + float num3 = 256 - Main.tile[j, i].LiquidAmount; + num3 /= 32f; + int num4 = 0; + if (Main.tile[j, i].LiquidType == LiquidID.Lava) + { + /*if (Main.drewLava) //disallows the back liquid to not draw until its alpha hits 1f apparently + { + continue; + }*/ + float num5 = Math.Abs((float)(j * 16 + 8) - (Main.screenPosition.X + (float)(Main.screenWidth / 2))); + float num6 = Math.Abs((float)(i * 16 + 8) - (Main.screenPosition.Y + (float)(Main.screenHeight / 2))); + if (num5 < (float)(Main.screenWidth * 2) && num6 < (float)(Main.screenHeight * 2)) + { + float num7 = (float)Math.Sqrt(num5 * num5 + num6 * num6); + float num8 = 1f - num7 / ((float)Main.screenWidth * 0.75f); + if (num8 > 0f) + { + num += num8; + } + } + if (num5 < num12) + { + num12 = num5; + num27 = j * 16 + 8; + } + if (num6 < num23) + { + num23 = num5; + num28 = i * 16 + 8; + } + } + if (num4 == 0) + { + num4 = Style; + } + if (Main.drewLava) + { + continue; + } + float num9 = 0.5f; + if (bg) + { + num9 = 1f; + } + num9 *= Alpha; + Main.DrawTileInWater(-Main.screenPosition + vector, j, i); //lily pads + vector2 = new((float)(j * 16), (float)(i * 16 + (int)num3 * 2)); + value = new(0, 0, 16, 16 - (int)num3 * 2); + bool flag2 = true; + if (Main.tile[j, i + 1].LiquidAmount < 245 && (!Main.tile[j, i + 1].HasUnactuatedTile || !Main.tileSolid[Main.tile[j, i + 1].TileType] || Main.tileSolidTop[Main.tile[j, i + 1].TileType])) + { + float num10 = 256 - Main.tile[j, i + 1].LiquidAmount; + num10 /= 32f; + num9 = 0.5f * (8f - num3) / 4f; + if ((double)num9 > 0.55) + { + num9 = 0.55f; + } + if ((double)num9 < 0.35) + { + num9 = 0.35f; + } + float num11 = num3 / 2f; + if (Main.tile[j, i + 1].LiquidAmount < 200) + { + if (bg) + { + continue; + } + if (Main.tile[j, i - 1].LiquidAmount > 0 && Main.tile[j, i - 1].LiquidAmount > 0) + { + value = new(0, 4, 16, 16); + num9 = 0.5f; + } + else if (Main.tile[j, i - 1].LiquidAmount > 0) + { + vector2 = new((float)(j * 16), (float)(i * 16 + 4)); + value = new(0, 4, 16, 12); + num9 = 0.5f; + } + else if (Main.tile[j, i + 1].LiquidAmount > 0) + { + vector2 = new((float)(j * 16), (float)(i * 16 + (int)num3 * 2 + (int)num10 * 2)); + value = new(0, 4, 16, 16 - (int)num3 * 2); + } + else + { + vector2 = new((float)(j * 16 + (int)num11), (float)(i * 16 + (int)num11 * 2 + (int)num10 * 2)); + value = new(0, 4, 16 - (int)num11 * 2, 16 - (int)num11 * 2); + } + } + else + { + num9 = 0.5f; + value = new(0, 4, 16, 16 - (int)num3 * 2 + (int)num10 * 2); + } + } + else if (Main.tile[j, i - 1].LiquidAmount > 32) + { + value = new(0, 4, value.Width, value.Height); + } + else if (num3 < 1f && Main.tile[j, i - 1].HasUnactuatedTile && Main.tileSolid[Main.tile[j, i - 1].TileType] && !Main.tileSolidTop[Main.tile[j, i - 1].TileType]) + { + vector2 = new((float)(j * 16), (float)(i * 16)); + value = new(0, 4, 16, 16); + } + else + { + for (int k = i + 1; k < i + 6 && (!Main.tile[j, k].HasUnactuatedTile || !Main.tileSolid[Main.tile[j, k].TileType] || Main.tileSolidTop[Main.tile[j, k].TileType]); k++) + { + if (Main.tile[j, k].LiquidAmount < 200) + { + flag2 = false; + break; + } + } + if (!flag2) + { + num9 = 0.5f; + value = new(0, 4, 16, 16); + } + else if (Main.tile[j, i - 1].LiquidAmount > 0) + { + value = new(0, 2, value.Width, value.Height); + } + } + if ((color.R > 20 || color.B > 20 || color.G > 20) && value.Y < 4) + { + int num13 = color.R; + if (color.G > num13) + { + num13 = color.G; + } + if (color.B > num13) + { + num13 = color.B; + } + num13 /= 30; + if (Main.rand.Next(20000) < num13) + { + newColor = new(255, 255, 255); + int num14 = Dust.NewDust(new Vector2((float)(j * 16), vector2.Y - 2f), 16, 8, DustID.TintableDustLighted, 0f, 0f, 254, newColor, 0.75f); + Dust obj = Main.dust[num14]; + obj.velocity *= 0f; + } + } + if (Main.tile[j, i].LiquidType == LiquidID.Lava) + { + num9 *= 1.8f; + if (num9 > 1f) + { + num9 = 1f; + } + if (Main.instance.IsActive && !Main.gamePaused && Dust.lavaBubbles < 200) + { + if (Main.tile[j, i].LiquidAmount > 200 && Main.rand.NextBool(700)) + { + Dust.NewDust(new Vector2((float)(j * 16), (float)(i * 16)), 16, 16, dustLava()); + } + if (value.Y == 0 && Main.rand.NextBool(350)) + { + int num15 = Dust.NewDust(new Vector2((float)(j * 16), (float)(i * 16) + num3 * 2f - 8f), 16, 8, dustLava(), 0f, 0f, 50, default(Color), 1.5f); + Dust obj2 = Main.dust[num15]; + obj2.velocity *= 0.8f; + Main.dust[num15].velocity.X *= 2f; + Main.dust[num15].velocity.Y -= (float)Main.rand.Next(1, 7) * 0.1f; + if (Main.rand.NextBool(10)) + { + Main.dust[num15].velocity.Y *= Main.rand.Next(2, 5); + } + Main.dust[num15].noGravity = true; + } + } + } + float num16 = (float)(int)color.R * num9; + float num17 = (float)(int)color.G * num9; + float num18 = (float)(int)color.B * num9; + float num19 = (float)(int)color.A * num9; + color = new((int)(byte)num16, (int)(byte)num17, (int)(byte)num18, (int)(byte)num19); + if (Lighting.NotRetro && !bg) + { + Color color2 = color; + if (((double)(int)color2.R > (double)num29 * 0.6 || (double)(int)color2.G > (double)num29 * 0.65 || (double)(int)color2.B > (double)num29 * 0.7)) + { + for (int l = 0; l < 4; l++) + { + int num20 = 0; + int num21 = 0; + int width = 8; + int height = 8; + Color color3 = color2; + Color color4 = Lighting.GetColor(j, i); + if (l == 0) + { + color4 = Lighting.GetColor(j - 1, i - 1); + if (value.Height < 8) + { + height = value.Height; + } + } + if (l == 1) + { + color4 = Lighting.GetColor(j + 1, i - 1); + num20 = 8; + if (value.Height < 8) + { + height = value.Height; + } + } + if (l == 2) + { + color4 = Lighting.GetColor(j - 1, i + 1); + num21 = 8; + height = 8 - (16 - value.Height); + } + if (l == 3) + { + color4 = Lighting.GetColor(j + 1, i + 1); + num20 = 8; + num21 = 8; + height = 8 - (16 - value.Height); + } + num16 = (float)(int)color4.R * num9; + num17 = (float)(int)color4.G * num9; + num18 = (float)(int)color4.B * num9; + num19 = (float)(int)color4.A * num9; + color4 = new((int)(byte)num16, (int)(byte)num17, (int)(byte)num18, (int)(byte)num19); + color3.R = (byte)((color2.R * 3 + color4.R * 2) / 5); + color3.G = (byte)((color2.G * 3 + color4.G * 2) / 5); + color3.B = (byte)((color2.B * 3 + color4.B * 2) / 5); + color3.A = (byte)((color2.A * 3 + color4.A * 2) / 5); + Main.spriteBatch.Draw(CalamityMod.LavaTextures.block[num4].Value, vector2 - Main.screenPosition + new Vector2((float)num20, (float)num21) + vector, (Rectangle?)new Rectangle(value.X + num20, value.Y + num21, width, height), color3, 0f, default(Vector2), 1f, (SpriteEffects)0, 0f); + } + } + else + { + Main.spriteBatch.Draw(CalamityMod.LavaTextures.block[num4].Value, vector2 - Main.screenPosition + vector, (Rectangle?)value, color, 0f, default(Vector2), 1f, (SpriteEffects)0, 0f); + } + } + else + { + if (value.Y < 4) + { + value.X += (int)(Main.wFrame * 18f); + } + Main.spriteBatch.Draw(CalamityMod.LavaTextures.block[num4].Value, vector2 - Main.screenPosition + vector, (Rectangle?)value, color, 0f, default(Vector2), 1f, (SpriteEffects)0, 0f); + } + if (!Main.tile[j, i + 1].IsHalfBlock) + { + continue; + } + color = Lighting.GetColor(j, i + 1); + num16 = (float)(int)color.R * num9; + num17 = (float)(int)color.G * num9; + num18 = (float)(int)color.B * num9; + num19 = (float)(int)color.A * num9; + color = new((int)(byte)num16, (int)(byte)num17, (int)(byte)num18, (int)(byte)num19); + vector2 = new((float)(j * 16), (float)(i * 16 + 16)); + Main.spriteBatch.Draw(CalamityMod.LavaTextures.block[num4].Value, vector2 - Main.screenPosition + vector, (Rectangle?)new Rectangle(0, 4, 16, 8), color, 0f, default(Vector2), 1f, (SpriteEffects)0, 0f); + float num22 = 6f; + float num24 = 0.75f; + num22 = 4f; + num24 = 0.5f; + for (int m = 0; (float)m < num22; m++) + { + int num25 = i + 2 + m; + if (WorldGen.SolidTile(j, num25)) + { + break; + } + float num26 = 1f - (float)m / num22; + num26 *= num24; + vector2 = new((float)(j * 16), (float)(num25 * 16 - 2)); + Main.spriteBatch.Draw(CalamityMod.LavaTextures.block[num4].Value, vector2 - Main.screenPosition + vector, (Rectangle?)new Rectangle(0, 18, 16, 16), color * num26, 0f, default(Vector2), 1f, (SpriteEffects)0, 0f); + } + } + } + if (!Main.drewLava) + { + Main.ambientLavaX = num27; + Main.ambientLavaY = num28; + Main.ambientLavaStrength = num; + } + Main.drewLava = true; + } + + private void DrawLiquidBehindTiles(int lavaStyleOverride = -1) + { + Vector2 unscaledPosition = Main.Camera.UnscaledPosition; + Vector2 vector = new((float)Main.offScreenRange, (float)Main.offScreenRange); + if (Main.drawToScreen) + { + vector = Vector2.Zero; + } + GetScreenDrawArea(unscaledPosition, vector + (Main.Camera.UnscaledPosition - Main.Camera.ScaledPosition), out var firstTileX, out var lastTileX, out var firstTileY, out var lastTileY); + for (int i = firstTileY; i < lastTileY + 4; i++) + { + for (int j = firstTileX - 2; j < lastTileX + 2; j++) + { + Tile tile = Main.tile[j, i]; + if (tile != null) + { + DrawTile_LiquidBehindTile(solidLayer: false, inFrontOfPlayers: false, lavaStyleOverride, unscaledPosition, vector, j, i, tile); + } + } + } + } + + private void GetScreenDrawArea(Vector2 screenPosition, Vector2 offSet, out int firstTileX, out int lastTileX, out int firstTileY, out int lastTileY) + { + firstTileX = (int)((screenPosition.X - offSet.X) / 16f - 1f); + lastTileX = (int)((screenPosition.X + (float)Main.screenWidth + offSet.X) / 16f) + 2; + firstTileY = (int)((screenPosition.Y - offSet.Y) / 16f - 1f); + lastTileY = (int)((screenPosition.Y + (float)Main.screenHeight + offSet.Y) / 16f) + 5; + if (firstTileX < 4) + { + firstTileX = 4; + } + if (lastTileX > Main.maxTilesX - 4) + { + lastTileX = Main.maxTilesX - 4; + } + if (firstTileY < 4) + { + firstTileY = 4; + } + if (lastTileY > Main.maxTilesY - 4) + { + lastTileY = Main.maxTilesY - 4; + } + if (Main.sectionManager.AnyUnfinishedSections) + { + TimeLogger.DetailedDrawReset(); + WorldGen.SectionTileFrameWithCheck(firstTileX, firstTileY, lastTileX, lastTileY); + TimeLogger.DetailedDrawTime(5); + } + if (Main.sectionManager.AnyNeedRefresh) + { + WorldGen.RefreshSections(firstTileX, firstTileY, lastTileX, lastTileY); + } + } + + public void DrawTile_LiquidBehindTile(bool solidLayer, bool inFrontOfPlayers, int waterStyleOverride, Vector2 screenPosition, Vector2 screenOffset, int tileX, int tileY, Tile tileCache) + { + Tile tile = Main.tile[tileX + 1, tileY]; + Tile tile2 = Main.tile[tileX - 1, tileY]; + Tile tile3 = Main.tile[tileX, tileY - 1]; + Tile tile4 = Main.tile[tileX, tileY + 1]; + if ((tileCache.LiquidType != LiquidID.Lava && tile.LiquidType != LiquidID.Lava && tile2.LiquidType != LiquidID.Lava && tile3.LiquidType != LiquidID.Lava && tile4.LiquidType != LiquidID.Lava)) + { + return; + } + //bool[] _tileSolidTop = (bool[])typeof(TileDrawing).GetField("_tileSolidTop", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance).GetValue(null); + if (!tileCache.HasTile || tileCache.IsActuated /*|| _tileSolidTop[tileCache.TileType]*/ || (tileCache.IsHalfBlock && (tile2.LiquidAmount > 160 || tile.LiquidAmount > 160) && Main.instance.waterfallManager.CheckForWaterfall(tileX, tileY)) || (TileID.Sets.BlocksWaterDrawingBehindSelf[tileCache.TileType] && tileCache.Slope == 0)) + { + return; + } + int num = 0; + bool flag = false; + bool flag2 = false; + bool flag3 = false; + bool flag4 = false; + bool flag5 = false; + int num2 = 0; + bool flag6 = true; + int num3 = (int)tileCache.Slope; + int num4 = (int)tileCache.BlockType; + if (tileCache.TileType == 546 && tileCache.LiquidAmount > 0) + { + flag5 = true; + flag4 = true; + flag = true; + flag2 = true; + num = tileCache.LiquidAmount; + } + else + { + if (tileCache.LiquidAmount > 0 && num4 != 0 && (num4 != 1 || tileCache.LiquidAmount > 160)) + { + flag5 = true; + if (tileCache.LiquidAmount > num) + { + num = tileCache.LiquidAmount; + } + } + if (tile2.LiquidAmount > 0 && num3 != 1 && num3 != 3) + { + flag = true; + if (tile2.LiquidAmount > num) + { + num = tile2.LiquidAmount; + } + } + if (tile.LiquidAmount > 0 && num3 != 2 && num3 != 4) + { + flag2 = true; + if (tile.LiquidAmount > num) + { + num = tile.LiquidAmount; + } + } + if (tile3.LiquidAmount > 0 && num3 != 3 && num3 != 4) + { + flag3 = true; + } + if (tile4.LiquidAmount > 0 && num3 != 1 && num3 != 2) + { + if (tile4.LiquidAmount > 240) + { + flag4 = true; + } + } + } + if (!flag3 && !flag4 && !flag && !flag2 && !flag5) + { + return; + } + if (waterStyleOverride != -1) + { + CalamityMod.LavaStyle = waterStyleOverride; + } + if (num2 == 0) + { + num2 = CalamityMod.LavaStyle; + } + Lighting.GetCornerColors(tileX, tileY, out var vertices); + Vector2 vector = new((float)(tileX * 16), (float)(tileY * 16)); + Rectangle liquidSize = new(0, 4, 16, 16); + if (flag4 && (flag || flag2)) + { + flag = true; + flag2 = true; + } + if (tileCache.HasTile && (Main.tileSolidTop[tileCache.TileType] || !Main.tileSolid[tileCache.TileType])) + { + return; + } + if ((!flag3 || !(flag || flag2)) && !(flag4 && flag3)) + { + if (flag3) + { + liquidSize = new(0, 4, 16, 4); + if (tileCache.IsHalfBlock || tileCache.Slope != 0) + { + liquidSize = new(0, 4, 16, 12); + } + } + else if (flag4 && !flag && !flag2) + { + vector = new((float)(tileX * 16), (float)(tileY * 16 + 12)); + liquidSize = new(0, 4, 16, 4); + } + else + { + float num8 = (float)(256 - num) / 32f; + int y = 4; + if (tile3.LiquidAmount == 0 && (num4 != 0 || !WorldGen.SolidTile(tileX, tileY - 1))) + { + y = 0; + } + int num5 = (int)num8 * 2; + if (tileCache.Slope != 0) + { + vector = new((float)(tileX * 16), (float)(tileY * 16 + num5)); + liquidSize = new(0, num5, 16, 16 - num5); + } + else if ((flag && flag2) || tileCache.IsHalfBlock) + { + vector = new((float)(tileX * 16), (float)(tileY * 16 + num5)); + liquidSize = new(0, y, 16, 16 - num5); + } + else if (flag) + { + vector = new((float)(tileX * 16), (float)(tileY * 16 + num5)); + liquidSize = new(0, y, 4, 16 - num5); + } + else + { + vector = new((float)(tileX * 16 + 12), (float)(tileY * 16 + num5)); + liquidSize = new(0, y, 4, 16 - num5); + } + } + } + Vector2 position = vector - screenPosition + screenOffset; + float num6 = 1f; + if ((double)tileY <= Main.worldSurface || num6 > 1f) + { + num6 = 1f; + if (tileCache.WallType == 21) + { + num6 = 0.9f; + } + else if (tileCache.WallType > 0) + { + num6 = 0.6f; + } + } + if (tileCache.IsHalfBlock && tile3.LiquidAmount > 0 && tileCache.WallType > 0) + { + num6 = 0f; + } + if (num3 == 4 && tile2.LiquidAmount == 0 && !WorldGen.SolidTile(tileX - 1, tileY)) + { + num6 = 0f; + } + if (num3 == 3 && tile.LiquidAmount == 0 && !WorldGen.SolidTile(tileX + 1, tileY)) + { + num6 = 0f; + } + ref Color bottomLeftColor = ref vertices.BottomLeftColor; + bottomLeftColor *= num6; + ref Color bottomRightColor = ref vertices.BottomRightColor; + bottomRightColor *= num6; + ref Color topLeftColor = ref vertices.TopLeftColor; + topLeftColor *= num6; + ref Color topRightColor = ref vertices.TopRightColor; + topRightColor *= num6; + bool flag7 = false; + if (flag6) + { + for (int i = 0; i < LavaStylesLoader.TotalCount; i++) + { + if (CalamityMod.lavaAlpha[i] > 0f && i != num2) + { + DrawPartialLiquid(!solidLayer, tileCache, ref position, ref liquidSize, i, ref vertices); + flag7 = true; + break; + } + } + } + VertexColors colors = vertices; + float num7 = (flag7 ? CalamityMod.lavaAlpha[num2] : 1f); + ref Color bottomLeftColor2 = ref colors.BottomLeftColor; + bottomLeftColor2 *= num7; + ref Color bottomRightColor2 = ref colors.BottomRightColor; + bottomRightColor2 *= num7; + ref Color topLeftColor2 = ref colors.TopLeftColor; + topLeftColor2 *= num7; + ref Color topRightColor2 = ref colors.TopRightColor; + topRightColor2 *= num7; + DrawPartialLiquid(!solidLayer, tileCache, ref position, ref liquidSize, num2, ref colors); + } + + private void DrawPartialLiquid(bool behindBlocks, Tile tileCache, ref Vector2 position, ref Rectangle liquidSize, int liquidType, ref VertexColors colors) + { + int num = (int)tileCache.Slope; + bool flag = !TileID.Sets.BlocksWaterDrawingBehindSelf[tileCache.TileType]; + if (!behindBlocks) + { + flag = false; + } + if (flag || num == 0) + { + Main.tileBatch.Draw(CalamityMod.LavaTextures.block[liquidType].Value, position, liquidSize, colors, default(Vector2), 1f, (SpriteEffects)0); + return; + } + liquidSize.X += 18 * (num - 1); + switch (num) + { + case 1: + Main.tileBatch.Draw(CalamityMod.LavaTextures.slope[liquidType].Value, position, liquidSize, colors, Vector2.Zero, 1f, (SpriteEffects)0); + break; + case 2: + Main.tileBatch.Draw(CalamityMod.LavaTextures.slope[liquidType].Value, position, liquidSize, colors, Vector2.Zero, 1f, (SpriteEffects)0); + break; + case 3: + Main.tileBatch.Draw(CalamityMod.LavaTextures.slope[liquidType].Value, position, liquidSize, colors, Vector2.Zero, 1f, (SpriteEffects)0); + break; + case 4: + Main.tileBatch.Draw(CalamityMod.LavaTextures.slope[liquidType].Value, position, liquidSize, colors, Vector2.Zero, 1f, (SpriteEffects)0); + break; + } + } + + public void InitialDrawLavafall(WaterfallManager waterfallManager) + { + for (int i = 0; i < LavaStylesLoader.TotalCount; i++) + { + if (CalamityMod.lavaAlpha[i] > 0f) + { + DrawLavafall(waterfallManager, i, CalamityMod.lavaAlpha[i]); + } + } + } + + internal void DrawLavafall(WaterfallManager waterfallManager, int Style = 0, float Alpha = 1f) + { + int waterfallDist = (int)typeof(WaterfallManager).GetField("waterfallDist", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance).GetValue(waterfallManager); + int rainFrameForeground = (int)typeof(WaterfallManager).GetField("rainFrameForeground", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance).GetValue(waterfallManager); + int rainFrameBackground = (int)typeof(WaterfallManager).GetField("rainFrameBackground", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance).GetValue(waterfallManager); + int snowFrameForeground = (int)typeof(WaterfallManager).GetField("snowFrameForeground", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance).GetValue(waterfallManager); + WaterfallData[] waterfalls = (WaterfallData[])typeof(WaterfallManager).GetField("waterfalls", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance).GetValue(waterfallManager); + int currentMax = (int)typeof(WaterfallManager).GetField("currentMax", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance).GetValue(waterfallManager); + int slowFrame = (int)typeof(WaterfallManager).GetField("slowFrame", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Public | BindingFlags.Instance).GetValue(waterfallManager); + Main.tileSolid[546] = false; + float num = 0f; + float num12 = 99999f; + float num23 = 99999f; + int num34 = -1; + int num45 = -1; + float num47 = 0f; + float num48 = 99999f; + float num49 = 99999f; + int num50 = -1; + int num2 = -1; + Rectangle value = default(Rectangle); + Rectangle value2 = default(Rectangle); + Vector2 origin = default(Vector2); + for (int i = 0; i < currentMax; i++) + { + if (waterfalls[i].type != 1) + { + continue; + } + int num3 = 0; + int num4 = Style; + int num5 = waterfalls[i].x; + int num6 = waterfalls[i].y; + int num7 = 0; + int num8 = 0; + int num9 = 0; + int num10 = 0; + int num11 = 0; + int num13 = 0; + int num14; + int num15; + if (waterfalls[i].stopAtStep == 0) + { + continue; + } + num14 = 32 * slowFrame; + int num22 = 0; + num15 = waterfallDist; + Color color4 = Color.White; + for (int k = 0; k < num15; k++) + { + if (num22 >= 2) + { + break; + } + typeof(WaterfallManager).GetMethod("AddLight", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static).Invoke(null, new object[] { 1, num5, num6 }); + Tile tile3 = Main.tile[num5, num6]; + if (tile3.HasUnactuatedTile && Main.tileSolid[tile3.TileType] && !Main.tileSolidTop[tile3.TileType] && !TileID.Sets.Platforms[tile3.TileType] && tile3.BlockType == 0) + { + break; + } + Tile tile4 = Main.tile[num5 - 1, num6]; + Tile tile5 = Main.tile[num5, num6 + 1]; + Tile tile6 = Main.tile[num5 + 1, num6]; + if (WorldGen.SolidTile(tile5) && !tile3.IsHalfBlock) + { + num3 = 8; + } + else if (num8 != 0) + { + num3 = 0; + } + int num24 = 0; + int num25 = num10; + int num26 = 0; + int num27 = 0; + bool flag2 = false; + if (tile5.TopSlope && !tile3.IsHalfBlock && tile5.TileType != 19) + { + flag2 = true; + if (tile5.Slope == (SlopeType)1) + { + num24 = 1; + num26 = 1; + num9 = 1; + num10 = num9; + } + else + { + num24 = -1; + num26 = -1; + num9 = -1; + num10 = num9; + } + num27 = 1; + } + else if ((!WorldGen.SolidTile(tile5) && !tile5.BottomSlope && !tile3.IsHalfBlock) || (!tile5.HasTile && !tile3.IsHalfBlock)) + { + num22 = 0; + num27 = 1; + num26 = 0; + } + else if ((WorldGen.SolidTile(tile4) || tile4.TopSlope || tile4.LiquidAmount > 0) && !WorldGen.SolidTile(tile6) && tile6.LiquidAmount == 0) + { + if (num9 == -1) + { + num22++; + } + num26 = 1; + num27 = 0; + num9 = 1; + } + else if ((WorldGen.SolidTile(tile6) || tile6.TopSlope || tile6.LiquidAmount > 0) && !WorldGen.SolidTile(tile4) && tile4.LiquidAmount == 0) + { + if (num9 == 1) + { + num22++; + } + num26 = -1; + num27 = 0; + num9 = -1; + } + else if (((!WorldGen.SolidTile(tile6) && !tile3.TopSlope) || tile6.LiquidAmount == 0) && !WorldGen.SolidTile(tile4) && !tile3.TopSlope && tile4.LiquidAmount == 0) + { + num27 = 0; + num26 = num9; + } + else + { + num22++; + num27 = 0; + num26 = 0; + } + if (num22 >= 2) + { + num9 *= -1; + num26 *= -1; + } + Color color5 = Lighting.GetColor(num5, num6); + if (k > 50) + { + typeof(WaterfallManager).GetMethod("TrySparkling", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static).Invoke(null, new object[] { num5, num6, num9, color5 }); + } + float alpha = GetLavafallAlpha(Alpha, num15, num6, k, tile3); + color5 = (Color)typeof(WaterfallManager).GetMethod("StylizeColor", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static).Invoke(null, new object[] { alpha, num15, 1, num6, k, tile3, color5 }); + float num33 = Math.Abs((float)(num5 * 16 + 8) - (Main.screenPosition.X + (float)(Main.screenWidth / 2))); + float num35 = Math.Abs((float)(num6 * 16 + 8) - (Main.screenPosition.Y + (float)(Main.screenHeight / 2))); + if (num33 < (float)(Main.screenWidth * 2) && num35 < (float)(Main.screenHeight * 2)) + { + float num36 = (float)Math.Sqrt(num33 * num33 + num35 * num35); + float num37 = 1f - num36 / ((float)Main.screenWidth * 0.75f); + if (num37 > 0f) + { + num += num37; + } + } + if (num33 < num12) + { + num12 = num33; + num34 = num5 * 16 + 8; + } + if (num35 < num23) + { + num23 = num33; + num45 = num6 * 16 + 8; + } + int num38 = tile3.LiquidAmount / 16; + if (flag2 && num9 != num25) + { + int num39 = 2; + if (num25 == 1) + { + DrawLavafall(num4, num5, num6, alpha, new Vector2((float)(num5 * 16 - 16), (float)(num6 * 16 + 16 - num39)) - Main.screenPosition, new Rectangle(num14, 24, 32, 16 - num38 - num39), color5, (SpriteEffects)1); + } + else + { + DrawLavafall(num4, num5, num6, alpha, new Vector2((float)(num5 * 16), (float)(num6 * 16 + 16 - num39)) - Main.screenPosition, new Rectangle(num14, 24, 32, 16 - num38 - num39), color5, (SpriteEffects)0); + } + } + if (num7 == 0 && num24 != 0 && num8 == 1 && num9 != num10) + { + num24 = 0; + num9 = num10; + color5 = Color.White; + if (num9 == 1) + { + DrawLavafall(num4, num5, num6, alpha, new Vector2((float)(num5 * 16 - 16), (float)(num6 * 16 + 16)) - Main.screenPosition, new Rectangle(num14, 24, 32, 16 - num38), color5, (SpriteEffects)1); + } + else + { + DrawLavafall(num4, num5, num6, alpha, new Vector2((float)(num5 * 16 - 16), (float)(num6 * 16 + 16)) - Main.screenPosition, new Rectangle(num14, 24, 32, 16 - num38), color5, (SpriteEffects)1); + } + } + if (num11 != 0 && num26 == 0 && num27 == 1) + { + if (num9 == 1) + { + if (num13 != num4) + { + DrawLavafall(num4, num5, num6, alpha, new Vector2((float)(num5 * 16), (float)(num6 * 16 + num3 + 8)) - Main.screenPosition, new Rectangle(num14, 0, 16, 16 - num38 - 8), color4, (SpriteEffects)1); + } + else + { + DrawLavafall(num4, num5, num6, alpha, new Vector2((float)(num5 * 16), (float)(num6 * 16 + num3 + 8)) - Main.screenPosition, new Rectangle(num14, 0, 16, 16 - num38 - 8), color5, (SpriteEffects)1); + } + } + else + { + DrawLavafall(num4, num5, num6, alpha, new Vector2((float)(num5 * 16), (float)(num6 * 16 + num3 + 8)) - Main.screenPosition, new Rectangle(num14, 0, 16, 16 - num38 - 8), color5, (SpriteEffects)0); + } + } + if (num3 == 8 && num8 == 1 && num11 == 0) + { + if (num10 == -1) + { + if (num13 != num4) + { + DrawLavafall(num13, num5, num6, alpha, new Vector2((float)(num5 * 16), (float)(num6 * 16)) - Main.screenPosition, new Rectangle(num14, 24, 32, 8), color4, (SpriteEffects)0); + } + else + { + DrawLavafall(num4, num5, num6, alpha, new Vector2((float)(num5 * 16), (float)(num6 * 16)) - Main.screenPosition, new Rectangle(num14, 24, 32, 8), color5, (SpriteEffects)0); + } + } + else if (num13 != num4) + { + DrawLavafall(num13, num5, num6, alpha, new Vector2((float)(num5 * 16 - 16), (float)(num6 * 16)) - Main.screenPosition, new Rectangle(num14, 24, 32, 8), color4, (SpriteEffects)1); + } + else + { + DrawLavafall(num4, num5, num6, alpha, new Vector2((float)(num5 * 16 - 16), (float)(num6 * 16)) - Main.screenPosition, new Rectangle(num14, 24, 32, 8), color5, (SpriteEffects)1); + } + } + if (num24 != 0 && num7 == 0) + { + if (num25 == 1) + { + if (num13 != num4) + { + DrawLavafall(num13, num5, num6, alpha, new Vector2((float)(num5 * 16 - 16), (float)(num6 * 16)) - Main.screenPosition, new Rectangle(num14, 24, 32, 16 - num38), color4, (SpriteEffects)1); + } + else + { + DrawLavafall(num4, num5, num6, alpha, new Vector2((float)(num5 * 16 - 16), (float)(num6 * 16)) - Main.screenPosition, new Rectangle(num14, 24, 32, 16 - num38), color5, (SpriteEffects)1); + } + } + else if (num13 != num4) + { + DrawLavafall(num13, num5, num6, alpha, new Vector2((float)(num5 * 16), (float)(num6 * 16)) - Main.screenPosition, new Rectangle(num14, 24, 32, 16 - num38), color4, (SpriteEffects)0); + } + else + { + DrawLavafall(num4, num5, num6, alpha, new Vector2((float)(num5 * 16), (float)(num6 * 16)) - Main.screenPosition, new Rectangle(num14, 24, 32, 16 - num38), color5, (SpriteEffects)0); + } + } + if (num27 == 1 && num24 == 0 && num11 == 0) + { + if (num9 == -1) + { + if (num8 == 0) + { + DrawLavafall(num4, num5, num6, alpha, new Vector2((float)(num5 * 16), (float)(num6 * 16 + num3)) - Main.screenPosition, new Rectangle(num14, 0, 16, 16 - num38), color5, (SpriteEffects)0); + } + else if (num13 != num4) + { + DrawLavafall(num13, num5, num6, alpha, new Vector2((float)(num5 * 16), (float)(num6 * 16)) - Main.screenPosition, new Rectangle(num14, 24, 32, 16 - num38), color4, (SpriteEffects)0); + } + else + { + DrawLavafall(num4, num5, num6, alpha, new Vector2((float)(num5 * 16), (float)(num6 * 16)) - Main.screenPosition, new Rectangle(num14, 24, 32, 16 - num38), color5, (SpriteEffects)0); + } + } + else if (num8 == 0) + { + DrawLavafall(num4, num5, num6, alpha, new Vector2((float)(num5 * 16), (float)(num6 * 16 + num3)) - Main.screenPosition, new Rectangle(num14, 0, 16, 16 - num38), color5, (SpriteEffects)1); + } + else if (num13 != num4) + { + DrawLavafall(num13, num5, num6, alpha, new Vector2((float)(num5 * 16 - 16), (float)(num6 * 16)) - Main.screenPosition, new Rectangle(num14, 24, 32, 16 - num38), color4, (SpriteEffects)1); + } + else + { + DrawLavafall(num4, num5, num6, alpha, new Vector2((float)(num5 * 16 - 16), (float)(num6 * 16)) - Main.screenPosition, new Rectangle(num14, 24, 32, 16 - num38), color5, (SpriteEffects)1); + } + } + else + { + switch (num26) + { + case 1: + if (Main.tile[num5, num6].LiquidAmount > 0 && !Main.tile[num5, num6].IsHalfBlock) + { + break; + } + if (num24 == 1) + { + for (int m = 0; m < 8; m++) + { + int num43 = m * 2; + int num44 = 14 - m * 2; + int num46 = num43; + num3 = 8; + if (num7 == 0 && m < 2) + { + num46 = 4; + } + DrawLavafall(num4, num5, num6, alpha, new Vector2((float)(num5 * 16 + num43), (float)(num6 * 16 + num3 + num46)) - Main.screenPosition, new Rectangle(16 + num14 + num44, 0, 2, 16 - num3), color5, (SpriteEffects)1); + } + } + else + { + int height2 = 16; + if (TileID.Sets.BlocksWaterDrawingBehindSelf[Main.tile[num5, num6].TileType]) + { + height2 = 8; + } + else if (TileID.Sets.BlocksWaterDrawingBehindSelf[Main.tile[num5, num6 + 1].TileType]) + { + height2 = 8; + } + DrawLavafall(num4, num5, num6, alpha, new Vector2((float)(num5 * 16), (float)(num6 * 16 + num3)) - Main.screenPosition, new Rectangle(16 + num14, 0, 16, height2), color5, (SpriteEffects)1); + } + break; + case -1: + if (Main.tile[num5, num6].LiquidAmount > 0 && !Main.tile[num5, num6].IsHalfBlock) + { + break; + } + if (num24 == -1) + { + for (int l = 0; l < 8; l++) + { + int num40 = l * 2; + int num41 = l * 2; + int num42 = 14 - l * 2; + num3 = 8; + if (num7 == 0 && l > 5) + { + num42 = 4; + } + DrawLavafall(num4, num5, num6, alpha, new Vector2((float)(num5 * 16 + num40), (float)(num6 * 16 + num3 + num42)) - Main.screenPosition, new Rectangle(16 + num14 + num41, 0, 2, 16 - num3), color5, (SpriteEffects)1); + } + } + else + { + int height = 16; + if (TileID.Sets.BlocksWaterDrawingBehindSelf[Main.tile[num5, num6].TileType]) + { + height = 8; + } + else if (TileID.Sets.BlocksWaterDrawingBehindSelf[Main.tile[num5, num6 + 1].TileType]) + { + height = 8; + } + DrawLavafall(num4, num5, num6, alpha, new Vector2((float)(num5 * 16), (float)(num6 * 16 + num3)) - Main.screenPosition, new Rectangle(16 + num14, 0, 16, height), color5, (SpriteEffects)0); + } + break; + case 0: + if (num27 == 0) + { + if (Main.tile[num5, num6].LiquidAmount <= 0 || Main.tile[num5, num6].IsHalfBlock) + { + DrawLavafall(num4, num5, num6, alpha, new Vector2((float)(num5 * 16), (float)(num6 * 16 + num3)) - Main.screenPosition, new Rectangle(16 + num14, 0, 16, 16), color5, (SpriteEffects)0); + } + k = 1000; + } + break; + } + } + if (tile3.LiquidAmount > 0 && !tile3.IsHalfBlock) + { + k = 1000; + } + num8 = num27; + num10 = num9; + num7 = num26; + num5 += num26; + num6 += num27; + num11 = num24; + color4 = color5; + if (num13 != num4) + { + num13 = num4; + } + if ((tile4.HasTile && (tile4.TileType == 189 || tile4.TileType == 196)) || (tile6.HasTile && (tile6.TileType == 189 || tile6.TileType == 196)) || (tile5.HasTile && (tile5.TileType == 189 || tile5.TileType == 196))) + { + num15 = (int)(40f * ((float)Main.maxTilesX / 4200f) * Main.gfxQuality); + } + } + } + Main.ambientWaterfallX = num34; + Main.ambientWaterfallY = num45; + Main.ambientWaterfallStrength = num; + Main.ambientLavafallX = num50; + Main.ambientLavafallY = num2; + Main.ambientLavafallStrength = num47; + Main.tileSolid[546] = true; + } + + private void DrawLavafall(int waterfallType, int x, int y, float opacity, Vector2 position, Rectangle sourceRect, Color color, SpriteEffects effects) + { + Texture2D value = CalamityMod.LavaTextures.fall[waterfallType].Value; + Main.spriteBatch.Draw(value, position, (Rectangle?)sourceRect, color, 0f, default(Vector2), 1f, effects, 0f); + } + + private static float GetLavafallAlpha(float Alpha, int maxSteps, int y, int s, Tile tileCache) + { + float num = (tileCache.WallType != 0 || !((double)y < Main.worldSurface)) ? (1f * Alpha) : Alpha; + if (s > maxSteps - 10) + { + num *= (float)(maxSteps - s) / 10f; + } + return num; + } + + public static int dustLava() + { + if (CalamityMod.LavaStyle >= 1) + { + return LavaStylesLoader.Get(CalamityMod.LavaStyle).GetSplashDust(); + } + else + { + return DustID.Lava; + } + } + + //just better as a method rather than hardcoded type values + public static int goreLava() + { + if (CalamityMod.LavaStyle >= 1) + { + return LavaStylesLoader.Get(CalamityMod.LavaStyle).GetDropletGore(); + } + else + { + return GoreID.LavaDrip; + } + } + } +} diff --git a/Systems/ModLavaStyle.cs b/Systems/ModLavaStyle.cs new file mode 100644 index 0000000000..84d229559a --- /dev/null +++ b/Systems/ModLavaStyle.cs @@ -0,0 +1,262 @@ +using System; +using System.Collections.Generic; +using System.Reflection; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using Terraria; +using Terraria.GameContent.Liquid; +using Terraria.GameContent; +using Terraria.Graphics; +using Terraria.ModLoader; +using System.Linq; +using Terraria.ID; +using Microsoft.Xna.Framework; +using CalamityMod.Items.Potions.Alcohol; + +namespace CalamityMod.Systems +{ + public abstract class ModLavaStyle : ModTexturedType + { + /// + /// The ID of the lava style. + /// + public int Slot { get; private set; } = -1; + + public override string Name => base.Name; + + public override string Texture => base.Texture; + + public virtual string BlockTexture => Texture + "_Block"; + + public virtual string SlopeTexture => Texture + "_Slope"; + + public virtual string WaterfallTexture => Texture + "_Waterfall"; + + protected sealed override void Register() + { + Slot = LavaStylesLoader.Register(this); + } + + public sealed override void SetupContent() + { + SetStaticDefaults(); + } + + /// + /// Allows you to determine how much light this lava emits.
+ /// It can also let you light up the block in front of this lava.
+ /// Keep in mind this also effects what color the lavafalls emit
+ /// See for vanilla tile light values to use as a reference.
+ ///
+ /// The x position in tile coordinates. + /// The y position in tile coordinates. + /// The red component of light, usually a value between 0 and 1 + /// The green component of light, usually a value between 0 and 1 + /// The blue component of light, usually a value between 0 and 1 + public virtual void ModifyLight(int i, int j, ref float r, ref float g, ref float b) + { + r = 0.55f; + g = 0.33f; + b = 0.11f; + } + + /// + /// Allows water styles to manipulate what color the liquid is drawn to, this can allow waters to be see-throughable to see backgrounds (surface and underground backgrounds not walls) + /// + /// X position of the water + /// Y position of the water + /// The vertexColor of the water color, this is both used to get the current color and to set the color of the water + public virtual void DrawColor(int x, int y, ref VertexColors liquidColor, bool isSlope) + { + } + + /// + /// The ID of the dust that is created when anything splashes in lava. + /// + public virtual int GetSplashDust() + { + return DustID.Lava; + } + + /// + /// The ID of the gore that represents droplets of lava falling down from a block. Return (or another existing droplet gore). + /// + public virtual int GetDropletGore() + { + return GoreID.LavaDrip; + } + + /// + /// Return true if the player is in the correct zone to activate the lava. + /// + /// + public virtual bool IsLavaActive() + { + return false; + } + + /// + /// Return false if the waterfall made by the lavastyle should have a glowmask + /// + /// + public virtual bool LavafallGlowmask() + { + return true; + } + + /// + /// Allows your lavastyle to inflict debuffs to Players and NPCs when they enter your lava style + /// + /// The Player that is inflicted with the debuff apon entering the lavastyle + /// The duration of the OnFire! debuff. This allows for easy replacement of OnFire + public virtual void InflictDebuff(Player player, int onfireDuration) + { + } + } + + public class LavaStylesLoader : ModSystem + { + private static readonly MethodInfo ResizeArrayMethodInfo; + + static LavaStylesLoader() + { + ResizeArrayMethodInfo = typeof(ModContent).GetMethod("ResizeArrays", BindingFlags.NonPublic | BindingFlags.Static); + } + + private static void ResizeArrays(ResizeArray_orig orig, bool unloading) + { + orig.Invoke(unloading); + int totalCount = TotalCount; + Array.Resize(ref CalamityMod.LavaTextures.liquid, totalCount); + Array.Resize(ref CalamityMod.LavaTextures.block, totalCount); + Array.Resize(ref CalamityMod.LavaTextures.slope, totalCount); + Array.Resize(ref CalamityMod.LavaTextures.fall, totalCount); + Array.Resize(ref CalamityMod.lavaAlpha, totalCount); + } + + private static readonly List _content = []; + + public static IReadOnlyList Content => _content; + + public static int VanillaCount => 1; + + public static int ModCount => _content.Count; + + public static int TotalCount => VanillaCount + ModCount; + + public override void Load() + { + if (ResizeArrayMethodInfo != null) + { + MonoModHooks.Add(ResizeArrayMethodInfo, ResizeArrays); + } + } + + public override void PostSetupContent() + { + foreach (ModLavaStyle item in Content) + { + int Slot = item.Slot; + CalamityMod.LavaTextures.liquid[Slot] = ModContent.Request(item.Texture, (AssetRequestMode)2); + CalamityMod.LavaTextures.block[Slot] = ModContent.Request(item.BlockTexture, (AssetRequestMode)2); + CalamityMod.LavaTextures.slope[Slot] = ModContent.Request(item.SlopeTexture, (AssetRequestMode)2); + CalamityMod.LavaTextures.fall[Slot] = ModContent.Request(item.WaterfallTexture, (AssetRequestMode)2); + } + } + + public static ModLavaStyle Get(int type) + { + type -= VanillaCount; + return type >= 0 && type < _content.Count ? _content[type] : null; + } + + internal static int Register(ModLavaStyle instance) + { + int type = TotalCount; + ModTypeLookup.Register(instance); + _content.Add(instance); + return type; + } + + private delegate void ResizeArray_orig(bool unloading); + + public static void UpdateLiquidAlphas() + { + if (CalamityMod.LavaStyle >= VanillaCount) + { + for (int i = 0; i < VanillaCount; i++) + { + CalamityMod.lavaAlpha[i] -= 0.2f; + if (CalamityMod.lavaAlpha[i] < 0f) + { + CalamityMod.lavaAlpha[i] = 0f; + } + } + } + foreach (ModLavaStyle item in Content) + { + int type = item.Slot; + if (CalamityMod.LavaStyle == type) + { + CalamityMod.lavaAlpha[type] += 0.2f; + if (CalamityMod.lavaAlpha[type] > 1f) + { + CalamityMod.lavaAlpha[type] = 1f; + } + } + else + { + CalamityMod.lavaAlpha[type] -= 0.2f; + if (CalamityMod.lavaAlpha[type] < 0f) + { + CalamityMod.lavaAlpha[type] = 0f; + } + } + } + } + + public static void ModifyLightSetup(int i, int j, int style, ref float r, ref float g, ref float b) + { + ModLavaStyle lavaStyle = Get(style); + if (lavaStyle != null) + { + lavaStyle?.ModifyLight(i, j, ref r, ref g, ref b); + } + } + + internal static void DrawColorSetup(int x, int y, int type, ref VertexColors liquidColor, bool isSlope = false) + { + ModLavaStyle styles = Get(type); + if (styles != null) + { + styles?.DrawColor(x, y, ref liquidColor, isSlope); + } + } + + public static void InflictDebuff(Player player, int type, int onfireDuration) + { + ModLavaStyle lavaStyle = Get(type); + if (lavaStyle != null) + { + lavaStyle?.InflictDebuff(player, onfireDuration); + } + } + + public static void IsLavaActive() + { + foreach (ModLavaStyle item in Content) + { + int type = item.Slot; + ModLavaStyle lavaStyle = Get(type); + if (lavaStyle != null) + { + bool? flag = lavaStyle?.IsLavaActive(); + if (flag != null && flag == true) + { + CalamityMod.LavaStyle = lavaStyle.Slot; + } + } + } + } + } +} diff --git a/Utilities/MiscUtils.cs b/Utilities/MiscUtils.cs index 08ab4456c4..eb9d1c06fe 100644 --- a/Utilities/MiscUtils.cs +++ b/Utilities/MiscUtils.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using CalamityMod.CalPlayer; using CalamityMod.Items.Tools.ClimateChange; +using CalamityMod.Systems; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Graphics; diff --git a/Utilities/TileUtils.cs b/Utilities/TileUtils.cs index 20c6313a7f..e0171e61c4 100644 --- a/Utilities/TileUtils.cs +++ b/Utilities/TileUtils.cs @@ -1,7 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; -using CalamityMod.Systems; +using System.Runtime.CompilerServices; using CalamityMod.Tiles; using CalamityMod.Tiles.Abyss; using CalamityMod.Tiles.Astral; @@ -583,6 +583,41 @@ namespace CalamityMod SetMerge(type, TileType()); } + /// + /// The X position of the Tile + /// + /// + /// + public static int X(this Tile tile) + { + TilePos(tile, out int x, out _); + return x; + } + + /// + /// The Y position of the Tile + /// + /// + /// + public static int Y(this Tile tile) + { + TilePos(tile, out _, out int y); + return y; + } + + /// + /// Gets the Position of the tile, the same values that would be inputted in Main.tile to get this Tile + /// + /// + /// The outputted X value, if you want the X by itself use Tile.X + /// The outputted Y value, if you want the Y by itself use Tile.Y + public static void TilePos(this Tile tile, out int x, out int y) + { + uint tileId = Unsafe.BitCast(tile); + x = Math.DivRem((int)tileId, Main.tile.Height, out y); //Thanks to FoxXD_ for the help with this + } + + /// /// Determines if a tile is solid ground based on whether it's active and not actuated or if the tile is solid in any way, including just the top. /// diff --git a/Waters/AstralWater.cs b/Waters/AstralWater.cs index 7064c4fadf..7928f6d6dd 100644 --- a/Waters/AstralWater.cs +++ b/Waters/AstralWater.cs @@ -1,4 +1,7 @@ -using Microsoft.Xna.Framework; +using CalamityMod.Dusts.WaterSplash; +using CalamityMod.Gores.WaterDroplet; +using CalamityMod.Systems; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using Terraria; @@ -6,13 +9,15 @@ using Terraria.ModLoader; namespace CalamityMod.Waters { - public class AstralWater : ModWaterStyle + public class AstralWaterflow : ModWaterfallStyle { } + + public class AstralWater : CalamityModWaterStyle { public override int ChooseWaterfallStyle() => ModContent.Find("CalamityMod/AstralWaterflow").Slot; - public override int GetSplashDust() => 52; //corruption water? - public override int GetDropletGore() => ModContent.Find("CalamityMod/AstralWaterDroplet").Type; + public override int GetSplashDust() => ModContent.DustType(); + public override int GetDropletGore() => ModContent.GoreType(); public override Asset GetRainTexture() => ModContent.Request("CalamityMod/Waters/AstralRain"); public override byte GetRainVariant() => (byte)Main.rand.Next(3); - public override Color BiomeHairColor() => Color.MediumPurple; + public override Color BiomeHairColor() => new Color(93, 78, 107); } } diff --git a/Waters/AstralWaterflow.cs b/Waters/AstralWaterflow.cs deleted file mode 100644 index 76e3fc81d6..0000000000 --- a/Waters/AstralWaterflow.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Terraria.ModLoader; -namespace CalamityMod.Waters -{ - public class AstralWaterflow : ModWaterfallStyle - { - - } -} diff --git a/Waters/BasaltGullyWater.cs b/Waters/BasaltGullyWater.cs index 6aa26ea180..4dbee891e9 100644 --- a/Waters/BasaltGullyWater.cs +++ b/Waters/BasaltGullyWater.cs @@ -1,33 +1,58 @@ -using Microsoft.Xna.Framework; +using CalamityMod.Particles; +using System; +using CalamityMod.Systems; +using CalamityMod.Tiles.Abyss; +using Microsoft.Xna.Framework; +using Terraria; using Terraria.ModLoader; +using Terraria.Graphics; +using CalamityMod.Dusts.WaterSplash; +using CalamityMod.Gores.WaterDroplet; namespace CalamityMod.Waters { - public class BasaltGullyWater : ModWaterStyle + public class SunkenSeaWaterflow : ModWaterfallStyle { } + + public class SunkenSeaWater : CalamityModWaterStyle { - public static int Type; - public override void SetStaticDefaults() + public override int ChooseWaterfallStyle() => ModContent.Find("CalamityMod/SunkenSeaWaterflow").Slot; + public override int GetSplashDust() => ModContent.DustType(); + public override int GetDropletGore() => ModContent.GoreType(); + public override Color BiomeHairColor() => new Color(46, 155, 171); + public override void DrawColor(int x, int y, ref VertexColors liquidColor, bool isSlope) => ILEditing.ILChanges.SelectSulphuricWaterColor(x, y, ref liquidColor, isSlope); + public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b) { - Type = Slot; - } - public override int ChooseWaterfallStyle() - { - return ModContent.Find("CalamityMod/BasaltGullyWaterflow").Slot; - } + Vector3 outputColor = new Vector3(r, g, b); + if (outputColor == Vector3.One || outputColor == new Vector3(0.25f, 0.25f, 0.25f) || outputColor == new Vector3(0.5f, 0.5f, 0.5f)) + return; - public override int GetSplashDust() - { - return 33; - } - - public override int GetDropletGore() - { - return 713; - } - - public override Color BiomeHairColor() - { - return Color.DarkGray; + if (CalamityUtils.ParanoidTileRetrieval(i, j).TileType != (ushort)ModContent.TileType()) + { + float brightness = MathHelper.Clamp(0.07f, 0f, 0.07f); + float waveScale1 = Main.GameUpdateCount * 0.028f; + float waveScale2 = Main.GameUpdateCount * 0.1f; + int yScale = -j / 2; + int xScale = i / 15; + float wave1 = Main.GameUpdateCount * 0.024f * -50 + ((-i / 30) + (j / 30)) * 25; + float wave2 = waveScale2 * -10 + ((-xScale) + yScale) * 45; + float wave3 = waveScale1 * -100 + ((i / 7) + (j / 50)) * 25; + float wave4 = Main.GameUpdateCount * 0.15f * 10 + ((i / 3) + yScale) * 45; + float wave5 = waveScale1 * -70 + ((-i / 25) + (-j / 25)) * 20; + float wave6 = waveScale2 * -10 + (xScale + yScale) * 45; + float bigwave = Main.GameUpdateCount * 0.01f * -70 + ((-i / 2) + (-j / 40)) * 5; + float wave1angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave1)); + float wave2angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave2)); + float wave3angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave3)); + float wave4angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave4)); + float wave5angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave5)); + float wave6angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave6)); + float bigwaveangle = 0.55f + 0.80f * (float)Math.Sin(MathHelper.ToRadians(bigwave)); + outputColor = Vector3.Lerp(outputColor, Color.DeepSkyBlue.ToVector3(), 0.07f + wave1angle + wave2angle + wave3angle + wave4angle + wave5angle + wave6angle + bigwaveangle); + outputColor *= brightness; + } + r = outputColor.X; + g = outputColor.Y; + b = outputColor.Z; } } } diff --git a/Waters/CragsLava.cs b/Waters/CragsLava.cs new file mode 100644 index 0000000000..3654038bbd --- /dev/null +++ b/Waters/CragsLava.cs @@ -0,0 +1,38 @@ +using CalamityMod.Buffs.DamageOverTime; +using CalamityMod.CalPlayer; +using CalamityMod.Items.Accessories; +using CalamityMod.Systems; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; +using Terraria.ModLoader; +using CalamityMod.Dusts.WaterSplash; +using CalamityMod.Gores.WaterDroplet; + +namespace CalamityMod.Waters +{ + public class CragsLava : ModLavaStyle + { + public override string WaterfallTexture => "CalamityMod/Waters/CragsLavaflow"; + + public override int GetSplashDust() => ModContent.DustType(); + + public override int GetDropletGore() => ModContent.GoreType(); + + public override bool IsLavaActive() => Main.LocalPlayer.Calamity().ZoneCalamity || Main.LocalPlayer.Calamity().BrimstoneLavaFountainCounter > 0; + + public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b) + { + r = 2.48f / 4; + g = 1.05f / 4; + b = 0.98f / 4; + } + + public override void InflictDebuff(Player player, int onfireDuration) + { + // Extra DoT in the lava of the crags. Negated by Flame-licked Shell. + if (!player.Calamity().flameLickedShell) + player.AddBuff(ModContent.BuffType(), 2, false); + } + } +} diff --git a/Waters/CragsLavaStyle.cs b/Waters/CragsLavaStyle.cs deleted file mode 100644 index 6ffe68bed0..0000000000 --- a/Waters/CragsLavaStyle.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Microsoft.Xna.Framework; -using Terraria; -using Terraria.ModLoader; - -namespace CalamityMod.Waters -{ - public class CragsLavaflow : ModWaterfallStyle { } - - public class CragsLavaStyle : CustomLavaStyle - { - public override string LavaTexturePath => "CalamityMod/Waters/CragsLava"; - - public override string BlockTexturePath => LavaTexturePath + "_Block"; - - public override string SlopeTexturePath => LavaTexturePath + "_Slope"; - - public override bool ChooseLavaStyle() => Main.LocalPlayer.Calamity().ZoneCalamity || Main.LocalPlayer.Calamity().BrimstoneLavaFountainCounter > 0; - - public override int ChooseWaterfallStyle() => ModContent.Find("CalamityMod/CragsLavaflow").Slot; - - public override int GetSplashDust() => 0; - - public override int GetDropletGore() => 0; - - public override void SelectLightColor(ref Color initialLightColor) - { - initialLightColor = Color.Lerp(initialLightColor, Color.White, 0.5f); - initialLightColor.A = 255; - } - } -} diff --git a/Waters/CustomLavaManagement.cs b/Waters/CustomLavaManagement.cs deleted file mode 100644 index e4018ddb5d..0000000000 --- a/Waters/CustomLavaManagement.cs +++ /dev/null @@ -1,92 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using ReLogic.Content; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; -using Terraria.ModLoader.Core; - -namespace CalamityMod.Waters -{ - // TODO -- This can be made into a ModSystem with simple OnModLoad and Unload hooks. - public static class CustomLavaManagement - { - internal static List CustomLavaStyles; - internal static Texture2D LavaBlockTexture; - internal static Texture2D LavaTexture; - internal static Texture2D LavaSlopeTexture; - - // The IL Edits are loaded separately. - internal static void Load() - { - CustomLavaStyles = new List(); - - Type[] types = AssemblyManager.GetLoadableTypes(CalamityMod.Instance.Code); - foreach (Type type in types) - { - // Ignore abstract types; they cannot have instances. - // Also ignore types which do not derive from CustomLavaStyle. - if (!type.IsSubclassOf(typeof(CustomLavaStyle)) || type.IsAbstract) - continue; - - CustomLavaStyles.Add(Activator.CreateInstance(type) as CustomLavaStyle); - CustomLavaStyles.Last().Load(); - } - - if (Main.netMode != NetmodeID.Server) - { - LavaBlockTexture = ModContent.Request("Terraria/Images/Liquid_1", AssetRequestMode.ImmediateLoad).Value; - LavaTexture = ModContent.Request("Terraria/Images/Misc/water_1", AssetRequestMode.ImmediateLoad).Value; - LavaSlopeTexture = ModContent.Request("Terraria/Images/LiquidSlope_1", AssetRequestMode.ImmediateLoad).Value; - } - } - - internal static void Unload() - { - if (CustomLavaStyles != null) - foreach (CustomLavaStyle lavaStyle in CustomLavaStyles) - lavaStyle?.Unload(); - - CustomLavaStyles = null; - LavaBlockTexture = null; - LavaTexture = null; - } - - internal static int SelectLavafallStyle(int initialLavafallStyle) - { - // Lava waterfall. - if (initialLavafallStyle != 1) - return initialLavafallStyle; - - foreach (CustomLavaStyle lavaStyle in CustomLavaStyles) - { - int waterfallStyle = lavaStyle.ChooseWaterfallStyle(); - if (lavaStyle.ChooseLavaStyle() && waterfallStyle >= 0) - return waterfallStyle; - } - - return initialLavafallStyle; - } - - internal static Color SelectLavafallColor(int initialLavafallStyle, Color initialLavafallColor) - { - // Lava waterfall. - if (initialLavafallStyle != 1) - return initialLavafallColor; - - foreach (CustomLavaStyle lavaStyle in CustomLavaStyles) - { - if (lavaStyle.ChooseLavaStyle()) - { - lavaStyle.SelectLightColor(ref initialLavafallColor); - return initialLavafallColor; - } - } - - return initialLavafallColor; - } - } -} diff --git a/Waters/CustomLavaStyle.cs b/Waters/CustomLavaStyle.cs deleted file mode 100644 index 5059a1134d..0000000000 --- a/Waters/CustomLavaStyle.cs +++ /dev/null @@ -1,51 +0,0 @@ -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Graphics; -using ReLogic.Content; -using Terraria; -using Terraria.ID; -using Terraria.ModLoader; - -namespace CalamityMod.Waters -{ - public abstract class CustomLavaStyle - { - internal Texture2D LavaTexture; - internal Texture2D BlockTexture; - internal Texture2D SlopeTexture; - - internal void Load() - { - // Don't load textures serverside. - if (Main.netMode == NetmodeID.Server) - return; - - LavaTexture = ModContent.Request(LavaTexturePath, AssetRequestMode.ImmediateLoad).Value; - BlockTexture = ModContent.Request(BlockTexturePath, AssetRequestMode.ImmediateLoad).Value; - SlopeTexture = ModContent.Request(SlopeTexturePath, AssetRequestMode.ImmediateLoad).Value; - } - - internal void Unload() - { - LavaTexture = null; - BlockTexture = null; - } - - public abstract string LavaTexturePath { get; } - - public abstract string BlockTexturePath { get; } - - public abstract string SlopeTexturePath { get; } - - public virtual bool ChooseLavaStyle() => false; - - public abstract int ChooseWaterfallStyle(); - - public abstract int GetSplashDust(); - - public abstract int GetDropletGore(); - - public virtual void SelectLightColor(ref Color initialLightColor) - { - } - } -} diff --git a/Waters/LiquidTileType.cs b/Waters/LiquidTileType.cs deleted file mode 100644 index 594a74731d..0000000000 --- a/Waters/LiquidTileType.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace CalamityMod.Waters -{ - public enum LiquidTileType - { - Block, - Waterflow, - Slope - } -} diff --git a/Waters/MiddleAbyssWater.cs b/Waters/MiddleAbyssWater.cs index 1c7f8250f8..bd15111e36 100644 --- a/Waters/MiddleAbyssWater.cs +++ b/Waters/MiddleAbyssWater.cs @@ -1,28 +1,20 @@ -using Microsoft.Xna.Framework; +using CalamityMod.Dusts.WaterSplash; +using CalamityMod.Gores.WaterDroplet; +using CalamityMod.Systems; +using Microsoft.Xna.Framework; +using Terraria.Graphics; using Terraria.ModLoader; namespace CalamityMod.Waters { - public class MiddleAbyssWater : ModWaterStyle + public class MiddleAbyssWaterflow : ModWaterfallStyle { } + + public class MiddleAbyssWater : CalamityModWaterStyle { - public override int ChooseWaterfallStyle() - { - return ModContent.Find("CalamityMod/MiddleAbyssWaterflow").Slot; - } - - public override int GetSplashDust() - { - return 33; - } - - public override int GetDropletGore() - { - return 713; - } - - public override Color BiomeHairColor() - { - return Color.Blue; - } + public override int ChooseWaterfallStyle() => ModContent.Find("CalamityMod/MiddleAbyssWaterflow").Slot; + public override int GetSplashDust() => ModContent.DustType(); + public override int GetDropletGore() => ModContent.GoreType(); + public override Color BiomeHairColor() => new Color(36, 23, 19); + public override void DrawColor(int x, int y, ref VertexColors liquidColor, bool isSlope) => ILEditing.ILChanges.SelectSulphuricWaterColor(x, y, ref liquidColor, isSlope); } } diff --git a/Waters/MiddleAbyssWaterflow.cs b/Waters/MiddleAbyssWaterflow.cs deleted file mode 100644 index 0105e3024f..0000000000 --- a/Waters/MiddleAbyssWaterflow.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Terraria.ModLoader; -namespace CalamityMod.Waters -{ - public class MiddleAbyssWaterflow : ModWaterfallStyle - { - - } -} diff --git a/Waters/PissWater.cs b/Waters/PissWater.cs index 0b315df535..629614b3fe 100644 --- a/Waters/PissWater.cs +++ b/Waters/PissWater.cs @@ -1,28 +1,17 @@ -using Microsoft.Xna.Framework; +using CalamityMod.Systems; +using Microsoft.Xna.Framework; +using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Waters { + public class PissWaterflow : ModWaterfallStyle { } + public class PissWater : ModWaterStyle { - public override int ChooseWaterfallStyle() - { - return ModContent.Find("CalamityMod/PissWaterflow").Slot; - } - - public override int GetSplashDust() - { - return 102; - } - - public override int GetDropletGore() - { - return 711; - } - - public override Color BiomeHairColor() - { - return Color.Yellow; - } + public override int ChooseWaterfallStyle() => ModContent.Find("CalamityMod/PissWaterflow").Slot; + public override int GetSplashDust() => DustID.Water_Desert; + public override int GetDropletGore() => GoreID.WaterDripDesert; + public override Color BiomeHairColor() => Color.Yellow; } } diff --git a/Waters/PissWaterflow.cs b/Waters/PissWaterflow.cs deleted file mode 100644 index a5189ea521..0000000000 --- a/Waters/PissWaterflow.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Terraria.ModLoader; -namespace CalamityMod.Waters -{ - public class PissWaterflow : ModWaterfallStyle - { - - } -} diff --git a/Waters/SulphuricDepthsWater.cs b/Waters/SulphuricDepthsWater.cs index 64aa588c33..4fdae19792 100644 --- a/Waters/SulphuricDepthsWater.cs +++ b/Waters/SulphuricDepthsWater.cs @@ -1,33 +1,37 @@ -using Microsoft.Xna.Framework; +using CalamityMod.Particles; +using System; +using CalamityMod.Systems; +using CalamityMod.Tiles.Abyss; +using Microsoft.Xna.Framework; +using Terraria; using Terraria.ModLoader; +using Terraria.Graphics; +using CalamityMod.Dusts.WaterSplash; +using CalamityMod.Gores.WaterDroplet; namespace CalamityMod.Waters { - public class SulphuricDepthsWater : ModWaterStyle + public class SulphuricDepthsWaterflow : ModWaterfallStyle { } + + public class SulphuricDepthsWater : CalamityModWaterStyle { - public static int Type; - public override void SetStaticDefaults() + public override int ChooseWaterfallStyle() => ModContent.Find("CalamityMod/SulphuricDepthsWaterflow").Slot; + public override int GetSplashDust() => ModContent.DustType(); + public override int GetDropletGore() => ModContent.GoreType(); + public override Color BiomeHairColor() => new Color(35, 117, 89); + public override void DrawColor(int x, int y, ref VertexColors liquidColor, bool isSlope) => ILEditing.ILChanges.SelectSulphuricWaterColor(x, y, ref liquidColor, isSlope); + public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b) { - Type = Slot; - } - public override int ChooseWaterfallStyle() - { - return ModContent.Find("CalamityMod/SulphuricDepthsWaterflow").Slot; - } - - public override int GetSplashDust() - { - return 33; - } - - public override int GetDropletGore() - { - return 713; - } - - public override Color BiomeHairColor() - { - return Color.Teal; + Vector3 outputColor = new Vector3(r, g, b); + if (outputColor == Vector3.One || outputColor == new Vector3(0.25f, 0.25f, 0.25f) || outputColor == new Vector3(0.5f, 0.5f, 0.5f)) + return; + if (CalamityUtils.ParanoidTileRetrieval(i, j).TileType != (ushort)ModContent.TileType()) + { + outputColor = Vector3.Lerp(outputColor, Color.MediumSeaGreen.ToVector3(), 0.18f); + } + r = outputColor.X; + g = outputColor.Y; + b = outputColor.Z; } } } diff --git a/Waters/SulphuricDepthsWaterflow.cs b/Waters/SulphuricDepthsWaterflow.cs deleted file mode 100644 index 5cf86274ff..0000000000 --- a/Waters/SulphuricDepthsWaterflow.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Terraria.ModLoader; -namespace CalamityMod.Waters -{ - public class SulphuricDepthsWaterflow : ModWaterfallStyle - { - - } -} diff --git a/Waters/SulphuricWater.cs b/Waters/SulphuricWater.cs index ef9ce540ea..036a6454d5 100644 --- a/Waters/SulphuricWater.cs +++ b/Waters/SulphuricWater.cs @@ -1,23 +1,104 @@ -using Microsoft.Xna.Framework; +using CalamityMod.Particles; +using System; +using CalamityMod.Systems; +using CalamityMod.Tiles.Abyss; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using Terraria; using Terraria.ModLoader; +using Terraria.Graphics; +using Terraria.ID; +using CalamityMod.Dusts.WaterSplash; +using CalamityMod.Gores.WaterDroplet; namespace CalamityMod.Waters { - public class SulphuricWater : ModWaterStyle + public class SulphuricWaterflow : ModWaterfallStyle { } + + public class SulphuricWater : CalamityModWaterStyle { - public static int Type; - public override void SetStaticDefaults() - { - Type = Slot; - } public override int ChooseWaterfallStyle() => ModContent.Find("CalamityMod/SulphuricWaterflow").Slot; - public override int GetSplashDust() => 101; - public override int GetDropletGore() => 708; + public override int GetSplashDust() => ModContent.DustType(); + public override int GetDropletGore() => ModContent.GoreType(); public override Asset GetRainTexture() => ModContent.Request("CalamityMod/Waters/SulphuricRain"); public override byte GetRainVariant() => (byte)Main.rand.Next(3); - public override Color BiomeHairColor() => Color.Turquoise; + public override Color BiomeHairColor() => new Color(43, 168, 110); + public override void DrawColor(int x, int y, ref VertexColors liquidColor, bool isSlope) => ILEditing.ILChanges.SelectSulphuricWaterColor(x, y, ref liquidColor, isSlope); + public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b) + { + Vector3 outputColor = new Vector3(r, g, b); + if (outputColor == Vector3.One || outputColor == new Vector3(0.25f, 0.25f, 0.25f) || outputColor == new Vector3(0.5f, 0.5f, 0.5f)) + return; + Tile tile = CalamityUtils.ParanoidTileRetrieval(i, j); + Tile above = CalamityUtils.ParanoidTileRetrieval(i, j - 1); + if (!Main.gamePaused && !above.HasTile && above.LiquidAmount <= 0 && Main.rand.NextBool(9)) + { + MediumMistParticle acidFoam = new(new(i * 16f + Main.rand.NextFloat(16f), j * 16f + 8f), -Vector2.UnitY.RotatedByRandom(0.67f) * Main.rand.NextFloat(1f, 2.4f), Color.LightSeaGreen, Color.White, 0.16f, 128f, 0.02f); + GeneralParticleHandler.SpawnParticle(acidFoam); + } + + if (tile.TileType != (ushort)ModContent.TileType()) + { + if (Main.dayTime && !Main.raining) + { + float brightness = MathHelper.Clamp(0.2f - (j / 680), 0f, 0.2f); + if (j > 580) + brightness *= 1f - (j - 580) / 100f; + + float waveScale1 = Main.GameUpdateCount * 0.014f; + float waveScale2 = Main.GameUpdateCount * 0.1f; + int scalar = i + (-j / 2); + float wave1 = waveScale1 * -50 + scalar * 15; + float wave2 = waveScale2 * -10 + scalar * 14; + float wave3 = waveScale1 * -100 + scalar * 13; + float wave4 = waveScale2 * 10 + scalar * 25; + float wave5 = waveScale1 * -70 + scalar * 5; + float wave1angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave1)); + float wave2angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave2)); + float wave3angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave3)); + float wave4angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave4)); + float wave5angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave5)); + outputColor = Vector3.Lerp(outputColor, Color.LightSeaGreen.ToVector3(), 0.41f + wave1angle + wave2angle + wave3angle + wave4angle + wave5angle); + outputColor *= brightness; + } + + if (!Main.dayTime && !Main.raining) + { + float brightness = MathHelper.Clamp(0.17f - (j / 680), 0f, 0.17f); + if (j > 580) + brightness *= 1f - (j - 580) / 100f; + + float waveScale1 = Main.GameUpdateCount * 0.014f; + float waveScale2 = Main.GameUpdateCount * 0.1f; + int scalar = i + (-j / 2); + float wave1 = waveScale1 * -50 + scalar * 15; + float wave2 = waveScale2 * -10 + scalar * 14; + float wave3 = waveScale1 * -100 + scalar * 13; + float wave4 = waveScale2 * 10 + scalar * 25; + float wave5 = waveScale1 * -70 + scalar * 5; + float wave1angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave1)); + float wave2angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave2)); + float wave3angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave3)); + float wave4angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave4)); + float wave5angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave5)); + outputColor = Vector3.Lerp(outputColor, Color.LightSeaGreen.ToVector3(), 0.41f + wave1angle + wave2angle + wave3angle + wave4angle + wave5angle); + outputColor *= brightness; + } + + if (Main.raining) + { + float brightness = MathHelper.Clamp(1f - (j / 680), 0f, 1f); + if (j > 580) + brightness *= 1f - (j - 580) / 100f; + + outputColor = Vector3.Lerp(outputColor, Color.LightSeaGreen.ToVector3(), 0.41f); + outputColor *= brightness; + } + } + r = outputColor.X; + g = outputColor.Y; + b = outputColor.Z; + } } } diff --git a/Waters/SulphuricWaterflow.cs b/Waters/SulphuricWaterflow.cs deleted file mode 100644 index f9ed907df3..0000000000 --- a/Waters/SulphuricWaterflow.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Terraria.ModLoader; -namespace CalamityMod.Waters -{ - public class SulphuricWaterflow : ModWaterfallStyle - { - - } -} diff --git a/Waters/UpperAbyssWater.cs b/Waters/UpperAbyssWater.cs index 965861fdf7..fed3016207 100644 --- a/Waters/UpperAbyssWater.cs +++ b/Waters/UpperAbyssWater.cs @@ -1,28 +1,20 @@ -using Microsoft.Xna.Framework; +using CalamityMod.Dusts.WaterSplash; +using CalamityMod.Gores.WaterDroplet; +using CalamityMod.Systems; +using Microsoft.Xna.Framework; +using Terraria.Graphics; using Terraria.ModLoader; namespace CalamityMod.Waters { - public class UpperAbyssWater : ModWaterStyle + public class UpperAbyssWaterflow : ModWaterfallStyle { } + + public class UpperAbyssWater : CalamityModWaterStyle { - public override int ChooseWaterfallStyle() - { - return ModContent.Find("CalamityMod/UpperAbyssWaterflow").Slot; - } - - public override int GetSplashDust() - { - return 33; - } - - public override int GetDropletGore() - { - return 713; - } - - public override Color BiomeHairColor() - { - return Color.Blue; - } + public override int ChooseWaterfallStyle() => ModContent.Find("CalamityMod/UpperAbyssWaterflow").Slot; + public override int GetSplashDust() => ModContent.DustType(); + public override int GetDropletGore() => ModContent.GoreType(); + public override Color BiomeHairColor() => new Color(9, 69, 82); + public override void DrawColor(int x, int y, ref VertexColors liquidColor, bool isSlope) => ILEditing.ILChanges.SelectSulphuricWaterColor(x, y, ref liquidColor, isSlope); } } diff --git a/Waters/UpperAbyssWaterflow.cs b/Waters/UpperAbyssWaterflow.cs deleted file mode 100644 index e61de17827..0000000000 --- a/Waters/UpperAbyssWaterflow.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Terraria.ModLoader; -namespace CalamityMod.Waters -{ - public class UpperAbyssWaterflow : ModWaterfallStyle - { - - } -} diff --git a/Waters/VoidWater.cs b/Waters/VoidWater.cs index bff3e0bf78..1ce1591140 100644 --- a/Waters/VoidWater.cs +++ b/Waters/VoidWater.cs @@ -1,28 +1,20 @@ -using Microsoft.Xna.Framework; +using CalamityMod.Dusts.WaterSplash; +using CalamityMod.Gores.WaterDroplet; +using CalamityMod.Systems; +using Microsoft.Xna.Framework; +using Terraria.Graphics; using Terraria.ModLoader; namespace CalamityMod.Waters { - public class VoidWater : ModWaterStyle + public class VoidWaterflow : ModWaterfallStyle { } + + public class VoidWater : CalamityModWaterStyle { - public override int ChooseWaterfallStyle() - { - return ModContent.Find("CalamityMod/VoidWaterflow").Slot; - } - - public override int GetSplashDust() - { - return 33; - } - - public override int GetDropletGore() - { - return 713; - } - - public override Color BiomeHairColor() - { - return Color.Blue; - } + public override int ChooseWaterfallStyle() => ModContent.Find("CalamityMod/VoidWaterflow").Slot; + public override int GetSplashDust() => ModContent.DustType(); + public override int GetDropletGore() => ModContent.GoreType(); + public override Color BiomeHairColor() => new Color(16, 8, 30); + public override void DrawColor(int x, int y, ref VertexColors liquidColor, bool isSlope) => ILEditing.ILChanges.SelectSulphuricWaterColor(x, y, ref liquidColor, isSlope); } } diff --git a/Waters/VoidWaterflow.cs b/Waters/VoidWaterflow.cs deleted file mode 100644 index bb408bd108..0000000000 --- a/Waters/VoidWaterflow.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Terraria.ModLoader; -namespace CalamityMod.Waters -{ - public class VoidWaterflow : ModWaterfallStyle - { - - } -} From 19a87739a4d2c4ad2678c0648207208b113ec7fb Mon Sep 17 00:00:00 2001 From: Flowaria Date: Sun, 1 Sep 2024 00:31:44 +0900 Subject: [PATCH 02/12] Adjusted Liquid Edit PR (#52) according to current state --- CalamityMod.cs | 7 +- Gores/WaterDroplet/AstralWaterDroplet.png | Bin 696 -> 0 bytes ILEditing/ILChangesLoading.cs | 3 +- ILEditing/MechanicILChanges.cs | 263 +++++++++++++++------- Systems/CalamityModWaterStyle.cs | 6 +- Utilities/LightingUtils.cs | 43 ++++ Waters/AstralWater.cs | 30 ++- Waters/BasaltGullyWater.cs | 54 ++--- Waters/BasaltGullyWaterflow.cs | 8 - Waters/FloralParadiseWater.cs | 27 +-- Waters/FloralParadiseWaterWaterflow.cs | 9 - Waters/MiddleAbyssWater.cs | 27 ++- Waters/PissWater.cs | 27 ++- Waters/SulphuricDepthsWater.cs | 31 ++- Waters/SulphuricWater.cs | 51 +++-- Waters/SunkenSeaBurrowsWater.cs | 48 ++-- Waters/SunkenSeaBurrowsWaterflow.cs | 8 - Waters/SunkenSeaPolypWater.cs | 47 ++-- Waters/SunkenSeaPolypWaterflow.cs | 8 - Waters/SunkenSeaReefsWater.cs | 47 ++-- Waters/SunkenSeaReefsWaterflow.cs | 8 - Waters/SunkenSeaShoresWater.cs | 47 ++-- Waters/SunkenSeaShoresWaterflow.cs | 8 - Waters/UpperAbyssWater.cs | 27 ++- Waters/VoidWater.cs | 27 ++- 25 files changed, 576 insertions(+), 285 deletions(-) delete mode 100644 Gores/WaterDroplet/AstralWaterDroplet.png create mode 100644 Utilities/LightingUtils.cs delete mode 100644 Waters/BasaltGullyWaterflow.cs delete mode 100644 Waters/FloralParadiseWaterWaterflow.cs delete mode 100644 Waters/SunkenSeaBurrowsWaterflow.cs delete mode 100644 Waters/SunkenSeaPolypWaterflow.cs delete mode 100644 Waters/SunkenSeaReefsWaterflow.cs delete mode 100644 Waters/SunkenSeaShoresWaterflow.cs diff --git a/CalamityMod.cs b/CalamityMod.cs index f61064ace2..aba4ba43e2 100644 --- a/CalamityMod.cs +++ b/CalamityMod.cs @@ -113,6 +113,9 @@ namespace CalamityMod // Destroyer glowmasks public static Asset[] DestroyerGlowmasks = new Asset[3]; + // Probe glowmask + public static Asset ProbeGlowmask; + // Holds the Texture Arrays for all the lava textures. // These are used for the lava styles. They are seperate from Textureasset.Instance._liquidTexture as they will conflict with ModWaterStyle // Can hold up to 255 lava styles (more than enough) (excluding the normal lava texture which is liquidTexture 1) @@ -328,6 +331,9 @@ namespace CalamityMod var waterfallTexture = (Asset[])typeof(WaterfallManager).GetField("waterfallTexture", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).GetValue(Main.instance.waterfallManager); LavaTextures.fall[0] = waterfallTexture[1]; + // Probe glowmask + ProbeGlowmask = ModContent.Request("CalamityMod/ExtraTextures/VanillaBossGlowmasks/ProbeGlow", AssetRequestMode.AsyncLoad); + // Wall of Flesh glowmasks WallOfFleshEyeGlowmask = ModContent.Request("CalamityMod/ExtraTextures/VanillaBossGlowmasks/WallOfFleshEyeTelegraphGlow", AssetRequestMode.AsyncLoad); WallOfFleshDemonSickleTexture = ModContent.Request("CalamityMod/Projectiles/Melee/ForbiddenOathbladeProjectile", AssetRequestMode.AsyncLoad); @@ -481,7 +487,6 @@ namespace CalamityMod NPCStats.Unload(); CalamityGlobalItem.UnloadTweaks(); CalamityGlobalProjectile.UnloadTweaks(); - FramedGlowMask.UnloadTexCache(); PopupGUIManager.UnloadGUIs(); InvasionProgressUIManager.UnloadGUIs(); diff --git a/Gores/WaterDroplet/AstralWaterDroplet.png b/Gores/WaterDroplet/AstralWaterDroplet.png deleted file mode 100644 index ae8e3c68208b97758c3e75399405b42892d9a13e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 696 zcmV;p0!RIcP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02p*dSaefwW^{L9 za%BK;VQFr3E^cLXAT%y8E;js(W8VM(0x3yEK~#8N?U*rc+&~OP_tfs)x=xYaRql}1 z=dvMyZy``(sL}j*mCb*^FT^1qAny(r@a_He=jW0iFK70+u4Ywh0`Ji^A9A6wjKtiMU{YhwDrhE{{NAA zZummR<9Vh<2p%uWf}CjU*&ALb+Ikq^vaTgdqOFI4X%T|!Y{=`0fWgxOkcrH{jO^o= ziMS#p%HvFnc%{dS@?cK1_3RC=6Ky>V$X;z)gupx7nEw^o)sTr;AMtpeVNvx8h^q5V zy=oj5u~IoeP=!9`LL(GGCu{{E69Iz^5bDv^BNG|(TyPb*oKe1W_|i^`IN(we21!2O z2xTG;;_*%vMETC9UNsJjGFgxlZ9UVXZlF8A(=~SI#+YwrvpNgfzG)F_frS?3lDzn$ z{1-%|5@rF3W1$FgLzfuave*2l#F#P0T#utaLz&H-Oa#?(&!I2Iw#Y=r7-KrBl{>s* eWugajyL|yFlo0=< i.MatchLdsfld
("drawToScreen"), i => i.MatchBrfalse(out _), i => i.MatchLdarg0(), i => i.MatchLdcI4(1), i => i.MatchCall
("DrawWaters"))) @@ -860,7 +861,7 @@ namespace CalamityMod.ILEditing }); } - private void RenderLavas(ILContext il) + private static void RenderLavas(ILContext il) { ILCursor cursor = new ILCursor(il); if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdarg0(), i => i.MatchLdcI4(0), i => i.MatchCall
("DrawWaters"))) @@ -873,7 +874,7 @@ namespace CalamityMod.ILEditing }); } - private void RenderLavaBackgrounds(ILContext il) + private static void RenderLavaBackgrounds(ILContext il) { ILCursor cursor = new ILCursor(il); if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdarg0(), i => i.MatchLdcI4(1), i => i.MatchCall
("DrawWaters"))) @@ -886,7 +887,7 @@ namespace CalamityMod.ILEditing }); } - private void DrawLavatoCapture(ILContext il) + private static void DrawLavatoCapture(ILContext il) { ILCursor cursor = new ILCursor(il); if (!cursor.TryGotoNext(MoveType.After, i => i.MatchLdsfld
("liquidAlpha"), i => i.MatchCall(out _), i => i.MatchStloc2())) @@ -964,7 +965,7 @@ namespace CalamityMod.ILEditing cursor.EmitLdloc(12); cursor.EmitLdloc(13); cursor.EmitLdloc(14); - cursor.EmitDelegate((Microsoft.Xna.Framework.Vector2 unscaledPosition, Microsoft.Xna.Framework.Vector2 vector, int j, int i, Terraria.Tile tile) => { + cursor.EmitDelegate((Vector2 unscaledPosition, Vector2 vector, int j, int i, Tile tile) => { LavaRendering.instance.DrawTile_LiquidBehindTile(solidLayer: false, inFrontOfPlayers: false, -1, unscaledPosition, vector, j, i, tile); }); } @@ -1021,14 +1022,25 @@ namespace CalamityMod.ILEditing private void BlockLavaDrawingForSlopes(On_TileDrawing.orig_DrawTile_LiquidBehindTile orig, TileDrawing self, bool solidLayer, bool inFrontOfPlayers, int waterStyleOverride, Vector2 screenPosition, Vector2 screenOffset, int tileX, int tileY, Tile tileCache) { - Tile tile = Main.tile[tileX + 1, tileY]; - Tile tile2 = Main.tile[tileX - 1, tileY]; - Tile tile3 = Main.tile[tileX, tileY - 1]; - Tile tile4 = Main.tile[tileX, tileY + 1]; - if (tileCache.LiquidType == LiquidID.Lava || tile.LiquidType == LiquidID.Lava || tile2.LiquidType == LiquidID.Lava || tile3.LiquidType == LiquidID.Lava || tile4.LiquidType == LiquidID.Lava) - { + if (tileCache.LiquidType == LiquidID.Lava) return; - } + + Tile tile = Main.tile[tileX + 1, tileY]; + if (tile.LiquidType == LiquidID.Lava) + return; + + Tile tile2 = Main.tile[tileX - 1, tileY]; + if (tile2.LiquidType == LiquidID.Lava) + return; + + Tile tile3 = Main.tile[tileX, tileY - 1]; + if (tile3.LiquidType == LiquidID.Lava) + return; + + Tile tile4 = Main.tile[tileX, tileY + 1]; + if (tile4.LiquidType == LiquidID.Lava) + return; + orig.Invoke(self, solidLayer, inFrontOfPlayers, waterStyleOverride, screenPosition, screenOffset, tileX, tileY, tileCache); } @@ -1166,78 +1178,80 @@ namespace CalamityMod.ILEditing #region Liquid Visuals //Contains all liquid light and liquid alpha (seethrough-ability) - private void LiquidEmitLight(On_TileLightScanner.orig_ApplyLiquidLight orig, TileLightScanner self, Tile tile, ref Vector3 lightColor) + private static void ApplyLiquidEmit(ILContext il) { - orig.Invoke(self, tile, ref lightColor); - if (tile.LiquidAmount > 0 && !tile.HasTile) + ILCursor cursor = new ILCursor(il); + if (!cursor.TryGotoNext(MoveType.Before, i => i.MatchRet())) { + LogFailure("Liquid Light Emit", "ret instruction is missing????? how is this even possible?????"); + return; + } + + cursor.EmitLdloc0(); // This should be tile + cursor.EmitLdarg1(); // x + cursor.EmitLdarg2(); // y + cursor.EmitLdarg3(); // ref OutputColor + cursor.EmitDelegate((Tile tile, int x, int y, ref Vector3 lightColor) => + { + if (tile.HasTile || tile.LiquidAmount <= 0) + return; + if (tile.LiquidType == LiquidID.Water) { float R = 0f; float G = 0f; float B = 0f; - CalamityWaterLoader.ModifyLightSetup(tile.X(), tile.Y(), Main.waterStyle, ref R, ref G, ref B); - if (lightColor.X < R) - { - lightColor.X = R; - } - if (lightColor.Y < G) - { - lightColor.Y = G; - } - if (lightColor.Z < B) - { - lightColor.Z = B; - } + CalamityWaterLoader.ModifyLightSetup(in tile, x, y, Main.waterStyle, ref R, ref G, ref B); + + lightColor.X = Math.Max(lightColor.X, R); + lightColor.Y = Math.Max(lightColor.Y, G); + lightColor.Z = Math.Max(lightColor.Z, B); } else if (tile.LiquidType == LiquidID.Lava && CalamityMod.Instance.biomeLava == null) { Vector3 lavaLight = new Vector3(0.55f, 0.33f, 0.11f); + float R = CalamityMod.LavaStyle == 0 ? lavaLight.X : 0f; float G = CalamityMod.LavaStyle == 0 ? lavaLight.Y : 0f; float B = CalamityMod.LavaStyle == 0 ? lavaLight.Z : 0f; - LavaStylesLoader.ModifyLightSetup(tile.X(), tile.Y(), CalamityMod.LavaStyle, ref R, ref G, ref B); - for (int j = 0; j < LavaStylesLoader.TotalCount; j++) + LavaStylesLoader.ModifyLightSetup(x, y, CalamityMod.LavaStyle, ref R, ref G, ref B); + + for (int styleIndex = 0; styleIndex < LavaStylesLoader.TotalCount; styleIndex++) { - if (CalamityMod.lavaAlpha[j] > 0f && j != CalamityMod.LavaStyle) + if (CalamityMod.lavaAlpha[styleIndex] > 0f && styleIndex != CalamityMod.LavaStyle) { - float r = j == 0 ? lavaLight.X : 0f; - float g = j == 0 ? lavaLight.Y : 0f; - float b = j == 0 ? lavaLight.Z : 0f; - LavaStylesLoader.ModifyLightSetup(tile.X(), tile.Y(), j, ref r, ref g, ref b); + float r = styleIndex == 0 ? lavaLight.X : 0f; + float g = styleIndex == 0 ? lavaLight.Y : 0f; + float b = styleIndex == 0 ? lavaLight.Z : 0f; + LavaStylesLoader.ModifyLightSetup(x, y, styleIndex, ref r, ref g, ref b); + float r2 = CalamityMod.LavaStyle == 0 ? lavaLight.X : 0f; float g2 = CalamityMod.LavaStyle == 0 ? lavaLight.Y : 0f; float b2 = CalamityMod.LavaStyle == 0 ? lavaLight.Z : 0f; - LavaStylesLoader.ModifyLightSetup(tile.X(), tile.Y(), CalamityMod.LavaStyle, ref r2, ref g2, ref b2); - R = Single.Lerp(r, r2, CalamityMod.lavaAlpha[CalamityMod.LavaStyle]); - G = Single.Lerp(g, g2, CalamityMod.lavaAlpha[CalamityMod.LavaStyle]); - B = Single.Lerp(b, b2, CalamityMod.lavaAlpha[CalamityMod.LavaStyle]); + LavaStylesLoader.ModifyLightSetup(x, y, CalamityMod.LavaStyle, ref r2, ref g2, ref b2); + + R = float.Lerp(r, r2, CalamityMod.lavaAlpha[CalamityMod.LavaStyle]); + G = float.Lerp(g, g2, CalamityMod.lavaAlpha[CalamityMod.LavaStyle]); + B = float.Lerp(b, b2, CalamityMod.lavaAlpha[CalamityMod.LavaStyle]); } } - if (!(R == 0 && G == 0 && B == 0)) + + if (R != 0.0f || G != 0.0f || B != 0.0f) { float colorManipulator = (float)(270 - Main.mouseTextColor) / 900f; R += colorManipulator; G += colorManipulator; B += colorManipulator; } - if (lightColor.X < R) - { - lightColor.X = R; - } - if (lightColor.Y < G) - { - lightColor.Y = G; - } - if (lightColor.Z < B) - { - lightColor.Z = B; - } + + lightColor.X = Math.Max(lightColor.X, R); + lightColor.Y = Math.Max(lightColor.Y, G); + lightColor.Z = Math.Max(lightColor.Z, B); } - } + }); } - private void LavafallLightEditor(On_WaterfallManager.orig_AddLight orig, int waterfallType, int x, int y) + private static void LavafallLightEditor(On_WaterfallManager.orig_AddLight orig, int waterfallType, int x, int y) { if (waterfallType == 1) { @@ -1290,37 +1304,69 @@ namespace CalamityMod.ILEditing { ILCursor cursor = new ILCursor(il); - if (!cursor.TryGotoNext(MoveType.Before, c => c.MatchLdcI4(0), c => c.MatchStloc(19), c => c.MatchLdloc(11), c => c.MatchBrfalse(out _))) + var loaderGetMethod = typeof(LoaderManager) + .GetMethod(nameof(LoaderManager.Get)) + .MakeGenericMethod([typeof(WaterStylesLoader)]); + if (loaderGetMethod is null) + { + LogFailure("Liquid Slope Draw Colors", "Cannot find \"LoaderManager.Get\" Method"); + return; + } + + var getTotalCountGetter = typeof(Loader) + .GetProperty("TotalCount", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static) + .GetMethod; + if (getTotalCountGetter is null) + { + LogFailure("Liquid Slope Draw Colors", "Cannot find \"Loader.TotalCount (internal)\" Method"); + return; + } + + if (!cursor.TryGotoNext(MoveType.After, + c => c.MatchCall(loaderGetMethod), + c => c.MatchCallOrCallvirt(getTotalCountGetter))) { LogFailure("Liquid Slope Draw Colors", "Could not locate the liquid slope vertex colors for drawing"); return; } - cursor.Emit(OpCodes.Ldarg, 6); - cursor.Emit(OpCodes.Ldarg, 7); - cursor.Emit(OpCodes.Ldloca, 14); - cursor.Emit(OpCodes.Ldloc, 11); - cursor.Emit(OpCodes.Ldloc, 10); + // callvirt Loader.TotalCount + // [We are here] + // stloc.s totalCount - cursor.EmitDelegate((int x, int y, ref VertexColors initialColor, bool flag6, int num2) => + // Starts from callvirt (ret: int) + // Stack now have TotalCount and about to pop by local variable, so: + cursor.EmitLdarg(8); // Push tileCache + cursor.EmitLdarg(6); // Push tileX + cursor.EmitLdarg(7); // Push tileY + cursor.EmitLdloca(14); // Push Color* + cursor.EmitDelegate((Tile tileCache, int x, int y, ref VertexColors initialColor) => { - if (flag6) - { - int totalCount = (int)typeof(Loader).GetProperty("TotalCount", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).GetValue(LoaderManager.Get()); - for (int i = 0; i < totalCount; i++) - { - Tile tile = Main.tile[x, y]; - if (i == Main.waterStyle && tile.LiquidType == LiquidID.Water) - { - CalamityWaterLoader.DrawColorSetup(x, y, Main.waterStyle, ref initialColor, true); - } - else if ((tile.LiquidType == LiquidID.Lava || i == 1) && CalamityMod.Instance.biomeLava == null) - { - LavaStylesLoader.DrawColorSetup(x, y, CalamityMod.LavaStyle, ref initialColor); - } - } - } + // TODO: Properly handle Transition between styles + // That will require extra il injection to achieve + if (tileCache.LiquidType == LiquidID.Water) + CalamityWaterLoader.DrawColorSetup(x, y, Main.waterStyle, ref initialColor, true); + + // Known Issue: Sloped Lava Rendering actually does not work on here! (It's been a case even before edited in 2024/08/30) + // Reason: Flag6 is "IsWater" flag, and since we don't modified that behaviour "yet" it will never be triggered here + // Fix this when there will be new lava style with dynamic color changes + else if (tileCache.LiquidType == LiquidID.Lava) + LavaStylesLoader.DrawColorSetup(x, y, CalamityMod.LavaStyle, ref initialColor); }); + + // And now remaining TotalCount is now could pass to local variable + + #region Intended Result for Reference + // callvirt Loader.TotalCount push 1 + // + // ldarg 8 (tileCache) push 1 + // ldarg 6 (tileX) push 1 + // ldarg 7 (tileY) push 1 + // ldloca 14 (vertices) push 1 + // call ModdedDelegate pop 4 + // + // stloc.s totalCount pop 1 + #endregion } #endregion @@ -1440,7 +1486,7 @@ namespace CalamityMod.ILEditing ForegroundManager.DrawTiles(); } - private static void ClearForegroundStuff(Terraria.GameContent.Drawing.On_TileDrawing.orig_PreDrawTiles orig, Terraria.GameContent.Drawing.TileDrawing self, bool solidLayer, bool forRenderTargets, bool intoRenderTargets) + private static void ClearForegroundStuff(On_TileDrawing.orig_PreDrawTiles orig, TileDrawing self, bool solidLayer, bool forRenderTargets, bool intoRenderTargets) { orig(self, solidLayer, forRenderTargets, intoRenderTargets); @@ -1450,7 +1496,7 @@ namespace CalamityMod.ILEditing #endregion #region Tile ping overlay - private static void ClearTilePings(Terraria.GameContent.Drawing.On_TileDrawing.orig_Draw orig, Terraria.GameContent.Drawing.TileDrawing self, bool solidLayer, bool forRenderTargets, bool intoRenderTargets, int waterStyleOverride) + private static void ClearTilePings(On_TileDrawing.orig_Draw orig, TileDrawing self, bool solidLayer, bool forRenderTargets, bool intoRenderTargets, int waterStyleOverride) { //Retro & Trippy light modes are fine. Just reset the cache before every time stuff gets drawn. if (Lighting.UpdateEveryFrame) @@ -1599,7 +1645,7 @@ namespace CalamityMod.ILEditing { return; } - + // Go through the World Selection Difficulty System's World Difficulty list backwards and choose the latest difficulty that applies for (int i = WorldSelectionDifficultySystem.WorldDifficulties.Count - 1; i >= 0; i--) { @@ -1749,5 +1795,62 @@ namespace CalamityMod.ILEditing } } #endregion + + #region Optimized GlowMask Rendering on Tile + private static void GlowMaskTileRender(On_TileDrawing.orig_DrawSingleTile orig, TileDrawing self, TileDrawInfo drawData, bool solidLayer, int waterStyleOverride, Vector2 screenPosition, Vector2 screenOffset, int tileX, int tileY) + { + orig(self, drawData, solidLayer, waterStyleOverride, screenPosition, screenOffset, tileX, tileY); + + var type = drawData.typeCache; + if (type < 0 || type >= GlowMaskTile.LookupLength) + return; + + var glowMaskTile = GlowMaskTile.InstanceLookup[type]; + if (glowMaskTile is null) + return; + + var glowMask = glowMaskTile.GlowMask; + int xPos = drawData.tileFrameX + drawData.addFrX; + int yPos = drawData.tileFrameY + drawData.addFrY; + if (glowMask.HasContentInFramePos(xPos, yPos)) + { + ref Tile tileCache = ref drawData.tileCache; + int colType = tileCache.TileColor; + + Color drawColor = glowMaskTile.GetGlowMaskColor(tileX, tileY, drawData); + Color tileLight = drawData.tileLight; + + if (tileLight.R > drawColor.R) drawColor.R = tileLight.R; + if (tileLight.G > drawColor.G) drawColor.G = tileLight.G; + if (tileLight.B > drawColor.B) drawColor.B = tileLight.B; + + drawColor = glowMaskTile.GlowMaskPaintInteraction switch + { + GlowMaskTile.PaintColorTint.OnlyByDeepPaint => GlowMaskTile.ApplyPaint(colType, drawColor, deepPaintOnly: true), + GlowMaskTile.PaintColorTint.ByEveryPaint => GlowMaskTile.ApplyPaint(colType, drawColor, deepPaintOnly: false), + _ => drawColor + }; + + // Cull no lit and too dark colors + if (drawColor.R <= 1 && drawColor.G <= 1 && drawColor.B <= 1) + return; + + drawColor.A = 255; + + if (Main.tileSolid[type]) + { + var drawRect = new Rectangle(xPos, yPos, 16, 16); + TileFramingSystem.SlopedGlowmask(in tileCache, tileX, tileY, glowMask.Texture, drawRect, drawColor, default); + } + else + { + Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange, Main.offScreenRange); + Vector2 drawPos = new Vector2(tileX * 16, tileY * 16 + 2) - Main.screenPosition + zero; + Rectangle drawRect = new Rectangle(xPos, yPos, 16, 16); + Main.spriteBatch.Draw(glowMask.Texture, drawPos, drawRect, drawColor, 0.0f, default, 1.0f, drawData.tileSpriteEffect, 0.0f); + } + } + } + #endregion } } diff --git a/Systems/CalamityModWaterStyle.cs b/Systems/CalamityModWaterStyle.cs index 66c3d6766f..55e346eae3 100644 --- a/Systems/CalamityModWaterStyle.cs +++ b/Systems/CalamityModWaterStyle.cs @@ -29,19 +29,19 @@ namespace CalamityMod.Systems /// The red component of light, usually a value between 0 and 1 /// The green component of light, usually a value between 0 and 1 /// The blue component of light, usually a value between 0 and 1 - public virtual void ModifyLight(int i, int j, ref float r, ref float g, ref float b) + public virtual void ModifyLight(ref readonly Tile tile, int i, int j, ref float r, ref float g, ref float b) { } } internal static class CalamityWaterLoader { - internal static void ModifyLightSetup(int i, int j, int type, ref float r, ref float g, ref float b) + internal static void ModifyLightSetup(ref readonly Tile tile, int i, int j, int type, ref float r, ref float g, ref float b) { CalamityModWaterStyle styles = (CalamityModWaterStyle)LoaderManager.Get().Get(type); if (styles != null) { - styles?.ModifyLight(i, j, ref r, ref g, ref b); + styles?.ModifyLight(in tile, i, j, ref r, ref g, ref b); } } diff --git a/Utilities/LightingUtils.cs b/Utilities/LightingUtils.cs new file mode 100644 index 0000000000..fd7f9d330e --- /dev/null +++ b/Utilities/LightingUtils.cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using CalamityMod.Waters; +using Microsoft.Xna.Framework; +using Terraria; + +namespace CalamityMod +{ + public static partial class CalamityUtils + { + public static void SunkenSeaWaterLighting(int x, int y, Vector3 waterColor, ref float r, ref float g, ref float b) + { + float tick = (float)Main.timeForVisualEffects; + float brightness = MathHelper.Clamp(0.07f, 0f, 0.07f); + float waveScale1 = tick * 0.028f; + float waveScale2 = tick * 0.1f; + int yScale = -y / 2; + int xScale = x / 15; + float wave1 = tick * 0.024f * -50 + ((-x / 30) + (y / 30)) * 25; + float wave2 = waveScale2 * -10 + ((-xScale) + yScale) * 45; + float wave3 = waveScale1 * -100 + ((x / 7) + (y / 50)) * 25; + float wave4 = tick * 0.15f * 10 + ((x / 3) + yScale) * 45; + float wave5 = waveScale1 * -70 + ((-x / 25) + (-y / 25)) * 20; + float wave6 = waveScale2 * -10 + (xScale + yScale) * 45; + float bigwave = tick * 0.01f * -70 + ((-x / 2) + (-y / 40)) * 5; + float wave1angle = 0.55f + 0.45f * MathF.Sin(MathHelper.ToRadians(wave1)); + float wave2angle = 0.55f + 0.45f * MathF.Sin(MathHelper.ToRadians(wave2)); + float wave3angle = 0.55f + 0.45f * MathF.Sin(MathHelper.ToRadians(wave3)); + float wave4angle = 0.55f + 0.45f * MathF.Sin(MathHelper.ToRadians(wave4)); + float wave5angle = 0.55f + 0.45f * MathF.Sin(MathHelper.ToRadians(wave5)); + float wave6angle = 0.55f + 0.45f * MathF.Sin(MathHelper.ToRadians(wave6)); + float bigwaveangle = 0.55f + 0.80f * MathF.Sin(MathHelper.ToRadians(bigwave)); + float sumofwave = 0.07f + wave1angle + wave2angle + wave3angle + wave4angle + wave5angle + wave6angle + bigwaveangle; + + r = MathHelper.Lerp(r, waterColor.X, sumofwave) * brightness; + g = MathHelper.Lerp(g, waterColor.Y, sumofwave) * brightness; + b = MathHelper.Lerp(b, waterColor.Z, sumofwave) * brightness; + } + } +} diff --git a/Waters/AstralWater.cs b/Waters/AstralWater.cs index 7928f6d6dd..22c337d41d 100644 --- a/Waters/AstralWater.cs +++ b/Waters/AstralWater.cs @@ -13,10 +13,32 @@ namespace CalamityMod.Waters public class AstralWater : CalamityModWaterStyle { - public override int ChooseWaterfallStyle() => ModContent.Find("CalamityMod/AstralWaterflow").Slot; - public override int GetSplashDust() => ModContent.DustType(); - public override int GetDropletGore() => ModContent.GoreType(); - public override Asset GetRainTexture() => ModContent.Request("CalamityMod/Waters/AstralRain"); + public static CalamityModWaterStyle Instance { get; private set; } + public static ModWaterfallStyle WaterfallStyle { get; private set; } + public static int SplashDust { get; private set; } + public static int DropletGore { get; private set; } + public static Asset RainTexture { get; private set; } + + public override void SetStaticDefaults() + { + Instance = this; + WaterfallStyle = ModContent.Find("CalamityMod/AstralWaterflow"); + SplashDust = ModContent.DustType(); + DropletGore = ModContent.GoreType(); + } + + public override void Unload() + { + Instance = null; + WaterfallStyle = null; + SplashDust = 0; + DropletGore = 0; + } + + public override int ChooseWaterfallStyle() => WaterfallStyle.Slot; + public override int GetSplashDust() => SplashDust; + public override int GetDropletGore() => DropletGore; + public override Asset GetRainTexture() => RainTexture ??= ModContent.Request("CalamityMod/Waters/AstralRain"); public override byte GetRainVariant() => (byte)Main.rand.Next(3); public override Color BiomeHairColor() => new Color(93, 78, 107); } diff --git a/Waters/BasaltGullyWater.cs b/Waters/BasaltGullyWater.cs index 4dbee891e9..311fd0ac46 100644 --- a/Waters/BasaltGullyWater.cs +++ b/Waters/BasaltGullyWater.cs @@ -8,51 +8,45 @@ using Terraria.ModLoader; using Terraria.Graphics; using CalamityMod.Dusts.WaterSplash; using CalamityMod.Gores.WaterDroplet; +using Terraria.ID; namespace CalamityMod.Waters { - public class SunkenSeaWaterflow : ModWaterfallStyle { } + public class BasaltGullyWaterflow : ModWaterfallStyle { } - public class SunkenSeaWater : CalamityModWaterStyle + public class BasaltGullyWater : CalamityModWaterStyle { - public override int ChooseWaterfallStyle() => ModContent.Find("CalamityMod/SunkenSeaWaterflow").Slot; - public override int GetSplashDust() => ModContent.DustType(); - public override int GetDropletGore() => ModContent.GoreType(); - public override Color BiomeHairColor() => new Color(46, 155, 171); - public override void DrawColor(int x, int y, ref VertexColors liquidColor, bool isSlope) => ILEditing.ILChanges.SelectSulphuricWaterColor(x, y, ref liquidColor, isSlope); - public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b) + public static int Type; + + private readonly Vector3 WaterGlowColor = new Color(144, 174, 200).ToVector3(); + + public override void SetStaticDefaults() + { + Type = Slot; + } + + public override void ModifyLight(ref readonly Tile tile, int i, int j, ref float r, ref float g, ref float b) { Vector3 outputColor = new Vector3(r, g, b); if (outputColor == Vector3.One || outputColor == new Vector3(0.25f, 0.25f, 0.25f) || outputColor == new Vector3(0.5f, 0.5f, 0.5f)) return; - if (CalamityUtils.ParanoidTileRetrieval(i, j).TileType != (ushort)ModContent.TileType()) + if (tile.TileType != RustyChestTile.Type) { - float brightness = MathHelper.Clamp(0.07f, 0f, 0.07f); - float waveScale1 = Main.GameUpdateCount * 0.028f; - float waveScale2 = Main.GameUpdateCount * 0.1f; - int yScale = -j / 2; - int xScale = i / 15; - float wave1 = Main.GameUpdateCount * 0.024f * -50 + ((-i / 30) + (j / 30)) * 25; - float wave2 = waveScale2 * -10 + ((-xScale) + yScale) * 45; - float wave3 = waveScale1 * -100 + ((i / 7) + (j / 50)) * 25; - float wave4 = Main.GameUpdateCount * 0.15f * 10 + ((i / 3) + yScale) * 45; - float wave5 = waveScale1 * -70 + ((-i / 25) + (-j / 25)) * 20; - float wave6 = waveScale2 * -10 + (xScale + yScale) * 45; - float bigwave = Main.GameUpdateCount * 0.01f * -70 + ((-i / 2) + (-j / 40)) * 5; - float wave1angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave1)); - float wave2angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave2)); - float wave3angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave3)); - float wave4angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave4)); - float wave5angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave5)); - float wave6angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave6)); - float bigwaveangle = 0.55f + 0.80f * (float)Math.Sin(MathHelper.ToRadians(bigwave)); - outputColor = Vector3.Lerp(outputColor, Color.DeepSkyBlue.ToVector3(), 0.07f + wave1angle + wave2angle + wave3angle + wave4angle + wave5angle + wave6angle + bigwaveangle); - outputColor *= brightness; + CalamityUtils.SunkenSeaWaterLighting(i, j, WaterGlowColor, ref outputColor.X, ref outputColor.Y, ref outputColor.Z); } + r = outputColor.X; g = outputColor.Y; b = outputColor.Z; } + + public override void DrawColor(int x, int y, ref VertexColors liquidColor, bool isSlope) => ILEditing.ILChanges.SelectSulphuricWaterColor(x, y, ref liquidColor, isSlope); + + public override int ChooseWaterfallStyle() => ModContent.Find("CalamityMod/BasaltGullyWaterflow").Slot; + // TODO: Create Dust and Gore for BasaltGullyWater (Including other SunkenSea waters too) + public override int GetSplashDust() => DustID.Water; + public override int GetDropletGore() => GoreID.WaterDripCavern; + public override Color BiomeHairColor() => Color.WhiteSmoke; } } diff --git a/Waters/BasaltGullyWaterflow.cs b/Waters/BasaltGullyWaterflow.cs deleted file mode 100644 index 545ff8daaf..0000000000 --- a/Waters/BasaltGullyWaterflow.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Terraria.ModLoader; - -namespace CalamityMod.Waters -{ - public class BasaltGullyWaterflow : ModWaterfallStyle - { - } -} diff --git a/Waters/FloralParadiseWater.cs b/Waters/FloralParadiseWater.cs index 9d67d11a46..182a84ad4b 100644 --- a/Waters/FloralParadiseWater.cs +++ b/Waters/FloralParadiseWater.cs @@ -1,28 +1,23 @@ -using Microsoft.Xna.Framework; +using CalamityMod.Systems; +using CalamityMod.Tiles.Abyss; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Waters { - public class FloralParadiseWater : ModWaterStyle + public class FloralParadiseWaterflow : ModWaterfallStyle { } + + public class FloralParadiseWater : CalamityModWaterStyle { public override int ChooseWaterfallStyle() { return ModContent.Find("CalamityMod/FloralParadiseWaterflow").Slot; } - public override int GetSplashDust() - { - return 33; - } - - public override int GetDropletGore() - { - return 713; - } - - public override Color BiomeHairColor() - { - return Color.PaleTurquoise; - } + public override int GetSplashDust() => DustID.Water; + public override int GetDropletGore() => GoreID.WaterDripCavern; + public override Color BiomeHairColor() => Color.PaleTurquoise; } } diff --git a/Waters/FloralParadiseWaterWaterflow.cs b/Waters/FloralParadiseWaterWaterflow.cs deleted file mode 100644 index 64a6ce4344..0000000000 --- a/Waters/FloralParadiseWaterWaterflow.cs +++ /dev/null @@ -1,9 +0,0 @@ -using Terraria.ModLoader; - -namespace CalamityMod.Waters -{ - public class FloralParadiseWaterflow : ModWaterfallStyle - { - - } -} diff --git a/Waters/MiddleAbyssWater.cs b/Waters/MiddleAbyssWater.cs index bd15111e36..b44b3c1556 100644 --- a/Waters/MiddleAbyssWater.cs +++ b/Waters/MiddleAbyssWater.cs @@ -11,9 +11,30 @@ namespace CalamityMod.Waters public class MiddleAbyssWater : CalamityModWaterStyle { - public override int ChooseWaterfallStyle() => ModContent.Find("CalamityMod/MiddleAbyssWaterflow").Slot; - public override int GetSplashDust() => ModContent.DustType(); - public override int GetDropletGore() => ModContent.GoreType(); + public static CalamityModWaterStyle Instance { get; private set; } + public static ModWaterfallStyle WaterfallStyle { get; private set; } + public static int SplashDust { get; private set; } + public static int DropletGore { get; private set; } + + public override void SetStaticDefaults() + { + Instance = this; + WaterfallStyle = ModContent.Find("CalamityMod/MiddleAbyssWaterflow"); + SplashDust = ModContent.DustType(); + DropletGore = ModContent.GoreType(); + } + + public override void Unload() + { + Instance = null; + WaterfallStyle = null; + SplashDust = 0; + DropletGore = 0; + } + + public override int ChooseWaterfallStyle() => WaterfallStyle.Slot; + public override int GetSplashDust() => SplashDust; + public override int GetDropletGore() => DropletGore; public override Color BiomeHairColor() => new Color(36, 23, 19); public override void DrawColor(int x, int y, ref VertexColors liquidColor, bool isSlope) => ILEditing.ILChanges.SelectSulphuricWaterColor(x, y, ref liquidColor, isSlope); } diff --git a/Waters/PissWater.cs b/Waters/PissWater.cs index 629614b3fe..7fe16643f5 100644 --- a/Waters/PissWater.cs +++ b/Waters/PissWater.cs @@ -1,4 +1,6 @@ -using CalamityMod.Systems; +using CalamityMod.Dusts.WaterSplash; +using CalamityMod.Gores.WaterDroplet; +using CalamityMod.Systems; using Microsoft.Xna.Framework; using Terraria.ID; using Terraria.ModLoader; @@ -9,7 +11,28 @@ namespace CalamityMod.Waters public class PissWater : ModWaterStyle { - public override int ChooseWaterfallStyle() => ModContent.Find("CalamityMod/PissWaterflow").Slot; + public static ModWaterStyle Instance { get; private set; } + public static ModWaterfallStyle WaterfallStyle { get; private set; } + public static int SplashDust { get; private set; } + public static int DropletGore { get; private set; } + + public override void SetStaticDefaults() + { + Instance = this; + WaterfallStyle = ModContent.Find("CalamityMod/PissWaterflow"); + SplashDust = DustID.Water_Desert; + DropletGore = GoreID.WaterDripDesert; + } + + public override void Unload() + { + Instance = null; + WaterfallStyle = null; + SplashDust = 0; + DropletGore = 0; + } + + public override int ChooseWaterfallStyle() => WaterfallStyle.Slot; public override int GetSplashDust() => DustID.Water_Desert; public override int GetDropletGore() => GoreID.WaterDripDesert; public override Color BiomeHairColor() => Color.Yellow; diff --git a/Waters/SulphuricDepthsWater.cs b/Waters/SulphuricDepthsWater.cs index 4fdae19792..8b0b4d2e31 100644 --- a/Waters/SulphuricDepthsWater.cs +++ b/Waters/SulphuricDepthsWater.cs @@ -15,17 +15,38 @@ namespace CalamityMod.Waters public class SulphuricDepthsWater : CalamityModWaterStyle { - public override int ChooseWaterfallStyle() => ModContent.Find("CalamityMod/SulphuricDepthsWaterflow").Slot; - public override int GetSplashDust() => ModContent.DustType(); - public override int GetDropletGore() => ModContent.GoreType(); + public static CalamityModWaterStyle Instance { get; private set; } + public static ModWaterfallStyle WaterfallStyle { get; private set; } + public static int SplashDust { get; private set; } + public static int DropletGore { get; private set; } + + public override void SetStaticDefaults() + { + Instance = this; + WaterfallStyle = ModContent.Find("CalamityMod/SulphuricDepthsWaterflow"); + SplashDust = ModContent.DustType(); + DropletGore = ModContent.GoreType(); + } + + public override void Unload() + { + Instance = null; + WaterfallStyle = null; + SplashDust = 0; + DropletGore = 0; + } + + public override int ChooseWaterfallStyle() => WaterfallStyle.Slot; + public override int GetSplashDust() => SplashDust; + public override int GetDropletGore() => DropletGore; public override Color BiomeHairColor() => new Color(35, 117, 89); public override void DrawColor(int x, int y, ref VertexColors liquidColor, bool isSlope) => ILEditing.ILChanges.SelectSulphuricWaterColor(x, y, ref liquidColor, isSlope); - public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b) + public override void ModifyLight(ref readonly Tile tile, int i, int j, ref float r, ref float g, ref float b) { Vector3 outputColor = new Vector3(r, g, b); if (outputColor == Vector3.One || outputColor == new Vector3(0.25f, 0.25f, 0.25f) || outputColor == new Vector3(0.5f, 0.5f, 0.5f)) return; - if (CalamityUtils.ParanoidTileRetrieval(i, j).TileType != (ushort)ModContent.TileType()) + if (tile.TileType != RustyChestTile.Type) { outputColor = Vector3.Lerp(outputColor, Color.MediumSeaGreen.ToVector3(), 0.18f); } diff --git a/Waters/SulphuricWater.cs b/Waters/SulphuricWater.cs index 036a6454d5..11db4fde67 100644 --- a/Waters/SulphuricWater.cs +++ b/Waters/SulphuricWater.cs @@ -18,19 +18,41 @@ namespace CalamityMod.Waters public class SulphuricWater : CalamityModWaterStyle { - public override int ChooseWaterfallStyle() => ModContent.Find("CalamityMod/SulphuricWaterflow").Slot; - public override int GetSplashDust() => ModContent.DustType(); - public override int GetDropletGore() => ModContent.GoreType(); - public override Asset GetRainTexture() => ModContent.Request("CalamityMod/Waters/SulphuricRain"); + public static CalamityModWaterStyle Instance { get; private set; } + public static ModWaterfallStyle WaterfallStyle { get; private set; } + public static int SplashDust { get; private set; } + public static int DropletGore { get; private set; } + public static Asset RainTexture { get; private set; } + + public override void SetStaticDefaults() + { + Instance = this; + WaterfallStyle = ModContent.Find("CalamityMod/SulphuricWaterflow"); + SplashDust = ModContent.DustType(); + DropletGore = ModContent.GoreType(); + } + + public override void Unload() + { + Instance = null; + WaterfallStyle = null; + SplashDust = 0; + DropletGore = 0; + RainTexture = null; + } + + public override int ChooseWaterfallStyle() => WaterfallStyle.Slot; + public override int GetSplashDust() => SplashDust; + public override int GetDropletGore() => DropletGore; + public override Asset GetRainTexture() => RainTexture ??= ModContent.Request("CalamityMod/Waters/SulphuricRain"); public override byte GetRainVariant() => (byte)Main.rand.Next(3); public override Color BiomeHairColor() => new Color(43, 168, 110); public override void DrawColor(int x, int y, ref VertexColors liquidColor, bool isSlope) => ILEditing.ILChanges.SelectSulphuricWaterColor(x, y, ref liquidColor, isSlope); - public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b) + public override void ModifyLight(ref readonly Tile tile, int i, int j, ref float r, ref float g, ref float b) { Vector3 outputColor = new Vector3(r, g, b); if (outputColor == Vector3.One || outputColor == new Vector3(0.25f, 0.25f, 0.25f) || outputColor == new Vector3(0.5f, 0.5f, 0.5f)) return; - Tile tile = CalamityUtils.ParanoidTileRetrieval(i, j); Tile above = CalamityUtils.ParanoidTileRetrieval(i, j - 1); if (!Main.gamePaused && !above.HasTile && above.LiquidAmount <= 0 && Main.rand.NextBool(9)) { @@ -38,7 +60,7 @@ namespace CalamityMod.Waters GeneralParticleHandler.SpawnParticle(acidFoam); } - if (tile.TileType != (ushort)ModContent.TileType()) + if (tile.TileType != RustyChestTile.Type) { if (Main.dayTime && !Main.raining) { @@ -46,19 +68,20 @@ namespace CalamityMod.Waters if (j > 580) brightness *= 1f - (j - 580) / 100f; - float waveScale1 = Main.GameUpdateCount * 0.014f; - float waveScale2 = Main.GameUpdateCount * 0.1f; + float time = Main.GameUpdateCount; + float waveScale1 = time * 0.014f; + float waveScale2 = time * 0.1f; int scalar = i + (-j / 2); float wave1 = waveScale1 * -50 + scalar * 15; float wave2 = waveScale2 * -10 + scalar * 14; float wave3 = waveScale1 * -100 + scalar * 13; float wave4 = waveScale2 * 10 + scalar * 25; float wave5 = waveScale1 * -70 + scalar * 5; - float wave1angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave1)); - float wave2angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave2)); - float wave3angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave3)); - float wave4angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave4)); - float wave5angle = 0.55f + 0.45f * (float)Math.Sin(MathHelper.ToRadians(wave5)); + float wave1angle = 0.55f + 0.45f * MathF.Sin(MathHelper.ToRadians(wave1)); + float wave2angle = 0.55f + 0.45f * MathF.Sin(MathHelper.ToRadians(wave2)); + float wave3angle = 0.55f + 0.45f * MathF.Sin(MathHelper.ToRadians(wave3)); + float wave4angle = 0.55f + 0.45f * MathF.Sin(MathHelper.ToRadians(wave4)); + float wave5angle = 0.55f + 0.45f * MathF.Sin(MathHelper.ToRadians(wave5)); outputColor = Vector3.Lerp(outputColor, Color.LightSeaGreen.ToVector3(), 0.41f + wave1angle + wave2angle + wave3angle + wave4angle + wave5angle); outputColor *= brightness; } diff --git a/Waters/SunkenSeaBurrowsWater.cs b/Waters/SunkenSeaBurrowsWater.cs index c01f2bbcc6..0790c6ca66 100644 --- a/Waters/SunkenSeaBurrowsWater.cs +++ b/Waters/SunkenSeaBurrowsWater.cs @@ -1,11 +1,20 @@ -using Microsoft.Xna.Framework; +using CalamityMod.Systems; +using CalamityMod.Tiles.Abyss; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Waters { - public class SunkenSeaBurrowsWater : ModWaterStyle + public class SunkenSeaBurrowsWaterflow : ModWaterfallStyle { } + + public class SunkenSeaBurrowsWater : CalamityModWaterStyle { public static int Type; + + private readonly Vector3 WaterGlowColor = new Color(76, 211, 231).ToVector3(); + public override void SetStaticDefaults() { Type = Slot; @@ -15,26 +24,31 @@ namespace CalamityMod.Waters return ModContent.Find("CalamityMod/SunkenSeaBurrowsWaterflow").Slot; } - public override int GetSplashDust() - { - return 33; - } - - public override int GetDropletGore() - { - return 713; - } - - public override Color BiomeHairColor() - { - return Color.Blue; - } - public override void LightColorMultiplier(ref float r, ref float g, ref float b) { r = 1.02f; g = 1.03f; b = 1.075f; } + + public override void ModifyLight(ref readonly Tile tile, int i, int j, ref float r, ref float g, ref float b) + { + Vector3 outputColor = new Vector3(r, g, b); + if (outputColor == Vector3.One || outputColor == new Vector3(0.25f, 0.25f, 0.25f) || outputColor == new Vector3(0.5f, 0.5f, 0.5f)) + return; + + if (tile.TileType != RustyChestTile.Type) + { + CalamityUtils.SunkenSeaWaterLighting(i, j, WaterGlowColor, ref outputColor.X, ref outputColor.Y, ref outputColor.Z); + } + + r = outputColor.X; + g = outputColor.Y; + b = outputColor.Z; + } + + public override int GetSplashDust() => DustID.Water; + public override int GetDropletGore() => GoreID.WaterDripCavern; + public override Color BiomeHairColor() => Color.Blue; } } diff --git a/Waters/SunkenSeaBurrowsWaterflow.cs b/Waters/SunkenSeaBurrowsWaterflow.cs deleted file mode 100644 index 79974dca2a..0000000000 --- a/Waters/SunkenSeaBurrowsWaterflow.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Terraria.ModLoader; - -namespace CalamityMod.Waters -{ - public class SunkenSeaBurrowsWaterflow : ModWaterfallStyle - { - } -} diff --git a/Waters/SunkenSeaPolypWater.cs b/Waters/SunkenSeaPolypWater.cs index 11a8967142..f65a7def69 100644 --- a/Waters/SunkenSeaPolypWater.cs +++ b/Waters/SunkenSeaPolypWater.cs @@ -1,33 +1,44 @@ -using Microsoft.Xna.Framework; +using CalamityMod.Systems; +using CalamityMod.Tiles.Abyss; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Waters { - public class SunkenSeaPolypWater : ModWaterStyle + public class SunkenSeaPolypWaterflow : ModWaterfallStyle { } + + public class SunkenSeaPolypWater : CalamityModWaterStyle { public static int Type; + + private readonly Vector3 WaterGlowColor = new Color(213, 185, 178).ToVector3(); + public override void SetStaticDefaults() { Type = Slot; } - public override int ChooseWaterfallStyle() + + public override void ModifyLight(ref readonly Tile tile, int i, int j, ref float r, ref float g, ref float b) { - return ModContent.Find("CalamityMod/SunkenSeaPolypWaterflow").Slot; + Vector3 outputColor = new Vector3(r, g, b); + if (outputColor == Vector3.One || outputColor == new Vector3(0.25f, 0.25f, 0.25f) || outputColor == new Vector3(0.5f, 0.5f, 0.5f)) + return; + + if (tile.TileType != RustyChestTile.Type) + { + CalamityUtils.SunkenSeaWaterLighting(i, j, WaterGlowColor, ref outputColor.X, ref outputColor.Y, ref outputColor.Z); + } + + r = outputColor.X; + g = outputColor.Y; + b = outputColor.Z; } - public override int GetSplashDust() - { - return 33; - } - - public override int GetDropletGore() - { - return 713; - } - - public override Color BiomeHairColor() - { - return Color.Coral; - } + public override int ChooseWaterfallStyle() => ModContent.Find("CalamityMod/SunkenSeaPolypWaterflow").Slot; + public override int GetSplashDust() => DustID.Water; + public override int GetDropletGore() => GoreID.WaterDripCavern; + public override Color BiomeHairColor() => Color.Coral; } } diff --git a/Waters/SunkenSeaPolypWaterflow.cs b/Waters/SunkenSeaPolypWaterflow.cs deleted file mode 100644 index 13c68fbe0b..0000000000 --- a/Waters/SunkenSeaPolypWaterflow.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Terraria.ModLoader; - -namespace CalamityMod.Waters -{ - public class SunkenSeaPolypWaterflow : ModWaterfallStyle - { - } -} diff --git a/Waters/SunkenSeaReefsWater.cs b/Waters/SunkenSeaReefsWater.cs index b83f7f4b57..80be57dad2 100644 --- a/Waters/SunkenSeaReefsWater.cs +++ b/Waters/SunkenSeaReefsWater.cs @@ -1,33 +1,44 @@ -using Microsoft.Xna.Framework; +using CalamityMod.Systems; +using CalamityMod.Tiles.Abyss; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Waters { - public class SunkenSeaReefsWater : ModWaterStyle + public class SunkenSeaReefsWaterflow : ModWaterfallStyle { } + + public class SunkenSeaReefsWater : CalamityModWaterStyle { public static int Type; + + private readonly Vector3 WaterGlowColor = new Color(140, 222, 239).ToVector3(); + public override void SetStaticDefaults() { Type = Slot; } - public override int ChooseWaterfallStyle() + + public override void ModifyLight(ref readonly Tile tile, int i, int j, ref float r, ref float g, ref float b) { - return ModContent.Find("CalamityMod/SunkenSeaReefsWaterflow").Slot; + Vector3 outputColor = new Vector3(r, g, b); + if (outputColor == Vector3.One || outputColor == new Vector3(0.25f, 0.25f, 0.25f) || outputColor == new Vector3(0.5f, 0.5f, 0.5f)) + return; + + if (tile.TileType != RustyChestTile.Type) + { + CalamityUtils.SunkenSeaWaterLighting(i, j, WaterGlowColor, ref outputColor.X, ref outputColor.Y, ref outputColor.Z); + } + + r = outputColor.X; + g = outputColor.Y; + b = outputColor.Z; } - public override int GetSplashDust() - { - return 33; - } - - public override int GetDropletGore() - { - return 713; - } - - public override Color BiomeHairColor() - { - return Color.SkyBlue; - } + public override int ChooseWaterfallStyle() => ModContent.Find("CalamityMod/SunkenSeaReefsWaterflow").Slot; + public override int GetSplashDust() => DustID.Water; + public override int GetDropletGore() => GoreID.WaterDripCavern; + public override Color BiomeHairColor() => Color.SkyBlue; } } diff --git a/Waters/SunkenSeaReefsWaterflow.cs b/Waters/SunkenSeaReefsWaterflow.cs deleted file mode 100644 index 353e3e372e..0000000000 --- a/Waters/SunkenSeaReefsWaterflow.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Terraria.ModLoader; - -namespace CalamityMod.Waters -{ - public class SunkenSeaReefsWaterflow : ModWaterfallStyle - { - } -} diff --git a/Waters/SunkenSeaShoresWater.cs b/Waters/SunkenSeaShoresWater.cs index 5dd4c5e590..dc8dbe5fff 100644 --- a/Waters/SunkenSeaShoresWater.cs +++ b/Waters/SunkenSeaShoresWater.cs @@ -1,33 +1,44 @@ -using Microsoft.Xna.Framework; +using CalamityMod.Systems; +using CalamityMod.Tiles.Abyss; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Waters { - public class SunkenSeaShoresWater : ModWaterStyle + public class SunkenSeaShoresWaterflow : ModWaterfallStyle { } + + public class SunkenSeaShoresWater : CalamityModWaterStyle { public static int Type; + + private readonly Vector3 WaterGlowColor = new Color(233, 170, 184).ToVector3(); + public override void SetStaticDefaults() { Type = Slot; } - public override int ChooseWaterfallStyle() + + public override void ModifyLight(ref readonly Tile tile, int i, int j, ref float r, ref float g, ref float b) { - return ModContent.Find("CalamityMod/SunkenSeaShoresWaterflow").Slot; + Vector3 outputColor = new Vector3(r, g, b); + if (outputColor == Vector3.One || outputColor == new Vector3(0.25f, 0.25f, 0.25f) || outputColor == new Vector3(0.5f, 0.5f, 0.5f)) + return; + + if (tile.TileType != RustyChestTile.Type) + { + CalamityUtils.SunkenSeaWaterLighting(i, j, WaterGlowColor, ref outputColor.X, ref outputColor.Y, ref outputColor.Z); + } + + r = outputColor.X; + g = outputColor.Y; + b = outputColor.Z; } - public override int GetSplashDust() - { - return 33; - } - - public override int GetDropletGore() - { - return 713; - } - - public override Color BiomeHairColor() - { - return Color.OrangeRed; - } + public override int ChooseWaterfallStyle() => ModContent.Find("CalamityMod/SunkenSeaShoresWaterflow").Slot; + public override int GetSplashDust() => DustID.Water; + public override int GetDropletGore() => GoreID.WaterDripCavern; + public override Color BiomeHairColor() => Color.OrangeRed; } } diff --git a/Waters/SunkenSeaShoresWaterflow.cs b/Waters/SunkenSeaShoresWaterflow.cs deleted file mode 100644 index 67620e943c..0000000000 --- a/Waters/SunkenSeaShoresWaterflow.cs +++ /dev/null @@ -1,8 +0,0 @@ -using Terraria.ModLoader; - -namespace CalamityMod.Waters -{ - public class SunkenSeaShoresWaterflow : ModWaterfallStyle - { - } -} diff --git a/Waters/UpperAbyssWater.cs b/Waters/UpperAbyssWater.cs index fed3016207..a24d2ff27c 100644 --- a/Waters/UpperAbyssWater.cs +++ b/Waters/UpperAbyssWater.cs @@ -11,9 +11,30 @@ namespace CalamityMod.Waters public class UpperAbyssWater : CalamityModWaterStyle { - public override int ChooseWaterfallStyle() => ModContent.Find("CalamityMod/UpperAbyssWaterflow").Slot; - public override int GetSplashDust() => ModContent.DustType(); - public override int GetDropletGore() => ModContent.GoreType(); + public static CalamityModWaterStyle Instance { get; private set; } + public static ModWaterfallStyle WaterfallStyle { get; private set; } + public static int SplashDust { get; private set; } + public static int DropletGore { get; private set; } + + public override void SetStaticDefaults() + { + Instance = this; + WaterfallStyle = ModContent.Find("CalamityMod/UpperAbyssWaterflow"); + SplashDust = ModContent.DustType(); + DropletGore = ModContent.GoreType(); + } + + public override void Unload() + { + Instance = null; + WaterfallStyle = null; + SplashDust = 0; + DropletGore = 0; + } + + public override int ChooseWaterfallStyle() => WaterfallStyle.Slot; + public override int GetSplashDust() => SplashDust; + public override int GetDropletGore() => DropletGore; public override Color BiomeHairColor() => new Color(9, 69, 82); public override void DrawColor(int x, int y, ref VertexColors liquidColor, bool isSlope) => ILEditing.ILChanges.SelectSulphuricWaterColor(x, y, ref liquidColor, isSlope); } diff --git a/Waters/VoidWater.cs b/Waters/VoidWater.cs index 1ce1591140..153151825a 100644 --- a/Waters/VoidWater.cs +++ b/Waters/VoidWater.cs @@ -11,9 +11,30 @@ namespace CalamityMod.Waters public class VoidWater : CalamityModWaterStyle { - public override int ChooseWaterfallStyle() => ModContent.Find("CalamityMod/VoidWaterflow").Slot; - public override int GetSplashDust() => ModContent.DustType(); - public override int GetDropletGore() => ModContent.GoreType(); + public static CalamityModWaterStyle Instance { get; private set; } + public static ModWaterfallStyle WaterfallStyle { get; private set; } + public static int SplashDust { get; private set; } + public static int DropletGore { get; private set; } + + public override void SetStaticDefaults() + { + Instance = this; + WaterfallStyle = ModContent.Find("CalamityMod/VoidWaterflow"); + SplashDust = ModContent.DustType(); + DropletGore = ModContent.GoreType(); + } + + public override void Unload() + { + Instance = null; + WaterfallStyle = null; + SplashDust = 0; + DropletGore = 0; + } + + public override int ChooseWaterfallStyle() => WaterfallStyle.Slot; + public override int GetSplashDust() => SplashDust; + public override int GetDropletGore() => DropletGore; public override Color BiomeHairColor() => new Color(16, 8, 30); public override void DrawColor(int x, int y, ref VertexColors liquidColor, bool isSlope) => ILEditing.ILChanges.SelectSulphuricWaterColor(x, y, ref liquidColor, isSlope); } From 5cc32cdca45975863f759243bf48ce3fd4eac188 Mon Sep 17 00:00:00 2001 From: Flowaria Date: Sun, 1 Sep 2024 00:32:05 +0900 Subject: [PATCH 03/12] Cache the BG Texture ID --- Backgrounds/AstralUndergroundBGStyle.cs | 36 +++++++++++++++++++++++-- Backgrounds/SunkenSeaBGStyle.cs | 25 +++++++++++++---- 2 files changed, 54 insertions(+), 7 deletions(-) diff --git a/Backgrounds/AstralUndergroundBGStyle.cs b/Backgrounds/AstralUndergroundBGStyle.cs index f3c9455798..20cc1d0d5b 100644 --- a/Backgrounds/AstralUndergroundBGStyle.cs +++ b/Backgrounds/AstralUndergroundBGStyle.cs @@ -5,10 +5,42 @@ namespace CalamityMod.Backgrounds { public class AstralUndergroundBGStyle : ModUndergroundBackgroundStyle { + private int AUBG0; + private int AUBG1; + private int AUBG2; + private int AUBG3; + + private int AUBG4_0; + private int AUBG4_1; + private int AUBG4_2; + + public override void SetStaticDefaults() + { + if (Main.dedServ) + return; + + AUBG0 = BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/AstralUG0"); + AUBG1 = BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/AstralUG1"); + AUBG2 = BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/AstralUG2"); + AUBG3 = BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/AstralUG3"); + + AUBG4_0 = BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/AstralUG4_0"); + AUBG4_1 = BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/AstralUG4_1"); + AUBG4_2 = BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/AstralUG4_2"); + } + public override void FillTextureArray(int[] textureSlots) { - for (int i = 0; i <= 4; i++) - textureSlots[i] = BackgroundTextureLoader.GetBackgroundSlot(i == 4 ? "CalamityMod/Backgrounds/AstralUG" + i.ToString() + "_" + Main.hellBackStyle : "CalamityMod/Backgrounds/AstralUG" + i.ToString()); + textureSlots[0] = AUBG0; + textureSlots[1] = AUBG1; + textureSlots[2] = AUBG2; + textureSlots[3] = AUBG3; + textureSlots[4] = Main.hellBackStyle switch + { + 0 => AUBG4_0, + 1 => AUBG4_1, + _ => AUBG4_2 + }; } } } diff --git a/Backgrounds/SunkenSeaBGStyle.cs b/Backgrounds/SunkenSeaBGStyle.cs index cfd743dd4f..11b86c7d67 100644 --- a/Backgrounds/SunkenSeaBGStyle.cs +++ b/Backgrounds/SunkenSeaBGStyle.cs @@ -5,13 +5,28 @@ namespace CalamityMod.Backgrounds { public class SunkenSeaBGStyle : ModUndergroundBackgroundStyle { + private int SSBG0; + private int SSBG1; + private int SSBG2; + private int SSBG3; + + public override void SetStaticDefaults() + { + if (Main.dedServ) + return; + + SSBG0 = BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/SunkenSeaBG0"); + SSBG1 = BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/SunkenSeaBG1"); + SSBG2 = BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/SunkenSeaBG2"); + SSBG3 = BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/SunkenSeaBG3"); + } + public override void FillTextureArray(int[] textureSlots) { - for (int i = 0; i <= 3; i++) - { - textureSlots[i] = BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/BlankPixel"); - //textureSlots[i] = BackgroundTextureLoader.GetBackgroundSlot("CalamityMod/Backgrounds/SunkenSeaBG" + i.ToString()); - } + textureSlots[0] = SSBG0; + textureSlots[1] = SSBG1; + textureSlots[2] = SSBG2; + textureSlots[3] = SSBG3; } } } From adf4efcb8254cd72214ee7972705dbe37b72a3c3 Mon Sep 17 00:00:00 2001 From: Flowaria Date: Sun, 1 Sep 2024 00:38:51 +0900 Subject: [PATCH 04/12] Biomes now fetch cache from Each WaterStyle types --- BiomeManagers/AbyssLayer1Biome.cs | 3 ++- BiomeManagers/AbyssLayer2Biome.cs | 3 ++- BiomeManagers/AbyssLayer3Biome.cs | 3 ++- BiomeManagers/AbyssLayer4Biome.cs | 3 ++- BiomeManagers/AstralInfectionBiome.cs | 3 ++- BiomeManagers/FloralParadiseBiome.cs | 3 ++- BiomeManagers/SulphurousSeaBiome.cs | 3 ++- BiomeManagers/SunkenSeaBurrowsBiome.cs | 3 ++- BiomeManagers/SunkenSeaPolypBiome.cs | 3 ++- BiomeManagers/SunkenSeaReefsBiome.cs | 3 ++- BiomeManagers/SunkenSeaShoresBiome.cs | 3 ++- Waters/FloralParadiseWater.cs | 15 +++++++++++++++ Waters/SulphuricDepthsWater.cs | 3 +++ Waters/SunkenSeaBurrowsWater.cs | 13 +++++++++++-- Waters/SunkenSeaPolypWater.cs | 12 ++++++++++-- Waters/SunkenSeaReefsWater.cs | 12 ++++++++++-- Waters/SunkenSeaShoresWater.cs | 12 ++++++++++-- 17 files changed, 81 insertions(+), 19 deletions(-) diff --git a/BiomeManagers/AbyssLayer1Biome.cs b/BiomeManagers/AbyssLayer1Biome.cs index a3b73e8f4b..8d852ea389 100644 --- a/BiomeManagers/AbyssLayer1Biome.cs +++ b/BiomeManagers/AbyssLayer1Biome.cs @@ -1,6 +1,7 @@ using CalamityMod.CalPlayer; using CalamityMod.Items.Placeables.FurnitureAbyss; using CalamityMod.Systems; +using CalamityMod.Waters; using CalamityMod.World; using Microsoft.Xna.Framework; using Terraria; @@ -46,7 +47,7 @@ namespace CalamityMod.BiomeManagers } // Temporarily use sulphur for now - public override ModWaterStyle WaterStyle => ModContent.Find("CalamityMod/SulphuricDepthsWater"); + public override ModWaterStyle WaterStyle => SulphuricDepthsWater.Instance; public override int BiomeTorchItemType => ModContent.ItemType(); public override SceneEffectPriority Priority => SceneEffectPriority.Environment; public override string BestiaryIcon => "CalamityMod/BiomeManagers/AbyssLayer1Icon"; diff --git a/BiomeManagers/AbyssLayer2Biome.cs b/BiomeManagers/AbyssLayer2Biome.cs index cf20c66664..7f520a6835 100644 --- a/BiomeManagers/AbyssLayer2Biome.cs +++ b/BiomeManagers/AbyssLayer2Biome.cs @@ -1,6 +1,7 @@ using CalamityMod.CalPlayer; using CalamityMod.Items.Placeables.FurnitureAbyss; using CalamityMod.Systems; +using CalamityMod.Waters; using CalamityMod.World; using Terraria; using Terraria.ID; @@ -20,7 +21,7 @@ namespace CalamityMod.BiomeManagers } } - public override ModWaterStyle WaterStyle => ModContent.Find("CalamityMod/UpperAbyssWater"); + public override ModWaterStyle WaterStyle => UpperAbyssWater.Instance; public override int BiomeTorchItemType => ModContent.ItemType(); public override SceneEffectPriority Priority => SceneEffectPriority.Environment; public override string BestiaryIcon => "CalamityMod/BiomeManagers/AbyssLayer2Icon"; diff --git a/BiomeManagers/AbyssLayer3Biome.cs b/BiomeManagers/AbyssLayer3Biome.cs index 5fa549ef5b..f9ad0fc426 100644 --- a/BiomeManagers/AbyssLayer3Biome.cs +++ b/BiomeManagers/AbyssLayer3Biome.cs @@ -1,6 +1,7 @@ using CalamityMod.CalPlayer; using CalamityMod.Items.Placeables.FurnitureAbyss; using CalamityMod.Systems; +using CalamityMod.Waters; using CalamityMod.World; using Terraria; using Terraria.ID; @@ -20,7 +21,7 @@ namespace CalamityMod.BiomeManagers } } - public override ModWaterStyle WaterStyle => ModContent.Find("CalamityMod/MiddleAbyssWater"); + public override ModWaterStyle WaterStyle => MiddleAbyssWater.Instance; public override int BiomeTorchItemType => ModContent.ItemType(); public override SceneEffectPriority Priority => SceneEffectPriority.Environment; public override string BestiaryIcon => "CalamityMod/BiomeManagers/AbyssLayer3Icon"; diff --git a/BiomeManagers/AbyssLayer4Biome.cs b/BiomeManagers/AbyssLayer4Biome.cs index de29933f2d..8a2de62e0e 100644 --- a/BiomeManagers/AbyssLayer4Biome.cs +++ b/BiomeManagers/AbyssLayer4Biome.cs @@ -1,6 +1,7 @@ using CalamityMod.CalPlayer; using CalamityMod.Items.Placeables.FurnitureAbyss; using CalamityMod.Systems; +using CalamityMod.Waters; using CalamityMod.World; using Terraria; using Terraria.ID; @@ -20,7 +21,7 @@ namespace CalamityMod.BiomeManagers } } - public override ModWaterStyle WaterStyle => ModContent.Find("CalamityMod/VoidWater"); + public override ModWaterStyle WaterStyle => VoidWater.Instance; public override int BiomeTorchItemType => ModContent.ItemType(); public override SceneEffectPriority Priority => SceneEffectPriority.Environment; public override string BestiaryIcon => "CalamityMod/BiomeManagers/AbyssLayer4Icon"; diff --git a/BiomeManagers/AstralInfectionBiome.cs b/BiomeManagers/AstralInfectionBiome.cs index 980d34e0da..75f0c03b52 100644 --- a/BiomeManagers/AstralInfectionBiome.cs +++ b/BiomeManagers/AstralInfectionBiome.cs @@ -1,5 +1,6 @@ using CalamityMod.Items.Placeables.Furniture; using CalamityMod.Systems; +using CalamityMod.Waters; using Terraria; using Terraria.GameContent.Events; using Terraria.ID; @@ -9,7 +10,7 @@ namespace CalamityMod.BiomeManagers { public class AstralInfectionBiome : ModBiome { - public override ModWaterStyle WaterStyle => ModContent.Find("CalamityMod/AstralWater"); + public override ModWaterStyle WaterStyle => AstralWater.Instance; public override ModSurfaceBackgroundStyle SurfaceBackgroundStyle { diff --git a/BiomeManagers/FloralParadiseBiome.cs b/BiomeManagers/FloralParadiseBiome.cs index 9789259705..bfe9d45095 100644 --- a/BiomeManagers/FloralParadiseBiome.cs +++ b/BiomeManagers/FloralParadiseBiome.cs @@ -1,4 +1,5 @@ using CalamityMod.Systems; +using CalamityMod.Waters; using Terraria; using Terraria.ModLoader; @@ -6,7 +7,7 @@ namespace CalamityMod.BiomeManagers { public class FloralParadiseBiome : ModBiome { - public override ModWaterStyle WaterStyle => ModContent.Find("CalamityMod/FloralParadiseWater"); + public override ModWaterStyle WaterStyle => FloralParadiseWater.Instance; public override ModUndergroundBackgroundStyle UndergroundBackgroundStyle => ModContent.Find("CalamityMod/FloralParadiseBGStyle"); public override SceneEffectPriority Priority => SceneEffectPriority.BiomeHigh; diff --git a/BiomeManagers/SulphurousSeaBiome.cs b/BiomeManagers/SulphurousSeaBiome.cs index fb170f3449..f0f6fa7eba 100644 --- a/BiomeManagers/SulphurousSeaBiome.cs +++ b/BiomeManagers/SulphurousSeaBiome.cs @@ -3,6 +3,7 @@ using CalamityMod.CalPlayer; using CalamityMod.Events; using CalamityMod.Items.Placeables.Furniture; using CalamityMod.Systems; +using CalamityMod.Waters; using CalamityMod.World; using Microsoft.Xna.Framework; using Terraria; @@ -14,7 +15,7 @@ namespace CalamityMod.BiomeManagers { public class SulphurousSeaBiome : ModBiome { - public override ModWaterStyle WaterStyle => Main.zenithWorld ? ModContent.Find("CalamityMod/PissWater") : ModContent.Find("CalamityMod/SulphuricWater"); + public override ModWaterStyle WaterStyle => Main.zenithWorld ? PissWater.Instance : SulphuricWater.Instance; public override ModSurfaceBackgroundStyle SurfaceBackgroundStyle => Main.zenithWorld ? ModContent.Find("CalamityMod/PissSeaSurfaceBGStyle") : ModContent.Find("CalamityMod/SulphurSeaSurfaceBGStyle"); public override int BiomeTorchItemType => ModContent.ItemType(); public override SceneEffectPriority Priority => SceneEffectPriority.BiomeHigh; diff --git a/BiomeManagers/SunkenSeaBurrowsBiome.cs b/BiomeManagers/SunkenSeaBurrowsBiome.cs index 1282bd2b34..b4e07aab9a 100644 --- a/BiomeManagers/SunkenSeaBurrowsBiome.cs +++ b/BiomeManagers/SunkenSeaBurrowsBiome.cs @@ -1,5 +1,6 @@ using CalamityMod.Items.Placeables.Furniture; using CalamityMod.Systems; +using CalamityMod.Waters; using Terraria; using Terraria.ID; using Terraria.ModLoader; @@ -8,7 +9,7 @@ namespace CalamityMod.BiomeManagers { public class SunkenSeaBurrowsBiome : ModBiome { - public override ModWaterStyle WaterStyle => ModContent.Find("CalamityMod/SunkenSeaBurrowsWater"); + public override ModWaterStyle WaterStyle => SunkenSeaBurrowsWater.Instance; public override ModUndergroundBackgroundStyle UndergroundBackgroundStyle => ModContent.Find("CalamityMod/SunkenSeaBGStyle"); public override int BiomeTorchItemType => ModContent.ItemType(); public override int Music => CalamityMod.Instance.GetMusicFromMusicMod("SunkenSea") ?? MusicID.OceanNight; diff --git a/BiomeManagers/SunkenSeaPolypBiome.cs b/BiomeManagers/SunkenSeaPolypBiome.cs index 813397405e..7d1ead79a5 100644 --- a/BiomeManagers/SunkenSeaPolypBiome.cs +++ b/BiomeManagers/SunkenSeaPolypBiome.cs @@ -1,5 +1,6 @@ using CalamityMod.Items.Placeables.Furniture; using CalamityMod.Systems; +using CalamityMod.Waters; using Terraria; using Terraria.ID; using Terraria.ModLoader; @@ -8,7 +9,7 @@ namespace CalamityMod.BiomeManagers { public class SunkenSeaPolypBiome : ModBiome { - public override ModWaterStyle WaterStyle => ModContent.Find("CalamityMod/SunkenSeaPolypWater"); + public override ModWaterStyle WaterStyle => SunkenSeaPolypWater.Instance; public override ModUndergroundBackgroundStyle UndergroundBackgroundStyle => ModContent.Find("CalamityMod/SunkenSeaBGStyle"); public override int BiomeTorchItemType => ModContent.ItemType(); public override int Music => CalamityMod.Instance.GetMusicFromMusicMod("SunkenSea") ?? MusicID.OceanNight; diff --git a/BiomeManagers/SunkenSeaReefsBiome.cs b/BiomeManagers/SunkenSeaReefsBiome.cs index 8ccbc5e8bd..09f15f24c2 100644 --- a/BiomeManagers/SunkenSeaReefsBiome.cs +++ b/BiomeManagers/SunkenSeaReefsBiome.cs @@ -1,5 +1,6 @@ using CalamityMod.Items.Placeables.Furniture; using CalamityMod.Systems; +using CalamityMod.Waters; using Terraria; using Terraria.ID; using Terraria.ModLoader; @@ -8,7 +9,7 @@ namespace CalamityMod.BiomeManagers { public class SunkenSeaReefsBiome : ModBiome { - public override ModWaterStyle WaterStyle => ModContent.Find("CalamityMod/SunkenSeaReefsWater"); + public override ModWaterStyle WaterStyle => SunkenSeaReefsWater.Instance; public override ModUndergroundBackgroundStyle UndergroundBackgroundStyle => ModContent.Find("CalamityMod/SunkenSeaBGStyle"); public override int BiomeTorchItemType => ModContent.ItemType(); public override int Music => CalamityMod.Instance.GetMusicFromMusicMod("SunkenSea") ?? MusicID.OceanNight; diff --git a/BiomeManagers/SunkenSeaShoresBiome.cs b/BiomeManagers/SunkenSeaShoresBiome.cs index 9b1e11d32e..3f18b862f6 100644 --- a/BiomeManagers/SunkenSeaShoresBiome.cs +++ b/BiomeManagers/SunkenSeaShoresBiome.cs @@ -1,5 +1,6 @@ using CalamityMod.Items.Placeables.Furniture; using CalamityMod.Systems; +using CalamityMod.Waters; using Terraria; using Terraria.ID; using Terraria.ModLoader; @@ -8,7 +9,7 @@ namespace CalamityMod.BiomeManagers { public class SunkenSeaShoresBiome : ModBiome { - public override ModWaterStyle WaterStyle => ModContent.Find("CalamityMod/SunkenSeaShoresWater"); + public override ModWaterStyle WaterStyle => SunkenSeaShoresWater.Instance; public override ModUndergroundBackgroundStyle UndergroundBackgroundStyle => ModContent.Find("CalamityMod/SunkenSeaBGStyle"); public override int BiomeTorchItemType => ModContent.ItemType(); public override int Music => CalamityMod.Instance.GetMusicFromMusicMod("SunkenSea") ?? MusicID.OceanNight; diff --git a/Waters/FloralParadiseWater.cs b/Waters/FloralParadiseWater.cs index 182a84ad4b..55c3c06ba0 100644 --- a/Waters/FloralParadiseWater.cs +++ b/Waters/FloralParadiseWater.cs @@ -11,6 +11,21 @@ namespace CalamityMod.Waters public class FloralParadiseWater : CalamityModWaterStyle { + public static int Type { get; private set; } + public static CalamityModWaterStyle Instance { get; private set; } + + public override void SetStaticDefaults() + { + Type = Slot; + Instance = this; + } + + public override void Unload() + { + Type = -1; + Instance = null; + } + public override int ChooseWaterfallStyle() { return ModContent.Find("CalamityMod/FloralParadiseWaterflow").Slot; diff --git a/Waters/SulphuricDepthsWater.cs b/Waters/SulphuricDepthsWater.cs index 8b0b4d2e31..7aa0ceefd3 100644 --- a/Waters/SulphuricDepthsWater.cs +++ b/Waters/SulphuricDepthsWater.cs @@ -15,6 +15,7 @@ namespace CalamityMod.Waters public class SulphuricDepthsWater : CalamityModWaterStyle { + public static int Type { get; private set; } public static CalamityModWaterStyle Instance { get; private set; } public static ModWaterfallStyle WaterfallStyle { get; private set; } public static int SplashDust { get; private set; } @@ -22,6 +23,7 @@ namespace CalamityMod.Waters public override void SetStaticDefaults() { + Type = Slot; Instance = this; WaterfallStyle = ModContent.Find("CalamityMod/SulphuricDepthsWaterflow"); SplashDust = ModContent.DustType(); @@ -30,6 +32,7 @@ namespace CalamityMod.Waters public override void Unload() { + Type = -1; Instance = null; WaterfallStyle = null; SplashDust = 0; diff --git a/Waters/SunkenSeaBurrowsWater.cs b/Waters/SunkenSeaBurrowsWater.cs index 0790c6ca66..81b3c30330 100644 --- a/Waters/SunkenSeaBurrowsWater.cs +++ b/Waters/SunkenSeaBurrowsWater.cs @@ -11,14 +11,23 @@ namespace CalamityMod.Waters public class SunkenSeaBurrowsWater : CalamityModWaterStyle { - public static int Type; - private readonly Vector3 WaterGlowColor = new Color(76, 211, 231).ToVector3(); + public static int Type { get; private set; } + public static CalamityModWaterStyle Instance { get; private set; } + public override void SetStaticDefaults() { Type = Slot; + Instance = this; } + + public override void Unload() + { + Type = -1; + Instance = null; + } + public override int ChooseWaterfallStyle() { return ModContent.Find("CalamityMod/SunkenSeaBurrowsWaterflow").Slot; diff --git a/Waters/SunkenSeaPolypWater.cs b/Waters/SunkenSeaPolypWater.cs index f65a7def69..e998f8c0c9 100644 --- a/Waters/SunkenSeaPolypWater.cs +++ b/Waters/SunkenSeaPolypWater.cs @@ -11,13 +11,21 @@ namespace CalamityMod.Waters public class SunkenSeaPolypWater : CalamityModWaterStyle { - public static int Type; - private readonly Vector3 WaterGlowColor = new Color(213, 185, 178).ToVector3(); + public static int Type { get; private set; } + public static CalamityModWaterStyle Instance { get; private set; } + public override void SetStaticDefaults() { Type = Slot; + Instance = this; + } + + public override void Unload() + { + Type = -1; + Instance = null; } public override void ModifyLight(ref readonly Tile tile, int i, int j, ref float r, ref float g, ref float b) diff --git a/Waters/SunkenSeaReefsWater.cs b/Waters/SunkenSeaReefsWater.cs index 80be57dad2..3072e87f2e 100644 --- a/Waters/SunkenSeaReefsWater.cs +++ b/Waters/SunkenSeaReefsWater.cs @@ -11,13 +11,21 @@ namespace CalamityMod.Waters public class SunkenSeaReefsWater : CalamityModWaterStyle { - public static int Type; - private readonly Vector3 WaterGlowColor = new Color(140, 222, 239).ToVector3(); + public static int Type { get; private set; } + public static CalamityModWaterStyle Instance { get; private set; } + public override void SetStaticDefaults() { Type = Slot; + Instance = this; + } + + public override void Unload() + { + Type = -1; + Instance = null; } public override void ModifyLight(ref readonly Tile tile, int i, int j, ref float r, ref float g, ref float b) diff --git a/Waters/SunkenSeaShoresWater.cs b/Waters/SunkenSeaShoresWater.cs index dc8dbe5fff..ac55cb151c 100644 --- a/Waters/SunkenSeaShoresWater.cs +++ b/Waters/SunkenSeaShoresWater.cs @@ -11,13 +11,21 @@ namespace CalamityMod.Waters public class SunkenSeaShoresWater : CalamityModWaterStyle { - public static int Type; - private readonly Vector3 WaterGlowColor = new Color(233, 170, 184).ToVector3(); + public static int Type { get; private set; } + public static CalamityModWaterStyle Instance { get; private set; } + public override void SetStaticDefaults() { Type = Slot; + Instance = this; + } + + public override void Unload() + { + Type = -1; + Instance = null; } public override void ModifyLight(ref readonly Tile tile, int i, int j, ref float r, ref float g, ref float b) From 59391f841afb2cdbd2a275b1602b0bc6bef7e03b Mon Sep 17 00:00:00 2001 From: Flowaria Date: Sun, 1 Sep 2024 00:40:45 +0900 Subject: [PATCH 05/12] Moved Texture utils under the path / Added GrayscaleTexture util --- .../FramedMaskTexture.cs} | 110 +++++++++++------- Utilities/TextureUtils/GrayscaleTexture1D.cs | 69 +++++++++++ Utilities/TextureUtils/GrayscaleTexture2D.cs | 76 ++++++++++++ 3 files changed, 212 insertions(+), 43 deletions(-) rename Utilities/{FramedGlowMask.cs => TextureUtils/FramedMaskTexture.cs} (51%) create mode 100644 Utilities/TextureUtils/GrayscaleTexture1D.cs create mode 100644 Utilities/TextureUtils/GrayscaleTexture2D.cs diff --git a/Utilities/FramedGlowMask.cs b/Utilities/TextureUtils/FramedMaskTexture.cs similarity index 51% rename from Utilities/FramedGlowMask.cs rename to Utilities/TextureUtils/FramedMaskTexture.cs index 33cbc00485..39e8e5e55e 100644 --- a/Utilities/FramedGlowMask.cs +++ b/Utilities/TextureUtils/FramedMaskTexture.cs @@ -11,45 +11,54 @@ using Terraria.ModLoader; namespace CalamityMod { - public sealed class FramedGlowMask + public sealed class FramedMaskTexture { /// /// Cached Texture2D reference, null on server /// - public Texture2D Texture { get; private set; } + public Texture2D Texture; // Leave this as field for performances sake /// /// X axis's frame count, 0 on server /// - public int FrameXCount { get; private set; } = 0; + public int FrameXCount => _FrameXCount; /// /// Y axis's frame count, 0 on server /// - public int FrameYCount { get; private set; } = 0; - + public int FrameYCount => _FrameYCount; + /// /// Pixel width for each frame /// - public int FrameWidth { get; private set; } + public int FrameWidth => _FrameWidth; /// /// Pixel height for each frame /// - public int FrameHeight { get; private set; } + public int FrameHeight => _FrameHeight; - private static event Action _OnUnload; - private readonly bool[,] _HasGlowContent; + /// + /// Pixel Width of Texture, 0 on server + /// + public int TextureWidth => _TextureWidth; - internal static void UnloadTexCache() + /// + /// Pixel Height of Texture, 0 on server + /// + public int TextureHeight => _TextureHeight; + + private int _FrameWidth = 0, _FrameHeight = 0; + private int _FrameXCount = 0, _FrameYCount = 0; + private int _TextureWidth = 0, _TextureHeight = 0; + private readonly bool[] _HasMaskContent; + + public FramedMaskTexture(string asset, int frameWidth, int frameHeight, bool pretendEveryFrameHaveGlow = false) { - _OnUnload?.Invoke(); - } + _FrameWidth = frameWidth; + _FrameHeight = frameHeight; - public FramedGlowMask(string asset, int frameWidth, int frameHeight, bool pretendEveryFrameHaveGlow = false) - { - FrameWidth = frameWidth; - FrameHeight = frameHeight; + FramedGlowMaskSystem.OnUnload += Unload; // Don't do anything further on server if (Main.dedServ) @@ -59,19 +68,12 @@ namespace CalamityMod if (Texture is null) return; - _OnUnload += () => - { - Texture = null; - FrameWidth = 0; - FrameHeight = 0; - FrameXCount = 0; - FrameYCount = 0; - }; + _TextureWidth = Texture.Width; + _TextureHeight = Texture.Height; + _FrameXCount = _TextureWidth / frameWidth; + _FrameYCount = _TextureHeight / frameHeight; - FrameXCount = Texture.Width / frameWidth; - FrameYCount = Texture.Height / frameHeight; - - _HasGlowContent = new bool[FrameXCount, FrameYCount]; + _HasMaskContent = new bool[FrameXCount * FrameYCount]; if (pretendEveryFrameHaveGlow) @@ -80,7 +82,7 @@ namespace CalamityMod { for (int y = 0; y { var colData = Texture.GetColorsFromTexture(); + + // Interesting case, not sure if this will even happens + if (colData is null) + return; + Parallel.For(0, FrameXCount * FrameYCount, (i) => { int xFrame = i % FrameXCount; int yFrame = i / FrameXCount; int xStart = xFrame * frameWidth; - int xEnd = xStart + frameWidth; + int xEnd = Math.Min(xStart + frameWidth, _TextureWidth); int yStart = yFrame * frameHeight; - int yEnd = yStart + frameHeight; + int yEnd = Math.Min(yStart + frameHeight, _TextureHeight); bool frameHasData = false; for (int x = xStart; x < xEnd; x++) @@ -119,41 +126,58 @@ namespace CalamityMod } } - _HasGlowContent[xFrame, yFrame] = frameHasData; + _HasMaskContent[xFrame + (yFrame * _FrameXCount)] = frameHasData; }); }); } } + public void Unload() + { + Texture = null; + _FrameWidth = 0; + _FrameHeight = 0; + _FrameXCount = 0; + _FrameYCount = 0; + } + public bool HasContentInFrameIndex(int xFrame, int yFrame) { if (Texture is null) return false; - if (xFrame < 0 || xFrame >= FrameXCount) + if (xFrame < 0 || xFrame >= _FrameXCount) return false; - if (yFrame < 0 || yFrame >= FrameYCount) + if (yFrame < 0 || yFrame >= _FrameYCount) return false; - return _HasGlowContent[xFrame, yFrame]; + return _HasMaskContent[xFrame + (yFrame * _FrameXCount)]; } public bool HasContentInFramePos(int xPos, int yPos) { - if (Texture is null) + int xFrame = xPos / _FrameWidth; + int yFrame = yPos / _FrameHeight; + + if (xFrame < 0 || xFrame >= _FrameXCount) return false; - int xFrame = xPos / FrameWidth; - int yFrame = yPos / FrameHeight; - - if (xFrame < 0 || xFrame >= FrameXCount) + if (yFrame < 0 || yFrame >= _FrameYCount) return false; - if (yFrame < 0 || yFrame >= FrameYCount) - return false; + return _HasMaskContent[xFrame + (yFrame * _FrameXCount)]; + } - return _HasGlowContent[xFrame, yFrame]; + private sealed class FramedGlowMaskSystem : ModSystem + { + public static event Action OnUnload; + + public override void Unload() + { + OnUnload?.Invoke(); + OnUnload = null; // Clear cache completly + } } } } diff --git a/Utilities/TextureUtils/GrayscaleTexture1D.cs b/Utilities/TextureUtils/GrayscaleTexture1D.cs new file mode 100644 index 0000000000..96c92c435b --- /dev/null +++ b/Utilities/TextureUtils/GrayscaleTexture1D.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using Terraria.ModLoader; +using Terraria; +using Microsoft.Xna.Framework; + +namespace CalamityMod +{ + /// + /// Utility Class for using 1D Grayscale Texture as gradient + /// + public sealed class GrayscaleTexture1D + { + private int _Width = 0; + private float[] _Scales; + + public GrayscaleTexture1D(string assetName) + { + if (Main.dedServ) + return; + + var texture = ModContent.Request(assetName, AssetRequestMode.ImmediateLoad).Value; + if (texture is null) + return; + + Main.QueueMainThreadAction(() => + { + _Width = texture.Width; + _Scales = new float[texture.Width]; + + var colorScheme = new Color[_Width]; + texture.GetData(colorScheme); + for (int i = 0; i<_Width; i++) + { + _Scales[i] = colorScheme[i].R / 255.0f; + } + }); + } + + public void Unload() + { + _Width = 0; + _Scales = null; + } + + public float GetClamp(int x) + { + if (_Width == 0) + return default; + + x = Math.Clamp(x, 0, _Width - 1); + return _Scales[x]; + } + + public float GetRepeat(int x) + { + if (_Width == 0) + return default; + + x %= _Width; + return _Scales[x]; + } + } +} diff --git a/Utilities/TextureUtils/GrayscaleTexture2D.cs b/Utilities/TextureUtils/GrayscaleTexture2D.cs new file mode 100644 index 0000000000..d369a3b709 --- /dev/null +++ b/Utilities/TextureUtils/GrayscaleTexture2D.cs @@ -0,0 +1,76 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using Microsoft.Xna.Framework.Graphics; +using ReLogic.Content; +using Terraria; +using Terraria.ModLoader; + +namespace CalamityMod +{ + /// + /// Utility Class for using 2D Grayscale Texture as gradient + /// + public sealed class GrayscaleTexture2D + { + private int _Width = 0; + private int _Height = 0; + private float[] _Scales; // 2D array is not thread-safe + + public GrayscaleTexture2D(string assetName) + { + if (Main.dedServ) + return; + + var texture = ModContent.Request(assetName, AssetRequestMode.ImmediateLoad).Value; + if (texture is null) + return; + + Main.QueueMainThreadAction(() => + { + _Width = texture.Width; + _Height = texture.Height; + _Scales = new float[_Width * _Height]; + + var colorScheme = texture.GetColorsFromTexture(); + for (int i = 0; i < _Width; i++) + { + for (int j = 0; j < _Height; j++) + { + _Scales[(j * _Width) + i] = colorScheme[i, j].R / 255.0f; + } + } + }); + } + + public void Unload() + { + _Width = 0; + _Height = 0; + _Scales = null; + } + + public float GetClamp(int x, int y) + { + if (_Width == 0 || _Height == 0) + return default; + + x = Math.Clamp(x, 0, _Width - 1); + y = Math.Clamp(x, 0, _Height - 1); + return _Scales[x + (y * _Height)]; + } + + public float GetRepeat(int x, int y) + { + if (_Width == 0 || _Height == 0) + return default; + + x %= _Width; + y %= _Height; + return _Scales[x + (y * _Height)]; + } + } +} From 9ad5928dc5391a1fb9cea9032f9c013a622210f9 Mon Sep 17 00:00:00 2001 From: Flowaria Date: Sun, 1 Sep 2024 00:41:16 +0900 Subject: [PATCH 06/12] Added GlowMaskTile type: Pre-implementation of tile with GlowMasks --- Tiles/GlowMaskTile.cs | 81 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 Tiles/GlowMaskTile.cs diff --git a/Tiles/GlowMaskTile.cs b/Tiles/GlowMaskTile.cs new file mode 100644 index 0000000000..ba46d223a2 --- /dev/null +++ b/Tiles/GlowMaskTile.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Xna.Framework; +using Terraria; +using Terraria.DataStructures; +using Terraria.ID; +using Terraria.ModLoader; + +namespace CalamityMod.Tiles +{ + public abstract class GlowMaskTile : ModTile + { + public enum PaintColorTint + { + OnlyByDeepPaint, + ByEveryPaint, + None, + } + + public FramedMaskTexture GlowMask; + + internal static GlowMaskTile[] InstanceLookup; // This Lookup is Array for performances sake + internal static int LookupLength; + + public PaintColorTint GlowMaskPaintInteraction = PaintColorTint.OnlyByDeepPaint; + + public abstract string GlowMaskAsset { get; } + + public sealed override void SetStaticDefaults() + { + if (GlowMask != null) + { + CalamityMod.Instance.Logger.Error($"{Name} has called {nameof(SetStaticDefaults)} themselve! This is not allowed!"); + return; + } + + GlowMask = new(GlowMaskAsset, 18, 18); + + InstanceLookup ??= new GlowMaskTile[TileLoader.TileCount]; + LookupLength = InstanceLookup.Length; + + InstanceLookup[Type] = this; + + SetupStatic(); + } + + public sealed override void Unload() + { + GlowMask?.Unload(); + GlowMask = null; + + InstanceLookup = null; + + OnUnload(); + } + + public virtual void SetupStatic() { } + + public virtual void OnUnload() { } + + public abstract Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData); + + public static Color ApplyPaint(int paintType, Color color, bool deepPaintOnly = true) + { + if (deepPaintOnly && !IsDeepPaint(paintType)) + return color; + + Color paintCol = WorldGen.paintColor(paintType); + color = color.MultiplyRGB(paintCol); + return color; + } + + private static bool IsDeepPaint(int paintType) + { + return PaintID.DeepRedPaint <= paintType && paintType <= PaintID.DeepPinkPaint; + } + } +} From 2f4861eb7205f2c1e11c67f094801d8ee01ccc81 Mon Sep 17 00:00:00 2001 From: Flowaria Date: Sun, 1 Sep 2024 00:41:57 +0900 Subject: [PATCH 07/12] VoidstoneWall: change because of helper type name change --- Walls/VoidstoneWall.cs | 19 +++++++++++++++++-- Walls/VoidstoneWallUnsafe.cs | 19 +++++++++++++++++-- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/Walls/VoidstoneWall.cs b/Walls/VoidstoneWall.cs index 5e4ef10005..b42f806957 100644 --- a/Walls/VoidstoneWall.cs +++ b/Walls/VoidstoneWall.cs @@ -11,7 +11,7 @@ namespace CalamityMod.Walls { public class VoidstoneWall : ModWall { - internal static FramedGlowMask GlowMask; + internal static FramedMaskTexture GlowMask; public override void SetStaticDefaults() { @@ -21,6 +21,12 @@ namespace CalamityMod.Walls AddMapEntry(new Color(0, 0, 0)); } + public override void Unload() + { + GlowMask?.Unload(); + GlowMask = null; + } + public override bool CreateDust(int i, int j, ref int type) { Dust.NewDust(new Vector2(i, j) * 16f, 16, 16, DustID.DungeonSpirit, 0f, 0f, 1, new Color(255, 255, 255), 1f); @@ -49,7 +55,9 @@ namespace CalamityMod.Walls zero = Vector2.Zero; Vector2 pos = new Vector2(i * 16 - (int)Main.screenPosition.X, j * 16 - (int)Main.screenPosition.Y) + zero; - spriteBatch.Draw(TextureAssets.Wall[wallType].Value, pos + new Vector2(-8 + xOff, -8), frame, Lighting.GetColor(i, j, Color.White), 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); + Color lightColor = Lighting.GetColor(i, j, Color.White); + + spriteBatch.Draw(TextureAssets.Wall[wallType].Value, pos + new Vector2(-8 + xOff, -8), frame, lightColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); if (GlowMask.HasContentInFramePos(xPos, yPos)) { @@ -62,6 +70,13 @@ namespace CalamityMod.Walls drawcolor *= brightness; Color glowColor = drawcolor * 0.4f; + if (glowColor.R > glowColor.R) glowColor.R = lightColor.R; + if (glowColor.G > glowColor.G) glowColor.G = lightColor.G; + if (glowColor.B > glowColor.B) glowColor.B = lightColor.B; + + if (glowColor.R <= 0 && glowColor.G <= 0 && glowColor.B <= 0) + return; + for (int k = 0; k < 3; k++) { Vector2 offset = new Vector2(Main.rand.NextFloat(-1, 1f), Main.rand.NextFloat(-1, 1f)) * 0.2f * k; diff --git a/Walls/VoidstoneWallUnsafe.cs b/Walls/VoidstoneWallUnsafe.cs index 6a98beb712..018abea0d9 100644 --- a/Walls/VoidstoneWallUnsafe.cs +++ b/Walls/VoidstoneWallUnsafe.cs @@ -11,7 +11,7 @@ namespace CalamityMod.Walls { public class VoidstoneWallUnsafe : ModWall { - internal static FramedGlowMask GlowMask; + internal static FramedMaskTexture GlowMask; public override string Texture => "CalamityMod/Walls/VoidstoneWall"; public override void SetStaticDefaults() @@ -24,6 +24,12 @@ namespace CalamityMod.Walls AddMapEntry(new Color(0, 0, 0)); } + public override void Unload() + { + GlowMask?.Unload(); + GlowMask = null; + } + public override void RandomUpdate(int i, int j) { if (Main.tile[i, j].LiquidAmount == 0 && j < Main.maxTilesY - 205) @@ -58,7 +64,9 @@ namespace CalamityMod.Walls zero = Vector2.Zero; Vector2 pos = new Vector2((i * 16 - (int)Main.screenPosition.X), (j * 16 - (int)Main.screenPosition.Y)) + zero; - spriteBatch.Draw(TextureAssets.Wall[wallType].Value, pos + new Vector2(-8 + xOff, -8), frame, Lighting.GetColor(i, j, Color.White), 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); + Color lightColor = Lighting.GetColor(i, j, Color.White); + + spriteBatch.Draw(TextureAssets.Wall[wallType].Value, pos + new Vector2(-8 + xOff, -8), frame, lightColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); if (GlowMask.HasContentInFramePos(xPos, yPos)) { @@ -71,6 +79,13 @@ namespace CalamityMod.Walls drawcolor *= brightness; Color glowColor = drawcolor * 0.4f; + if (glowColor.R > glowColor.R) glowColor.R = lightColor.R; + if (glowColor.G > glowColor.G) glowColor.G = lightColor.G; + if (glowColor.B > glowColor.B) glowColor.B = lightColor.B; + + if (glowColor.R <= 0 && glowColor.G <= 0 && glowColor.B <= 0) + return; + // For now checking for glowing frames greatly reducing the bottleneck // But maybe we could squeeze bit more by removing the loop for (int k = 0; k < 3; k++) From a243c0ce892ae4b916fbf71accca3bf5c063a06c Mon Sep 17 00:00:00 2001 From: Flowaria Date: Sun, 1 Sep 2024 00:42:15 +0900 Subject: [PATCH 08/12] tile with glowmask now uses GlowMaskTile --- Systems/TileFramingSystem.cs | 169 ++++++++++--- Tiles/Abyss/AbyssAmbient/AbyssGiantKelp1.cs | 30 +-- Tiles/Abyss/AbyssAmbient/AbyssGiantKelp3.cs | 20 +- Tiles/Abyss/AbyssAmbient/AbyssGiantKelp4.cs | 20 +- Tiles/Abyss/AbyssAmbient/BulbTree.cs | 30 +-- Tiles/Abyss/AbyssAmbient/PirateCrate.cs | 30 +-- Tiles/Abyss/AbyssAmbient/SpiderCoral.cs | 34 +-- Tiles/Abyss/AbyssAmbient/SulphurPireCoral.cs | 30 +-- Tiles/Abyss/AbyssGravel.cs | 89 +------ Tiles/Abyss/PlantyMush.cs | 110 ++------ Tiles/Abyss/PyreMantleMolten.cs | 50 +--- Tiles/Abyss/RustyChestTile.cs | 4 + Tiles/Abyss/SulphurousShale.cs | 100 +------- Tiles/Abyss/Voidstone.cs | 237 ++---------------- Tiles/Astral/AstralGrass.cs | 89 +------ Tiles/AstralBrick.cs | 44 +--- .../Furniture/Fountains/AbyssFountainTile.cs | 3 +- .../Furniture/Fountains/AstralFountainTile.cs | 3 +- .../Fountains/SulphurousFountainTile.cs | 3 +- .../Fountains/SunkenSeaFountainTile.cs | 3 +- Tiles/FurnitureAshen/SmoothBrimstoneSlag.cs | 37 +-- .../FurnitureAuric/ActivatedAuricPanelTile.cs | 37 +-- Tiles/FurnitureAuric/AuricAbsorberTile.cs | 9 +- .../FurnitureAuric/AuricRepulserPanelTile.cs | 37 +-- Tiles/FurnitureAuric/ExoAuricPanelTile.cs | 37 +-- Tiles/FurnitureCosmilite/CosmiliteBrick.cs | 38 +-- Tiles/FurnitureExo/ExoPlatingTile.cs | 41 +-- Tiles/FurnitureExo/ExoPrismPanelTile.cs | 41 +-- Tiles/FurniturePlaguedPlate/PlaguedPlate.cs | 42 +--- Tiles/FurnitureProfaned/ProfanedRock.cs | 220 +--------------- Tiles/FurnitureProfaned/RunicProfanedBrick.cs | 48 +--- Tiles/FurnitureStratus/StratusBricks.cs | 43 +--- Tiles/FurnitureVoid/SmoothVoidstone.cs | 227 ++--------------- Tiles/FurnitureVoid/VoidstoneSlab.cs | 163 +----------- Tiles/GiantPlanteraBulb.cs | 28 +-- Tiles/Ores/AerialiteOre.cs | 191 +------------- Tiles/Ores/AerialiteOreDisenchanted.cs | 89 +------ Tiles/Ores/AuricOre.cs | 37 +-- Tiles/Ores/PerennialOre.cs | 222 +--------------- Tiles/Ores/ScoriaOre.cs | 36 +-- Tiles/Plates/Cinderplate.cs | 66 ++--- Tiles/Plates/Elumplate.cs | 66 ++--- Tiles/Plates/Havocplate.cs | 68 ++--- Tiles/Plates/Navyplate.cs | 66 ++--- Tiles/Plates/Onyxplate.cs | 58 ++--- Tiles/Plates/PlagueContainmentCells.cs | 64 ++--- Tiles/Rubblemaker/SunkenSea/FanCoralEcho.cs | 3 +- Tiles/ScoriaBrick.cs | 48 +--- Tiles/SunkenSea/Ambient/FanCoral.cs | 4 +- Tiles/SunkenSea/EutrophicGlass.cs | 8 +- Tiles/SunkenSea/EutrophicSand.cs | 116 +++++---- Tiles/SunkenSea/SeaPrism.cs | 5 +- 52 files changed, 595 insertions(+), 2698 deletions(-) diff --git a/Systems/TileFramingSystem.cs b/Systems/TileFramingSystem.cs index a5ac62a0b8..06a3ad39bf 100644 --- a/Systems/TileFramingSystem.cs +++ b/Systems/TileFramingSystem.cs @@ -214,6 +214,112 @@ namespace CalamityMod.Systems } #endregion + #region Tile Variation Helpers + public static int GetVariation4x4_012_Low0(int i, int j) + { + int xRel = i & 0b0011; + int yRel = j & 0b0011; + var output = xRel switch + { + 0 => (yRel switch + { + 0 => 0, + 1 => 2, + 2 => 1, + _ => 2 + }), + 1 => (yRel switch + { + 0 => 2, + 1 => 0, + 2 => 2, + _ => 2 + }), + 2 => (yRel switch + { + 0 => 2, + 1 => 0, + 2 => 1, + _ => 2 + }), + _ => (yRel switch + { + 0 => 1, + 1 => 2, + 2 => 0, + _ => 2 + }), + }; + return output; + } + + public static int GetVariation4x4_01_Low0(int i, int j) + { + int xRel = i & 0b0011; + int yRel = j & 0b0011; + var output = xRel switch + { + 0 => (yRel switch + { + 0 => 0, + 1 => 0, + 2 => 1, + _ => 1 + }), + 1 => (yRel switch + { + 0 => 1, + 1 => 0, + 2 => 1, + _ => 1 + }), + 2 => (yRel switch + { + 0 => 1, + 1 => 0, + 2 => 0, + _ => 1 + }), + _ => (yRel switch + { + 0 => 0, + 1 => 1, + 2 => 0, + _ => 1 + }), + }; + return output; + } + + public static int GetVariation3x3_01234_Low3(int i, int j) + { + int xRel = i % 3; + int yRel = j % 3; + var output = xRel switch + { + 0 => (yRel switch + { + 0 => 0, + 1 => 1, + _ => 2 + }), + 1 => (yRel switch + { + 0 => 2, + 1 => 3, + _ => 4 + }), + _ => (yRel switch + { + 0 => 4, + 1 => 0, + _ => 1 + }), + }; + return output; + } + #endregion + #region Framing Helpers private static bool GetMerge(Tile myTile, Tile mergeTile) { @@ -1301,57 +1407,48 @@ namespace CalamityMod.Systems #endregion } - internal static void SlopedGlowmask(int i, int j, int type, Texture2D texture, Vector2 position, Rectangle? sourceRectangle, Color drawColor, Vector2 positionOffset, bool overrideTileFrame = false) + internal static void SlopedGlowmask(ref readonly Tile tile, int i, int j, Texture2D texture, Rectangle? sourceRectangle, Color drawColor, Vector2 positionOffset) { - var tile = Main.tile[i, j]; + int frameX = tile.TileFrameX; + int frameY = tile.TileFrameY; - int TileFrameX = tile.TileFrameX; - int TileFrameY = tile.TileFrameY; - - if (overrideTileFrame) - { - TileFrameX = 0; - TileFrameY = 0; - } - - var width = 16; - var height = 16; + int width = 16; + int height = 16; if (sourceRectangle != null) { - TileFrameX = ((Rectangle)sourceRectangle).X; - TileFrameY = ((Rectangle)sourceRectangle).Y; + frameX = ((Rectangle)sourceRectangle).X; + frameY = ((Rectangle)sourceRectangle).Y; } - var iX16 = i * 16; - var jX16 = j * 16; - var location = new Vector2(iX16, jX16); - var zero = new Vector2(Main.offScreenRange, Main.offScreenRange); - if (Main.drawToScreen) - zero = Vector2.Zero; + int iX16 = i * 16; + int jX16 = j * 16; - var offsets = -Main.screenPosition + zero + positionOffset; - var drawCoordinates = location + offsets; - if (tile.Slope == 0 && !tile.IsHalfBlock || Main.tileSolid[tile.TileType] && Main.tileSolidTop[tile.TileType]) //second one should be for platforms + Vector2 location = new Vector2(iX16, jX16); + Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange, Main.offScreenRange); + Vector2 offsets = -Main.screenPosition + zero + positionOffset; + Vector2 drawCoordinates = location + offsets; + + if ((tile.Slope == 0 && !tile.IsHalfBlock) || (Main.tileSolid[tile.TileType] && Main.tileSolidTop[tile.TileType])) //second one should be for platforms { - Main.spriteBatch.Draw(texture, drawCoordinates, new Rectangle(TileFrameX, TileFrameY, width, height), drawColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); + Main.spriteBatch.Draw(texture, drawCoordinates, new Rectangle(frameX, frameY, width, height), drawColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); } else if (tile.IsHalfBlock) { - Main.spriteBatch.Draw(texture, new Vector2(drawCoordinates.X, drawCoordinates.Y + 8), new Rectangle(TileFrameX, TileFrameY, width, 8), drawColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); + Main.spriteBatch.Draw(texture, new Vector2(drawCoordinates.X, drawCoordinates.Y + 8), new Rectangle(frameX, frameY, width, 8), drawColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0f); } else { - var b = (byte)tile.Slope; + byte b = (byte)tile.Slope; Rectangle TileFrame; Vector2 drawPos; if (b == 1 || b == 2) { int length; int height2; - for (var a = 0; a < 8; ++a) + for (int a = 0; a < 8; ++a) { - var aX2 = a * 2; + int aX2 = a * 2; if (b == 2) { length = 16 - aX2 - 2; @@ -1363,12 +1460,12 @@ namespace CalamityMod.Systems height2 = 14 - length; } - TileFrame = new Rectangle(TileFrameX + length, TileFrameY, 2, height2); + TileFrame = new Rectangle(frameX + length, frameY, 2, height2); drawPos = new Vector2(iX16 + length, jX16 + aX2) + offsets; Main.spriteBatch.Draw(texture, drawPos, TileFrame, drawColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); } - TileFrame = new Rectangle(TileFrameX, TileFrameY + 14, 16, 2); + TileFrame = new Rectangle(frameX, frameY + 14, 16, 2); drawPos = new Vector2(iX16, jX16 + 14) + offsets; Main.spriteBatch.Draw(texture, drawPos, TileFrame, drawColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); } @@ -1376,9 +1473,9 @@ namespace CalamityMod.Systems { int length; int height2; - for (var a = 0; a < 8; ++a) + for (int a = 0; a < 8; ++a) { - var aX2 = a * 2; + int aX2 = a * 2; if (b == 3) { length = aX2; @@ -1390,15 +1487,15 @@ namespace CalamityMod.Systems height2 = 16 - aX2; } - TileFrame = new Rectangle(TileFrameX + length, TileFrameY + 16 - height2, 2, height2); + TileFrame = new Rectangle(frameX + length, frameY + 16 - height2, 2, height2); drawPos = new Vector2(iX16 + length, jX16) + offsets; Main.spriteBatch.Draw(texture, drawPos, TileFrame, drawColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); } drawPos = new Vector2(iX16, jX16) + offsets; - if (tile.TileType != ModContent.TileType()) + if (tile.TileType != EutrophicGlass.TypeCache) { - TileFrame = new Rectangle(TileFrameX, TileFrameY, 16, 2); + TileFrame = new Rectangle(frameX, frameY, 16, 2); Main.spriteBatch.Draw(texture, drawPos, TileFrame, drawColor, 0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); } } diff --git a/Tiles/Abyss/AbyssAmbient/AbyssGiantKelp1.cs b/Tiles/Abyss/AbyssAmbient/AbyssGiantKelp1.cs index dce2106312..9a9483acf8 100644 --- a/Tiles/Abyss/AbyssAmbient/AbyssGiantKelp1.cs +++ b/Tiles/Abyss/AbyssAmbient/AbyssGiantKelp1.cs @@ -10,18 +10,11 @@ using Terraria.ObjectData; namespace CalamityMod.Tiles.Abyss.AbyssAmbient { - public class AbyssGiantKelp1 : ModTile + public class AbyssGiantKelp1 : GlowMaskTile { - protected virtual string GlowAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/AbyssGiantKelp1Glow"; - internal static FramedGlowMask GlowMask; - - public override void SetStaticDefaults() + public override string GlowMaskAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/AbyssGiantKelp1Glow"; + public override void SetupStatic() { - if (!string.IsNullOrEmpty(GlowAsset)) - { - GlowMask = new(GlowAsset, 18, 18); - } - Main.tileLighted[Type] = true; Main.tileFrameImportant[Type] = true; TileObjectData.newTile.Width = 2; @@ -39,9 +32,8 @@ namespace CalamityMod.Tiles.Abyss.AbyssAmbient AddMapEntry(new Color(92, 93, 42)); DustType = DustID.Grass; HitSound = SoundID.Grass; - - base.SetStaticDefaults(); } + public override void NearbyEffects(int i, int j, bool closer) { if (closer && Main.rand.NextBool(100) && j > Main.worldSurface) @@ -70,23 +62,15 @@ namespace CalamityMod.Tiles.Abyss.AbyssAmbient num = fail ? 1 : 2; } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - Tile tile = Framing.GetTileSafely(i, j); - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange, Main.offScreenRange); - - if (GlowMask is not null && GlowMask.HasContentInFramePos(tile.TileFrameX, tile.TileFrameY)) - { - Vector2 pos = new Vector2(i * 16, j * 16 + 2) - Main.screenPosition + zero; - Rectangle frame = new Rectangle(tile.TileFrameX, tile.TileFrameY, 16, 16); - spriteBatch.Draw(GlowMask.Texture, pos, frame, Color.White); - } + return Color.White; } } //just clone the first one its literally the same size public class AbyssGiantKelp2 : AbyssGiantKelp1 { - protected override string GlowAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/AbyssGiantKelp2Glow"; + public override string GlowMaskAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/AbyssGiantKelp2Glow"; } } diff --git a/Tiles/Abyss/AbyssAmbient/AbyssGiantKelp3.cs b/Tiles/Abyss/AbyssAmbient/AbyssGiantKelp3.cs index 77ed6250f1..78b8f09f8c 100644 --- a/Tiles/Abyss/AbyssAmbient/AbyssGiantKelp3.cs +++ b/Tiles/Abyss/AbyssAmbient/AbyssGiantKelp3.cs @@ -10,14 +10,12 @@ using Terraria.ObjectData; namespace CalamityMod.Tiles.Abyss.AbyssAmbient { - public class AbyssGiantKelp3 : ModTile + public class AbyssGiantKelp3 : GlowMaskTile { - internal static FramedGlowMask GlowMask; + public override string GlowMaskAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/AbyssGiantKelp3Glow"; - public override void SetStaticDefaults() + public override void SetupStatic() { - GlowMask = new("CalamityMod/Tiles/Abyss/AbyssAmbient/AbyssGiantKelp3Glow", 18, 18); - Main.tileLighted[Type] = true; Main.tileFrameImportant[Type] = true; TileObjectData.newTile.Width = 2; @@ -35,8 +33,6 @@ namespace CalamityMod.Tiles.Abyss.AbyssAmbient AddMapEntry(new Color(92, 93, 42)); DustType = DustID.Grass; HitSound = SoundID.Grass; - - base.SetStaticDefaults(); } public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b) @@ -66,15 +62,9 @@ namespace CalamityMod.Tiles.Abyss.AbyssAmbient num = fail ? 1 : 2; } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - Tile tile = Framing.GetTileSafely(i, j); - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange, Main.offScreenRange); - - if (GlowMask.HasContentInFramePos(tile.TileFrameX, tile.TileFrameY)) - { - spriteBatch.Draw(GlowMask.Texture, new Vector2(i * 16, j * 16 + 2) - Main.screenPosition + zero, new Rectangle(tile.TileFrameX, tile.TileFrameY, 16, 16), Color.White); - } + return Color.White; } } } diff --git a/Tiles/Abyss/AbyssAmbient/AbyssGiantKelp4.cs b/Tiles/Abyss/AbyssAmbient/AbyssGiantKelp4.cs index d239d0098b..4068da5232 100644 --- a/Tiles/Abyss/AbyssAmbient/AbyssGiantKelp4.cs +++ b/Tiles/Abyss/AbyssAmbient/AbyssGiantKelp4.cs @@ -10,14 +10,12 @@ using Terraria.ObjectData; namespace CalamityMod.Tiles.Abyss.AbyssAmbient { - public class AbyssGiantKelp4 : ModTile + public class AbyssGiantKelp4 : GlowMaskTile { - internal static FramedGlowMask GlowMask; + public override string GlowMaskAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/AbyssGiantKelp4Glow"; - public override void SetStaticDefaults() + public override void SetupStatic() { - GlowMask = new("CalamityMod/Tiles/Abyss/AbyssAmbient/AbyssGiantKelp4Glow", 18, 18); - Main.tileLighted[Type] = true; Main.tileFrameImportant[Type] = true; TileObjectData.newTile.Width = 2; @@ -35,8 +33,6 @@ namespace CalamityMod.Tiles.Abyss.AbyssAmbient AddMapEntry(new Color(92, 93, 42)); DustType = DustID.Grass; HitSound = SoundID.Grass; - - base.SetStaticDefaults(); } public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b) @@ -66,15 +62,9 @@ namespace CalamityMod.Tiles.Abyss.AbyssAmbient num = fail ? 1 : 2; } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - Tile tile = Framing.GetTileSafely(i, j); - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange, Main.offScreenRange); - - if (GlowMask.HasContentInFramePos(tile.TileFrameX, tile.TileFrameY)) - { - spriteBatch.Draw(GlowMask.Texture, new Vector2(i * 16, j * 16 + 2) - Main.screenPosition + zero, new Rectangle(tile.TileFrameX, tile.TileFrameY, 16, 16), Color.White); - } + return Color.White; } } } diff --git a/Tiles/Abyss/AbyssAmbient/BulbTree.cs b/Tiles/Abyss/AbyssAmbient/BulbTree.cs index 146de972b3..c4900cc1c9 100644 --- a/Tiles/Abyss/AbyssAmbient/BulbTree.cs +++ b/Tiles/Abyss/AbyssAmbient/BulbTree.cs @@ -9,18 +9,12 @@ using Terraria.ObjectData; namespace CalamityMod.Tiles.Abyss.AbyssAmbient { - public class BulbTree1 : ModTile + public class BulbTree1 : GlowMaskTile { - protected virtual string GlowAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/BulbTree1Glow"; - internal static FramedGlowMask GlowMask; + public override string GlowMaskAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/BulbTree1Glow"; - public override void SetStaticDefaults() + public override void SetupStatic() { - if (!string.IsNullOrEmpty(GlowAsset)) - { - GlowMask = new(GlowAsset, 18, 18); - } - Main.tileLighted[Type] = true; Main.tileFrameImportant[Type] = true; TileObjectData.newTile.Width = 3; @@ -37,8 +31,6 @@ namespace CalamityMod.Tiles.Abyss.AbyssAmbient TileObjectData.addTile(Type); AddMapEntry(new Color(52, 124, 153)); DustType = 33; - - base.SetStaticDefaults(); } public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b) @@ -53,27 +45,19 @@ namespace CalamityMod.Tiles.Abyss.AbyssAmbient num = fail ? 1 : 2; } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - Tile tile = Framing.GetTileSafely(i, j); - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange, Main.offScreenRange); - - if (GlowMask is not null && GlowMask.HasContentInFramePos(tile.TileFrameX, tile.TileFrameY)) - { - Vector2 pos = new Vector2(i * 16, j * 16 + 2) - Main.screenPosition + zero; - Rectangle frame = new Rectangle(tile.TileFrameX, tile.TileFrameY, 16, 16); - spriteBatch.Draw(GlowMask.Texture, pos, frame, Color.White); - } + return Color.White; } } public class BulbTree2 : BulbTree1 { - protected override string GlowAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/BulbTree3Glow"; + public override string GlowMaskAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/BulbTree2Glow"; } public class BulbTree3 : BulbTree1 { - protected override string GlowAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/BulbTree3Glow"; + public override string GlowMaskAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/BulbTree3Glow"; } } diff --git a/Tiles/Abyss/AbyssAmbient/PirateCrate.cs b/Tiles/Abyss/AbyssAmbient/PirateCrate.cs index af87b809f4..d23102c5d6 100644 --- a/Tiles/Abyss/AbyssAmbient/PirateCrate.cs +++ b/Tiles/Abyss/AbyssAmbient/PirateCrate.cs @@ -12,19 +12,13 @@ namespace CalamityMod.Tiles.Abyss.AbyssAmbient // // Pirate Crate With Glow - public class PirateCrate1 : ModTile + public class PirateCrate1 : GlowMaskTile { - protected virtual string GlowAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/PirateCrate1Glow"; - internal static FramedGlowMask GlowMask; + public override string GlowMaskAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/PirateCrate1Glow"; public static readonly SoundStyle MineSound = new("CalamityMod/Sounds/Custom/CrateBreak", 3) { Volume = 0.8f }; - public override void SetStaticDefaults() + public override void SetupStatic() { - if (!string.IsNullOrEmpty(GlowAsset)) - { - GlowMask = new(GlowAsset, 18, 18); - } - Main.tileFrameImportant[Type] = true; Main.tileLavaDeath[Type] = true; Main.tileWaterDeath[Type] = false; @@ -35,8 +29,6 @@ namespace CalamityMod.Tiles.Abyss.AbyssAmbient AddMapEntry(new Color(97, 69, 52), CalamityUtils.GetText("Tiles.PirateCrate")); DustType = DustID.WoodFurniture; HitSound = MineSound; - - base.SetStaticDefaults(); } public override void KillMultiTile(int i, int j, int frameX, int frameY) @@ -54,28 +46,20 @@ namespace CalamityMod.Tiles.Abyss.AbyssAmbient num = fail ? 1 : 2; } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - Tile tile = Framing.GetTileSafely(i, j); - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange, Main.offScreenRange); - - if (GlowMask is not null && GlowMask.HasContentInFramePos(tile.TileFrameX, tile.TileFrameY)) - { - Vector2 pos = new Vector2(i * 16, j * 16 + 2) - Main.screenPosition + zero; - Rectangle frame = new Rectangle(tile.TileFrameX, tile.TileFrameY, 16, 16); - spriteBatch.Draw(GlowMask.Texture, pos, frame, Color.White); - } + return Color.White; } } public class PirateCrate2 : PirateCrate1 { - protected override string GlowAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/PirateCrate2Glow"; + public override string GlowMaskAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/PirateCrate2Glow"; } public class PirateCrate3 : PirateCrate1 { - protected override string GlowAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/PirateCrate3Glow"; + public override string GlowMaskAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/PirateCrate3Glow"; } // diff --git a/Tiles/Abyss/AbyssAmbient/SpiderCoral.cs b/Tiles/Abyss/AbyssAmbient/SpiderCoral.cs index c9fbaa387a..75c72a5ecc 100644 --- a/Tiles/Abyss/AbyssAmbient/SpiderCoral.cs +++ b/Tiles/Abyss/AbyssAmbient/SpiderCoral.cs @@ -11,18 +11,12 @@ using Terraria.ObjectData; namespace CalamityMod.Tiles.Abyss.AbyssAmbient { - public class SpiderCoral1 : ModTile + public class SpiderCoral1 : GlowMaskTile { - protected virtual string GlowAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/SpiderCoral1Glow"; - internal static FramedGlowMask GlowMask; + public override string GlowMaskAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/SpiderCoral1Glow"; - public override void SetStaticDefaults() + public override void SetupStatic() { - if (!string.IsNullOrEmpty(GlowAsset)) - { - GlowMask = new(GlowAsset, 18, 18); - } - Main.tileLighted[Type] = true; Main.tileFrameImportant[Type] = true; Main.tileNoAttach[Type] = true; @@ -30,8 +24,6 @@ namespace CalamityMod.Tiles.Abyss.AbyssAmbient TileObjectData.addTile(Type); AddMapEntry(new Color(82, 49, 27)); DustType = 32; - - base.SetStaticDefaults(); } public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b) @@ -41,37 +33,29 @@ namespace CalamityMod.Tiles.Abyss.AbyssAmbient b = 0.08f; } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - Tile tile = Framing.GetTileSafely(i, j); - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange, Main.offScreenRange); - - if (GlowMask is not null && GlowMask.HasContentInFramePos(tile.TileFrameX, tile.TileFrameY)) - { - Vector2 pos = new Vector2(i * 16, j * 16 + 2) - Main.screenPosition + zero; - Rectangle frame = new Rectangle(tile.TileFrameX, tile.TileFrameY, 16, 16); - spriteBatch.Draw(GlowMask.Texture, pos, frame, Color.White); - } + return Color.White; } } public class SpiderCoral2 : SpiderCoral1 { - protected override string GlowAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/SpiderCoral2Glow"; + public override string GlowMaskAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/SpiderCoral2Glow"; } public class SpiderCoral3 : SpiderCoral1 { - protected override string GlowAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/SpiderCoral3Glow"; + public override string GlowMaskAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/SpiderCoral3Glow"; } public class SpiderCoral4 : SpiderCoral1 { - protected override string GlowAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/SpiderCoral4Glow"; + public override string GlowMaskAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/SpiderCoral4Glow"; } public class SpiderCoral5 : SpiderCoral1 { - protected override string GlowAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/SpiderCoral5Glow"; + public override string GlowMaskAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/SpiderCoral5Glow"; } } diff --git a/Tiles/Abyss/AbyssAmbient/SulphurPireCoral.cs b/Tiles/Abyss/AbyssAmbient/SulphurPireCoral.cs index 0e4c74303f..76857a6d62 100644 --- a/Tiles/Abyss/AbyssAmbient/SulphurPireCoral.cs +++ b/Tiles/Abyss/AbyssAmbient/SulphurPireCoral.cs @@ -9,18 +9,12 @@ using Terraria.ObjectData; namespace CalamityMod.Tiles.Abyss.AbyssAmbient { - public class SulphurPireCoral1 : ModTile + public class SulphurPireCoral1 : GlowMaskTile { - protected virtual string GlowAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/SulphurPireCoral2Glow"; - internal static FramedGlowMask GlowMask; + public override string GlowMaskAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/SulphurPireCoral1Glow"; - public override void SetStaticDefaults() + public override void SetupStatic() { - if (!string.IsNullOrEmpty(GlowAsset)) - { - GlowMask = new(GlowAsset, 18, 18); - } - Main.tileLighted[Type] = true; Main.tileFrameImportant[Type] = true; TileObjectData.newTile.Width = 3; @@ -37,8 +31,6 @@ namespace CalamityMod.Tiles.Abyss.AbyssAmbient TileObjectData.addTile(Type); AddMapEntry(new Color(91, 128, 13)); DustType = 32; - - base.SetStaticDefaults(); } public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b) @@ -53,27 +45,19 @@ namespace CalamityMod.Tiles.Abyss.AbyssAmbient num = fail ? 1 : 2; } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - Tile tile = Framing.GetTileSafely(i, j); - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange, Main.offScreenRange); - - if (GlowMask is not null && GlowMask.HasContentInFramePos(tile.TileFrameX, tile.TileFrameY)) - { - Vector2 pos = new Vector2(i * 16, j * 16 + 2) - Main.screenPosition + zero; - Rectangle frame = new Rectangle(tile.TileFrameX, tile.TileFrameY, 16, 16); - spriteBatch.Draw(GlowMask.Texture, pos, frame, Color.White); - } + return Color.White; } } public class SulphurPireCoral2 : SulphurPireCoral1 { - protected override string GlowAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/SulphurPireCoral2Glow"; + public override string GlowMaskAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/SulphurPireCoral2Glow"; } public class SulphurPireCoral3 : SulphurPireCoral1 { - protected override string GlowAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/SulphurPireCoral3Glow"; + public override string GlowMaskAsset => "CalamityMod/Tiles/Abyss/AbyssAmbient/SulphurPireCoral3Glow"; } } diff --git a/Tiles/Abyss/AbyssGravel.cs b/Tiles/Abyss/AbyssGravel.cs index 04d2dd8bb0..11b173fd95 100644 --- a/Tiles/Abyss/AbyssGravel.cs +++ b/Tiles/Abyss/AbyssGravel.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using CalamityMod.Systems; using CalamityMod.Tiles.Abyss.AbyssAmbient; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; @@ -67,93 +68,7 @@ namespace CalamityMod.Tiles.Abyss public override void AnimateIndividualTile(int type, int i, int j, ref int frameXOffset, ref int frameYOffset) { - int uniqueAnimationFrameX = 0; - int xPos = i % 4; - int yPos = j % 4; - switch (xPos) - { - case 0: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 0; - break; - case 1: - uniqueAnimationFrameX = 2; - break; - case 2: - uniqueAnimationFrameX = 1; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - case 1: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 2; - break; - case 1: - uniqueAnimationFrameX = 0; - break; - case 2: - uniqueAnimationFrameX = 2; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - case 2: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 2; - break; - case 1: - uniqueAnimationFrameX = 0; - break; - case 2: - uniqueAnimationFrameX = 1; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - case 3: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 1; - break; - case 1: - uniqueAnimationFrameX = 2; - break; - case 2: - uniqueAnimationFrameX = 0; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - } - frameXOffset = uniqueAnimationFrameX * animationFrameWidth; + frameXOffset = animationFrameWidth * TileFramingSystem.GetVariation4x4_012_Low0(i, j); } } } diff --git a/Tiles/Abyss/PlantyMush.cs b/Tiles/Abyss/PlantyMush.cs index 52fa770985..378a4400bd 100644 --- a/Tiles/Abyss/PlantyMush.cs +++ b/Tiles/Abyss/PlantyMush.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using CalamityMod.Systems; using CalamityMod.Tiles.Abyss.AbyssAmbient; using CalamityMod.Walls; using Microsoft.Xna.Framework; @@ -51,93 +52,7 @@ namespace CalamityMod.Tiles.Abyss public override void AnimateIndividualTile(int type, int i, int j, ref int frameXOffset, ref int frameYOffset) { - int uniqueAnimationFrameX = 0; - int xPos = i % 4; - int yPos = j % 4; - switch (xPos) - { - case 0: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 0; - break; - case 1: - uniqueAnimationFrameX = 0; - break; - case 2: - uniqueAnimationFrameX = 1; - break; - case 3: - uniqueAnimationFrameX = 1; - break; - default: - uniqueAnimationFrameX = 0; - break; - } - break; - case 1: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 1; - break; - case 1: - uniqueAnimationFrameX = 0; - break; - case 2: - uniqueAnimationFrameX = 1; - break; - case 3: - uniqueAnimationFrameX = 1; - break; - default: - uniqueAnimationFrameX = 0; - break; - } - break; - case 2: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 1; - break; - case 1: - uniqueAnimationFrameX = 0; - break; - case 2: - uniqueAnimationFrameX = 0; - break; - case 3: - uniqueAnimationFrameX = 1; - break; - default: - uniqueAnimationFrameX = 0; - break; - } - break; - case 3: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 0; - break; - case 1: - uniqueAnimationFrameX = 1; - break; - case 2: - uniqueAnimationFrameX = 0; - break; - case 3: - uniqueAnimationFrameX = 1; - break; - default: - uniqueAnimationFrameX = 0; - break; - } - break; - } - frameXOffset = uniqueAnimationFrameX * animationFrameWidth; + frameXOffset = animationFrameWidth * TileFramingSystem.GetVariation4x4_01_Low0(i, j); } public override void RandomUpdate(int i, int j) @@ -161,24 +76,26 @@ namespace CalamityMod.Tiles.Abyss NetMessage.SendTileSquare(-1, i, j - 1, 3, TileChangeType.None); } + Tile down = Main.tile[i, j + 1]; int vineLength = WorldGen.genRand.Next((int)Main.rockLayer, (int)(Main.rockLayer + (double)Main.maxTilesY * 0.143)); - if (Main.tile[i, j + 1] != null) + if (down != null) { - if (!Main.tile[i, j + 1].HasTile && Main.tile[i, j + 1].TileType != (ushort)ModContent.TileType()) + if (!down.HasTile && down.TileType != (ushort)ModContent.TileType()) { - if (Main.tile[i, j + 1].LiquidAmount == 255 && - Main.tile[i, j + 1].WallType == (ushort)ModContent.WallType() && - Main.tile[i, j + 1].LiquidType != LiquidID.Lava) + if (down.LiquidAmount == 255 && + down.WallType == (ushort)ModContent.WallType() && + down.LiquidType != LiquidID.Lava) { bool canGrowVine = false; for (int k = vineLength; k > vineLength - 10; k--) { - if (Main.tile[i, k].BottomSlope) + var vineTile = Main.tile[i, k]; + if (vineTile.BottomSlope) { canGrowVine = false; break; } - if (Main.tile[i, k].HasTile && !Main.tile[i, k].BottomSlope) + if (vineTile.HasTile && !vineTile.BottomSlope) { canGrowVine = true; break; @@ -188,8 +105,9 @@ namespace CalamityMod.Tiles.Abyss { int vineX = i; int vineY = j + 1; - Main.tile[vineX, vineY].TileType = (ushort)ModContent.TileType(); - Main.tile[vineX, vineY].Get().HasTile = true; + var newVineTile = Main.tile[vineX, vineY]; + newVineTile.TileType = (ushort)ModContent.TileType(); + newVineTile.Get().HasTile = true; WorldGen.SquareTileFrame(vineX, vineY, true); if (Main.netMode == NetmodeID.Server) NetMessage.SendTileSquare(-1, vineX, vineY, 3, TileChangeType.None); diff --git a/Tiles/Abyss/PyreMantleMolten.cs b/Tiles/Abyss/PyreMantleMolten.cs index 48a803f6df..ea4522232d 100644 --- a/Tiles/Abyss/PyreMantleMolten.cs +++ b/Tiles/Abyss/PyreMantleMolten.cs @@ -7,21 +7,20 @@ using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using Terraria; using Terraria.Audio; +using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Tiles.Abyss { - public class PyreMantleMolten : ModTile + public class PyreMantleMolten : GlowMaskTile { public static readonly SoundStyle MineSound = new("CalamityMod/Sounds/Custom/VoidstoneMine", 3) { Volume = 0.4f }; - internal static FramedGlowMask GlowMask; + public override string GlowMaskAsset => "CalamityMod/Tiles/Abyss/PyreMantleMolten_Glowmask"; - public override void SetStaticDefaults() + public override void SetupStatic() { - GlowMask = new("CalamityMod/Tiles/Abyss/PyreMantleMolten_Glowmask", 18, 18); - Main.tileLighted[Type] = true; Main.tileSolid[Type] = true; Main.tileBlockLight[Type] = true; @@ -75,34 +74,10 @@ namespace CalamityMod.Tiles.Abyss } } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) - { - if (GlowMask.Texture is null) - return; - - int xPos = Main.tile[i, j].TileFrameX; - int yPos = Main.tile[i, j].TileFrameY; - - if (GlowMask.HasContentInFramePos(xPos, yPos)) - { - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - Color drawColour = GetDrawColour(i, j, new Color(200, 200, 200, 200)); - Tile trackTile = Main.tile[i, j]; - float glowbrightness = 1f; - float glowspeed = Main.GameUpdateCount * 0.01f; - glowbrightness *= (float)MathF.Sin(i / 60f + glowspeed); - drawColour *= glowbrightness; - double num6 = Main.time * 0.08; - TileFramingSystem.SlopedGlowmask(i, j, 0, GlowMask.Texture, drawOffset, null, GetDrawColour(i, j, drawColour), default); - glowbrightness += 0.3f; - } - } - public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b) { float brightness = 0.7f; - float lightspeed = Main.GameUpdateCount * 0.01f; + float lightspeed = (float)(Main.timeForVisualEffects * 0.01); brightness *= (float)MathF.Sin(i / 60f + lightspeed); brightness += 0.3f; r = 1f; @@ -113,17 +88,12 @@ namespace CalamityMod.Tiles.Abyss b *= brightness; } - private Color GetDrawColour(int i, int j, Color colour) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - int colType = Main.tile[i, j].TileColor; - Color paintCol = WorldGen.paintColor(colType); - if (colType >= 13 && colType <= 24) - { - colour.R = (byte)(paintCol.R / 255f * colour.R); - colour.G = (byte)(paintCol.G / 255f * colour.G); - colour.B = (byte)(paintCol.B / 255f * colour.B); - } - return colour; + float glowbrightness = 1f; + float glowspeed = (float)(Main.timeForVisualEffects * 0.01); + glowbrightness *= MathF.Sin(i / 60f + glowspeed); + return Color.White * glowbrightness; } } } diff --git a/Tiles/Abyss/RustyChestTile.cs b/Tiles/Abyss/RustyChestTile.cs index 3e41284181..fa7a0a62b8 100644 --- a/Tiles/Abyss/RustyChestTile.cs +++ b/Tiles/Abyss/RustyChestTile.cs @@ -10,8 +10,12 @@ namespace CalamityMod.Tiles.Abyss { public class RustyChestTile : ModTile { + public static int Type; + public override void SetStaticDefaults() { + Type = (ushort)ModContent.TileType(); + this.SetUpChest(ModContent.ItemType()); AddMapEntry(new Color(113, 90, 71), CalamityUtils.GetItemName(), CalamityUtils.GetMapChestName); } diff --git a/Tiles/Abyss/SulphurousShale.cs b/Tiles/Abyss/SulphurousShale.cs index dbd4219573..7b5000cd0a 100644 --- a/Tiles/Abyss/SulphurousShale.cs +++ b/Tiles/Abyss/SulphurousShale.cs @@ -1,4 +1,6 @@ -using CalamityMod.Tiles.Abyss.AbyssAmbient; +using CalamityMod.Systems; +using CalamityMod.Tiles.Abyss.AbyssAmbient; +using CalamityMod.Waters; using CalamityMod.World; using Microsoft.Xna.Framework; using Terraria; @@ -13,7 +15,7 @@ namespace CalamityMod.Tiles.Abyss int animationFrameWidth = 234; public static readonly SoundStyle MineSound = new("CalamityMod/Sounds/Custom/AbyssGravelMine", 3); - + public override void SetStaticDefaults() { Main.tileSolid[Type] = true; @@ -35,9 +37,12 @@ namespace CalamityMod.Tiles.Abyss public override void NearbyEffects(int i, int j, bool closer) { + if (Main.dedServ) + return; + if (Main.LocalPlayer.InModBiome(ModContent.GetInstance())) { - Main.SceneMetrics.ActiveFountainColor = ModContent.Find("CalamityMod/SulphuricDepthsWater").Slot; + Main.SceneMetrics.ActiveFountainColor = SulphuricDepthsWater.Instance.Slot; } } @@ -53,7 +58,6 @@ namespace CalamityMod.Tiles.Abyss public override void RandomUpdate(int i, int j) { - int vineLength = WorldGen.genRand.Next((int)Main.rockLayer, (int)(Main.rockLayer + (double)Main.maxTilesY * 0.143)); int nearbyVineCount = 0; for (int x = i - 15; x <= i + 15; x++) @@ -130,93 +134,7 @@ namespace CalamityMod.Tiles.Abyss public override void AnimateIndividualTile(int type, int i, int j, ref int frameXOffset, ref int frameYOffset) { - int uniqueAnimationFrameX = 0; - int xPos = i % 4; - int yPos = j % 4; - switch (xPos) - { - case 0: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 0; - break; - case 1: - uniqueAnimationFrameX = 2; - break; - case 2: - uniqueAnimationFrameX = 1; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - case 1: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 2; - break; - case 1: - uniqueAnimationFrameX = 0; - break; - case 2: - uniqueAnimationFrameX = 2; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - case 2: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 2; - break; - case 1: - uniqueAnimationFrameX = 0; - break; - case 2: - uniqueAnimationFrameX = 1; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - case 3: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 1; - break; - case 1: - uniqueAnimationFrameX = 2; - break; - case 2: - uniqueAnimationFrameX = 0; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - } - frameXOffset = uniqueAnimationFrameX * animationFrameWidth; + frameXOffset = animationFrameWidth * TileFramingSystem.GetVariation4x4_012_Low0(i, j); } } } diff --git a/Tiles/Abyss/Voidstone.cs b/Tiles/Abyss/Voidstone.cs index c63eefe42f..70dfd6b0f2 100644 --- a/Tiles/Abyss/Voidstone.cs +++ b/Tiles/Abyss/Voidstone.cs @@ -7,23 +7,26 @@ using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using Terraria; using Terraria.Audio; +using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Tiles.Abyss { - public class Voidstone : ModTile + public class Voidstone : GlowMaskTile { public static readonly SoundStyle MineSound = new("CalamityMod/Sounds/Custom/VoidstoneMine", 3) { Volume = 0.4f }; - internal static FramedGlowMask GlowMask; - public override void SetStaticDefaults() + public override string GlowMaskAsset => "CalamityMod/Tiles/Abyss/Voidstone_Glowmask"; + public GrayscaleTexture2D NoiseTexture; + + public override void SetupStatic() { - GlowMask = new("CalamityMod/Tiles/Abyss/Voidstone_Glowmask", 18, 18); + NoiseTexture = new("CalamityMod/ExtraTextures/GreyscaleGradients/BlobbyNoise"); Main.tileSolid[Type] = true; Main.tileBlockLight[Type] = true; - Main.tileBrick[Type] = true; + Main.tileBrick[Type] = true; CalamityUtils.MergeWithGeneral(Type); CalamityUtils.MergeWithAbyss(Type); @@ -39,6 +42,12 @@ namespace CalamityMod.Tiles.Abyss this.RegisterUniversalMerge(ModContent.TileType(), "CalamityMod/Tiles/Merges/PyreMantleMerge"); } + public override void OnUnload() + { + NoiseTexture?.Unload(); + NoiseTexture = null; + } + int animationFrameWidth = 234; public override bool CreateDust(int i, int j, ref int type) @@ -76,221 +85,15 @@ namespace CalamityMod.Tiles.Abyss public override void AnimateIndividualTile(int type, int i, int j, ref int frameXOffset, ref int frameYOffset) { - int uniqueAnimationFrameX = 0; - int xPos = i % 4; - int yPos = j % 4; - switch (xPos) - { - case 0: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 0; - break; - case 1: - uniqueAnimationFrameX = 2; - break; - case 2: - uniqueAnimationFrameX = 1; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - case 1: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 2; - break; - case 1: - uniqueAnimationFrameX = 0; - break; - case 2: - uniqueAnimationFrameX = 2; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - case 2: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 2; - break; - case 1: - uniqueAnimationFrameX = 0; - break; - case 2: - uniqueAnimationFrameX = 1; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - case 3: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 1; - break; - case 1: - uniqueAnimationFrameX = 2; - break; - case 2: - uniqueAnimationFrameX = 0; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - } - frameXOffset = uniqueAnimationFrameX * animationFrameWidth; + frameXOffset = animationFrameWidth * TileFramingSystem.GetVariation4x4_012_Low0(i, j); } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - if (GlowMask.Texture is null) - return; - - int xPos = Main.tile[i, j].TileFrameX; - int yPos = Main.tile[i, j].TileFrameY; - int xOffset = 0; - int relativeXPos = i % 4; - int relativeYPos = j % 4; - switch (relativeXPos) - { - case 0: - switch (relativeYPos) - { - case 0: - xOffset = 0; - break; - case 1: - xOffset = 2; - break; - case 2: - xOffset = 1; - break; - case 3: - xOffset = 2; - break; - default: - xOffset = 2; - break; - } - break; - case 1: - switch (relativeYPos) - { - case 0: - xOffset = 2; - break; - case 1: - xOffset = 0; - break; - case 2: - xOffset = 2; - break; - case 3: - xOffset = 2; - break; - default: - xOffset = 2; - break; - } - break; - case 2: - switch (relativeYPos) - { - case 0: - xOffset = 2; - break; - case 1: - xOffset = 0; - break; - case 2: - xOffset = 1; - break; - case 3: - xOffset = 2; - break; - default: - xOffset = 2; - break; - } - break; - case 3: - switch (relativeYPos) - { - case 0: - xOffset = 1; - break; - case 1: - xOffset = 2; - break; - case 2: - xOffset = 0; - break; - case 3: - xOffset = 2; - break; - default: - xOffset = 2; - break; - } - break; - } - - xOffset *= 234; - xPos += xOffset; - - if (GlowMask.HasContentInFramePos(xPos, yPos)) - { - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - Color drawColour = GetDrawColour(i, j, new Color(255, 255, 255, 255)); - Tile trackTile = Main.tile[i, j]; - float brightness = 1f; - float declareThisHereToPreventRunningTheSameCalculationMultipleTimes = Main.GameUpdateCount * 0.007f; - brightness *= (float)MathF.Sin(i / 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); - brightness *= (float)MathF.Sin(j / 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); - brightness *= (float)MathF.Sin(i * 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); - brightness *= (float)MathF.Sin(j * 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); - brightness *= 0.5f; - drawColour *= brightness; - TileFramingSystem.SlopedGlowmask(i, j, 0, GlowMask.Texture, drawOffset, null, GetDrawColour(i, j, drawColour), default); - } - } - - private Color GetDrawColour(int i, int j, Color colour) - { - int colType = Main.tile[i, j].TileColor; - Color paintCol = WorldGen.paintColor(colType); - if (colType >= 13 && colType <= 24) - { - colour.R = (byte)(paintCol.R / 255f * colour.R); - colour.G = (byte)(paintCol.G / 255f * colour.G); - colour.B = (byte)(paintCol.B / 255f * colour.B); - } - return colour; + int time = (int)(Main.timeForVisualEffects * 0.11); + float brightness = 1.0f - NoiseTexture.GetRepeat((i * 100) + time, (j * 100) + time); + brightness -= 0.55f; + return new Color(brightness, brightness, brightness); } } } diff --git a/Tiles/Astral/AstralGrass.cs b/Tiles/Astral/AstralGrass.cs index f5256945c1..876726f13d 100644 --- a/Tiles/Astral/AstralGrass.cs +++ b/Tiles/Astral/AstralGrass.cs @@ -1,4 +1,5 @@ using CalamityMod.Dusts; +using CalamityMod.Systems; using Microsoft.Xna.Framework; using Terraria; using Terraria.GameContent.Metadata; @@ -81,93 +82,7 @@ namespace CalamityMod.Tiles.Astral } public override void AnimateIndividualTile(int type, int i, int j, ref int frameXOffset, ref int frameYOffset) { - int uniqueAnimationFrameX = 0; - int xPos = i % 4; - int yPos = j % 4; - switch (xPos) - { - case 0: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 0; - break; - case 1: - uniqueAnimationFrameX = 0; - break; - case 2: - uniqueAnimationFrameX = 1; - break; - case 3: - uniqueAnimationFrameX = 1; - break; - default: - uniqueAnimationFrameX = 0; - break; - } - break; - case 1: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 1; - break; - case 1: - uniqueAnimationFrameX = 0; - break; - case 2: - uniqueAnimationFrameX = 1; - break; - case 3: - uniqueAnimationFrameX = 1; - break; - default: - uniqueAnimationFrameX = 0; - break; - } - break; - case 2: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 1; - break; - case 1: - uniqueAnimationFrameX = 0; - break; - case 2: - uniqueAnimationFrameX = 0; - break; - case 3: - uniqueAnimationFrameX = 1; - break; - default: - uniqueAnimationFrameX = 0; - break; - } - break; - case 3: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 0; - break; - case 1: - uniqueAnimationFrameX = 1; - break; - case 2: - uniqueAnimationFrameX = 0; - break; - case 3: - uniqueAnimationFrameX = 1; - break; - default: - uniqueAnimationFrameX = 0; - break; - } - break; - } - frameXOffset = uniqueAnimationFrameX * animationFrameWidth; + frameXOffset = animationFrameWidth * TileFramingSystem.GetVariation4x4_01_Low0(i, j); } public override void KillTile(int i, int j, ref bool fail, ref bool effectOnly, ref bool noItem) diff --git a/Tiles/AstralBrick.cs b/Tiles/AstralBrick.cs index f7f937fcec..1daaa84617 100644 --- a/Tiles/AstralBrick.cs +++ b/Tiles/AstralBrick.cs @@ -5,23 +5,21 @@ using CalamityMod.Tiles.Astral; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; +using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Tiles { - public class AstralBrick : ModTile + public class AstralBrick : GlowMaskTile { private const short subsheetWidth = 324; private const short subsheetHeight = 90; - internal static FramedGlowMask GlowMask; + public override string GlowMaskAsset => "CalamityMod/Tiles/AstralBrickGlow"; - - public override void SetStaticDefaults() + public override void SetupStatic() { - GlowMask = new("CalamityMod/Tiles/AstralBrickGlow", 18, 18); - Main.tileSolid[Type] = true; Main.tileBlockLight[Type] = true; HitSound = SoundID.Tink; @@ -50,39 +48,9 @@ namespace CalamityMod.Tiles frameYOffset = yPos * subsheetHeight; } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - int xPos = Main.tile[i, j].TileFrameX; - int yPos = Main.tile[i, j].TileFrameY; - int xOffset = i % 2; - int yOffset = j % 2; - xOffset *= subsheetWidth; - yOffset *= subsheetHeight; - xPos += xOffset; - yPos += yOffset; - - if (GlowMask.HasContentInFramePos(xPos, yPos)) - { - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - Color drawColour = GetDrawColour(i, j, new Color(50, 50, 50, 50)); - Tile trackTile = Main.tile[i, j]; - - TileFramingSystem.SlopedGlowmask(i, j, 0, GlowMask.Texture, drawOffset, null, GetDrawColour(i, j, drawColour), default); - } - } - - private Color GetDrawColour(int i, int j, Color colour) - { - int colType = Main.tile[i, j].TileColor; - Color paintCol = WorldGen.paintColor(colType); - if (colType >= 13 && colType <= 24) - { - colour.R = (byte)(paintCol.R / 255f * colour.R); - colour.G = (byte)(paintCol.G / 255f * colour.G); - colour.B = (byte)(paintCol.B / 255f * colour.B); - } - return colour; + return new Color(50, 50, 50); } } } diff --git a/Tiles/Furniture/Fountains/AbyssFountainTile.cs b/Tiles/Furniture/Fountains/AbyssFountainTile.cs index 02fde7f55c..9bdc67d1b1 100644 --- a/Tiles/Furniture/Fountains/AbyssFountainTile.cs +++ b/Tiles/Furniture/Fountains/AbyssFountainTile.cs @@ -1,4 +1,5 @@ using CalamityMod.Items.Placeables.Furniture.Fountains; +using CalamityMod.Waters; using Microsoft.Xna.Framework; using Terraria; using Terraria.Audio; @@ -15,7 +16,7 @@ namespace CalamityMod.Tiles.Furniture.Fountains public override void NearbyEffects(int i, int j, bool closer) { if (!Main.dedServ && Main.tile[i, j].TileFrameX >= 36) - Main.SceneMetrics.ActiveFountainColor = ModContent.Find("CalamityMod/VoidWater").Slot; + Main.SceneMetrics.ActiveFountainColor = VoidWater.Instance.Slot; } public override bool HasSmartInteract(int i, int j, SmartInteractScanSettings settings) => true; diff --git a/Tiles/Furniture/Fountains/AstralFountainTile.cs b/Tiles/Furniture/Fountains/AstralFountainTile.cs index 44c0823d18..b21b19bd74 100644 --- a/Tiles/Furniture/Fountains/AstralFountainTile.cs +++ b/Tiles/Furniture/Fountains/AstralFountainTile.cs @@ -1,5 +1,6 @@ using CalamityMod.Dusts; using CalamityMod.Items.Placeables.Furniture.Fountains; +using CalamityMod.Waters; using Microsoft.Xna.Framework; using Terraria; using Terraria.Audio; @@ -16,7 +17,7 @@ namespace CalamityMod.Tiles.Furniture.Fountains public override void NearbyEffects(int i, int j, bool closer) { if (!Main.dedServ && Main.tile[i, j].TileFrameX >= 36) - Main.SceneMetrics.ActiveFountainColor = ModContent.Find("CalamityMod/AstralWater").Slot; + Main.SceneMetrics.ActiveFountainColor = AstralWater.Instance.Slot; } public override bool HasSmartInteract(int i, int j, SmartInteractScanSettings settings) => true; diff --git a/Tiles/Furniture/Fountains/SulphurousFountainTile.cs b/Tiles/Furniture/Fountains/SulphurousFountainTile.cs index 5c79c78750..6b52380f3d 100644 --- a/Tiles/Furniture/Fountains/SulphurousFountainTile.cs +++ b/Tiles/Furniture/Fountains/SulphurousFountainTile.cs @@ -1,4 +1,5 @@ using CalamityMod.Items.Placeables.Furniture.Fountains; +using CalamityMod.Waters; using Microsoft.Xna.Framework; using Terraria; using Terraria.Audio; @@ -16,7 +17,7 @@ namespace CalamityMod.Tiles.Furniture.Fountains { string waterColor = Main.zenithWorld ? "CalamityMod/PissWater" : "CalamityMod/SulphuricWater"; if (!Main.dedServ && Main.tile[i, j].TileFrameX >= 36) - Main.SceneMetrics.ActiveFountainColor = ModContent.Find(waterColor).Slot; + Main.SceneMetrics.ActiveFountainColor = Main.zenithWorld ? PissWater.Instance.Slot : SulphuricWater.Instance.Slot; } public override bool HasSmartInteract(int i, int j, SmartInteractScanSettings settings) => true; diff --git a/Tiles/Furniture/Fountains/SunkenSeaFountainTile.cs b/Tiles/Furniture/Fountains/SunkenSeaFountainTile.cs index 9aaf10a2d5..52a33930ad 100644 --- a/Tiles/Furniture/Fountains/SunkenSeaFountainTile.cs +++ b/Tiles/Furniture/Fountains/SunkenSeaFountainTile.cs @@ -1,4 +1,5 @@ using CalamityMod.Items.Placeables.Furniture.Fountains; +using CalamityMod.Waters; using Microsoft.Xna.Framework; using Terraria; using Terraria.Audio; @@ -15,7 +16,7 @@ namespace CalamityMod.Tiles.Furniture.Fountains public override void NearbyEffects(int i, int j, bool closer) { if (!Main.dedServ && Main.tile[i, j].TileFrameX >= 36) - Main.SceneMetrics.ActiveFountainColor = ModContent.Find("CalamityMod/SunkenSeaWater").Slot; + Main.SceneMetrics.ActiveFountainColor = BasaltGullyWater.Type; } public override bool HasSmartInteract(int i, int j, SmartInteractScanSettings settings) => true; diff --git a/Tiles/FurnitureAshen/SmoothBrimstoneSlag.cs b/Tiles/FurnitureAshen/SmoothBrimstoneSlag.cs index 44abdceee6..6c5b1290a7 100644 --- a/Tiles/FurnitureAshen/SmoothBrimstoneSlag.cs +++ b/Tiles/FurnitureAshen/SmoothBrimstoneSlag.cs @@ -3,19 +3,18 @@ using CalamityMod.Systems; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; +using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Tiles.FurnitureAshen { - public class SmoothBrimstoneSlag : ModTile + public class SmoothBrimstoneSlag : GlowMaskTile { - internal static FramedGlowMask GlowMask; + public override string GlowMaskAsset => "CalamityMod/Tiles/FurnitureAshen/SmoothBrimstoneSlagGlow"; - public override void SetStaticDefaults() + public override void SetupStatic() { - GlowMask = new("CalamityMod/Tiles/FurnitureAshen/SmoothBrimstoneSlagGlow", 18, 18); - Main.tileSolid[Type] = true; Main.tileMergeDirt[Type] = false; Main.tileBlockLight[Type] = true; @@ -37,33 +36,9 @@ namespace CalamityMod.Tiles.FurnitureAshen return false; } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - int xPos = Main.tile[i, j].TileFrameX; - int yPos = Main.tile[i, j].TileFrameY; - - if (GlowMask.HasContentInFramePos(xPos, yPos)) - { - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - Color drawColour = GetDrawColour(i, j, new Color(25, 25, 25, 25)); - Tile trackTile = Main.tile[i, j]; - - TileFramingSystem.SlopedGlowmask(i, j, 0, GlowMask.Texture, drawOffset, null, GetDrawColour(i, j, drawColour), default); - } - } - - private Color GetDrawColour(int i, int j, Color colour) - { - int colType = Main.tile[i, j].TileColor; - Color paintCol = WorldGen.paintColor(colType); - if (colType >= 13 && colType <= 24) - { - colour.R = (byte)(paintCol.R / 255f * colour.R); - colour.G = (byte)(paintCol.G / 255f * colour.G); - colour.B = (byte)(paintCol.B / 255f * colour.B); - } - return colour; + return new Color(25, 25, 25); } } } diff --git a/Tiles/FurnitureAuric/ActivatedAuricPanelTile.cs b/Tiles/FurnitureAuric/ActivatedAuricPanelTile.cs index 0cb0752600..24a4d7ed7d 100644 --- a/Tiles/FurnitureAuric/ActivatedAuricPanelTile.cs +++ b/Tiles/FurnitureAuric/ActivatedAuricPanelTile.cs @@ -4,19 +4,18 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using Terraria; +using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Tiles.FurnitureAuric { - public class ActivatedAuricPanelTile : ModTile + public class ActivatedAuricPanelTile : GlowMaskTile { - internal static FramedGlowMask GlowMask; + public override string GlowMaskAsset => "CalamityMod/Tiles/FurnitureAuric/ActivatedAuricPanelTile_Glow"; - public override void SetStaticDefaults() + public override void SetupStatic() { - GlowMask = new("CalamityMod/Tiles/FurnitureAuric/ActivatedAuricPanelTile_Glow", 18, 18); - Main.tileSolid[Type] = true; Main.tileBlockLight[Type] = true; HitSound = AuricOre.MineSound; @@ -31,35 +30,11 @@ namespace CalamityMod.Tiles.FurnitureAuric return false; } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - int xPos = Main.tile[i, j].TileFrameX; - int yPos = Main.tile[i, j].TileFrameY; - - if (GlowMask.HasContentInFramePos(xPos, yPos)) - { - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - Color drawColour = GetDrawColour(i, j, Color.White); - Tile trackTile = Main.tile[i, j]; - double num6 = Main.time * 0.08; - - TileFramingSystem.SlopedGlowmask(i, j, 0, GlowMask.Texture, drawOffset, null, GetDrawColour(i, j, drawColour), default); - } + return Color.White; } - private Color GetDrawColour(int i, int j, Color colour) - { - int colType = Main.tile[i, j].TileColor; - Color paintCol = WorldGen.paintColor(colType); - if (colType >= 13 && colType <= 24) - { - colour.R = (byte)(paintCol.R / 255f * colour.R); - colour.G = (byte)(paintCol.G / 255f * colour.G); - colour.B = (byte)(paintCol.B / 255f * colour.B); - } - return colour; - } public override bool TileFrame(int i, int j, ref bool resetFrame, ref bool noBreak) { return TileFramingSystem.BetterGemsparkFraming(i, j, resetFrame); diff --git a/Tiles/FurnitureAuric/AuricAbsorberTile.cs b/Tiles/FurnitureAuric/AuricAbsorberTile.cs index 67c8f07997..2d6f075873 100644 --- a/Tiles/FurnitureAuric/AuricAbsorberTile.cs +++ b/Tiles/FurnitureAuric/AuricAbsorberTile.cs @@ -23,15 +23,10 @@ namespace CalamityMod.Tiles.FurnitureAuric public override void PostDraw(int i, int j, SpriteBatch spriteBatch) { - int xPos = Main.tile[i, j].TileFrameX; - int yPos = Main.tile[i, j].TileFrameY; - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; + var tileCache = Main.tile[i, j]; Color drawColour = GetDrawColour(i, j, Color.White); - Tile trackTile = Main.tile[i, j]; - double num6 = Main.time * 0.08; - TileFramingSystem.SlopedGlowmask(i, j, 0, TextureAssets.Tile[Type].Value, drawOffset, null, GetDrawColour(i, j, drawColour), default); + TileFramingSystem.SlopedGlowmask(in tileCache, i, j, TextureAssets.Tile[Type].Value, null, GetDrawColour(i, j, drawColour), default); } private Color GetDrawColour(int i, int j, Color colour) diff --git a/Tiles/FurnitureAuric/AuricRepulserPanelTile.cs b/Tiles/FurnitureAuric/AuricRepulserPanelTile.cs index 4b38dc3aac..236306d9cb 100644 --- a/Tiles/FurnitureAuric/AuricRepulserPanelTile.cs +++ b/Tiles/FurnitureAuric/AuricRepulserPanelTile.cs @@ -4,19 +4,18 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using Terraria; +using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Tiles.FurnitureAuric { - public class AuricRepulserPanelTile : ModTile + public class AuricRepulserPanelTile : GlowMaskTile { - internal static FramedGlowMask GlowMask; + public override string GlowMaskAsset => "CalamityMod/Tiles/FurnitureAuric/AuricRepulserPanelTile_Glow"; - public override void SetStaticDefaults() + public override void SetupStatic() { - GlowMask = new("CalamityMod/Tiles/FurnitureAuric/AuricRepulserPanelTile_Glow", 18, 18); - Main.tileSolid[Type] = true; Main.tileBlockLight[Type] = true; HitSound = AuricOre.MineSound; @@ -31,35 +30,11 @@ namespace CalamityMod.Tiles.FurnitureAuric return false; } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - int xPos = Main.tile[i, j].TileFrameX; - int yPos = Main.tile[i, j].TileFrameY; - - if (GlowMask.HasContentInFramePos(xPos, yPos)) - { - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - Color drawColour = GetDrawColour(i, j, Color.White); - Tile trackTile = Main.tile[i, j]; - double num6 = Main.time * 0.08; - - TileFramingSystem.SlopedGlowmask(i, j, 0, GlowMask.Texture, drawOffset, null, GetDrawColour(i, j, drawColour), default); - } + return Color.White; } - private Color GetDrawColour(int i, int j, Color colour) - { - int colType = Main.tile[i, j].TileColor; - Color paintCol = WorldGen.paintColor(colType); - if (colType >= 13 && colType <= 24) - { - colour.R = (byte)(paintCol.R / 255f * colour.R); - colour.G = (byte)(paintCol.G / 255f * colour.G); - colour.B = (byte)(paintCol.B / 255f * colour.B); - } - return colour; - } public override bool TileFrame(int i, int j, ref bool resetFrame, ref bool noBreak) { return TileFramingSystem.BetterGemsparkFraming(i, j, resetFrame); diff --git a/Tiles/FurnitureAuric/ExoAuricPanelTile.cs b/Tiles/FurnitureAuric/ExoAuricPanelTile.cs index 23738fec60..7f30c72c0b 100644 --- a/Tiles/FurnitureAuric/ExoAuricPanelTile.cs +++ b/Tiles/FurnitureAuric/ExoAuricPanelTile.cs @@ -4,19 +4,18 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using Terraria; +using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Tiles.FurnitureAuric { - public class ExoAuricPanelTile : ModTile + public class ExoAuricPanelTile : GlowMaskTile { - internal static FramedGlowMask GlowMask; + public override string GlowMaskAsset => "CalamityMod/Tiles/FurnitureAuric/ExoAuricPanelTile_Glow"; - public override void SetStaticDefaults() + public override void SetupStatic() { - GlowMask = new("CalamityMod/Tiles/FurnitureAuric/ExoAuricPanelTile_Glow", 18, 18); - Main.tileSolid[Type] = true; Main.tileBlockLight[Type] = true; HitSound = AuricOre.MineSound; @@ -31,35 +30,11 @@ namespace CalamityMod.Tiles.FurnitureAuric return false; } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - int xPos = Main.tile[i, j].TileFrameX; - int yPos = Main.tile[i, j].TileFrameY; - - if (GlowMask.HasContentInFramePos(xPos, yPos)) - { - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - Color drawColour = GetDrawColour(i, j, Color.White); - Tile trackTile = Main.tile[i, j]; - double num6 = Main.time * 0.08; - - TileFramingSystem.SlopedGlowmask(i, j, 0, GlowMask.Texture, drawOffset, null, GetDrawColour(i, j, drawColour), default); - } + return Color.White; } - private Color GetDrawColour(int i, int j, Color colour) - { - int colType = Main.tile[i, j].TileColor; - Color paintCol = WorldGen.paintColor(colType); - if (colType >= 13 && colType <= 24) - { - colour.R = (byte)(paintCol.R / 255f * colour.R); - colour.G = (byte)(paintCol.G / 255f * colour.G); - colour.B = (byte)(paintCol.B / 255f * colour.B); - } - return colour; - } public override bool TileFrame(int i, int j, ref bool resetFrame, ref bool noBreak) { return TileFramingSystem.BetterGemsparkFraming(i, j, resetFrame); diff --git a/Tiles/FurnitureCosmilite/CosmiliteBrick.cs b/Tiles/FurnitureCosmilite/CosmiliteBrick.cs index 56c0145275..c91d283dad 100644 --- a/Tiles/FurnitureCosmilite/CosmiliteBrick.cs +++ b/Tiles/FurnitureCosmilite/CosmiliteBrick.cs @@ -3,19 +3,18 @@ using CalamityMod.Systems; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; +using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Tiles.FurnitureCosmilite { - public class CosmiliteBrick : ModTile + public class CosmiliteBrick : GlowMaskTile { - internal static FramedGlowMask GlowMask; + public override string GlowMaskAsset => "CalamityMod/Tiles/FurnitureCosmilite/CosmiliteBrickGlow"; - public override void SetStaticDefaults() + public override void SetupStatic() { - GlowMask = new("CalamityMod/Tiles/FurnitureCosmilite/CosmiliteBrickGlow", 18, 18); - Main.tileSolid[Type] = true; Main.tileBlockLight[Type] = true; HitSound = SoundID.Tink; @@ -30,34 +29,9 @@ namespace CalamityMod.Tiles.FurnitureCosmilite return false; } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - int xPos = Main.tile[i, j].TileFrameX; - int yPos = Main.tile[i, j].TileFrameY; - - if (GlowMask.HasContentInFramePos(xPos, yPos)) - { - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - Color drawColour = GetDrawColour(i, j, Color.White); - Tile trackTile = Main.tile[i, j]; - double num6 = Main.time * 0.08; - - TileFramingSystem.SlopedGlowmask(i, j, 0, GlowMask.Texture, drawOffset, null, GetDrawColour(i, j, drawColour), default); - } - } - - private Color GetDrawColour(int i, int j, Color colour) - { - int colType = Main.tile[i, j].TileColor; - Color paintCol = WorldGen.paintColor(colType); - if (colType >= 13 && colType <= 24) - { - colour.R = (byte)(paintCol.R / 255f * colour.R); - colour.G = (byte)(paintCol.G / 255f * colour.G); - colour.B = (byte)(paintCol.B / 255f * colour.B); - } - return colour; + return Color.White; } } } diff --git a/Tiles/FurnitureExo/ExoPlatingTile.cs b/Tiles/FurnitureExo/ExoPlatingTile.cs index e9362c3376..9a4408ed15 100644 --- a/Tiles/FurnitureExo/ExoPlatingTile.cs +++ b/Tiles/FurnitureExo/ExoPlatingTile.cs @@ -4,19 +4,18 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using Terraria; +using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Tiles.FurnitureExo { - public class ExoPlatingTile : ModTile + public class ExoPlatingTile : GlowMaskTile { - internal static FramedGlowMask GlowMask; + public override string GlowMaskAsset => "CalamityMod/Tiles/FurnitureExo/ExoPlatingTileGlow"; - public override void SetStaticDefaults() + public override void SetupStatic() { - GlowMask = new("CalamityMod/Tiles/FurnitureExo/ExoPlatingTileGlow", 18, 18); - Main.tileSolid[Type] = true; Main.tileBlockLight[Type] = true; @@ -43,37 +42,9 @@ namespace CalamityMod.Tiles.FurnitureExo frameYOffset = yPos * AnimationFrameHeight; } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - // If the cached textures don't exist for some reason, don't bother using them. - if (GlowMask.Texture is null) - return; - - Tile tile = CalamityUtils.ParanoidTileRetrieval(i, j); - int xPos = tile.TileFrameX; - int frameOffset = j % 2 * AnimationFrameHeight; - int yPos = tile.TileFrameY + frameOffset; - - if (GlowMask.HasContentInFramePos(xPos, yPos)) - { - Color drawColour = GetDrawColour(i, j, Color.White); - Vector2 drawOffset = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawPosition = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + drawOffset; - - TileFramingSystem.SlopedGlowmask(i, j, 0, GlowMask.Texture, drawOffset, null, GetDrawColour(i, j, drawColour), default); - } - } - private Color GetDrawColour(int i, int j, Color colour) - { - int colType = Main.tile[i, j].TileColor; - Color paintCol = WorldGen.paintColor(colType); - if (colType >= 13 && colType <= 24) - { - colour.R = (byte)(paintCol.R / 255f * colour.R); - colour.G = (byte)(paintCol.G / 255f * colour.G); - colour.B = (byte)(paintCol.B / 255f * colour.B); - } - return colour; + return Color.White; } } } diff --git a/Tiles/FurnitureExo/ExoPrismPanelTile.cs b/Tiles/FurnitureExo/ExoPrismPanelTile.cs index 5d531fb550..5a560bf5eb 100644 --- a/Tiles/FurnitureExo/ExoPrismPanelTile.cs +++ b/Tiles/FurnitureExo/ExoPrismPanelTile.cs @@ -4,19 +4,18 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using Terraria; +using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Tiles.FurnitureExo { - public class ExoPrismPanelTile : ModTile + public class ExoPrismPanelTile : GlowMaskTile { - internal static FramedGlowMask GlowMask; + public override string GlowMaskAsset => "CalamityMod/Tiles/FurnitureExo/ExoPrismPanelTileGlow"; - public override void SetStaticDefaults() + public override void SetupStatic() { - GlowMask = new("CalamityMod/Tiles/FurnitureExo/ExoPrismPanelTileGlow", 18, 18); - Main.tileSolid[Type] = true; Main.tileBlockLight[Type] = true; @@ -43,37 +42,9 @@ namespace CalamityMod.Tiles.FurnitureExo frameYOffset = frameOffset * AnimationFrameHeight; } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - // If the cached textures don't exist for some reason, don't bother using them. - if (GlowMask.Texture is null) - return; - - Tile tile = CalamityUtils.ParanoidTileRetrieval(i, j); - int xPos = tile.TileFrameX; - int frameOffset = (i + j) % 6 * AnimationFrameHeight; - int yPos = tile.TileFrameY + frameOffset; - - if (GlowMask.HasContentInFramePos(xPos, yPos)) - { - Color drawColour = GetDrawColour(i, j, Color.White); - Vector2 drawOffset = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawPosition = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + drawOffset; - - TileFramingSystem.SlopedGlowmask(i, j, 0, GlowMask.Texture, drawOffset, null, GetDrawColour(i, j, drawColour), default); - } - } - private Color GetDrawColour(int i, int j, Color colour) - { - int colType = Main.tile[i, j].TileColor; - Color paintCol = WorldGen.paintColor(colType); - if (colType >= 13 && colType <= 24) - { - colour.R = (byte)(paintCol.R / 255f * colour.R); - colour.G = (byte)(paintCol.G / 255f * colour.G); - colour.B = (byte)(paintCol.B / 255f * colour.B); - } - return colour; + return Color.White; } } } diff --git a/Tiles/FurniturePlaguedPlate/PlaguedPlate.cs b/Tiles/FurniturePlaguedPlate/PlaguedPlate.cs index 8df409c0d9..be6084f4d0 100644 --- a/Tiles/FurniturePlaguedPlate/PlaguedPlate.cs +++ b/Tiles/FurniturePlaguedPlate/PlaguedPlate.cs @@ -3,19 +3,18 @@ using CalamityMod.Systems; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; +using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Tiles.FurniturePlaguedPlate { - public class PlaguedPlate : ModTile + public class PlaguedPlate : GlowMaskTile { - internal static FramedGlowMask GlowMask; + public override string GlowMaskAsset => "CalamityMod/Tiles/FurniturePlaguedPlate/PlaguedPlateGlow"; - public override void SetStaticDefaults() + public override void SetupStatic() { - GlowMask = new("CalamityMod/Tiles/FurniturePlaguedPlate/PlaguedPlateGlow", 18, 18); - Main.tileSolid[Type] = true; Main.tileBlockLight[Type] = true; HitSound = SoundID.Tink; @@ -34,37 +33,14 @@ namespace CalamityMod.Tiles.FurniturePlaguedPlate num = fail ? 1 : 3; } + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) + { + return new Color(128, 128, 128); + } + public override bool TileFrame(int i, int j, ref bool resetFrame, ref bool noBreak) { return TileFramingSystem.BrimstoneFraming(i, j, resetFrame); } - - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) - { - int xPos = Main.tile[i, j].TileFrameX; - int yPos = Main.tile[i, j].TileFrameY; - - if (GlowMask.HasContentInFramePos(xPos, yPos)) - { - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - Color drawColour = GetDrawColour(i, j, new Color(128, 128, 128, 128)); - Tile trackTile = Main.tile[i, j]; - TileFramingSystem.SlopedGlowmask(i, j, 0, GlowMask.Texture, drawOffset, null, GetDrawColour(i, j, drawColour), default); - } - } - - private Color GetDrawColour(int i, int j, Color colour) - { - int colType = Main.tile[i, j].TileColor; - Color paintCol = WorldGen.paintColor(colType); - if (colType >= 13 && colType <= 24) - { - colour.R = (byte)(paintCol.R / 255f * colour.R); - colour.G = (byte)(paintCol.G / 255f * colour.G); - colour.B = (byte)(paintCol.B / 255f * colour.B); - } - return colour; - } } } diff --git a/Tiles/FurnitureProfaned/ProfanedRock.cs b/Tiles/FurnitureProfaned/ProfanedRock.cs index da4358dccc..8aaa7b04f4 100644 --- a/Tiles/FurnitureProfaned/ProfanedRock.cs +++ b/Tiles/FurnitureProfaned/ProfanedRock.cs @@ -4,19 +4,20 @@ using CalamityMod.Systems; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; +using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Tiles.FurnitureProfaned { - public class ProfanedRock : ModTile + public class ProfanedRock : GlowMaskTile { - internal static FramedGlowMask GlowMask; + public const int AnimationFrameWidth = 288; - public override void SetStaticDefaults() + public override string GlowMaskAsset => "CalamityMod/Tiles/FurnitureProfaned/ProfanedRockGlow"; + + public override void SetupStatic() { - GlowMask = new("CalamityMod/Tiles/FurnitureProfaned/ProfanedRockGlow", 18, 18); - Main.tileSolid[Type] = true; Main.tileMergeDirt[Type] = true; Main.tileBlockLight[Type] = true; @@ -30,7 +31,8 @@ namespace CalamityMod.Tiles.FurnitureProfaned MinPick = 225; AddMapEntry(new Color(84, 38, 33)); } - int animationFrameWidth = 288; + + public override bool CreateDust(int i, int j, ref int type) { @@ -41,212 +43,12 @@ namespace CalamityMod.Tiles.FurnitureProfaned public override void AnimateIndividualTile(int type, int i, int j, ref int frameXOffset, ref int frameYOffset) { - int uniqueAnimationFrameX = 0; - int xPos = i % 4; - int yPos = j % 4; - switch (xPos) - { - case 0: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 0; - break; - case 1: - uniqueAnimationFrameX = 2; - break; - case 2: - uniqueAnimationFrameX = 1; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - case 1: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 2; - break; - case 1: - uniqueAnimationFrameX = 0; - break; - case 2: - uniqueAnimationFrameX = 2; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - case 2: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 2; - break; - case 1: - uniqueAnimationFrameX = 0; - break; - case 2: - uniqueAnimationFrameX = 1; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - case 3: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 1; - break; - case 1: - uniqueAnimationFrameX = 2; - break; - case 2: - uniqueAnimationFrameX = 0; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - } - frameXOffset = uniqueAnimationFrameX * animationFrameWidth; + frameXOffset = AnimationFrameWidth * TileFramingSystem.GetVariation4x4_012_Low0(i, j); } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - if (GlowMask.Texture is null) - return; - - int xPos = Main.tile[i, j].TileFrameX; - int yPos = Main.tile[i, j].TileFrameY; - int xOffset = 0; - int relativeXPos = i % 4; - int relativeYPos = j % 4; - switch (relativeXPos) - { - case 0: - switch (relativeYPos) - { - case 0: - xOffset = 0; - break; - case 1: - xOffset = 2; - break; - case 2: - xOffset = 1; - break; - case 3: - xOffset = 2; - break; - default: - xOffset = 2; - break; - } - break; - case 1: - switch (relativeYPos) - { - case 0: - xOffset = 2; - break; - case 1: - xOffset = 0; - break; - case 2: - xOffset = 2; - break; - case 3: - xOffset = 2; - break; - default: - xOffset = 2; - break; - } - break; - case 2: - switch (relativeYPos) - { - case 0: - xOffset = 2; - break; - case 1: - xOffset = 0; - break; - case 2: - xOffset = 1; - break; - case 3: - xOffset = 2; - break; - default: - xOffset = 2; - break; - } - break; - case 3: - switch (relativeYPos) - { - case 0: - xOffset = 1; - break; - case 1: - xOffset = 2; - break; - case 2: - xOffset = 0; - break; - case 3: - xOffset = 2; - break; - default: - xOffset = 2; - break; - } - break; - } - xOffset *= 288; - xPos += xOffset; - - if (GlowMask.HasContentInFramePos(xPos, yPos)) - { - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - Color drawColour = GetDrawColour(i, j, new Color(25, 25, 25, 25)); - Tile trackTile = Main.tile[i, j]; - TileFramingSystem.SlopedGlowmask(i, j, 0, GlowMask.Texture, drawOffset, null, GetDrawColour(i, j, drawColour), default); - } - } - - private Color GetDrawColour(int i, int j, Color colour) - { - int colType = Main.tile[i, j].TileColor; - Color paintCol = WorldGen.paintColor(colType); - if (colType >= 13 && colType <= 24) - { - colour.R = (byte)(paintCol.R / 255f * colour.R); - colour.G = (byte)(paintCol.G / 255f * colour.G); - colour.B = (byte)(paintCol.B / 255f * colour.B); - } - return colour; + return Color.White * 0.098f; } } } diff --git a/Tiles/FurnitureProfaned/RunicProfanedBrick.cs b/Tiles/FurnitureProfaned/RunicProfanedBrick.cs index d3b35e775b..059beaa28e 100644 --- a/Tiles/FurnitureProfaned/RunicProfanedBrick.cs +++ b/Tiles/FurnitureProfaned/RunicProfanedBrick.cs @@ -4,19 +4,20 @@ using CalamityMod.Systems; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; +using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Tiles.FurnitureProfaned { - public class RunicProfanedBrick : ModTile + public class RunicProfanedBrick : GlowMaskTile { - internal static FramedGlowMask GlowMask; + public const int AnimationFrameWidth = 234; - public override void SetStaticDefaults() + public override string GlowMaskAsset => "CalamityMod/Tiles/FurnitureProfaned/RunicProfanedBrickGlow"; + + public override void SetupStatic() { - GlowMask = new("CalamityMod/Tiles/FurnitureProfaned/RunicProfanedBrickGlow", 18, 18); - Main.tileSolid[Type] = true; Main.tileBlockLight[Type] = true; @@ -29,7 +30,6 @@ namespace CalamityMod.Tiles.FurnitureProfaned AddMapEntry(new Color(122, 66, 59)); AnimationFrameHeight = 90; } - int animationFrameWidth = 234; public override bool CreateDust(int i, int j, ref int type) { @@ -40,43 +40,13 @@ namespace CalamityMod.Tiles.FurnitureProfaned public override void AnimateIndividualTile(int type, int i, int j, ref int frameXOffset, ref int frameYOffset) { - frameXOffset = i % 2 * animationFrameWidth; + frameXOffset = i % 2 * AnimationFrameWidth; frameYOffset = j % 2 * AnimationFrameHeight; } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - int xPos = Main.tile[i, j].TileFrameX; - int yPos = Main.tile[i, j].TileFrameY; - int xOffset = i % 2; - int yOffset = j % 2; - xOffset *= animationFrameWidth; - yOffset *= AnimationFrameHeight; - xPos += xOffset; - yPos += yOffset; - - if (GlowMask.HasContentInFramePos(xPos, yPos)) - { - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - Color drawColour = GetDrawColour(i, j, new Color(128, 128, 128, 128)); - Tile trackTile = Main.tile[i, j]; - - TileFramingSystem.SlopedGlowmask(i, j, 0, GlowMask.Texture, drawOffset, null, GetDrawColour(i, j, drawColour), default); - } - } - - private Color GetDrawColour(int i, int j, Color colour) - { - int colType = Main.tile[i, j].TileColor; - Color paintCol = WorldGen.paintColor(colType); - if (colType >= 13 && colType <= 24) - { - colour.R = (byte)(paintCol.R / 255f * colour.R); - colour.G = (byte)(paintCol.G / 255f * colour.G); - colour.B = (byte)(paintCol.B / 255f * colour.B); - } - return colour; + return Color.White * 0.5f; } } } diff --git a/Tiles/FurnitureStratus/StratusBricks.cs b/Tiles/FurnitureStratus/StratusBricks.cs index da0b76cb1d..74a2e92c79 100644 --- a/Tiles/FurnitureStratus/StratusBricks.cs +++ b/Tiles/FurnitureStratus/StratusBricks.cs @@ -3,19 +3,18 @@ using CalamityMod.Systems; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; +using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Tiles.FurnitureStratus { - public class StratusBricks : ModTile + public class StratusBricks : GlowMaskTile { - internal static FramedGlowMask GlowMask; + public override string GlowMaskAsset => "CalamityMod/Tiles/FurnitureStratus/StratusBricksGlow"; - public override void SetStaticDefaults() + public override void SetupStatic() { - GlowMask = new("CalamityMod/Tiles/FurnitureStratus/StratusBricksGlow", 18, 18); - Main.tileSolid[Type] = true; Main.tileBlockLight[Type] = true; TileID.Sets.HasSlopeFrames[Type] = true; @@ -34,38 +33,14 @@ namespace CalamityMod.Tiles.FurnitureStratus return false; } + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) + { + return new Color(100, 100, 100); + } + public override bool TileFrame(int i, int j, ref bool resetFrame, ref bool noBreak) { return TileFramingSystem.BetterGemsparkFraming(i, j, resetFrame); } - - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) - { - int xPos = Main.tile[i, j].TileFrameX; - int yPos = Main.tile[i, j].TileFrameY; - - if (GlowMask.HasContentInFramePos(xPos, yPos)) - { - Color drawColour = GetDrawColour(i, j, new Color(100, 100, 100, 100)); - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - Tile trackTile = Main.tile[i, j]; - - TileFramingSystem.SlopedGlowmask(i, j, 0, GlowMask.Texture, drawOffset, null, GetDrawColour(i, j, drawColour), default); - } - } - - private Color GetDrawColour(int i, int j, Color colour) - { - int colType = Main.tile[i, j].TileColor; - Color paintCol = WorldGen.paintColor(colType); - if (colType >= 13 && colType <= 24) - { - colour.R = (byte)(paintCol.R / 255f * colour.R); - colour.G = (byte)(paintCol.G / 255f * colour.G); - colour.B = (byte)(paintCol.B / 255f * colour.B); - } - return colour; - } } } diff --git a/Tiles/FurnitureVoid/SmoothVoidstone.cs b/Tiles/FurnitureVoid/SmoothVoidstone.cs index 2332a12843..530df2f4ff 100644 --- a/Tiles/FurnitureVoid/SmoothVoidstone.cs +++ b/Tiles/FurnitureVoid/SmoothVoidstone.cs @@ -4,19 +4,18 @@ using CalamityMod.Systems; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; +using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Tiles.FurnitureVoid { - public class SmoothVoidstone : ModTile + public class SmoothVoidstone : GlowMaskTile { - internal static FramedGlowMask GlowMask; + public override string GlowMaskAsset => "CalamityMod/Tiles/FurnitureVoid/SmoothVoidstoneGlow"; - public override void SetStaticDefaults() + public override void SetupStatic() { - GlowMask = new("CalamityMod/Tiles/FurnitureVoid/SmoothVoidstoneGlow", 18, 18); - Main.tileSolid[Type] = true; Main.tileMergeDirt[Type] = true; Main.tileBlockLight[Type] = true; @@ -30,6 +29,7 @@ namespace CalamityMod.Tiles.FurnitureVoid MineResist = 2.1f; AddMapEntry(new Color(27, 24, 31)); } + int animationFrameWidth = 288; public override bool CreateDust(int i, int j, ref int type) @@ -40,217 +40,18 @@ namespace CalamityMod.Tiles.FurnitureVoid public override void AnimateIndividualTile(int type, int i, int j, ref int frameXOffset, ref int frameYOffset) { - int uniqueAnimationFrameX = 0; - int xPos = i % 4; - int yPos = j % 4; - switch (xPos) - { - case 0: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 0; - break; - case 1: - uniqueAnimationFrameX = 0; - break; - case 2: - uniqueAnimationFrameX = 1; - break; - case 3: - uniqueAnimationFrameX = 1; - break; - default: - uniqueAnimationFrameX = 0; - break; - } - break; - case 1: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 1; - break; - case 1: - uniqueAnimationFrameX = 0; - break; - case 2: - uniqueAnimationFrameX = 1; - break; - case 3: - uniqueAnimationFrameX = 1; - break; - default: - uniqueAnimationFrameX = 0; - break; - } - break; - case 2: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 1; - break; - case 1: - uniqueAnimationFrameX = 0; - break; - case 2: - uniqueAnimationFrameX = 0; - break; - case 3: - uniqueAnimationFrameX = 1; - break; - default: - uniqueAnimationFrameX = 0; - break; - } - break; - case 3: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 0; - break; - case 1: - uniqueAnimationFrameX = 1; - break; - case 2: - uniqueAnimationFrameX = 0; - break; - case 3: - uniqueAnimationFrameX = 1; - break; - default: - uniqueAnimationFrameX = 0; - break; - } - break; - } - frameXOffset = uniqueAnimationFrameX * animationFrameWidth; + frameXOffset = animationFrameWidth * TileFramingSystem.GetVariation4x4_01_Low0(i, j); } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - int xPos = Main.tile[i, j].TileFrameX; - int yPos = Main.tile[i, j].TileFrameY; - int xOffset = 0; - int relativeXPos = i % 4; - int relativeYPos = j % 4; - switch (relativeXPos) - { - case 0: - switch (relativeYPos) - { - case 0: - xOffset = 0; - break; - case 1: - xOffset = 0; - break; - case 2: - xOffset = 1; - break; - case 3: - xOffset = 1; - break; - default: - xOffset = 0; - break; - } - break; - case 1: - switch (relativeYPos) - { - case 0: - xOffset = 1; - break; - case 1: - xOffset = 0; - break; - case 2: - xOffset = 1; - break; - case 3: - xOffset = 1; - break; - default: - xOffset = 0; - break; - } - break; - case 2: - switch (relativeYPos) - { - case 0: - xOffset = 1; - break; - case 1: - xOffset = 0; - break; - case 2: - xOffset = 0; - break; - case 3: - xOffset = 1; - break; - default: - xOffset = 0; - break; - } - break; - case 3: - switch (relativeYPos) - { - case 0: - xOffset = 0; - break; - case 1: - xOffset = 1; - break; - case 2: - xOffset = 0; - break; - case 3: - xOffset = 1; - break; - default: - xOffset = 0; - break; - } - break; - } - xOffset *= 288; - xPos += xOffset; - - if (GlowMask.HasContentInFramePos(xPos, yPos)) - { - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - Color drawColour = GetDrawColour(i, j, new Color(255, 255, 255, 255)); - Tile trackTile = Main.tile[i, j]; - float brightness = 1f; - float declareThisHereToPreventRunningTheSameCalculationMultipleTimes = Main.GameUpdateCount * 0.007f; - brightness *= (float)MathF.Sin(i / 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); - brightness *= (float)MathF.Sin(j / 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); - brightness *= (float)MathF.Sin(i * 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); - brightness *= (float)MathF.Sin(j * 18f + declareThisHereToPreventRunningTheSameCalculationMultipleTimes); - drawColour *= brightness; - - TileFramingSystem.SlopedGlowmask(i, j, 0, GlowMask.Texture, drawOffset, null, GetDrawColour(i, j, drawColour), default); - } - } - - private Color GetDrawColour(int i, int j, Color colour) - { - int colType = Main.tile[i, j].TileColor; - Color paintCol = WorldGen.paintColor(colType); - if (colType >= 13 && colType <= 24) - { - colour.R = (byte)(paintCol.R / 255f * colour.R); - colour.G = (byte)(paintCol.G / 255f * colour.G); - colour.B = (byte)(paintCol.B / 255f * colour.B); - } - return colour; + float brightness = 1f; + float timeFactor = Main.GameUpdateCount * 0.007f; + brightness *= (float)MathF.Sin(i / 18f + timeFactor); + brightness *= (float)MathF.Sin(j / 18f + timeFactor); + brightness *= (float)MathF.Sin(i * 18f + timeFactor); + brightness *= (float)MathF.Sin(j * 18f + timeFactor); + return Color.White * brightness; } } } diff --git a/Tiles/FurnitureVoid/VoidstoneSlab.cs b/Tiles/FurnitureVoid/VoidstoneSlab.cs index 1acda50480..eb5b1e2f82 100644 --- a/Tiles/FurnitureVoid/VoidstoneSlab.cs +++ b/Tiles/FurnitureVoid/VoidstoneSlab.cs @@ -1,14 +1,18 @@ -using Microsoft.Xna.Framework; +using CalamityMod.Systems; +using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; +using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Tiles.FurnitureVoid { - public class VoidstoneSlab : ModTile + public class VoidstoneSlab : GlowMaskTile { - public override void SetStaticDefaults() + public override string GlowMaskAsset => "CalamityMod/Tiles/FurnitureVoid/VoidstoneSlabGlow"; + + public override void SetupStatic() { Main.tileSolid[Type] = true; Main.tileMergeDirt[Type] = true; @@ -28,159 +32,12 @@ namespace CalamityMod.Tiles.FurnitureVoid public override void AnimateIndividualTile(int type, int i, int j, ref int frameXOffset, ref int frameYOffset) { - int uniqueAnimationFrame = Main.tileFrame[Type] + i; - int xPos = i % 3; - int yPos = j % 3; - switch (xPos) - { - case 0: - switch (yPos) - { - case 0: - uniqueAnimationFrame = 0; - break; - case 1: - uniqueAnimationFrame = 1; - break; - case 2: - uniqueAnimationFrame = 2; - break; - default: - uniqueAnimationFrame = 0; - break; - } - break; - case 1: - switch (yPos) - { - case 0: - uniqueAnimationFrame = 2; - break; - case 1: - uniqueAnimationFrame = 3; - break; - case 2: - uniqueAnimationFrame = 4; - break; - default: - uniqueAnimationFrame = 0; - break; - } - break; - case 2: - switch (yPos) - { - case 0: - uniqueAnimationFrame = 4; - break; - case 1: - uniqueAnimationFrame = 0; - break; - case 2: - uniqueAnimationFrame = 1; - break; - default: - uniqueAnimationFrame = 0; - break; - } - break; - } - - frameYOffset = uniqueAnimationFrame * AnimationFrameHeight; + frameYOffset = AnimationFrameHeight * TileFramingSystem.GetVariation3x3_01234_Low3(i, j); } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - if (Main.tile[i, j].TileType == ModContent.TileType()) - { - int xPos = Main.tile[i, j].TileFrameX; - int yPos = Main.tile[i, j].TileFrameY; - int yOffset = 0; - int relavtiveXPos = i % 3; - int relavtiveYPos = j % 3; - switch (relavtiveXPos) - { - case 0: - switch (relavtiveYPos) - { - case 0: - yOffset = 0; - break; - case 1: - yOffset = 1; - break; - case 2: - yOffset = 2; - break; - default: - yOffset = 0; - break; - } - break; - case 1: - switch (relavtiveYPos) - { - case 0: - yOffset = 2; - break; - case 1: - yOffset = 3; - break; - case 2: - yOffset = 4; - break; - default: - yOffset = 0; - break; - } - break; - case 2: - switch (relavtiveYPos) - { - case 0: - yOffset = 4; - break; - case 1: - yOffset = 0; - break; - case 2: - yOffset = 1; - break; - default: - yOffset = 0; - break; - } - break; - } - yOffset *= 270; - yPos += yOffset; - Texture2D glowmask = ModContent.Request("CalamityMod/Tiles/FurnitureVoid/VoidstoneSlabGlow").Value; - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - Color drawColour = GetDrawColour(i, j, new Color(75, 75, 75, 75)); - Tile trackTile = Main.tile[i, j]; - if (!trackTile.IsHalfBlock && trackTile.Slope == 0) - { - Main.spriteBatch.Draw(glowmask, drawOffset, new Rectangle?(new Rectangle(xPos, yPos, 18, 18)), drawColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - } - else if (trackTile.IsHalfBlock) - { - Main.spriteBatch.Draw(glowmask, drawOffset + new Vector2(0f, 8f), new Rectangle?(new Rectangle(xPos, yPos, 18, 8)), drawColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); - } - } - } - - private Color GetDrawColour(int i, int j, Color colour) - { - int colType = Main.tile[i, j].TileColor; - Color paintCol = WorldGen.paintColor(colType); - if (colType >= 13 && colType <= 24) - { - colour.R = (byte)(paintCol.R / 255f * colour.R); - colour.G = (byte)(paintCol.G / 255f * colour.G); - colour.B = (byte)(paintCol.B / 255f * colour.B); - } - return colour; + return new Color(75, 75, 75); } } } diff --git a/Tiles/GiantPlanteraBulb.cs b/Tiles/GiantPlanteraBulb.cs index 0d14f8dfcf..dfb8727821 100644 --- a/Tiles/GiantPlanteraBulb.cs +++ b/Tiles/GiantPlanteraBulb.cs @@ -13,17 +13,14 @@ using Terraria.ObjectData; namespace CalamityMod.Tiles { - public class GiantPlanteraBulb : ModTile + public class GiantPlanteraBulb : GlowMaskTile { - public static FramedGlowMask GlowMask { get; private set; } + public override string GlowMaskAsset => $"{Texture}Glow"; - public override void Load() + public override void SetupStatic() { - GlowMask = new($"{Texture}Glow", 18, 18); - } + GlowMaskPaintInteraction = PaintColorTint.None; - public override void SetStaticDefaults() - { // Tile can provide light Main.tileLighted[Type] = true; @@ -192,22 +189,9 @@ namespace CalamityMod.Tiles } } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - var tile = Main.tile[i, j]; - - var xPos = tile.TileFrameX; - var yPos = tile.TileFrameY + AnimationFrameHeight * Main.tileFrame[Type]; - - if (GlowMask.HasContentInFramePos(xPos, yPos)) - { - spriteBatch.Draw( - GlowMask.Texture, - new Vector2(i * 16, j * 16 + 2) - Main.screenPosition + CalamityUtils.TileDrawOffset, - new Rectangle(xPos, yPos, 16, 16), - Color.Yellow - ); - } + return Color.Yellow; } } } diff --git a/Tiles/Ores/AerialiteOre.cs b/Tiles/Ores/AerialiteOre.cs index 4c0aeb9049..c22543b639 100644 --- a/Tiles/Ores/AerialiteOre.cs +++ b/Tiles/Ores/AerialiteOre.cs @@ -1,12 +1,10 @@ - -using System.Collections.Generic; +using CalamityMod.Systems; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using Terraria; using Terraria.Audio; using Terraria.ID; -using Terraria.Localization; using Terraria.ModLoader; namespace CalamityMod.Tiles.Ores @@ -70,199 +68,26 @@ namespace CalamityMod.Tiles.Ores } public override void AnimateIndividualTile(int type, int i, int j, ref int frameXOffset, ref int frameYOffset) { - int uniqueAnimationFrameX = 0; - int xPos = i % 4; - int yPos = j % 4; - switch (xPos) - { - case 0: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 0; - break; - case 1: - uniqueAnimationFrameX = 2; - break; - case 2: - uniqueAnimationFrameX = 1; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - case 1: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 2; - break; - case 1: - uniqueAnimationFrameX = 0; - break; - case 2: - uniqueAnimationFrameX = 2; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - case 2: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 2; - break; - case 1: - uniqueAnimationFrameX = 0; - break; - case 2: - uniqueAnimationFrameX = 1; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - case 3: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 1; - break; - case 1: - uniqueAnimationFrameX = 2; - break; - case 2: - uniqueAnimationFrameX = 0; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - } - frameXOffset = uniqueAnimationFrameX * animationFrameWidth; + frameXOffset = animationFrameWidth * TileFramingSystem.GetVariation4x4_012_Low0(i, j); } public override void PostDraw(int i, int j, SpriteBatch spriteBatch) { if (GlowTexture is null) return; - int xPos = Main.tile[i, j].TileFrameX; - int yPos = Main.tile[i, j].TileFrameY; - int xOffset = 0; - int relativeXPos = i % 4; - int relativeYPos = j % 4; - switch (relativeXPos) - { - case 0: - switch (relativeYPos) - { - case 0: - xOffset = 0; - break; - case 1: - xOffset = 2; - break; - case 2: - xOffset = 1; - break; - case 3: - xOffset = 2; - break; - default: - xOffset = 2; - break; - } - break; - case 1: - switch (relativeYPos) - { - case 0: - xOffset = 2; - break; - case 1: - xOffset = 0; - break; - case 2: - xOffset = 2; - break; - case 3: - xOffset = 2; - break; - default: - xOffset = 2; - break; - } - break; - case 2: - switch (relativeYPos) - { - case 0: - xOffset = 2; - break; - case 1: - xOffset = 0; - break; - case 2: - xOffset = 1; - break; - case 3: - xOffset = 2; - break; - default: - xOffset = 2; - break; - } - break; - case 3: - switch (relativeYPos) - { - case 0: - xOffset = 1; - break; - case 1: - xOffset = 2; - break; - case 2: - xOffset = 0; - break; - case 3: - xOffset = 2; - break; - default: - xOffset = 2; - break; - } - break; - } - xOffset *= 234; + var tile = Main.tile[i, j]; + int xPos = tile.TileFrameX; + int yPos = tile.TileFrameY; + int xOffset = animationFrameWidth * TileFramingSystem.GetVariation4x4_012_Low0(i, j); xPos += xOffset; Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; Color drawColour = GetDrawColour(i, j, new Color(100, 100, 100, 50)); - Tile trackTile = Main.tile[i, j]; - - if (!trackTile.IsHalfBlock && trackTile.Slope == 0) + if (!tile.IsHalfBlock && tile.Slope == 0) { Main.spriteBatch.Draw(GlowTexture, drawOffset, new Rectangle?(new Rectangle(xPos, yPos, 18, 18)), drawColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); } - else if (trackTile.IsHalfBlock) + else if (tile.IsHalfBlock) { Main.spriteBatch.Draw(GlowTexture, drawOffset + new Vector2(0f, 8f), new Rectangle?(new Rectangle(xPos, yPos, 18, 8)), drawColour, 0.0f, Vector2.Zero, 1f, SpriteEffects.None, 0.0f); } diff --git a/Tiles/Ores/AerialiteOreDisenchanted.cs b/Tiles/Ores/AerialiteOreDisenchanted.cs index bd6f41dac4..9e067e8c91 100644 --- a/Tiles/Ores/AerialiteOreDisenchanted.cs +++ b/Tiles/Ores/AerialiteOreDisenchanted.cs @@ -1,4 +1,5 @@ using System.Collections.Generic; +using CalamityMod.Systems; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Terraria; @@ -59,93 +60,7 @@ namespace CalamityMod.Tiles.Ores public override void AnimateIndividualTile(int type, int i, int j, ref int frameXOffset, ref int frameYOffset) { - int uniqueAnimationFrameX = 0; - int xPos = i % 4; - int yPos = j % 4; - switch (xPos) - { - case 0: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 0; - break; - case 1: - uniqueAnimationFrameX = 2; - break; - case 2: - uniqueAnimationFrameX = 1; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - case 1: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 2; - break; - case 1: - uniqueAnimationFrameX = 0; - break; - case 2: - uniqueAnimationFrameX = 2; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - case 2: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 2; - break; - case 1: - uniqueAnimationFrameX = 0; - break; - case 2: - uniqueAnimationFrameX = 1; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - case 3: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 1; - break; - case 1: - uniqueAnimationFrameX = 2; - break; - case 2: - uniqueAnimationFrameX = 0; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - } - frameXOffset = uniqueAnimationFrameX * AnimationFrameWidth; + frameXOffset = AnimationFrameWidth * TileFramingSystem.GetVariation4x4_012_Low0(i, j); } } } diff --git a/Tiles/Ores/AuricOre.cs b/Tiles/Ores/AuricOre.cs index 851a2ab95b..db314ce609 100644 --- a/Tiles/Ores/AuricOre.cs +++ b/Tiles/Ores/AuricOre.cs @@ -15,18 +15,15 @@ using Terraria.ObjectData; namespace CalamityMod.Tiles.Ores { - public class AuricOre : ModTile + public class AuricOre : GlowMaskTile { public static readonly SoundStyle MineSound = new("CalamityMod/Sounds/Custom/AuricMine", 3); public static bool Animate; - internal static FramedGlowMask GlowMask; + public override string GlowMaskAsset => "CalamityMod/Tiles/Ores/AuricOreGlow"; - - public override void SetStaticDefaults() + public override void SetupStatic() { - GlowMask = new("CalamityMod/Tiles/Ores/AuricOreGlow", 18, 18); - AnimationFrameHeight = 90; Main.tileLighted[Type] = true; Main.tileSolid[Type] = true; @@ -86,33 +83,9 @@ namespace CalamityMod.Tiles.Ores } } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - int xPos = Main.tile[i, j].TileFrameX; - int yPos = Main.tile[i, j].TileFrameY + AnimationFrameHeight * Main.tileFrame[Type]; - - if (GlowMask.HasContentInFramePos(xPos, yPos)) - { - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - Color drawColour = GetDrawColour(i, j, new Color(225, 255, 255, 255)); - Tile trackTile = Main.tile[i, j]; - double num6 = Main.time * 0.08; - TileFramingSystem.SlopedGlowmask(i, j, 0, GlowMask.Texture, drawOffset, null, GetDrawColour(i, j, drawColour), default); - } - } - - private Color GetDrawColour(int i, int j, Color colour) - { - int colType = Main.tile[i, j].TileColor; - Color paintCol = WorldGen.paintColor(colType); - if (colType >= 13 && colType <= 24) - { - colour.R = (byte)(paintCol.R / 255f * colour.R); - colour.G = (byte)(paintCol.G / 255f * colour.G); - colour.B = (byte)(paintCol.B / 255f * colour.B); - } - return colour; + return Color.White; } } } diff --git a/Tiles/Ores/PerennialOre.cs b/Tiles/Ores/PerennialOre.cs index 5e163d274f..29706fc4e4 100644 --- a/Tiles/Ores/PerennialOre.cs +++ b/Tiles/Ores/PerennialOre.cs @@ -7,20 +7,21 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using Terraria; +using Terraria.DataStructures; using Terraria.ID; using Terraria.Localization; using Terraria.ModLoader; namespace CalamityMod.Tiles.Ores { - public class PerennialOre : ModTile + public class PerennialOre : GlowMaskTile { - internal static FramedGlowMask GlowMask; + public const int AnimationFrameWidth = 234; - public override void SetStaticDefaults() + public override string GlowMaskAsset => "CalamityMod/Tiles/Ores/PerennialOreGlow"; + + public override void SetupStatic() { - GlowMask = new("CalamityMod/Tiles/Ores/PerennialOreGlow", 18, 18); - Main.tileLighted[Type] = true; Main.tileSolid[Type] = true; Main.tileMergeDirt[Type] = true; @@ -46,7 +47,9 @@ namespace CalamityMod.Tiles.Ores this.RegisterUniversalMerge(TileID.Mud, "CalamityMod/Tiles/Merges/MudMerge"); } - int animationFrameWidth = 234; + + + public override bool CanExplode(int i, int j) { @@ -107,213 +110,12 @@ namespace CalamityMod.Tiles.Ores public override void AnimateIndividualTile(int type, int i, int j, ref int frameXOffset, ref int frameYOffset) { - int uniqueAnimationFrameX = 0; - int xPos = i % 4; - int yPos = j % 4; - switch (xPos) - { - case 0: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 0; - break; - case 1: - uniqueAnimationFrameX = 2; - break; - case 2: - uniqueAnimationFrameX = 1; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - case 1: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 2; - break; - case 1: - uniqueAnimationFrameX = 0; - break; - case 2: - uniqueAnimationFrameX = 2; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - case 2: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 2; - break; - case 1: - uniqueAnimationFrameX = 0; - break; - case 2: - uniqueAnimationFrameX = 1; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - case 3: - switch (yPos) - { - case 0: - uniqueAnimationFrameX = 1; - break; - case 1: - uniqueAnimationFrameX = 2; - break; - case 2: - uniqueAnimationFrameX = 0; - break; - case 3: - uniqueAnimationFrameX = 2; - break; - default: - uniqueAnimationFrameX = 2; - break; - } - break; - } - frameXOffset = uniqueAnimationFrameX * animationFrameWidth; + frameXOffset = AnimationFrameWidth * TileFramingSystem.GetVariation4x4_012_Low0(i, j); } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - if (GlowMask.Texture is null) - return; - - int xPos = Main.tile[i, j].TileFrameX; - int yPos = Main.tile[i, j].TileFrameY; - int xOffset = 0; - int relativeXPos = i % 4; - int relativeYPos = j % 4; - switch (relativeXPos) - { - case 0: - switch (relativeYPos) - { - case 0: - xOffset = 0; - break; - case 1: - xOffset = 2; - break; - case 2: - xOffset = 1; - break; - case 3: - xOffset = 2; - break; - default: - xOffset = 2; - break; - } - break; - case 1: - switch (relativeYPos) - { - case 0: - xOffset = 2; - break; - case 1: - xOffset = 0; - break; - case 2: - xOffset = 2; - break; - case 3: - xOffset = 2; - break; - default: - xOffset = 2; - break; - } - break; - case 2: - switch (relativeYPos) - { - case 0: - xOffset = 2; - break; - case 1: - xOffset = 0; - break; - case 2: - xOffset = 1; - break; - case 3: - xOffset = 2; - break; - default: - xOffset = 2; - break; - } - break; - case 3: - switch (relativeYPos) - { - case 0: - xOffset = 1; - break; - case 1: - xOffset = 2; - break; - case 2: - xOffset = 0; - break; - case 3: - xOffset = 2; - break; - default: - xOffset = 2; - break; - } - break; - } - - xOffset *= 234; - xPos += xOffset; - - if (GlowMask.HasContentInFramePos(xPos, yPos)) - { - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - Color drawColour = GetDrawColour(i, j, new Color(175, 175, 175, 175)); - Tile trackTile = Main.tile[i, j]; - TileFramingSystem.SlopedGlowmask(i, j, 0, GlowMask.Texture, drawOffset, null, GetDrawColour(i, j, drawColour), default); - } - } - - private Color GetDrawColour(int i, int j, Color colour) - { - int colType = Main.tile[i, j].TileColor; - Color paintCol = WorldGen.paintColor(colType); - if (colType >= 13 && colType <= 24) - { - colour.R = (byte)(paintCol.R / 255f * colour.R); - colour.G = (byte)(paintCol.G / 255f * colour.G); - colour.B = (byte)(paintCol.B / 255f * colour.B); - } - return colour; + return Color.White * 0.686f; } } } diff --git a/Tiles/Ores/ScoriaOre.cs b/Tiles/Ores/ScoriaOre.cs index 6801b8e6de..d29d32726f 100644 --- a/Tiles/Ores/ScoriaOre.cs +++ b/Tiles/Ores/ScoriaOre.cs @@ -13,14 +13,12 @@ using Terraria.ModLoader; namespace CalamityMod.Tiles.Ores { [LegacyName("ChaoticOre")] - public class ScoriaOre : ModTile + public class ScoriaOre : GlowMaskTile { - internal static FramedGlowMask GlowMask; + public override string GlowMaskAsset => "CalamityMod/Tiles/Ores/ScoriaOreGlow"; - public override void SetStaticDefaults() + public override void SetupStatic() { - GlowMask = new("CalamityMod/Tiles/Ores/ScoriaOreGlow", 18, 18); - Main.tileLighted[Type] = true; Main.tileSolid[Type] = true; Main.tileBlockLight[Type] = true; @@ -91,34 +89,10 @@ namespace CalamityMod.Tiles.Ores g = 0.00f; b = 0.00f; } - - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) - { - int xPos = Main.tile[i, j].TileFrameX; - int yPos = Main.tile[i, j].TileFrameY; - if (GlowMask.HasContentInFramePos(xPos, yPos)) - { - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - Color drawColour = GetDrawColour(i, j, new Color(50, 50, 50, 50)); - Tile trackTile = Main.tile[i, j]; - double num6 = Main.time * 0.08; - TileFramingSystem.SlopedGlowmask(i, j, 0, GlowMask.Texture, drawOffset, null, GetDrawColour(i, j, drawColour), default); - } - } - - private Color GetDrawColour(int i, int j, Color colour) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - int colType = Main.tile[i, j].TileColor; - Color paintCol = WorldGen.paintColor(colType); - if (colType >= 13 && colType <= 24) - { - colour.R = (byte)(paintCol.R / 255f * colour.R); - colour.G = (byte)(paintCol.G / 255f * colour.G); - colour.B = (byte)(paintCol.B / 255f * colour.B); - } - return colour; + return Color.White * 0.195f; } } } diff --git a/Tiles/Plates/Cinderplate.cs b/Tiles/Plates/Cinderplate.cs index d9f596d9da..f59526667e 100644 --- a/Tiles/Plates/Cinderplate.cs +++ b/Tiles/Plates/Cinderplate.cs @@ -1,30 +1,26 @@  -using CalamityMod.Systems; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using Terraria; using Terraria.Audio; +using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Tiles.Plates { - public class Cinderplate : ModTile + public class Cinderplate : GlowMaskTile { + public override string GlowMaskAsset => "CalamityMod/Tiles/Plates/CinderplateGlow"; + public static readonly SoundStyle MinePlatingSound = new("CalamityMod/Sounds/Custom/PlatingMine", 3); - internal static Texture2D GlowTexture; - internal static Texture2D PulseTexture; - internal static Color[] PulseColors; - public override void SetStaticDefaults() + internal static GrayscaleTexture1D PulseGradient; + + public override void SetupStatic() { - if (!Main.dedServ) - { - PulseTexture = ModContent.Request("CalamityMod/Tiles/Plates/CinderplatePulse", AssetRequestMode.ImmediateLoad).Value; - PulseColors = new Color[PulseTexture.Width]; - Main.QueueMainThreadAction(() => PulseTexture.GetData(PulseColors)); - GlowTexture = ModContent.Request("CalamityMod/Tiles/Plates/CinderplateGlow", AssetRequestMode.ImmediateLoad).Value; - } + PulseGradient = new("CalamityMod/Tiles/Plates/CinderplatePulse"); + Main.tileSolid[Type] = true; Main.tileMergeDirt[Type] = true; Main.tileBlockLight[Type] = true; @@ -36,6 +32,12 @@ namespace CalamityMod.Tiles.Plates AddMapEntry(new Color(242, 216, 131)); } + public override void OnUnload() + { + PulseGradient?.Unload(); + PulseGradient = null; + } + public override bool CreateDust(int i, int j, ref int type) { Dust.NewDust(new Vector2(i, j) * 16f, 16, 16, DustID.Torch, 0f, 0f, 1, new Color(255, 255, 255), 1f); @@ -48,41 +50,11 @@ namespace CalamityMod.Tiles.Plates Dust.NewDust(new Vector2(i, j) * 16f, 16, 16, DustID.Torch, 0f, 0f, 1, new Color(255, 255, 255), 1f); } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - // If the cached textures don't exist for some reason, don't bother using them. - if (GlowTexture is null || PulseTexture is null) - return; - - int xPos = Main.tile[i, j].TileFrameX; - int yPos = Main.tile[i, j].TileFrameY; - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - - // Glowmask 'pulse' effect - int factor = (int)Main.GameUpdateCount % PulseTexture.Width; - float brightness = PulseColors[factor].R / 255f; - int drawBrightness = (int)(40 * brightness) + 10; - Color drawColour = GetDrawColour(i, j, new Color(drawBrightness, drawBrightness, drawBrightness, drawBrightness)); - - // If these tiles cause lag, comment out the pulse effect code and uncomment this: - //Color drawColour = GetDrawColour(i, j, new Color(50, 50, 50, 50)); - - Tile trackTile = Main.tile[i, j]; - TileFramingSystem.SlopedGlowmask(i, j, 0, GlowTexture, drawOffset, null, GetDrawColour(i, j, drawColour), default); - } - - private Color GetDrawColour(int i, int j, Color colour) - { - int colType = Main.tile[i, j].TileColor; - Color paintCol = WorldGen.paintColor(colType); - if (colType >= 13 && colType <= 24) - { - colour.R = (byte)(paintCol.R / 255f * colour.R); - colour.G = (byte)(paintCol.G / 255f * colour.G); - colour.B = (byte)(paintCol.B / 255f * colour.B); - } - return colour; + float brightness = PulseGradient.GetRepeat((int)Main.GameUpdateCount); + brightness = 0.04f + (brightness * 0.156f); + return Color.White * brightness; } } } diff --git a/Tiles/Plates/Elumplate.cs b/Tiles/Plates/Elumplate.cs index 251e42818b..9578aae8e5 100644 --- a/Tiles/Plates/Elumplate.cs +++ b/Tiles/Plates/Elumplate.cs @@ -1,30 +1,26 @@  -using CalamityMod.Systems; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using Terraria; using Terraria.Audio; +using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Tiles.Plates { - public class Elumplate : ModTile + public class Elumplate : GlowMaskTile { + public override string GlowMaskAsset => "CalamityMod/Tiles/Plates/ElumplateGlow"; + public static readonly SoundStyle MinePlatingSound = new("CalamityMod/Sounds/Custom/PlatingMine", 3); - internal static Texture2D GlowTexture; - internal static Texture2D PulseTexture; - internal static Color[] PulseColors; - public override void SetStaticDefaults() + internal static GrayscaleTexture1D PulseGradient; + + public override void SetupStatic() { - if (!Main.dedServ) - { - PulseTexture = ModContent.Request("CalamityMod/Tiles/Plates/ElumplatePulse", AssetRequestMode.ImmediateLoad).Value; - PulseColors = new Color[PulseTexture.Width]; - Main.QueueMainThreadAction(() => PulseTexture.GetData(PulseColors)); - GlowTexture = ModContent.Request("CalamityMod/Tiles/Plates/ElumplateGlow", AssetRequestMode.ImmediateLoad).Value; - } + PulseGradient = new("CalamityMod/Tiles/Plates/ElumplatePulse"); + Main.tileSolid[Type] = true; Main.tileMergeDirt[Type] = true; Main.tileBlockLight[Type] = true; @@ -35,6 +31,12 @@ namespace CalamityMod.Tiles.Plates MineResist = 1f; AddMapEntry(new Color(121, 180, 212)); } + public override void OnUnload() + { + PulseGradient?.Unload(); + PulseGradient = null; + } + public override bool CreateDust(int i, int j, ref int type) { @@ -48,41 +50,11 @@ namespace CalamityMod.Tiles.Plates Dust.NewDust(new Vector2(i, j) * 16f, 16, 16, DustID.PlatinumCoin, 0f, 0f, 1, new Color(255, 255, 255), 1f); } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - // If the cached textures don't exist for some reason, don't bother using them. - if (GlowTexture is null || PulseTexture is null) - return; - - int xPos = Main.tile[i, j].TileFrameX; - int yPos = Main.tile[i, j].TileFrameY; - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - - // Glowmask 'pulse' effect - int factor = (int)Main.GameUpdateCount % PulseTexture.Width; - float brightness = PulseColors[factor].R / 255f; - int drawBrightness = (int)(40 * brightness) + 10; - Color drawColour = GetDrawColour(i, j, new Color(drawBrightness, drawBrightness, drawBrightness, drawBrightness)); - - // If these tiles cause lag, comment out the pulse effect code and uncomment this: - //Color drawColour = GetDrawColour(i, j, new Color(50, 50, 50, 50)); - - Tile trackTile = Main.tile[i, j]; - TileFramingSystem.SlopedGlowmask(i, j, 0, GlowTexture, drawOffset, null, GetDrawColour(i, j, drawColour), default); - } - - private Color GetDrawColour(int i, int j, Color colour) - { - int colType = Main.tile[i, j].TileColor; - Color paintCol = WorldGen.paintColor(colType); - if (colType >= 13 && colType <= 24) - { - colour.R = (byte)(paintCol.R / 255f * colour.R); - colour.G = (byte)(paintCol.G / 255f * colour.G); - colour.B = (byte)(paintCol.B / 255f * colour.B); - } - return colour; + float brightness = PulseGradient.GetRepeat((int)Main.GameUpdateCount); + brightness = 0.04f + (brightness * 0.156f); + return Color.White * brightness; } } } diff --git a/Tiles/Plates/Havocplate.cs b/Tiles/Plates/Havocplate.cs index 5893e6765a..92040fd0a1 100644 --- a/Tiles/Plates/Havocplate.cs +++ b/Tiles/Plates/Havocplate.cs @@ -1,32 +1,28 @@  -using CalamityMod.Systems; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using Terraria; using Terraria.Audio; +using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Tiles.Plates { [LegacyName("Chaosplate")] - public class Havocplate : ModTile + public class Havocplate : GlowMaskTile { - public static readonly SoundStyle MinePlatingSound = new("CalamityMod/Sounds/Custom/PlatingMine", 3); - internal static Texture2D GlowTexture; - internal static Texture2D PulseTexture; - internal static Color[] PulseColors; + public override string GlowMaskAsset => "CalamityMod/Tiles/Plates/HavocplateGlow"; - public override void SetStaticDefaults() + public static readonly SoundStyle MinePlatingSound = new("CalamityMod/Sounds/Custom/PlatingMine", 3); + + internal static GrayscaleTexture1D PulseGradient; + + public override void SetupStatic() { - if (!Main.dedServ) - { - PulseTexture = ModContent.Request("CalamityMod/Tiles/Plates/HavocplatePulse", AssetRequestMode.ImmediateLoad).Value; - PulseColors = new Color[PulseTexture.Width]; - Main.QueueMainThreadAction(() => PulseTexture.GetData(PulseColors)); - GlowTexture = ModContent.Request("CalamityMod/Tiles/Plates/HavocplateGlow", AssetRequestMode.ImmediateLoad).Value; - } + PulseGradient = new("CalamityMod/Tiles/Plates/HavocplatePulse"); + Main.tileSolid[Type] = true; Main.tileMergeDirt[Type] = true; Main.tileBlockLight[Type] = true; @@ -38,6 +34,12 @@ namespace CalamityMod.Tiles.Plates AddMapEntry(new Color(235, 108, 108)); } + public override void OnUnload() + { + PulseGradient?.Unload(); + PulseGradient = null; + } + public override bool CreateDust(int i, int j, ref int type) { Dust.NewDust(new Vector2(i, j) * 16f, 16, 16, DustID.RedTorch, 0f, 0f, 1, new Color(255, 255, 255), 1f); @@ -50,41 +52,11 @@ namespace CalamityMod.Tiles.Plates Dust.NewDust(new Vector2(i, j) * 16f, 16, 16, DustID.RedTorch, 0f, 0f, 1, new Color(255, 255, 255), 1f); } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - // If the cached textures don't exist for some reason, don't bother using them. - if (GlowTexture is null || PulseTexture is null) - return; - - int xPos = Main.tile[i, j].TileFrameX; - int yPos = Main.tile[i, j].TileFrameY; - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - - // Glowmask 'pulse' effect - int factor = (int)Main.GameUpdateCount % PulseTexture.Width; - float brightness = PulseColors[factor].R / 255f; - int drawBrightness = (int)(40 * brightness) + 10; - Color drawColour = GetDrawColour(i, j, new Color(drawBrightness, drawBrightness, drawBrightness, drawBrightness)); - - // If these tiles cause lag, comment out the pulse effect code and uncomment this: - //Color drawColour = GetDrawColour(i, j, new Color(50, 50, 50, 50)); - - Tile trackTile = Main.tile[i, j]; - TileFramingSystem.SlopedGlowmask(i, j, 0, GlowTexture, drawOffset, null, GetDrawColour(i, j, drawColour), default); - } - - private Color GetDrawColour(int i, int j, Color colour) - { - int colType = Main.tile[i, j].TileColor; - Color paintCol = WorldGen.paintColor(colType); - if (colType >= 13 && colType <= 24) - { - colour.R = (byte)(paintCol.R / 255f * colour.R); - colour.G = (byte)(paintCol.G / 255f * colour.G); - colour.B = (byte)(paintCol.B / 255f * colour.B); - } - return colour; + float brightness = PulseGradient.GetRepeat((int)Main.GameUpdateCount); + brightness = 0.04f + (brightness * 0.156f); + return Color.White * brightness; } } } diff --git a/Tiles/Plates/Navyplate.cs b/Tiles/Plates/Navyplate.cs index a297c08941..af79386386 100644 --- a/Tiles/Plates/Navyplate.cs +++ b/Tiles/Plates/Navyplate.cs @@ -1,30 +1,26 @@  -using CalamityMod.Systems; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using Terraria; using Terraria.Audio; +using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Tiles.Plates { - public class Navyplate : ModTile + public class Navyplate : GlowMaskTile { + public override string GlowMaskAsset => "CalamityMod/Tiles/Plates/NavyplateGlow"; + public static readonly SoundStyle MinePlatingSound = new("CalamityMod/Sounds/Custom/PlatingMine", 3); - internal static Texture2D GlowTexture; - internal static Texture2D PulseTexture; - internal static Color[] PulseColors; - public override void SetStaticDefaults() + internal static GrayscaleTexture1D PulseGradient; + + public override void SetupStatic() { - if (!Main.dedServ) - { - PulseTexture = ModContent.Request("CalamityMod/Tiles/Plates/NavyplatePulse", AssetRequestMode.ImmediateLoad).Value; - PulseColors = new Color[PulseTexture.Width]; - Main.QueueMainThreadAction(() => PulseTexture.GetData(PulseColors)); - GlowTexture = ModContent.Request("CalamityMod/Tiles/Plates/NavyplateGlow", AssetRequestMode.ImmediateLoad).Value; - } + PulseGradient = new("CalamityMod/Tiles/Plates/NavyplatePulse"); + Main.tileSolid[Type] = true; Main.tileMergeDirt[Type] = true; Main.tileBlockLight[Type] = true; @@ -36,6 +32,12 @@ namespace CalamityMod.Tiles.Plates AddMapEntry(new Color(85, 151, 196)); } + public override void OnUnload() + { + PulseGradient?.Unload(); + PulseGradient = null; + } + public override bool CreateDust(int i, int j, ref int type) { Dust.NewDust(new Vector2(i, j) * 16f, 16, 16, DustID.Flare_Blue, 0f, 0f, 1, new Color(255, 255, 255), 1f); @@ -48,41 +50,11 @@ namespace CalamityMod.Tiles.Plates Dust.NewDust(new Vector2(i, j) * 16f, 16, 16, DustID.Flare_Blue, 0f, 0f, 1, new Color(255, 255, 255), 1f); } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - // If the cached textures don't exist for some reason, don't bother using them. - if (GlowTexture is null || PulseTexture is null) - return; - - int xPos = Main.tile[i, j].TileFrameX; - int yPos = Main.tile[i, j].TileFrameY; - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - - // Glowmask 'pulse' effect - int factor = (int)Main.GameUpdateCount % PulseTexture.Width; - float brightness = PulseColors[factor].R / 255f; - int drawBrightness = (int)(40 * brightness) + 10; - Color drawColour = GetDrawColour(i, j, new Color(drawBrightness, drawBrightness, drawBrightness, drawBrightness)); - - // If these tiles cause lag, comment out the pulse effect code and uncomment this: - //Color drawColour = GetDrawColour(i, j, new Color(50, 50, 50, 50)); - - Tile trackTile = Main.tile[i, j]; - TileFramingSystem.SlopedGlowmask(i, j, 0, GlowTexture, drawOffset, null, GetDrawColour(i, j, drawColour), default); - } - - private Color GetDrawColour(int i, int j, Color colour) - { - int colType = Main.tile[i, j].TileColor; - Color paintCol = WorldGen.paintColor(colType); - if (colType >= 13 && colType <= 24) - { - colour.R = (byte)(paintCol.R / 255f * colour.R); - colour.G = (byte)(paintCol.G / 255f * colour.G); - colour.B = (byte)(paintCol.B / 255f * colour.B); - } - return colour; + float brightness = PulseGradient.GetRepeat((int)Main.GameUpdateCount); + brightness = 0.04f + (brightness * 0.156f); + return Color.White * brightness; } } } diff --git a/Tiles/Plates/Onyxplate.cs b/Tiles/Plates/Onyxplate.cs index 4fd164dd66..35af4fe794 100644 --- a/Tiles/Plates/Onyxplate.cs +++ b/Tiles/Plates/Onyxplate.cs @@ -4,26 +4,22 @@ using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using Terraria; using Terraria.Audio; +using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Tiles.Plates { - public class Onyxplate : ModTile + public class Onyxplate : GlowMaskTile { + public override string GlowMaskAsset => "CalamityMod/Tiles/Plates/OnyxplateGlow"; + public static readonly SoundStyle MinePlatingSound = new("CalamityMod/Sounds/Custom/PlatingMine", 3); - internal static Texture2D GlowTexture; - internal static Texture2D PulseTexture; - internal static Color[] PulseColors; - public override void SetStaticDefaults() + internal static GrayscaleTexture1D PulseGradient; + public override void SetupStatic() { - if (!Main.dedServ) - { - PulseTexture = ModContent.Request("CalamityMod/Tiles/Plates/OnyxplatePulse", AssetRequestMode.ImmediateLoad).Value; - PulseColors = new Color[PulseTexture.Width]; - Main.QueueMainThreadAction(() => PulseTexture.GetData(PulseColors)); - GlowTexture = ModContent.Request("CalamityMod/Tiles/Plates/OnyxplateGlow", AssetRequestMode.ImmediateLoad).Value; - } + PulseGradient = new("CalamityMod/Tiles/Plates/OnyxplatePulse"); + Main.tileSolid[Type] = true; Main.tileMergeDirt[Type] = true; Main.tileBlockLight[Type] = true; @@ -36,41 +32,17 @@ namespace CalamityMod.Tiles.Plates AddMapEntry(new Color(182, 28, 232)); } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override void OnUnload() { - // If the cached textures don't exist for some reason, don't bother using them. - if (GlowTexture is null || PulseTexture is null) - return; - - int xPos = Main.tile[i, j].TileFrameX; - int yPos = Main.tile[i, j].TileFrameY; - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - - // Glowmask 'pulse' effect - int factor = (int)Main.GameUpdateCount % PulseTexture.Width; - float brightness = PulseColors[factor].R / 255f; - int drawBrightness = (int)(80 * brightness) + 10; - Color drawColour = GetDrawColour(i, j, new Color(drawBrightness, drawBrightness, drawBrightness, drawBrightness)); - - // If these tiles cause lag, comment out the pulse effect code and uncomment this: - //Color drawColour = GetDrawColour(i, j, new Color(50, 50, 50, 50)); - - Tile trackTile = Main.tile[i, j]; - TileFramingSystem.SlopedGlowmask(i, j, 0, GlowTexture, drawOffset, null, GetDrawColour(i, j, drawColour), default); + PulseGradient?.Unload(); + PulseGradient = null; } - private Color GetDrawColour(int i, int j, Color colour) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - int colType = Main.tile[i, j].TileColor; - Color paintCol = WorldGen.paintColor(colType); - if (colType >= 13 && colType <= 24) - { - colour.R = (byte)(paintCol.R / 255f * colour.R); - colour.G = (byte)(paintCol.G / 255f * colour.G); - colour.B = (byte)(paintCol.B / 255f * colour.B); - } - return colour; + float brightness = PulseGradient.GetRepeat((int)Main.GameUpdateCount); + brightness = 0.04f + (brightness * 0.31f); + return Color.White * brightness; } } } diff --git a/Tiles/Plates/PlagueContainmentCells.cs b/Tiles/Plates/PlagueContainmentCells.cs index e022ee4dc3..f06f934d1c 100644 --- a/Tiles/Plates/PlagueContainmentCells.cs +++ b/Tiles/Plates/PlagueContainmentCells.cs @@ -4,26 +4,22 @@ using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using Terraria; using Terraria.Audio; +using Terraria.DataStructures; using Terraria.ID; using Terraria.ModLoader; namespace CalamityMod.Tiles.Plates { - public class PlagueContainmentCells : ModTile + public class PlagueContainmentCells : GlowMaskTile { + public override string GlowMaskAsset => "CalamityMod/Tiles/Plates/PlagueContainmentCellsGlow"; + public static readonly SoundStyle MinePlatingSound = new("CalamityMod/Sounds/Custom/PlatingMine", 3); - internal static Texture2D GlowTexture; - internal static Texture2D PulseTexture; - internal static Color[] PulseColors; - public override void SetStaticDefaults() + internal static GrayscaleTexture1D PulseGradient; + public override void SetupStatic() { - if (!Main.dedServ) - { - PulseTexture = ModContent.Request("CalamityMod/Tiles/Plates/PlagueContainmentCellsPulse", AssetRequestMode.ImmediateLoad).Value; - PulseColors = new Color[PulseTexture.Width]; - Main.QueueMainThreadAction(() => PulseTexture.GetData(PulseColors)); - GlowTexture = ModContent.Request("CalamityMod/Tiles/Plates/PlagueContainmentCellsGlow", AssetRequestMode.ImmediateLoad).Value; - } + PulseGradient = new("CalamityMod/Tiles/Plates/PlagueContainmentCellsPulse"); + Main.tileSolid[Type] = true; Main.tileMergeDirt[Type] = true; Main.tileBlockLight[Type] = true; @@ -35,6 +31,12 @@ namespace CalamityMod.Tiles.Plates AddMapEntry(new Color(128, 188, 67)); } + public override void OnUnload() + { + PulseGradient?.Unload(); + PulseGradient = null; + } + public override bool CreateDust(int i, int j, ref int type) { int dust = Dust.NewDust(new Vector2(i, j) * 16f, 16, 16, DustID.GemEmerald, 0f, 0f, 100, default, 2f); @@ -52,41 +54,11 @@ namespace CalamityMod.Tiles.Plates Main.dust[dust].velocity.Y = -0.15f; } - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) { - // If the cached textures don't exist for some reason, don't bother using them. - if (GlowTexture is null || PulseTexture is null) - return; - - int xPos = Main.tile[i, j].TileFrameX; - int yPos = Main.tile[i, j].TileFrameY; - Vector2 zero = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawOffset = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + zero; - - // Glowmask 'pulse' effect - int factor = (int)Main.GameUpdateCount % PulseTexture.Width; - float brightness = PulseColors[factor].R / 255f; - int drawBrightness = (int)(40 * brightness) + 10; - Color drawColour = GetDrawColour(i, j, new Color(drawBrightness, drawBrightness, drawBrightness, drawBrightness)); - - // If these tiles cause lag, comment out the pulse effect code and uncomment this: - //Color drawColour = GetDrawColour(i, j, new Color(50, 50, 50, 50)); - - Tile trackTile = Main.tile[i, j]; - TileFramingSystem.SlopedGlowmask(i, j, 0, GlowTexture, drawOffset, null, GetDrawColour(i, j, drawColour), default); - } - - private Color GetDrawColour(int i, int j, Color colour) - { - int colType = Main.tile[i, j].TileColor; - Color paintCol = WorldGen.paintColor(colType); - if (colType >= 13 && colType <= 24) - { - colour.R = (byte)(paintCol.R / 255f * colour.R); - colour.G = (byte)(paintCol.G / 255f * colour.G); - colour.B = (byte)(paintCol.B / 255f * colour.B); - } - return colour; + float brightness = PulseGradient.GetRepeat((int)Main.GameUpdateCount); + brightness = 0.04f + (brightness * 0.156f); + return Color.White * brightness; } } } diff --git a/Tiles/Rubblemaker/SunkenSea/FanCoralEcho.cs b/Tiles/Rubblemaker/SunkenSea/FanCoralEcho.cs index 621d2a1ccd..73da906b60 100644 --- a/Tiles/Rubblemaker/SunkenSea/FanCoralEcho.cs +++ b/Tiles/Rubblemaker/SunkenSea/FanCoralEcho.cs @@ -1,4 +1,5 @@ using CalamityMod.Items.Placeables; +using CalamityMod.Waters; using Microsoft.Xna.Framework; using Terraria; using Terraria.Enums; @@ -31,7 +32,7 @@ namespace CalamityMod.Tiles.Rubblemaker.SunkenSea public override void NearbyEffects(int i, int j, bool closer) { if (!Main.dedServ) - Main.SceneMetrics.ActiveFountainColor = ModContent.Find("CalamityMod/SunkenSeaWater").Slot; + Main.SceneMetrics.ActiveFountainColor = BasaltGullyWater.Type; } public override void NumDust(int i, int j, bool fail, ref int num) diff --git a/Tiles/ScoriaBrick.cs b/Tiles/ScoriaBrick.cs index 46f061f57b..5cb0edfa21 100644 --- a/Tiles/ScoriaBrick.cs +++ b/Tiles/ScoriaBrick.cs @@ -4,6 +4,7 @@ using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using ReLogic.Content; using Terraria; +using Terraria.DataStructures; using Terraria.GameContent.Metadata; using Terraria.ID; using Terraria.ModLoader; @@ -11,16 +12,14 @@ using Terraria.ModLoader; namespace CalamityMod.Tiles { [LegacyName("ChaoticBrick")] - public class ScoriaBrick : ModTile + public class ScoriaBrick : GlowMaskTile { + public override string GlowMaskAsset => "CalamityMod/Tiles/ScoriaBrickGlow"; + int subsheetHeight = 72; - internal static FramedGlowMask GlowMask; - - public override void SetStaticDefaults() + public override void SetupStatic() { - GlowMask = new("CalamityMod/Tiles/ScoriaBrickGlow", 18, 18); - Main.tileLighted[Type] = true; Main.tileSolid[Type] = true; Main.tileBlockLight[Type] = true; @@ -50,42 +49,15 @@ namespace CalamityMod.Tiles frameYOffset = yPos * subsheetHeight; } + public override Color GetGlowMaskColor(int i, int j, TileDrawInfo drawData) + { + return Color.White; + } + public override bool TileFrame(int i, int j, ref bool resetFrame, ref bool noBreak) { TileFramingSystem.CompactFraming(i, j, resetFrame); return false; } - - public override void PostDraw(int i, int j, SpriteBatch spriteBatch) - { - // If the cached textures don't exist for some reason, don't bother using them. - if (GlowMask.Texture is null) - return; - - Tile tile = CalamityUtils.ParanoidTileRetrieval(i, j); - int xPos = tile.TileFrameX; - int frameOffset = j % 2 * 72; - int yPos = tile.TileFrameY + frameOffset; - - if (GlowMask.HasContentInFramePos(xPos, yPos)) - { - Color drawColour = GetDrawColour(i, j, Color.White); - Vector2 drawOffset = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange); - Vector2 drawPosition = new Vector2(i * 16 - Main.screenPosition.X, j * 16 - Main.screenPosition.Y) + drawOffset; - TileFramingSystem.SlopedGlowmask(i, j, 0, GlowMask.Texture, drawPosition + new Vector2(0f, 8f), new Rectangle?(new Rectangle(xPos, yPos, 18, 8)), GetDrawColour(i, j, drawColour), default); - } - } - private Color GetDrawColour(int i, int j, Color colour) - { - int colType = Main.tile[i, j].TileColor; - Color paintCol = WorldGen.paintColor(colType); - if (colType >= 13 && colType <= 24) - { - colour.R = (byte)(paintCol.R / 255f * colour.R); - colour.G = (byte)(paintCol.G / 255f * colour.G); - colour.B = (byte)(paintCol.B / 255f * colour.B); - } - return colour; - } } } diff --git a/Tiles/SunkenSea/Ambient/FanCoral.cs b/Tiles/SunkenSea/Ambient/FanCoral.cs index 26e5feed73..ecf774185d 100644 --- a/Tiles/SunkenSea/Ambient/FanCoral.cs +++ b/Tiles/SunkenSea/Ambient/FanCoral.cs @@ -1,4 +1,4 @@ -using System; +using CalamityMod.Waters; using Microsoft.Xna.Framework; using Terraria; using Terraria.Enums; @@ -26,7 +26,7 @@ namespace CalamityMod.Tiles.SunkenSea.Ambient public override void NearbyEffects(int i, int j, bool closer) { if (!Main.dedServ) - Main.SceneMetrics.ActiveFountainColor = ModContent.Find("CalamityMod/SunkenSeaBurrowsWater").Slot; + Main.SceneMetrics.ActiveFountainColor = SunkenSeaBurrowsWater.Type; } public override void NumDust(int i, int j, bool fail, ref int num) diff --git a/Tiles/SunkenSea/EutrophicGlass.cs b/Tiles/SunkenSea/EutrophicGlass.cs index 4b2d2cdf0e..b7831db43e 100644 --- a/Tiles/SunkenSea/EutrophicGlass.cs +++ b/Tiles/SunkenSea/EutrophicGlass.cs @@ -14,8 +14,12 @@ namespace CalamityMod.Tiles.SunkenSea private static int sheetWidth = 216; private static int sheetHeight = 72; + public static int TypeCache; + public override void SetStaticDefaults() { + TypeCache = Type; + Main.tileSolid[Type] = true; Main.tileBlockLight[Type] = false; CalamityUtils.MergeWithGeneral(Type); @@ -54,9 +58,7 @@ namespace CalamityMod.Tiles.SunkenSea Rectangle frame = new Rectangle(tile.TileFrameX + frameXOffset, tile.TileFrameY + frameYOffset, 16, 16); Color color = Lighting.GetColor(i, j) * transparency; - Vector2 offScreenRange = Main.drawToScreen ? Vector2.Zero : new Vector2(Main.offScreenRange, Main.offScreenRange); - Vector2 drawPos = new Vector2(i * 16, j * 16) - Main.screenPosition + offScreenRange; - TileFramingSystem.SlopedGlowmask(i, j, tile.TileType, tex, drawPos, frame, GetDrawColour(i, j, color), default); + TileFramingSystem.SlopedGlowmask(in tile, i, j, tex, frame, GetDrawColour(i, j, color), default); } private Color GetDrawColour(int i, int j, Color colour) diff --git a/Tiles/SunkenSea/EutrophicSand.cs b/Tiles/SunkenSea/EutrophicSand.cs index b4feea3854..4bb35609b7 100644 --- a/Tiles/SunkenSea/EutrophicSand.cs +++ b/Tiles/SunkenSea/EutrophicSand.cs @@ -9,6 +9,7 @@ using Terraria.GameContent.Metadata; using Terraria.ID; using Terraria.Localization; using Terraria.ModLoader; +using Terraria.ModLoader.UI.ModBrowser; namespace CalamityMod.Tiles.SunkenSea { @@ -41,80 +42,91 @@ namespace CalamityMod.Tiles.SunkenSea public override void RandomUpdate(int i, int j) { + if (!WorldGen.genRand.NextBool(8)) + return; + Tile tile = Main.tile[i, j]; + if (tile.HasTile || tile.LiquidAmount <= 0) + return; + + if (tile.LeftSlope || tile.RightSlope || tile.IsHalfBlock) + return; + Tile up = Main.tile[i, j - 1]; + if (up.HasTile || up.LiquidAmount <= 0) + return; + Tile up2 = Main.tile[i, j - 2]; + if (up2.HasTile || up2.LiquidAmount <= 0) + return; - if (!up.HasTile && !up2.HasTile && up.LiquidAmount > 0 && up2.LiquidAmount > 0 && !tile.LeftSlope && !tile.RightSlope && !tile.IsHalfBlock) + // Place corals + if (WorldGen.genRand.NextBool(3)) { - // Place corals - if (WorldGen.genRand.NextBool(3)) + up.TileType = (ushort)ModContent.TileType(); + up.HasTile = true; + up.TileFrameY = 0; + + // 15 different frames, choose a random one + up.TileFrameX = (short)(WorldGen.genRand.Next(15) * 18); + WorldGen.SquareTileFrame(i, j - 1, true); + + if (Main.netMode == NetmodeID.Server) { - up.TileType = (ushort)ModContent.TileType(); - up.HasTile = true; - up.TileFrameY = 0; - - // 15 different frames, choose a random one - up.TileFrameX = (short)(WorldGen.genRand.Next(15) * 18); - WorldGen.SquareTileFrame(i, j - 1, true); - - if (Main.netMode == NetmodeID.Server) - { - NetMessage.SendTileSquare(-1, i, j - 1, 3, TileChangeType.None); - } + NetMessage.SendTileSquare(-1, i, j - 1, 3, TileChangeType.None); } + } - //multi-colored corals - if (WorldGen.genRand.NextBool(3)) - { - ushort[] ColoredCorals = new ushort[] { (ushort)ModContent.TileType(), + //multi-colored corals + if (WorldGen.genRand.NextBool(3)) + { + ushort[] ColoredCorals = new ushort[] { (ushort)ModContent.TileType(), (ushort)ModContent.TileType(), (ushort)ModContent.TileType() }; - ushort newObject = Main.rand.Next(ColoredCorals); + ushort newObject = Main.rand.Next(ColoredCorals); - WorldGen.PlaceObject(i, j - 1, newObject, true); - NetMessage.SendObjectPlacement(-1, i, j - 1, newObject, 0, 0, -1, -1); - } + WorldGen.PlaceObject(i, j - 1, newObject, true); + NetMessage.SendObjectPlacement(-1, i, j - 1, newObject, 0, 0, -1, -1); + } - //blue coral trees - if (WorldGen.genRand.NextBool(6)) - { - ushort[] BlueCorals = new ushort[] { (ushort)ModContent.TileType(), (ushort)ModContent.TileType() }; + //blue coral trees + if (WorldGen.genRand.NextBool(6)) + { + ushort[] BlueCorals = new ushort[] { (ushort)ModContent.TileType(), (ushort)ModContent.TileType() }; - ushort newObject = Main.rand.Next(BlueCorals); + ushort newObject = Main.rand.Next(BlueCorals); - WorldGen.PlaceObject(i, j - 1, newObject, true); - NetMessage.SendObjectPlacement(-1, i, j - 1, newObject, 0, 0, -1, -1); - } + WorldGen.PlaceObject(i, j - 1, newObject, true); + NetMessage.SendObjectPlacement(-1, i, j - 1, newObject, 0, 0, -1, -1); + } - //brown coral trees - if (WorldGen.genRand.NextBool(6)) - { - ushort[] BrownCorals = new ushort[] { (ushort)ModContent.TileType(), (ushort)ModContent.TileType() }; + //brown coral trees + if (WorldGen.genRand.NextBool(6)) + { + ushort[] BrownCorals = new ushort[] { (ushort)ModContent.TileType(), (ushort)ModContent.TileType() }; - ushort newObject = Main.rand.Next(BrownCorals); + ushort newObject = Main.rand.Next(BrownCorals); - WorldGen.PlaceObject(i, j - 1, newObject, true); - NetMessage.SendObjectPlacement(-1, i, j - 1, newObject, 0, 0, -1, -1); - } + WorldGen.PlaceObject(i, j - 1, newObject, true); + NetMessage.SendObjectPlacement(-1, i, j - 1, newObject, 0, 0, -1, -1); + } - //fan coral - if (WorldGen.genRand.NextBool(10)) - { - WorldGen.PlaceObject(i, j - 1, (ushort)ModContent.TileType()); - } + //fan coral + if (WorldGen.genRand.NextBool(10)) + { + WorldGen.PlaceObject(i, j - 1, (ushort)ModContent.TileType()); + } - //misc corals - if (WorldGen.genRand.NextBool()) - { - ushort[] MiscCorals = new ushort[] { (ushort)ModContent.TileType(), + //misc corals + if (WorldGen.genRand.NextBool()) + { + ushort[] MiscCorals = new ushort[] { (ushort)ModContent.TileType(), (ushort)ModContent.TileType(), (ushort)ModContent.TileType() }; - ushort newObject = Main.rand.Next(MiscCorals); + ushort newObject = Main.rand.Next(MiscCorals); - WorldGen.PlaceObject(i, j - 1, newObject, true); - NetMessage.SendObjectPlacement(-1, i, j - 1, newObject, 0, 0, -1, -1); - } + WorldGen.PlaceObject(i, j - 1, newObject, true); + NetMessage.SendObjectPlacement(-1, i, j - 1, newObject, 0, 0, -1, -1); } } diff --git a/Tiles/SunkenSea/SeaPrism.cs b/Tiles/SunkenSea/SeaPrism.cs index 0b597c77f7..e588164a13 100644 --- a/Tiles/SunkenSea/SeaPrism.cs +++ b/Tiles/SunkenSea/SeaPrism.cs @@ -40,8 +40,9 @@ namespace CalamityMod.Tiles.SunkenSea public override void AnimateIndividualTile(int type, int i, int j, ref int frameXOffset, ref int frameYOffset) { - frameXOffset = i % 2 * subsheetWidth; - frameYOffset = j % 2 * subsheetHeight; + // (i & 0b0001) = (i % 2) + frameXOffset = (i & 0b0001) * subsheetWidth; + frameYOffset = (j & 0b0001) * subsheetHeight; } public override void ModifyLight(int i, int j, ref float r, ref float g, ref float b) { From 5e6b2677d4642c23c81a970c27b9324a3d183945 Mon Sep 17 00:00:00 2001 From: Flowaria Date: Sun, 1 Sep 2024 00:46:30 +0900 Subject: [PATCH 09/12] Deleted unnecessary if condition on Water Emit calculations --- Waters/SulphuricDepthsWater.cs | 3 +-- Waters/SulphuricWater.cs | 3 +-- Waters/SunkenSeaBurrowsWater.cs | 2 -- Waters/SunkenSeaPolypWater.cs | 2 -- Waters/SunkenSeaReefsWater.cs | 2 -- Waters/SunkenSeaShoresWater.cs | 2 -- 6 files changed, 2 insertions(+), 12 deletions(-) diff --git a/Waters/SulphuricDepthsWater.cs b/Waters/SulphuricDepthsWater.cs index 7aa0ceefd3..4642b32461 100644 --- a/Waters/SulphuricDepthsWater.cs +++ b/Waters/SulphuricDepthsWater.cs @@ -47,8 +47,7 @@ namespace CalamityMod.Waters public override void ModifyLight(ref readonly Tile tile, int i, int j, ref float r, ref float g, ref float b) { Vector3 outputColor = new Vector3(r, g, b); - if (outputColor == Vector3.One || outputColor == new Vector3(0.25f, 0.25f, 0.25f) || outputColor == new Vector3(0.5f, 0.5f, 0.5f)) - return; + if (tile.TileType != RustyChestTile.Type) { outputColor = Vector3.Lerp(outputColor, Color.MediumSeaGreen.ToVector3(), 0.18f); diff --git a/Waters/SulphuricWater.cs b/Waters/SulphuricWater.cs index 11db4fde67..e05e84db59 100644 --- a/Waters/SulphuricWater.cs +++ b/Waters/SulphuricWater.cs @@ -51,8 +51,7 @@ namespace CalamityMod.Waters public override void ModifyLight(ref readonly Tile tile, int i, int j, ref float r, ref float g, ref float b) { Vector3 outputColor = new Vector3(r, g, b); - if (outputColor == Vector3.One || outputColor == new Vector3(0.25f, 0.25f, 0.25f) || outputColor == new Vector3(0.5f, 0.5f, 0.5f)) - return; + Tile above = CalamityUtils.ParanoidTileRetrieval(i, j - 1); if (!Main.gamePaused && !above.HasTile && above.LiquidAmount <= 0 && Main.rand.NextBool(9)) { diff --git a/Waters/SunkenSeaBurrowsWater.cs b/Waters/SunkenSeaBurrowsWater.cs index 81b3c30330..e4a133d192 100644 --- a/Waters/SunkenSeaBurrowsWater.cs +++ b/Waters/SunkenSeaBurrowsWater.cs @@ -43,8 +43,6 @@ namespace CalamityMod.Waters public override void ModifyLight(ref readonly Tile tile, int i, int j, ref float r, ref float g, ref float b) { Vector3 outputColor = new Vector3(r, g, b); - if (outputColor == Vector3.One || outputColor == new Vector3(0.25f, 0.25f, 0.25f) || outputColor == new Vector3(0.5f, 0.5f, 0.5f)) - return; if (tile.TileType != RustyChestTile.Type) { diff --git a/Waters/SunkenSeaPolypWater.cs b/Waters/SunkenSeaPolypWater.cs index e998f8c0c9..7960b4924d 100644 --- a/Waters/SunkenSeaPolypWater.cs +++ b/Waters/SunkenSeaPolypWater.cs @@ -31,8 +31,6 @@ namespace CalamityMod.Waters public override void ModifyLight(ref readonly Tile tile, int i, int j, ref float r, ref float g, ref float b) { Vector3 outputColor = new Vector3(r, g, b); - if (outputColor == Vector3.One || outputColor == new Vector3(0.25f, 0.25f, 0.25f) || outputColor == new Vector3(0.5f, 0.5f, 0.5f)) - return; if (tile.TileType != RustyChestTile.Type) { diff --git a/Waters/SunkenSeaReefsWater.cs b/Waters/SunkenSeaReefsWater.cs index 3072e87f2e..1412238999 100644 --- a/Waters/SunkenSeaReefsWater.cs +++ b/Waters/SunkenSeaReefsWater.cs @@ -31,8 +31,6 @@ namespace CalamityMod.Waters public override void ModifyLight(ref readonly Tile tile, int i, int j, ref float r, ref float g, ref float b) { Vector3 outputColor = new Vector3(r, g, b); - if (outputColor == Vector3.One || outputColor == new Vector3(0.25f, 0.25f, 0.25f) || outputColor == new Vector3(0.5f, 0.5f, 0.5f)) - return; if (tile.TileType != RustyChestTile.Type) { diff --git a/Waters/SunkenSeaShoresWater.cs b/Waters/SunkenSeaShoresWater.cs index ac55cb151c..a3f1e30e6d 100644 --- a/Waters/SunkenSeaShoresWater.cs +++ b/Waters/SunkenSeaShoresWater.cs @@ -31,8 +31,6 @@ namespace CalamityMod.Waters public override void ModifyLight(ref readonly Tile tile, int i, int j, ref float r, ref float g, ref float b) { Vector3 outputColor = new Vector3(r, g, b); - if (outputColor == Vector3.One || outputColor == new Vector3(0.25f, 0.25f, 0.25f) || outputColor == new Vector3(0.5f, 0.5f, 0.5f)) - return; if (tile.TileType != RustyChestTile.Type) { From 81179e03e6ef284f38569eaabaf6e62d9cfe38ae Mon Sep 17 00:00:00 2001 From: Flowaria Date: Sun, 1 Sep 2024 01:00:30 +0900 Subject: [PATCH 10/12] what --- Utilities/TileUtils.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Utilities/TileUtils.cs b/Utilities/TileUtils.cs index e0171e61c4..9877c9d708 100644 --- a/Utilities/TileUtils.cs +++ b/Utilities/TileUtils.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; +using CalamityMod.Systems; using CalamityMod.Tiles; using CalamityMod.Tiles.Abyss; using CalamityMod.Tiles.Astral; From fd4e1c3816b3eb21adda6a748ccfda0cf2df41d9 Mon Sep 17 00:00:00 2001 From: Flowaria Date: Sun, 1 Sep 2024 01:12:22 +0900 Subject: [PATCH 11/12] Added Missing Droplet resource --- Gores/WaterDroplet/AstralWaterDroplet.png | Bin 0 -> 696 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Gores/WaterDroplet/AstralWaterDroplet.png diff --git a/Gores/WaterDroplet/AstralWaterDroplet.png b/Gores/WaterDroplet/AstralWaterDroplet.png new file mode 100644 index 0000000000000000000000000000000000000000..ae8e3c68208b97758c3e75399405b42892d9a13e GIT binary patch literal 696 zcmV;p0!RIcP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D02p*dSaefwW^{L9 za%BK;VQFr3E^cLXAT%y8E;js(W8VM(0x3yEK~#8N?U*rc+&~OP_tfs)x=xYaRql}1 z=dvMyZy``(sL}j*mCb*^FT^1qAny(r@a_He=jW0iFK70+u4Ywh0`Ji^A9A6wjKtiMU{YhwDrhE{{NAA zZummR<9Vh<2p%uWf}CjU*&ALb+Ikq^vaTgdqOFI4X%T|!Y{=`0fWgxOkcrH{jO^o= ziMS#p%HvFnc%{dS@?cK1_3RC=6Ky>V$X;z)gupx7nEw^o)sTr;AMtpeVNvx8h^q5V zy=oj5u~IoeP=!9`LL(GGCu{{E69Iz^5bDv^BNG|(TyPb*oKe1W_|i^`IN(we21!2O z2xTG;;_*%vMETC9UNsJjGFgxlZ9UVXZlF8A(=~SI#+YwrvpNgfzG)F_frS?3lDzn$ z{1-%|5@rF3W1$FgLzfuave*2l#F#P0T#utaLz&H-Oa#?(&!I2Iw#Y=r7-KrBl{>s* eWugajyL|yFlo0=< Date: Fri, 6 Sep 2024 07:36:15 +0900 Subject: [PATCH 12/12] Fixed faulty light culling condition on Voidstone walls --- Walls/VoidstoneWall.cs | 6 +++--- Walls/VoidstoneWallUnsafe.cs | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Walls/VoidstoneWall.cs b/Walls/VoidstoneWall.cs index b42f806957..a239873c54 100644 --- a/Walls/VoidstoneWall.cs +++ b/Walls/VoidstoneWall.cs @@ -70,9 +70,9 @@ namespace CalamityMod.Walls drawcolor *= brightness; Color glowColor = drawcolor * 0.4f; - if (glowColor.R > glowColor.R) glowColor.R = lightColor.R; - if (glowColor.G > glowColor.G) glowColor.G = lightColor.G; - if (glowColor.B > glowColor.B) glowColor.B = lightColor.B; + if (lightColor.R > glowColor.R) glowColor.R = lightColor.R; + if (lightColor.G > glowColor.G) glowColor.G = lightColor.G; + if (lightColor.B > glowColor.B) glowColor.B = lightColor.B; if (glowColor.R <= 0 && glowColor.G <= 0 && glowColor.B <= 0) return; diff --git a/Walls/VoidstoneWallUnsafe.cs b/Walls/VoidstoneWallUnsafe.cs index 018abea0d9..b132122b57 100644 --- a/Walls/VoidstoneWallUnsafe.cs +++ b/Walls/VoidstoneWallUnsafe.cs @@ -79,9 +79,9 @@ namespace CalamityMod.Walls drawcolor *= brightness; Color glowColor = drawcolor * 0.4f; - if (glowColor.R > glowColor.R) glowColor.R = lightColor.R; - if (glowColor.G > glowColor.G) glowColor.G = lightColor.G; - if (glowColor.B > glowColor.B) glowColor.B = lightColor.B; + if (lightColor.R > glowColor.R) glowColor.R = lightColor.R; + if (lightColor.G > glowColor.G) glowColor.G = lightColor.G; + if (lightColor.B > glowColor.B) glowColor.B = lightColor.B; if (glowColor.R <= 0 && glowColor.G <= 0 && glowColor.B <= 0) return;