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

◆ ConsumeItem()

bool Terraria.Player.ConsumeItem ( int type,
bool reverseOrder = false,
bool includeVoidBag = false )
inline

Use to consume a single item. The item does not have to be F:Terraria.Item.consumable.
Attempts to reduce the F:Terraria.Item.stack of the first T:Terraria.Item found in the F:Terraria.Player.inventory by 1.
Respects M:Terraria.ModLoader.ItemLoader.ConsumeItem(Terraria.Item,Terraria.Player), so the item won't necessarily be consumed.
To consume multiple of the item, first check M:Terraria.Player.CountItem(System.Int32,System.Int32) to ensure that there are enough of the item, then use a for loop to call this method many times.

Parameters
typeThe item type to consume
reverseOrderIf true, the search for the item will start at the end of the player inventory
includeVoidBagIf true, the void bag, if open, will also be considered for finding an item to consume
Returns
True if the item was found and attempted to be consumed

Definition at line 7567 of file Player.cs.

7568 {
7569 int num = 0;
7570 int num2 = 58;
7571 int num3 = 1;
7572 if (reverseOrder)
7573 {
7574 num = 57;
7575 num2 = -1;
7576 num3 = -1;
7577 }
7578 for (int i = num; i != num2; i += num3)
7579 {
7580 if (inventory[i].stack > 0 && inventory[i].type == type)
7581 {
7582 if (ItemLoader.ConsumeItem(inventory[i], this))
7583 {
7584 inventory[i].stack--;
7585 }
7586 if (inventory[i].stack <= 0)
7587 {
7589 }
7590 return true;
7591 }
7592 }
7593 if (includeVoidBag && useVoidBag())
7594 {
7595 int num4 = FindItem(type, bank4.item);
7596 if (num4 == -1)
7597 {
7598 return false;
7599 }
7600 Item item = bank4.item[num4];
7601 item.stack--;
7602 if (item.stack <= 0)
7603 {
7604 item.TurnToAir();
7605 }
7606 return true;
7607 }
7608 return false;
7609 }
Item[] item
The items this chest contains. F:Terraria.Chest.maxItems elements long.
Definition Chest.cs:93
int stack
The current stack of the item. F:Terraria.Item.maxStack indicates the max possible stack.
Definition Item.cs:396
void SetDefaults(int Type=0)
Definition Item.cs:48800
static bool ConsumeItem(Item item, Player player)
If ModItem.ConsumeItem or any of the GlobalItem.ConsumeItem hooks returns false, sets consume to fals...
This serves as the central class from which item-related functions are carried out....
Definition ItemLoader.cs:26
int FindItem(int netid)
Definition Player.cs:56652
bool useVoidBag()
Definition Player.cs:21132
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.bank4, Terraria.ModLoader.ItemLoader.ConsumeItem(), Terraria.Player.FindItem(), Terraria.Player.inventory, Terraria.Chest.item, Terraria.Item.SetDefaults(), Terraria.Item.stack, Terraria.Item.TurnToAir(), and Terraria.Player.useVoidBag().

Referenced by Terraria.Wiring.MassWireOperation(), Terraria.Player.PayDD2CrystalsBeforeUse(), Terraria.Player.TileInteractionsUse(), and Terraria.UI.ItemSlot.TryOpenContainer().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: