import { EntityComponentTypes } from "@minecraft/server";
/**
 * Removes a specified amount of items from an item stack.
 *
 * @param {ItemStack} itemStack - The item stack to remove items from.
 * @param {number} count - The amount of items to remove.
 *
 * @returns {ItemStack|undefined} The modified item stack if the removal was
 * successful, or undefined if the item stack does not have enough items.
 */
export function decreaseItemStackAmount(itemStack, count) {
    // player.runCommand("clear @s oct_dogs:ball 0 1");
    if (itemStack.amount > count) {
        itemStack.amount -= count;
        return itemStack;
    } else {
        return undefined;
    }
}

export function removeFromHeldItemStack(player, itemStack, count) {
    player
        .getComponent(EntityComponentTypes.Inventory)
        .container
        .setItem(player.selectedSlotIndex, decreaseItemStackAmount(itemStack, count));
}