export function onPlace(event) {
    const { block, dimension } = event;
    const blockLocation = block.location;
    const original = block.typeId;

    // Remove both 'lv_mo:' at the start and '_trophy' at the end
    const cleaned = original.replace(/^lv_mo:/, "").replace(/_trophy_block$/, "");
    
    dimension.runCommand(`summon lv_mo:boss_trophy ${blockLocation.x + 0.5} ${blockLocation.y} ${blockLocation.z + 0.5} facing @p ${cleaned}`);
}


export function onPlayerDestroy(event) {

    const { dimension, block } = event;

    let entity = block.dimension.getEntitiesAtBlockLocation({ x: block.location.x + 0.5, y: block.location.y, z: block.location.z + 0.5 })[0];

    entity.triggerEvent("lv_mo:despawn");
}

const boss_trophy = {
    onPlace: onPlace,
    onPlayerDestroy: onPlayerDestroy,
};

export default boss_trophy;
