From e4a046734ebde6bd1cd9ac8aae1babcb9c71b796 Mon Sep 17 00:00:00 2001 From: YouHaveTrouble Date: Tue, 27 Jan 2026 20:00:59 +0100 Subject: [PATCH] fix running without calamity installed --- Changes/BossKillListener.cs | 28 +++++++++++++---------- Changes/CalamityHelper.cs | 37 +++++++++++++++++++++++++++++++ Changes/SummonerOnHitEffects.cs | 39 ++++++++++++++++++++++++--------- Items/SummonersAmbition.cs | 13 +++++------ 4 files changed, 89 insertions(+), 28 deletions(-) create mode 100644 Changes/CalamityHelper.cs diff --git a/Changes/BossKillListener.cs b/Changes/BossKillListener.cs index 2f274e5..ff52c40 100644 --- a/Changes/BossKillListener.cs +++ b/Changes/BossKillListener.cs @@ -1,9 +1,4 @@ using System.Collections.Generic; -using CalamityMod.NPCs.Crabulon; -using CalamityMod.NPCs.DesertScourge; -using CalamityMod.NPCs.HiveMind; -using CalamityMod.NPCs.Perforator; -using CalamityMod.NPCs.SlimeGod; using Microsoft.Xna.Framework; using Terraria; using Terraria.Chat; @@ -13,6 +8,7 @@ using Terraria.ModLoader; namespace YHTMod.Changes; +[ExtendsFromMod("CalamityMod")] public class BossKillListener : GlobalNPC { private static readonly Dictionary BossIds = new(); @@ -29,12 +25,22 @@ public class BossKillListener : GlobalNPC { BossIds.Add(NPCID.SkeletronHead, "skeletron"); BossIds.Add(NPCID.WallofFlesh, "wall_of_flesh"); - if (ModLoader.HasMod("CalamityMod")) { - BossIds.Add(ModContent.NPCType(), "desert_scourge"); - BossIds.Add(ModContent.NPCType(), "crabulon"); - BossIds.Add(ModContent.NPCType(), "perforators"); - BossIds.Add(ModContent.NPCType(), "hive_mind"); - BossIds.Add(ModContent.NPCType(), "slime_god"); + Mod calamity = CalamityHelper.GetCalamityMod(); + if (calamity == null) return; + if (calamity.TryFind("DesertScourgeHead", out ModNPC desertScourgeHead)) { + BossIds.Add(desertScourgeHead.Type, "desert_scourge_head"); + } + if (calamity.TryFind("Crabulon", out ModNPC crabulon)) { + BossIds.Add(crabulon.Type, "crabulon"); + } + if (calamity.TryFind("PerforatorHive", out ModNPC perforatorHive)) { + BossIds.Add(perforatorHive.Type, "perforators"); + } + if (calamity.TryFind("HiveMind", out ModNPC hiveMind)) { + BossIds.Add(hiveMind.Type, "hive_mind"); + } + if (calamity.TryFind("SlimeGodCore", out ModNPC slimeGodCore)) { + BossIds.Add(slimeGodCore.Type, "slime_god"); } } diff --git a/Changes/CalamityHelper.cs b/Changes/CalamityHelper.cs new file mode 100644 index 0000000..a2d4e0d --- /dev/null +++ b/Changes/CalamityHelper.cs @@ -0,0 +1,37 @@ +using System.Collections.Generic; +using Terraria.ModLoader; + +namespace YHTMod.Changes; + +[ExtendsFromMod("CalamityMod")] +public class CalamityHelper { + + public static readonly CalamityHelper Instance = new(); + + private static Dictionary _bossIconIds; + + private static Mod _calamity; + + private CalamityHelper() { + ModLoader.TryGetMod("CalamityMod", out Mod calamity); + _calamity = calamity; + if (_calamity == null) return; + + _bossIconIds = new Dictionary { + { "desert_scourge", ModContent.TryFind("CalamityMod", "LoreDesertScourge", out ModItem item1) ? item1.Type : -1 }, + { "crabulon", ModContent.TryFind("CalamityMod", "LoreCrabulon", out ModItem item2) ? item2.Type : -1 }, + { "perforators", ModContent.TryFind("CalamityMod", "LorePerforators", out ModItem item3) ? item3.Type : -1 }, + { "hive_mind", ModContent.TryFind("CalamityMod", "LoreHiveMind", out ModItem item4) ? item4.Type : -1 }, + { "slime_god", ModContent.TryFind("CalamityMod", "LoreSlimeGod", out ModItem item5) ? item5.Type : -1 } + }; + } + + public static int GetBossIconId(string bossKey) { + return _bossIconIds.GetValueOrDefault(bossKey, -1); + } + + public static Mod GetCalamityMod() { + return _calamity; + } + +} diff --git a/Changes/SummonerOnHitEffects.cs b/Changes/SummonerOnHitEffects.cs index 407c2a5..f8c3dc9 100644 --- a/Changes/SummonerOnHitEffects.cs +++ b/Changes/SummonerOnHitEffects.cs @@ -7,20 +7,39 @@ using Vector2 = Microsoft.Xna.Framework.Vector2; namespace YHTMod.Changes; +[ExtendsFromMod("CalamityMod")] public class SummonerOnHitEffects : GlobalProjectile { + public override void OnSpawn(Projectile projectile, IEntitySource source) { - if (ModLoader.HasMod("CalamityMod") && projectile.type == ModContent.ProjectileType()) { - if (source is EntitySource_Parent { Entity: Projectile parentProj }) { - int shadeType = ModContent.ProjectileType(); - if (parentProj.type == shadeType && parentProj.friendly && !parentProj.hostile) { - projectile.friendly = true; - projectile.hostile = false; - projectile.DamageType = DamageClass.Summon; - projectile.damage = parentProj.damage; - } - } + Mod calamity = CalamityHelper.GetCalamityMod(); + + if (calamity is null + || source is not EntitySource_Parent { Entity: Projectile { friendly: true } parentProj } + || parentProj.hostile + ) { + base.OnSpawn(projectile, source); + return; } + // Get Calamity projectile types safely + if (!calamity.TryFind("ShadeNimbusHostile", out ModProjectile shadeNimbus) + || parentProj.type != shadeNimbus.Type + ) { + base.OnSpawn(projectile, source); + return; + } + + if (!calamity.TryFind("ShaderainHostile", out ModProjectile shaderainHostile) || + projectile.type != shaderainHostile.Type) { + base.OnSpawn(projectile, source); + return; + } + + projectile.friendly = true; + projectile.hostile = false; + projectile.DamageType = DamageClass.Summon; + projectile.damage = parentProj.damage; + base.OnSpawn(projectile, source); } diff --git a/Items/SummonersAmbition.cs b/Items/SummonersAmbition.cs index 54f821e..7252c8b 100644 --- a/Items/SummonersAmbition.cs +++ b/Items/SummonersAmbition.cs @@ -5,6 +5,7 @@ using Terraria.GameContent.Creative; using Terraria.ID; using Terraria.Localization; using Terraria.ModLoader; +using YHTMod.Changes; namespace YHTMod.Items; @@ -47,7 +48,7 @@ public class SummonersAmbition : ModItem { } if (ModLoader.HasMod("CalamityMod") && player.SummonerAmbitions.Contains("desert_scourge")) { - int id = ModContent.ItemType(); + int id = CalamityHelper.GetBossIconId("desert_scourge"); tooltips.Add(new TooltipLine(Mod, "SummonerAmbitionDesertScourge", Language.GetTextValue("Mods.YHTMod.Items.SummonersAmbition.DesertScourge", "[i:" + id + "]"))); } @@ -58,7 +59,7 @@ public class SummonersAmbition : ModItem { } if (ModLoader.HasMod("CalamityMod") && player.SummonerAmbitions.Contains("crabulon")) { - int id = ModContent.ItemType(); + int id = CalamityHelper.GetBossIconId("crabulon"); tooltips.Add(new TooltipLine(Mod, "SummonerAmbitionCrabulon", Language.GetTextValue("Mods.YHTMod.Items.SummonersAmbition.Crabulon", "[i:" + id + "]"))); } @@ -79,13 +80,13 @@ public class SummonersAmbition : ModItem { } if (ModLoader.HasMod("CalamityMod") && player.SummonerAmbitions.Contains("perforators")) { - int id = ModContent.ItemType(); + int id = CalamityHelper.GetBossIconId("perforators"); tooltips.Add(new TooltipLine(Mod, "SummonerAmbitionPerforators", Language.GetTextValue("Mods.YHTMod.Items.SummonersAmbition.Perforators", "[i:" + id + "]"))); } if (ModLoader.HasMod("CalamityMod") && player.SummonerAmbitions.Contains("hive_mind")) { - int id = ModContent.ItemType(); + int id = CalamityHelper.GetBossIconId("hive_mind"); tooltips.Add(new TooltipLine(Mod, "SummonerAmbitionHiveMind", Language.GetTextValue("Mods.YHTMod.Items.SummonersAmbition.HiveMind", "[i:" + id + "]"))); } @@ -101,7 +102,7 @@ public class SummonersAmbition : ModItem { } if (ModLoader.HasMod("CalamityMod") && player.SummonerAmbitions.Contains("slime_god")) { - int id = ModContent.ItemType(); + int id = CalamityHelper.GetBossIconId("slime_god"); tooltips.Add(new TooltipLine(Mod, "SummonerAmbitionSlimeGod", Language.GetTextValue("Mods.YHTMod.Items.SummonersAmbition.SlimeGod", "[i:" + id + "]"))); } @@ -152,8 +153,6 @@ public class SummonersAmbition : ModItem { return false; } } - - return bossesToCheck.All(boss => modPlayer.SummonerAmbitions.Contains(boss)); }