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


const headBlocks = [
  'minecraft:carved_pumpkin',
  'minecraft:lit_pumpkin'
];


world.afterEvents.playerPlaceBlock.subscribe((event) => {
  const block = event.block;
  const player = event.player;

  if (!block || !player) {
    return;
  }

  if (!headBlocks.includes(block.typeId)) return;

  const below = block.below()

  if (below.typeId === 'minecraft:tuff') {

    block.setType('minecraft:air')
    below.setType('minecraft:air')

    const golem = block.dimension.spawnEntity('mv:tuff_golem', below.center());

    golem.runCommandAsync('particle mv:tuff_break ~~~')
    golem.runCommandAsync('playsound break.tuff @a ~~~')

  }
  if (below.typeId === 'minecraft:copper_block') {

    block.setType('minecraft:air')
    below.setType('minecraft:air')

    const golem = block.dimension.spawnEntity('mv:copper_golem', below.center());

    golem.runCommandAsync('particle mv:copper_break ~~~')
    golem.runCommandAsync('playsound dig.copper @a ~~~')

  }
})

