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

// Credit to halo333x
Player.prototype.climb = function () {
    if (this.isFlying) return;
    const block = this.dimension.getBlock(this.location);
    if (!block?.hasTag("rustic:can_climb")) {
        this.dimension.runCommand("gamerule falldamage true")
        return
    }
    
    if (this.isJumping)this.applyKnockback({x: 0, z: 0}, 0.25);
  
    if (this.isSneaking && !this.isJumping) {
      this.applyKnockback({x: 0, z: 0}, 0.04);
    }
    if (this.isFalling && !block.below().hasTag("rustic:can_climb")){
        this.dimension.runCommand("gamerule falldamage false")
    }
  };

system.runInterval(() => {
    for (const player of world.getPlayers()) {
        player.climb(); // Calling the method
    }
});