Help with detecting if a block is touching air

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the community!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Ezziex

Member
Jan 2, 2026
1
0
1
I have tried so many different ways to see if a block is touch air (not including top and bottom) and if it’s not it doesn’t let u break a block can somone help
 
Code:
function checkBlocksAround(block: block, player: player):
    loop blocks in radius 1 around {_block}:
        if loop-block's location is not 1 block above below location of {_block}:
            if loop-block's location is not 1 block below location of {_block}:
                add 1 to {_blockCounter}
    if {_blockCounter} >= 1:
        send "&c%{_blockCounter}% blocks were found!" to {_player}
    else:
        send "&aNo blocks were found." to {_player}


I didn't test that but I'm quite sure this method will work. You might have to correct a bit of the syntax. You can use on break and cancel event if the function returns a specific value.
 
Code:
function checkBlocksAround(block: block) :: boolean:
    block above location of {_block} is not air
    block below location of {_block} is not air
    block 1 block east of location of {_block} is not air
    block 1 block north of location of {_block} is not air
    block 1 block west of location of {_block} is not air
    block 1 block south of location of {_block} is not air
    return true
    
on block break:
    # parameters to monitor checking go here (ie permission checks)
    checkBlocksAround(event-block) is set
    send "%event-player% has broken %event-block% at %location of event-block%, no contact with air!" to the player

Hm... This might work better, and it should be far more lightweight considering you are checking block-breaks.

The Function checks blocks Above/Below/North/East/South/West of the event-block for AIR. If it finds air, the function is interrupted and returns nothing, but if it doesn't find air it returns TRUE.

Then, simply listen to block breaks and if the function returns any value, notify the player!
TESTED