import { ItemStack } from '@minecraft/server';
import { playerCooldowns } from '../../main.js';

export function onUse(event) {
    const { itemStack, source } = event;
    const block = source.getBlockFromViewDirection({ maxDistance: 8 });

    if (block) {
        if (block.block.above().typeId === `minecraft:water`) {
            block.block.above().setType(`air`);

            const equippable = source.getComponent("equippable");
            const WaterBucket = new ItemStack('lv_mo:infinite_water_bucket', 1);
            equippable.setEquipment('Mainhand', WaterBucket);

            const uniqueId = itemStack.getDynamicProperty("cooldownUniqueId");
            if (uniqueId) {
                playerCooldowns.delete(uniqueId);
            }
        }
    }
}

const empty_infinite_water_bucket = {
    onUse: onUse,
};
export default empty_infinite_water_bucket;
