import { Task } from "./task";
import { EmoteTask } from "./emote";
import { BlockPermutation } from "@minecraft/server";
export class PlaceBlockTask extends Task {
    async performTask() {
        var _a;
        if (this.options.emoteData) {
            await new EmoteTask(this.npc, this.options.emoteData, this).start();
        }
        this.shouldAbort();
        this.npc.broadcastEvent(`placed.${this.options.block.block.split(":").pop()}`);
        const permutation = BlockPermutation.resolve(this.options.block.block, this.options.block.properties);
        this.npc.Entity.dimension.setBlockPermutation(this.options.location, permutation);
        if ((_a = this.npc.Entity.dimension.getBlock(this.options.location)) === null || _a === void 0 ? void 0 : _a.permutation.matches(this.options.block.block, this.options.block.properties)) {
            return { outcome: "succeeded" };
        }
        else {
            return { outcome: "failed" };
        }
    }
    formatBlockProperties(properties) {
        if (properties) {
            return JSON.stringify(properties).replace('{', '[').replace('}', ']');
        }
        return '';
    }
}
