Force bestiary critter registration for certain NPCs

* Certain NPC that don't fit the Vanilla criteria of "critter" can now be forcibly registered as one in the bestiary via simply adding them to the CalamaityNPCSets.ForciblyRegisterAsCritterInBestiary list
* Removed all instances of critters manually registering kills to unlock their entries in the bestiary
* Returned Divine Swine's health back to  99999999 now that it doesn't need to abide by Vanilla's critter criteria to be automatically registered
* Moved variant bestiary credit matching to a new Dictionary, CalamaityNPCSets.CountVariantsAsTheSameInBestiary
* BaseWormNPCHitbox NPCs are now automatically hidden from the bestiary
This commit is contained in:
fryzahh committed 2026-07-29 15:13:53 -04:00
1 parent 844c6be55d
commit d57fc7d223
10 files changed
+100 -38

No files matched your search

+5
View File
@@ -645,6 +645,11 @@ namespace CalamityMod.NPCs
//The segments near a player spawn a hitbox NPC to allow damaging players and taking damage
public abstract class BaseWormHitboxNPC : ModNPC
{
public override void SetStaticDefaults()
{
this.HideFromBestiary();
}
public override void SetDefaults()
{
NPC.width = 200;
-5
View File
@@ -210,11 +210,6 @@ namespace CalamityMod.NPCs.Deconstructors
public override void AI()
{
//Force burrower bestiary to unlock
if (Main.netMode != NetmodeID.MultiplayerClient && Main.BestiaryTracker.Kills.GetKillCount(NPC) <= 0)
{
Main.BestiaryTracker.Kills.RegisterKill(NPC);
}
HandleAIStates();
MainTimer++;
UpdateSegments();
-6
View File
@@ -151,12 +151,6 @@ namespace CalamityMod.NPCs.DraedonLabThings
}
break;
}
// Force bestiary unlock
if (Main.netMode != NetmodeID.MultiplayerClient && Main.BestiaryTracker.Kills.GetKillCount(NPC) <= 0)
{
Main.BestiaryTracker.Kills.RegisterKill(NPC);
}
}
public void ChangeAI(int phase)
+1 -6
View File
@@ -137,13 +137,8 @@ namespace CalamityMod.NPCs.DraedonLabThings
break;
}
Time++;
// Force bestiary unlock
if (Main.netMode != NetmodeID.MultiplayerClient && Main.BestiaryTracker.Kills.GetKillCount(NPC) <= 0)
{
Main.BestiaryTracker.Kills.RegisterKill(NPC);
}
}
public override bool? CanFallThroughPlatforms() => CurrentState == BehaviorState.WalkOnWalls;
public void WalkAroundOnGround()
+2 -2
View File
@@ -118,7 +118,7 @@ namespace CalamityMod.NPCs.NormalNPCs
Main.npcFrameCount[Type] = 14;
NPCID.Sets.CountsAsCritter[Type] = true;
NPCID.Sets.CantTakeLunchMoney[Type] = true;
NPCID.Sets.NormalGoldCritterBestiaryPriority.Insert(NPCID.Sets.NormalGoldCritterBestiaryPriority.IndexOf(NPCID.GoldBunny) + 1, Type);
NPCID.Sets.NormalGoldCritterBestiaryPriority.Add(Type);
NPCID.Sets.ImmuneToAllBuffs[Type] = true;
NPCID.Sets.ShimmerImmunity[Type] = true;
}
@@ -128,7 +128,7 @@ namespace CalamityMod.NPCs.NormalNPCs
NPC.damage = 0;
NPC.width = 32;
NPC.height = 34;
NPC.lifeMax = 5;
NPC.lifeMax = 99999999;
NPC.defense = 99999999;
NPC.rarity = 5;
NPC.aiStyle = -1;
+1 -5
View File
@@ -106,7 +106,7 @@ namespace CalamityMod.NPCs.NormalNPCs
NPCID.Sets.CountsAsCritter[Type] = true;
NPCID.Sets.CantTakeLunchMoney[Type] = true;
NPCID.Sets.TakesDamageFromHostilesWithoutBeingFriendly[Type] = true;
NPCID.Sets.NormalGoldCritterBestiaryPriority.Insert(NPCID.Sets.NormalGoldCritterBestiaryPriority.IndexOf(NPCID.GoldBunny) + 1, Type);
NPCID.Sets.NormalGoldCritterBestiaryPriority.Add(Type);
}
public override void SetDefaults()
@@ -142,10 +142,6 @@ namespace CalamityMod.NPCs.NormalNPCs
public override void AI()
{
// Force bestiary cause this doesn't count as Vanilla's definition of a critter for the Bestiary.
if (Main.netMode != NetmodeID.MultiplayerClient && Main.BestiaryTracker.Kills.GetKillCount(NPC) <= 0)
Main.BestiaryTracker.Kills.SetKillCountDirectly(NPC.GetBestiaryCreditId(), 100);
if (NPC.direction == 0)
NPC.direction = Utils.SelectRandom(Main.rand, -1, 1);
+6 -4
View File
@@ -23,7 +23,7 @@ namespace CalamityMod.NPCs.NormalNPCs
NPCID.Sets.CantTakeLunchMoney[Type] = true;
NPCID.Sets.TakesDamageFromHostilesWithoutBeingFriendly[Type] = true;
NPCID.Sets.GoldCrittersCollection.Add(Type);
NPCID.Sets.NormalGoldCritterBestiaryPriority.Insert(NPCID.Sets.NormalGoldCritterBestiaryPriority.IndexOf(ModContent.NPCType<Piggy>()) + 1, Type);
NPCID.Sets.NormalGoldCritterBestiaryPriority.Add(Type);
}
public override void SetDefaults()
@@ -32,16 +32,18 @@ namespace CalamityMod.NPCs.NormalNPCs
NPC.rarity = 3;
NPC.catchItem = (short)ModContent.ItemType<PiggyGoldItem>();
Banner = 0;
BannerItem = 0;
}
public override void SetBestiary(BestiaryDatabase database, BestiaryEntry bestiaryEntry)
{
// All gold critters have the same Bestiary entry.
var flavorText = database.FindEntryByNPCID(NPCID.GoldBunny).Info.Where(info => info is FlavorTextBestiaryInfoElement).FirstOrDefault();
string key = Lang.GetNPCName(NPCID.GoldBunny).Key.Replace("NPCName.", "");
string flavorText = "Bestiary_FlavorText.npc_" + key;
bestiaryEntry.AddTags(
BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Times.DayTime,
BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Biomes.Surface,
flavorText);
BestiaryDatabaseNPCsPopulator.CommonTags.SpawnConditions.Biomes.Surface,
new FlavorTextBestiaryInfoElement(flavorText));
}
public override void AI()
-6
View File
@@ -49,12 +49,6 @@ namespace CalamityMod.NPCs.NormalNPCs
public override void AI()
{
// Force bestiary unlock
if (Main.netMode != NetmodeID.MultiplayerClient && Main.BestiaryTracker.Kills.GetKillCount(NPC) <= 0)
{
Main.BestiaryTracker.Kills.RegisterKill(NPC);
}
bool walking = NPC.ai[0] == 1;
// Do a cute lil' hop randomly
int jumpChance = walking ? 600 : 100;
+31
View File
@@ -12,8 +12,10 @@ using CalamityMod.NPCs.CeaselessVoid;
using CalamityMod.NPCs.Crabulon;
using CalamityMod.NPCs.Crags;
using CalamityMod.NPCs.Cryogen;
using CalamityMod.NPCs.Deconstructors;
using CalamityMod.NPCs.DesertScourge;
using CalamityMod.NPCs.DevourerofGods;
using CalamityMod.NPCs.DraedonLabThings;
using CalamityMod.NPCs.ExoMechs.Apollo;
using CalamityMod.NPCs.ExoMechs.Ares;
using CalamityMod.NPCs.ExoMechs.Artemis;
@@ -338,6 +340,35 @@ namespace CalamityMod.Systems.Collections
NPCType<PrimordialWyrmHead>(), 18000 // 5:00 (300 seconds)
);
/// <summary>
/// Allows an NPC to be automatically registered as a critter in the Bestiary when the player is near them. <br/>
/// Should only be used in cases where an NPC does NOT follow the Vanilla definition of a critter. See <see cref="NPC.CountsAsACritter"/>.
/// </summary>
public static List<int> ForciblyRegisterAsCritterInBestiary = new List<int>
{
NPCType<Androomba>(),
NPCType<RepairUnitCritter>(),
NPCType<Burrower>(),
NPCType<BurrowerHitbox>(),
NPCType<DivineSwine>(),
NPCType<Piggy>(),
NPCType<PiggyGold>(),
NPCType<Shroomble>()
};
/// <summary>
/// Allows a variant of an NPC to count as credits towards another in the Bestiary. <br/>
/// This exists to prevent cases where dupilcate entries are made for two variants of the same creature, such as worms and their segments.
/// </summary>
public static Dictionary<int, int> CountVariantsAsTheSameInBestiary = new Dictionary<int, int>
{
{ NPCType<AstralachneaGround>(), NPCType<AstralachneaWall>() },
{ NPCType<DevilFishAlt>(), NPCType<DevilFish>() },
{ NPCType<ScryllarRage>(), NPCType<Scryllar>() },
{ NPCType<BurrowerHitbox>(), NPCType<Burrower>() },
};
/// <summary>
/// Associates an NPC type with the base value of their max health in Boss Rush.<br/>
/// If an NPC type is not a key in this dictionary, then it will use its standard max health value.
+54 -4
View File
@@ -1,6 +1,11 @@
using CalamityMod.NPCs.Abyss;
using System.Collections.Generic;
using CalamityMod.NPCs.Abyss;
using CalamityMod.NPCs.Astral;
using CalamityMod.NPCs.Crags;
using CalamityMod.NPCs.Deconstructors;
using CalamityMod.Systems.Collections;
using Terraria;
using Terraria.GameContent.Bestiary;
using Terraria.ID;
using Terraria.ModLoader;
using static Terraria.ModLoader.ModContent;
@@ -11,10 +16,55 @@ namespace CalamityMod.Systems
{
public override void PostSetupContent()
{
On_BestiaryDatabaseNPCsPopulator.AddEmptyEntries_CrittersAndEnemies_Automated += ForciblyAddEmptyEntriesForCritters;
On_NPCWasNearPlayerTracker.ScanWorldForFinds += ForciblySetWasSeenByPlayer;
// Manually register variants post-initiailization
ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[NPCType<AstralachneaGround>()] = ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[NPCType<AstralachneaWall>()];
ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[NPCType<DevilFishAlt>()] = ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[NPCType<DevilFish>()];
ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[NPCType<ScryllarRage>()] = ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[NPCType<Scryllar>()];
foreach (var pair in CalamityNPCSets.CountVariantsAsTheSameInBestiary)
ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[pair.Key] = ContentSamples.NpcBestiaryCreditIdsByNpcNetIds[pair.Value];
}
private void ForciblyAddEmptyEntriesForCritters(On_BestiaryDatabaseNPCsPopulator.orig_AddEmptyEntries_CrittersAndEnemies_Automated orig, BestiaryDatabaseNPCsPopulator self)
{
orig(self);
// Run through all entries again and remove the empty Enemy entries that are added by tMod itself.
// Afterwards, mnually add empty Critter entries for all NPCs within the ID set.
HashSet<int> exclusions = BestiaryDatabaseNPCsPopulator.GetExclusions();
foreach (KeyValuePair<int, NPC> pair in ContentSamples.NpcsByNetId)
{
if (!exclusions.Contains(pair.Key))
{
if (CalamityNPCSets.ForciblyRegisterAsCritterInBestiary.Contains(pair.Value.type))
{
if (BestiaryDatabaseNPCsPopulator._currentDatabase._byNpcId.TryGetValue(pair.Value.netID, out BestiaryEntry enemyEntry) && enemyEntry.UIInfoProvider is not CritterUICollectionInfoProvider)
BestiaryDatabaseNPCsPopulator._currentDatabase.Entries.Remove(enemyEntry);
NPCLoader.SetBestiary(pair.Value, BestiaryDatabaseNPCsPopulator._currentDatabase, self.Register(BestiaryEntry.Critter(pair.Key)));
}
}
}
}
private void ForciblySetWasSeenByPlayer(On_NPCWasNearPlayerTracker.orig_ScanWorldForFinds orig, NPCWasNearPlayerTracker self)
{
orig(self);
// Allow NPCs with manully added empty critter entries to be registered by player proximity.
foreach (NPC npc in Main.ActiveNPCs)
{
if (!CalamityNPCSets.ForciblyRegisterAsCritterInBestiary.Contains(npc.type) || self._wasSeenNearPlayerByNetId.Contains(npc.netID))
continue;
for (int i = 0; i < self._playerHitboxesForBestiary.Count; i++)
{
if (npc.Hitbox.Intersects(self._playerHitboxesForBestiary[i]))
{
self._wasSeenNearPlayerByNetId.Add(npc.netID);
self.RegisterWasNearby(npc);
}
}
}
}
}
}