(async (bot) => {

    
    // Plan:
    // 1. Find a suitable 5x5 free space for the house.
    // 2. Build the floor (5x5).
    // 3. Build the walls (3 blocks high, leaving an opening for a door).
    // 4. Build the roof (5x5).
    
    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 wallHeight = 3; // Inner height of walls
    
    // 1. Find a suitable 5x5 free space for the house within 10 blocks
    const startPos = await world.getNearestFreeSpace(bot, houseWidth, 10); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    if (!startPos) {
        log(bot,"Could not find a suitable space to build the house."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        // If no space is found, the bot can't build, so return.
        return; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    }
    
    log(bot,`Building a ${houseWidth}x${houseDepth}x${wallHeight+2} wood house at ${startPos.x}, ${startPos.y}, ${startPos.z}`); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    
    // 2. Build the floor
    // The floor will be at startPos.y
    for (let x = 0; x < houseWidth; x++) {
        for (let z = 0; z < houseDepth; z++) {
            await skills.placeBlock(bot, 'oak_log', startPos.x + x, startPos.y, startPos.z + z); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        }
    }
    
    // 3. Build the walls
    // Walls will be built from startPos.y + 1 up to startPos.y + wallHeight
    const doorX = startPos.x + Math.floor(houseWidth / 2); // Center of the front wall for the door
    const doorZ = startPos.z; // Front wall (along the lowest Z)
    
    for (let yOffset = 1; yOffset <= wallHeight; yOffset++) {
        for (let x = 0; x < houseWidth; x++) {
            for (let z = 0; z < houseDepth; z++) {
                // Check if it's an outer wall block
                if (x === 0 || x === houseWidth - 1 || z === 0 || z === houseDepth - 1) {
                    // Check if this position is for the door opening
                    if ((x === doorX && z === doorZ) && (yOffset === 1 || yOffset === 2)) {
                        // Skip placing a block to create the door opening
                        continue; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                    }
                    await skills.placeBlock(bot, 'oak_log', startPos.x + x, startPos.y + yOffset, startPos.z + z); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                }
            }
        }
    }
    
    // 4. Build the roof
    // The roof will be at startPos.y + wallHeight + 1
    const roofY = startPos.y + wallHeight + 1; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    for (let x = 0; x < houseWidth; x++) {
        for (let z = 0; z < houseDepth; z++) {
            await skills.placeBlock(bot, 'oak_log', startPos.x + x, roofY, startPos.z + z); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        }
    }
    
    log(bot,"Finished building the simple wood house.");

log(bot, 'Code finished.');

})