import * as mc from "@minecraft/server";
import * as utils from "../../utils/index";
export class SpawnPlacement extends utils.ActorComponent {
    constructor() {
        super(...arguments);
        this.useItemBinding = this.onUseItem.bind(this);
    }
    onComponentAdded() {
        mc.world.afterEvents.itemUseOn.subscribe(this.useItemBinding);
        utils.waitForEvent(1, () => mc.world.afterEvents.itemUseOn.unsubscribe(this.useItemBinding));
    }
    onComponentRemoved() {
        mc.world.afterEvents.itemUseOn.unsubscribe(this.useItemBinding);
    }
    onUseItem(event) {
        if (event.itemStack.typeId === `${this.actor.typeId}_spawn_egg`) {
            mc.world.afterEvents.itemUseOn.unsubscribe(this.useItemBinding);
            const Owner = event.source;
            if (Owner) {
                const OwnerViewDirection = Owner.getViewDirection();
                if (!OwnerViewDirection)
                    return;
                if (OwnerViewDirection.y > -0.8)
                    return;
                if (OwnerViewDirection.y <= -0.8) {
                    this.actor.setProperty("face_up", true);
                }
            }
        }
    }
}
