ItemEvents.rightClicked('kubejs:bonus_case', event => {
    // Check if the player is holding the bonus_case
    if (event.item.id == 'kubejs:bonus_case') {
        event.item.count-- // Consume one case

        let caseContent = global.getCaseContent('bonus_case');
        if (caseContent && caseContent.length > 0) {
            // Randomly select one of the content arrays (e.g., a "tier" of loot)
            let randomTier = caseContent[Math.floor(Math.random() * caseContent.length)];

            if (randomTier && randomTier.length > 0) {
                // Randomly select one item from the chosen tier
                let randomItemString = randomTier[Math.floor(Math.random() * randomTier.length)];

                // Parse the item string (e.g., "32x minecraft:lapis_lazuli")
                let parts = randomItemString.split('x ');
                let count = parseInt(parts[0]);
                let itemId = parts[1];

                // Give the item to the player
                event.player.give(Item.of(itemId, count));
            }
        }
    }
});

// You would repeat the above ItemEvents.rightClicked block for each case type:
// 'silver_case', 'gold_case', 'diamond_case', 'draconic_case', 'botania_case', 'solar_case'

// A more generic approach would be to loop through all cases:
ItemEvents.rightClicked(event => {
    const cases = global.getCases(); // Get the list of all defined cases

    for (let i = 0; i < cases.length; i++) {
        let caseId = cases[i][0];
        if (event.item.id == `kubejs:${caseId}`) {
            event.item.count-- // Consume one case

            let caseContent = global.getCaseContent(caseId); // Get the content for this specific case
            if (caseContent && caseContent.length > 0) {
                // Randomly select one of the content arrays (e.g., a "tier" of loot)
                let randomTier = caseContent[Math.floor(Math.random() * caseContent.length)];

                if (randomTier && randomTier.length > 0) {
                    // Randomly select one item from the chosen tier
                    let randomItemString = randomTier[Math.floor(Math.random() * randomTier.length)];

                    // Parse the item string (e.g., "32x minecraft:lapis_lazuli")
                    // Handle cases where there's no explicit count (e.g., 'minecraft:cake')
                    let count = 1;
                    let itemId = randomItemString;
                    if (randomItemString.includes('x ')) {
                        let parts = randomItemString.split('x ');
                        count = parseInt(parts[0]);
                        itemId = parts[1];
                    }

                    // Give the item to the player
                    event.player.give(Item.of(itemId, count));
                }
            }
            return; // Stop after handling the correct case
        }
    }
});