import { world, BlockPermutation, system } from '@minecraft/server';

world.afterEvents.playerPlaceBlock.subscribe(eventData => {
    const { block, player } = eventData;


    system.run(() => {
        if (!block) {
            return;
        }
        
        // Smoke Pillar Logic
        if (block.typeId === 'pu_biomes:smoke_pillar') {
            const belowBlock = block.below();
            if (belowBlock && belowBlock.typeId === 'pu_biomes:smoke_pillar') {
                let updatedBlockPermutation = BlockPermutation.resolve(block.typeId, { 'pu_biomes:part': 'body' });
                block.setPermutation(updatedBlockPermutation);
            } else {
                let updatedBlockPermutation = BlockPermutation.resolve(block.typeId, { 'pu_biomes:part': 'base' });
                block.setPermutation(updatedBlockPermutation);
            }
        }
    });
});
