import { EntityInventoryComponent, Player } from "@minecraft/server";

/**
 * 
 * @param {Player} player 
 * @param {string} typeId
 * @returns {number} 
 */
export function inventoryItemCount(player, typeId) {
    /**
     * @type {EntityInventoryComponent}
     */
    const inv = player.getComponent("minecraft:inventory")
    const c = inv.container
    const size = c.size
    let count = 0

    for (let i = 0; i < size; i++) {
        const item = c.getItem(i)
        if (item?.typeId == typeId) count += item.amount
    }

    return count
}