#Preven placing block[Resolved]

1 messages · Page 1 of 1 (latest)

noble hornet
#

Hello, i need a lil bit of help here, i want to know how to prevent placing a slab while completing one full block (interacting with another slab)?

#

oh, btw, this is the script ```world.beforeEvents.playerInteractWithBlock.subscribe((event)=>{
const {itemStack, block, isFirstEvent, blockFace, player} = event

const isSlab = block.hasTag(`sl:slab`);
const isSlabV = block.hasTag(`sl:vertical_slab`);
const isSlabH = block.hasTag(`sl:horizontal_slab`);

const vertical_slab_rotation = block.permutation.getState(`minecraft:cardinal_direction`) as string;
const horizontal_slab_position = block.permutation.getState(`minecraft:vertical_half`) as string;

if (itemStack?.typeId === block.typeId && isSlab){
    const lowerWallId = 'sl:stone_wall_hcz';
    const mediumWallId = 'sl:stone_wall_hcz2';
    const topWallId = 'sl:stone_wall_hcz3';

    if (isSlabV){
        const completationFace = vertical_slab_rotation.toLowerCase()
        if (blockFace.toLowerCase() !== completationFace) return
    }
    if (isSlabH){
        if ((horizontal_slab_position.toLowerCase() === "bottom" && !(blockFace === Direction.Up)) || (horizontal_slab_position.toLowerCase() === "top" && !(blockFace === Direction.Down)) ) return
    }

    system.run(()=>{
        player.playAnimation("animation.player.first_person.attack_rotation_item")
        if (['sl:slab_wall_hcz', 'sl:slab_vertical_wall_hcz'].includes(itemStack.typeId)) block.setType(lowerWallId);
        if (['sl:slab_wall_hcz2', 'sl:slab_vertical_wall_hcz2'].includes(itemStack.typeId)) block.setType(mediumWallId);
        if (['sl:slab_wall_hcz3', 'sl:slab_vertical_wall_hcz3'].includes(itemStack.typeId)) block.setType(topWallId);
        event.cancel = true
        return block.dimension.playSound(`use.stone`, block.location);
    })
}

})```

steep geode
#

if it interacts your block slab typeid, cancel the event

noble hornet
#

Wut?

#

Preven placing block[Resolved]

#

oh wait i got it, hank

#

thanks*