import { system, world, Vector, EntityTypes, BlockTypes } from '@minecraft/server';  

system.runInterval(()=>{
    let players = world.getAllPlayers()
    for(let player of players){
        if(player.fallDistance > 2 && !player.isOnGround){
            player.setDynamicProperty(`fall`,true)
            player.setDynamicProperty(`velocityY`,Math.abs(player.getVelocity().y))
            player.setDynamicProperty(`velocityX`,Math.abs(player.getVelocity().x))
        }else if(player.getDynamicProperty(`fall`)){
            player.setDynamicProperty(`fall`,false)
            let knockbackY = player.getDynamicProperty(`velocityY`)
            let knockbackX = player.getDynamicProperty(`velocityX`)
            system.runTimeout(()=>{               
                player.applyKnockback(0,0,knockbackX,knockbackY)
            },2)                      
        }
    }
})

world.afterEvents.chatSend.subscribe(({sender, message})=>{
    sender.applyKnockback(sender.getViewDirection().x,sender.getViewDirection().z,50,1)
})
