(async (bot) => {

    
    // Define house parameters
    const houseWidth = 5; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    const houseDepth = 5; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    const houseHeight = 3; // Wall height (number of blocks high for the walls)
    const material = "dirt"; // Material to build the house with
    
    // 1. Find a suitable building location
    // Search for a 5x5 area within 15 blocks of the bot's current position.
    // This space will serve as the base for the house.
    const buildPos = await world.getNearestFreeSpace(bot, houseWidth, 15); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    
    if (!buildPos) {
        // If no suitable free space is found, report and exit.
        log(bot,"Could not find a suitable free space to build the house."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        return; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    }
    
    const baseStartX = buildPos.x; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    const baseStartY = buildPos.y; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    const baseStartZ = buildPos.z; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    
    log(bot,`Building a ${houseWidth}x${houseDepth}x${houseHeight} dirt house at X:${baseStartX}, Y:${baseStartY}, Z:${baseStartZ}`); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    
    // 2. Build the base (floor) of the house
    for (let x = 0; x < houseWidth; x++) {
        for (let z = 0; z < houseDepth; z++) {
            // Place a block at each coordinate of the 5x5 base layer.
            await skills.placeBlock(bot, material, baseStartX + x, baseStartY, baseStartZ + z); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        }
    }
    
    // 3. Build the walls of the house
    // Iterate through each vertical layer of the walls (from 1 block above the floor up to the wall height).
    for (let y = 1; y <= houseHeight; y++) {
        // Build the front and back walls
        for (let x = 0; x < houseWidth; x++) {
            await skills.placeBlock(bot, material, baseStartX + x, baseStartY + y, baseStartZ); // Front wall
            await skills.placeBlock(bot, material, baseStartX + x, baseStartY + y, baseStartZ + houseDepth - 1); // Back wall
        }
        // Build the side walls (excluding the corners, which are covered by front/back walls)
        for (let z = 1; z < houseDepth - 1; z++) {
            await skills.placeBlock(bot, material, baseStartX, baseStartY + y, baseStartZ + z); // Left wall
            await skills.placeBlock(bot, material, baseStartX + houseWidth - 1, baseStartY + y, baseStartZ + z); // Right wall
        }
    }
    
    // 4. Build the roof of the house
    // The roof will be placed on top of the highest wall layer.
    const roofY = baseStartY + houseHeight + 1; // Y-coordinate for the roof layer
    for (let x = 0; x < houseWidth; x++) {
        for (let z = 0; z < houseDepth; z++) {
            // Place a block at each coordinate of the 5x5 roof layer.
            await skills.placeBlock(bot, material, baseStartX + x, roofY, baseStartZ + z); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        }
    }
    
    log(bot,"House building complete!");

log(bot, 'Code finished.');

})