import { system, world } from "@minecraft/server"

system.runInterval(() => {

    for (const player of world.getAllPlayers()) {

        let block = player.dimension.getBlock({ x: player.location.x, y: player.location.y, z: player.location.z, }).typeId;

        if (!block == "pa:climbable_rope") {
            player.removeTag('stop_climb');
        }
        if (!block == "pa:climbable_rope" && player.isFalling) {
            player.removeTag('climb_down');
        }
        if (block == "pa:climbable_rope" && player.isJumping) {
            player.applyKnockback(0, 0, 0, 0.22);
            player.removeTag('stop_climb');
            player.removeTag('climb_down');
        }
        if (block == "pa:climbable_rope" && !player.isJumping && !player.isSneaking && !player.isFlying) {
            player.applyKnockback(0, 0, 0, -0.1);
            player.removeTag('stop_climb');
            player.addTag('climb_down'); //Falling
        }
        if (block == "pa:climbable_rope" && !player.isJumping && player.isSneaking && !player.hasTag('stop_climb')) {
            player.runCommand('tp ^^^');
            player.addTag('stop_climb');
            player.removeTag('climb_down');
        }
        if (player.hasTag('climb_safe') && player.isFalling) {
            player.removeTag("climb_safe");
            player.applyKnockback(0, 0, 0, 0.13);
        }

    }

}, 1)