#check for player on block

1 messages · Page 1 of 1 (latest)

covert saffron
#

how can i make it so it only check when the play is on the block, cause it still launches me even when im above the block and i press space bar
import { world, system } from "@minecraft/server";

// Run every tick
system.runInterval(() => {
for (const player of world.getPlayers()) {
const dim = player.dimension;
const loc = player.location;
const view = player.getViewDirection();

    // Block directly under player
    const block = dim.getBlockBelow(player.location);
    if (block?.typeId === "minecraft:resin_bricks" && player.inputInfo.getButtonState("Jump") === "Pressed") {
        // Apply knockback in the direction they're facing
        player.applyKnockback({ x: view.x * 0, y: 3, z: view.z * 0 }, 1);
        player.playSound("jump", { volume: 1 })
    }
}

}, 1); // check every tick

covert saffron
vague ravine
slate ridge
#
system.runInterval(() => {
    for (const source of world.getPlayers()) {
        const blockBelow = source.dimension.getBlock({
            x: Math.floor(source.location.x),
            y: Math.floor(source.location.y) - 1,
            z: Math.floor(source.location.z)
        });
        if (blockBelow && blockBelow.permutation.matches('yourblock')) {
            //code here
        }
    }
})```
#

idk, may there is a better solution