import { system, world, EquipmentSlot } from "@minecraft/server";

world.beforeEvents.playerInteractWithBlock.subscribe((piss) => {

    system.run(() => {
        const block = piss.block;
        const player = piss.player;
        const dimension = player.dimension;
        const location = block.location;
        const hand = player.getComponent("minecraft:equippable");
        const empty = hand.getEquipmentSlot(EquipmentSlot.Mainhand);
        const noItem = empty.hasItem();

        if (block.typeId === "stupidstuff:toilet" && !noItem) {
            dimension.playSound("toilet_flush", location);
        };
    });
});