import { Direction, EntityEquippableComponent, EquipmentSlot } from "@minecraft/server";
import { ItemManager } from "../../Item/manager";
export var VerticalHalf;
(function (VerticalHalf) {
    VerticalHalf["Top"] = "top";
    VerticalHalf["Bottom"] = "bottom";
})(VerticalHalf || (VerticalHalf = {}));
export class BlockComponentSlabInteraction {
    stateId;
    itemId;
    sound;
    onPlayerInteract = (data) => {
        const { block, face, player } = data;
        if (!player)
            return;
        const mainhand = player.getComponent(EntityEquippableComponent.componentId).getEquipmentSlot(EquipmentSlot.Mainhand);
        if (!mainhand)
            return;
        const item = mainhand.getItem();
        if (!item || item.typeId != this.itemId)
            return;
        let neededFace = Direction.Down;
        const state = block.permutation.getState("minecraft:vertical_half");
        if (state == VerticalHalf.Bottom)
            neededFace = Direction.Up;
        if (face != neededFace)
            return;
        mainhand.setItem(ItemManager.reduceAmount(item));
        block.setPermutation(block.permutation.withState(this.stateId, true));
        if (!this.sound)
            return;
        const sound = this.sound;
        block.dimension.playSound(sound.id, block.center(), { volume: sound.volume, pitch: sound.pitch });
    };
    constructor(stateId, itemId, sound) {
        this.stateId = stateId;
        this.itemId = itemId;
        this.sound = sound;
    }
}
