diff --git a/Utilities/EntityUtils.cs b/Utilities/EntityUtils.cs index 75704529d5..13a11b4bd1 100644 --- a/Utilities/EntityUtils.cs +++ b/Utilities/EntityUtils.cs @@ -39,17 +39,66 @@ namespace CalamityMod Main.LocalPlayer.GetModPlayer().GeneralScreenShakePower += (intensity * dist); } + #region Fallback Method for IndexInRange /// - /// Fallback method for Main.[EntityType].IndexInRange which provide accurate range check (0 <= index < Main.max[EntityType]s) + /// Fallback method for Main.npc.IndexInRange which provide accurate range check (0 <= index < Main.maxNPCs) /// - /// /// whoAmI index to check - /// true if index is in valid range [0 <= index < Main.max[EntityType]s] - public static bool IndexInRange(this Entity[] entityArrayFromMainISuppose, int index) + /// true if index is in valid range [0 <= index < Main.maxNPCs] + public static bool IndexInRange(this NPC[] _, int index) { if (index >= 0) - return index < entityArrayFromMainISuppose.Length - 1; + return index < Main.maxNPCs; return false; } + + /// + /// Fallback method for Main.player.IndexInRange which provide accurate range check (0 <= index < Main.maxPlayers) + /// + /// whoAmI index to check + /// true if index is in valid range [0 <= index < Main.maxPlayers] + public static bool IndexInRange(this Player[] _, int index) + { + if (index >= 0) + return index < Main.maxPlayers; + return false; + } + + /// + /// Fallback method for Main.projectile.IndexInRange which provide accurate range check (0 <= index < Main.maxProjectiles) + /// + /// whoAmI index to check + /// true if index is in valid range [0 <= index < Main.maxProjectiles] + public static bool IndexInRange(this Projectile[] _, int index) + { + if (index >= 0) + return index < Main.maxProjectiles; + return false; + } + + /// + /// Fallback method for Main.gore.IndexInRange which provide accurate range check (0 <= index < Main.maxGore) + /// + /// whoAmI index to check + /// true if index is in valid range [0 <= index < Main.maxGore] + public static bool IndexInRange(this Gore[] _, int index) + { + if (index >= 0) + return index < Main.maxGore; + return false; + } + + /// + /// Fallback method for Main.npc.IndexInRange which provide accurate range check (0 <= index < Main.maxDust) + /// + /// whoAmI index to check + /// true if index is in valid range [0 <= index < Main.maxDust] + public static bool IndexInRange(this Dust[] _, int index) + { + if (index >= 0) + return index < Main.maxDust; + return false; + } + #endregion } }