import * as mc from "@minecraft/server";
import * as effects from "../effects";
import * as selectors from "../utils/selectors";
import * as vector from "../utils/vector";

export function tick1(entity) {
    const blockBelow = entity.dimension.getBlock(vector.add(entity.location, {x:0, y: -1, z:0}));
    if (!blockBelow.isAir) {
        const pos = blockBelow.above().location;
        entity.dimension.setBlockType(pos, entity.getProperty("hf_mzs:red") ? "hf_mzs:red_raked_sand" : "hf_mzs:raked_sand");
        const block = entity.dimension.getBlock(pos);

        let perm = block.permutation;
        perm = perm.withState("minecraft:cardinal_direction", entity.getProperty("hf_mzs:cardinal_direction"));
        perm = perm.withState("hf_mzs:corner", entity.getProperty("hf_mzs:corner"));
        perm = perm.withState("hf_mzs:north_east", entity.getProperty("hf_mzs:north_east"));
        perm = perm.withState("hf_mzs:north_west", entity.getProperty("hf_mzs:north_west"));
        perm = perm.withState("hf_mzs:south_east", entity.getProperty("hf_mzs:south_east"));
        perm = perm.withState("hf_mzs:south_west", entity.getProperty("hf_mzs:south_west"));

        block.setPermutation(perm);
        entity.dimension.playSound("dig.sand", entity.location, { volume: 1.0, pitch: 1.0 });
        if (blockBelow.typeId === "minecraft:torch" || blockBelow.typeId === "minecraft:redstone_torch")
            entity.runCommand("setblock ~~~ air destroy")
        entity.remove();
    }
}