TModLoader v1.4.4.9
TModLoader source code documentation
Loading...
Searching...
No Matches

◆ CountItem()

int Terraria.Player.CountItem ( int type,
int stopCountingAt = 0 )
inline

Counts the total stack of the specified item type in this players F:Terraria.Player.inventory.
Does not check Void Bag.
Use M:Terraria.Player.HasItem(System.Int32) to check if the player has the item at all.

Parameters
typeThe item type to count
stopCountingAtWhen to stop counting, useful to avoid unnecessary calculations
Returns
The total amount counted

Definition at line 7540 of file Player.cs.

7541 {
7542 int num = 0;
7543 for (int i = 0; i != 58; i++)
7544 {
7545 if (inventory[i].stack > 0 && inventory[i].type == type)
7546 {
7547 num += inventory[i].stack;
7548 if (num >= stopCountingAt)
7549 {
7550 return num;
7551 }
7552 }
7553 }
7554 return num;
7555 }
int stack
The current stack of the item. F:Terraria.Item.maxStack indicates the max possible stack.
Definition Item.cs:396
Item[] inventory
The player's normal inventory. Indexes 0-9 hold the hotbar items, 10-49 the rest of the main inventor...
Definition Player.cs:1767

References Terraria.Player.inventory, and Terraria.Item.stack.

Referenced by Terraria.Player.CheckDD2CrystalPaymentLock().

+ Here is the caller graph for this function: