fix running without calamity installed

This commit is contained in:
2026-01-27 20:00:59 +01:00
parent a40a3b624d
commit e4a046734e
4 changed files with 89 additions and 28 deletions
+17 -11
View File
@@ -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<int, string> 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<DesertScourgeHead>(), "desert_scourge");
BossIds.Add(ModContent.NPCType<Crabulon>(), "crabulon");
BossIds.Add(ModContent.NPCType<PerforatorHive>(), "perforators");
BossIds.Add(ModContent.NPCType<HiveMind>(), "hive_mind");
BossIds.Add(ModContent.NPCType<SlimeGodCore>(), "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");
}
}
+37
View File
@@ -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<string, int> _bossIconIds;
private static Mod _calamity;
private CalamityHelper() {
ModLoader.TryGetMod("CalamityMod", out Mod calamity);
_calamity = calamity;
if (_calamity == null) return;
_bossIconIds = new Dictionary<string, int> {
{ "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;
}
}
+26 -7
View File
@@ -7,19 +7,38 @@ 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<CalamityMod.Projectiles.Boss.ShaderainHostile>()) {
if (source is EntitySource_Parent { Entity: Projectile parentProj }) {
int shadeType = ModContent.ProjectileType<CalamityMod.Projectiles.Boss.ShadeNimbusHostile>();
if (parentProj.type == shadeType && parentProj.friendly && !parentProj.hostile) {
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);
}
+6 -7
View File
@@ -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<CalamityMod.Items.LoreItems.LoreDesertScourge>();
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<CalamityMod.Items.LoreItems.LoreCrabulon>();
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<CalamityMod.Items.LoreItems.LorePerforators>();
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<CalamityMod.Items.LoreItems.LoreHiveMind>();
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<CalamityMod.Items.LoreItems.LoreSlimeGod>();
int id = CalamityHelper.GetBossIconId("slime_god");
tooltips.Add(new TooltipLine(Mod, "SummonerAmbitionSlimeGod",
Language.GetTextValue("Mods.YHTMod.Items.SummonersAmbition.SlimeGod", "[i:" + id + "]")));
}
@@ -153,8 +154,6 @@ public class SummonersAmbition : ModItem {
}
}
return bossesToCheck.All(boss => modPlayer.SummonerAmbitions.Contains(boss));
}
}