import { system, world } from "@minecraft/server";
export class ClimbBlock {
    constructor({ id, speed }) {
        this.id = id;
        this.speed = speed;
    }
    static registerBehavior(config) {
        const block = new ClimbBlock(config);
        this.register(block);
    }
    static register(block) {
        ClimbBlock.blocks.push(block);
    }
    static initialize() {
        system.runInterval(() => {
            const players = world.getPlayers();
            players.forEach((player) => {
                const currentBlock = player.dimension.getBlock(player.location);
                const climbBlock = ClimbBlock.blocks.find((block) => block.id === currentBlock?.typeId);
                const velocity = player.getVelocity();
                if (climbBlock) {
                    // Check if player is moving toward the climbable block
                    const facingBlock = player.dimension.getBlock({
                        x: player.location.x + player.getVelocity().x,
                        y: player.location.y,
                        z: player.location.z + player.getVelocity().z,
                    });
                    if (facingBlock && facingBlock.typeId === climbBlock.id) {
                        // Apply upward boost if the player is moving towards the block
                        player.applyKnockback(0, 0, 0, 0.5); // Adjust this value for desired climbing speed
                    }
                    // Regular climbing behavior while jumping
                    if (player.isJumping) {
                        player.applyKnockback(0, 0, 0, climbBlock.speed ?? 0.3);
                    }
                    if (!player.isJumping) {
                        player.applyKnockback(0, 0, 0, -Math.abs(0.02));
                    }
                }
            });
        }, 1);
    }
}
ClimbBlock.blocks = [];
