import { system, world } from "@minecraft/server";
import ScriptingModule from "./scriptingModule";
import { namespace } from "../config/_config";
export default class DebugModule extends ScriptingModule {
    constructor() {
        super("DebugModule");
    }
    onInitialize() {
        // world.beforeEvents.playerInteractWithBlock.subscribe((event) => {
        //   const block = event.block;
        //   const states = block.permutation.getAllStates();
        //   // Format the states as a string
        //   const formattedStates = Object.entries(states)
        //     .map(([key, value]) => `§8${key}: §7${value}§8`)
        //     .join(", ");
        //   world.sendMessage(`States: ${formattedStates}`);
        // });
        world.afterEvents.playerInteractWithEntity.subscribe((event) => {
            world.sendMessage(`Entity: ${event.target.getProperty("cc:hunger_state")}`);
        });
        system.runInterval(() => {
            world.getPlayers().forEach((player) => {
                // const direction = getCardinalDirection(player.getViewDirection());
                // player.runCommand(`title @s actionbar §8${direction}`);
                if (player.hasTag(`${namespace}:debug`)) {
                    const block = player.getBlockFromViewDirection({
                        maxDistance: 10,
                    })?.block;
                    if (block) {
                        const states = block.permutation.getAllStates();
                        // Format the states as a string
                        const formattedStates = Object.entries(states)
                            .map(([key, value]) => `§8${key}: §7${value}§8`)
                            .join(", ");
                        // Display the block type and all states in the action bar
                        player.runCommandAsync(`title @s actionbar ${formattedStates}`);
                    }
                }
                if (player.hasTag(`${namespace}:speed`) && player.getGameMode() === "creative") {
                    if (player.isSprinting && !player.isOnGround) {
                        const direction = player.getViewDirection();
                        player.applyKnockback(direction.x, direction.z, 4, direction.y * 2);
                    }
                }
            }, 1);
        });
    }
}
