(async (bot) => {

    
    // Planning:
    // The immediate goal is to fix the "No usable pickaxe available" error.
    // The bot has 57 cobblestone and 28 sticks, which is sufficient for a stone pickaxe.
    // The previous logic attempted to craft one, but it seems either the crafting failed silently,
    // or the pickaxe wasn't properly detected or equipped afterwards.
    
    // Refined Strategy for Pickaxe (Step 0):
    // 1. Explicitly check for a 'stone_pickaxe' first. If present and equipped, good to go.
    // 2. If no stone pickaxe, check for 'wooden_pickaxe'.
    // 3. If no suitable pickaxe is found (i.e., missing or only wooden and stone is craftable):
    //    a. Find a temporary spot for a crafting table.
    //    b. Place the crafting table. Handle placement failure.
    //    c. Attempt to craft a 'stone_pickaxe'. Add more robust error handling around crafting.
    //    d. If stone pickaxe fails or is not craftable, attempt to craft a 'wooden_pickaxe'.
    //    e. After crafting, perform a direct check of the inventory to ensure the *newly crafted* pickaxe exists.
    //    f. Only if the pickaxe is confirmed in inventory, then equip it using `setQuickBarSlot`.
    //    g. Finally, reclaim the temporary crafting table.
    // 4. Final verification: Re-check inventory for any pickaxe and ensure it's equipped before proceeding.
    
    const houseWidth = 7; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    const houseLength = 7; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    const houseHeight = 4; // This is the wall height. Roof will be at y + houseHeight.
    const wallBlockType = "oak_planks"; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    const roofBlockType = "oak_planks"; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    
    // Specific Crafting Table Location from memory
    const mainCraftingTablePos = new Vec3(95, 19, -72); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    
    // --- Step 0: Ensure bot has a stone pickaxe ---
    let equippedPickaxeItem = bot.inventory.items().find(item => item.name.includes("stone_pickaxe")); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    let needsToCraftPickaxe = false; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    
    if (!equippedPickaxeItem) {
        equippedPickaxeItem = bot.inventory.items().find(item => item.name.includes("wooden_pickaxe")); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        if (equippedPickaxeItem) {
            bot.chat("Only a wooden pickaxe found. Checking if stone pickaxe can be crafted to upgrade."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
            needsToCraftPickaxe = true; // Flag to attempt upgrade
        } else {
            bot.chat("No pickaxe found in inventory."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
            needsToCraftPickaxe = true; // Flag to craft any pickaxe
        }
    } else {
        bot.chat(`Found and equipped ${equippedPickaxeItem.name}.`); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        await bot.setQuickBarSlot(equippedPickaxeItem.slot); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    }
    
    if (needsToCraftPickaxe) {
        let tempCraftingTablePlaced = false; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        let tempCraftingTablePos = null; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    
        bot.chat("Attempting to craft a better pickaxe (stone preferred)."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    
        // Find a temporary spot to place the crafting table
        tempCraftingTablePos = bot.entity.position.offset(1, -1, 0); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        const blockBelowTemp = bot.blockAt(tempCraftingTablePos.offset(0, -1, 0)); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        const blockAtTemp = bot.blockAt(tempCraftingTablePos); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    
        if (blockBelowTemp && blockBelowTemp.type !== 0 && blockAtTemp && blockAtTemp.type === 0) {
            const craftingTableItem = bot.inventory.items().find(item => item.name === "crafting_table"); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
            if (!craftingTableItem) {
                bot.chat("No crafting table in inventory to place for pickaxe crafting. Critical error."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                throw new Error("No crafting table in inventory to craft pickaxe."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
            }
            await bot.setQuickBarSlot(craftingTableItem.slot); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
            const placed = await skills.placeBlock(bot, "crafting_table", tempCraftingTablePos.x, tempCraftingTablePos.y, tempCraftingTablePos.z); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
            if (placed) {
                tempCraftingTablePlaced = true; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                bot.chat("Successfully placed temporary crafting table."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                await skills.wait(bot, 500); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    
                const craftingTableBlock = bot.blockAt(tempCraftingTablePos); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                if (!craftingTableBlock || craftingTableBlock.name !== "crafting_table") {
                    bot.chat("Temporary crafting table not found at expected position after placing. Cannot craft pickaxe here."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                } else {
                    let pickaxeRecipe = null; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                    // Try stone pickaxe first
                    pickaxeRecipe = bot.recipesFor("stone_pickaxe", null, 1, craftingTableBlock)[0]; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                    if (pickaxeRecipe) {
                        bot.chat("Crafting stone pickaxe."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                        try {
                            await bot.craft.craftItem(pickaxeRecipe, 1, craftingTableBlock); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                            bot.chat("Crafted stone pickaxe."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                        } catch (err) {
                            bot.chat(`Failed to craft stone pickaxe: ${err.message}. Trying wooden pickaxe.`); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                            pickaxeRecipe = null; // Reset to try wooden
                        }
                    }
    
                    // If stone pickaxe couldn't be crafted or wasn't found, try wooden
                    if (!pickaxeRecipe) {
                        pickaxeRecipe = bot.recipesFor("wooden_pickaxe", null, 1, craftingTableBlock)[0]; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                        if (pickaxeRecipe) {
                            bot.chat("Crafting wooden pickaxe."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                            try {
                                await bot.craft.craftItem(pickaxeRecipe, 1, craftingTableBlock); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                                bot.chat("Crafted wooden pickaxe."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                            } catch (err) {
                                bot.chat(`Failed to craft wooden pickaxe: ${err.message}.`); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                                throw new Error("Cannot craft any pickaxe."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                            }
                        } else {
                            bot.chat("No recipe found for any pickaxe. Cannot proceed without a pickaxe."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                            throw new Error("Cannot craft any pickaxe."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                        }
                    }
                }
            } else {
                bot.chat("Failed to place temporary crafting table. This might cause issues."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
            }
        } else {
            bot.chat("Could not find a suitable spot to place temporary crafting table near current position."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        }
    
        // Verify pickaxe is in inventory and equip it
        equippedPickaxeItem = bot.inventory.items().find(item => item.name.includes("stone_pickaxe") || item.name.includes("wooden_pickaxe")); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        if (equippedPickaxeItem) {
            await bot.setQuickBarSlot(equippedPickaxeItem.slot); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
            bot.chat(`Equipped newly crafted ${equippedPickaxeItem.name}.`); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        } else {
            bot.chat("Failed to find any usable pickaxe in inventory after crafting attempts."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
            throw new Error("No usable pickaxe available after crafting attempts."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        }
    
        // Reclaim the temporary crafting table if placed
        if (tempCraftingTablePlaced && tempCraftingTablePos) {
            bot.chat("Breaking temporary crafting table."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
            // Ensure pickaxe is equipped *before* trying to break
            if (equippedPickaxeItem) {
                await bot.setQuickBarSlot(equippedPickaxeItem.slot); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
            }
            await skills.breakBlockAt(bot, tempCraftingTablePos.x, tempCraftingTablePos.y, tempCraftingTablePos.z); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
            await skills.wait(bot, 500); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
            bot.chat("Reclaimed temporary crafting table."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        }
    }
    
    // Final check to ensure a pickaxe is equipped before proceeding
    equippedPickaxeItem = bot.inventory.items().find(item => item.name.includes("stone_pickaxe") || item.name.includes("wooden_pickaxe")); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    if (equippedPickaxeItem) {
        await bot.setQuickBarSlot(equippedPickaxeItem.slot); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        bot.chat(`Confirmed and equipped ${equippedPickaxeItem.name}.`); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    } else {
        bot.chat("Still no pickaxe equipped after all attempts. This will likely cause issues."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        throw new Error("No usable pickaxe available."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    }
    
    
    // --- Step 1: Find a suitable building location ---
    bot.chat("Finding a suitable location for the 7x7x4 house..."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    let houseBasePos = await world.getNearestFreeSpace(bot, houseWidth, 64); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    
    if (!houseBasePos) {
        bot.chat("Could not find a suitable free space to build the house within 64 blocks. Expanding search range."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        houseBasePos = await world.getNearestFreeSpace(bot, houseWidth, 128); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        if (!houseBasePos) {
            bot.chat("Still could not find a suitable free space to build the house. I cannot proceed."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
            throw new Error("No suitable building location found."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        }
    }
    bot.chat(`Found a building spot at ${houseBasePos.x}, ${houseBasePos.y}, ${houseBasePos.z}.`); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    
    
    // --- Step 2: Craft oak planks if needed ---
    const requiredPlanks = 145; // Calculated: (7*7*4) for walls + (7*7) for roof assuming full planks
    let currentPlanks = bot.inventory.count("oak_planks"); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    let planksToCraft = requiredPlanks - currentPlanks; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    
    if (planksToCraft > 0) {
        bot.chat(`Need to craft ${planksToCraft} oak planks.`); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    
        bot.chat(`Going to crafting table at ${mainCraftingTablePos.x}, ${mainCraftingTablePos.y}, ${mainCraftingTablePos.z}.`); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        const arrivedAtCraftingTable = await skills.goToPosition(bot, mainCraftingTablePos.x, mainCraftingTablePos.y, mainCraftingTablePos.z, 1); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    
        if (!arrivedAtCraftingTable) {
            bot.chat("Failed to reach the main crafting table. Cannot craft planks."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
            throw new Error("Failed to reach crafting table for plank crafting."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        }
        bot.chat("Arrived at crafting table location."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    
        let actualCraftingTableBlock = bot.blockAt(mainCraftingTablePos); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        if (!actualCraftingTableBlock || actualCraftingTableBlock.name !== "crafting_table") {
            bot.chat("Crafting table not found at the specified location after going there. Attempting to place one if available."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
            const craftingTableItem = bot.inventory.items().find(item => item.name === "crafting_table"); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
            if (craftingTableItem) {
                await bot.setQuickBarSlot(craftingTableItem.slot); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                const placedMainCraftingTable = await skills.placeBlock(bot, "crafting_table", mainCraftingTablePos.x, mainCraftingTablePos.y, mainCraftingTablePos.z); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                if (placedMainCraftingTable) {
                    bot.chat("Placed crafting table at the specified location."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                    await skills.wait(bot, 500); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                    actualCraftingTableBlock = bot.blockAt(mainCraftingTablePos); // Refresh block reference
                } else {
                    bot.chat("Failed to place crafting table at the specified location. Cannot craft planks."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                    throw new Error("Crafting table not available for plank crafting."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                }
            } else {
                bot.chat("No crafting table in inventory to place at the specified location. Cannot craft planks."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                throw new Error("No crafting table in inventory for plank crafting."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
            }
        }
    
        if (!actualCraftingTableBlock || actualCraftingTableBlock.name !== "crafting_table") {
            bot.chat("Still no crafting table at location after all attempts. Cannot craft planks."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
            throw new Error("Crafting table unavailable for plank crafting."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        }
    
        const oakPlanksRecipe = bot.recipesFor("oak_planks", null, 1, actualCraftingTableBlock)[0]; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        if (!oakPlanksRecipe) {
            bot.chat("No recipe found for oak planks. Ensure oak logs are available. Inventory: " + bot.inventory.count("oak_log") + " oak logs."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
            throw new Error("No recipe for oak planks."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        }
    
        while (planksToCraft > 0) {
            const amountToCraft = Math.min(planksToCraft, oakPlanksRecipe.result.count); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
            try {
                await bot.craft.craftItem(oakPlanksRecipe, amountToCraft, actualCraftingTableBlock); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                planksToCraft -= amountToCraft; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                bot.chat(`Crafted ${amountToCraft} oak planks. ${planksToCraft} remaining.`); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                await skills.wait(bot, 100); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                currentPlanks = bot.inventory.count("oak_planks"); // Update current planks count
            } catch (err) {
                bot.chat(`Failed to craft oak planks: ${err.message}`); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                if (err.message.includes("not enough")) {
                    bot.chat("Not enough oak logs to craft planks. Cannot proceed. Current logs: " + bot.inventory.count("oak_log")); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                    throw new Error("Not enough oak logs."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                }
                throw err; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
            }
        }
        bot.chat("Finished crafting oak planks."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    } else {
        bot.chat("Already have enough oak planks."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    }
    
    const oakPlanksItem = bot.inventory.items().find(item => item.name === "oak_planks"); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    if (oakPlanksItem) {
        await bot.setQuickBarSlot(oakPlanksItem.slot); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        bot.chat("Selected oak planks for building."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    } else {
        bot.chat("No oak planks in inventory after crafting. Cannot build."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        throw new Error("No oak planks for building."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    }
    
    // --- Step 3: Build the house structure (Walls, Windows, Roof) ---
    bot.chat("Starting to build the house structure."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    await skills.goToPosition(bot, houseBasePos.x, houseBasePos.y, houseBasePos.z); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    
    const doorOffsetX = Math.floor(houseWidth / 2); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    const doorOffsetZ = houseLength - 1; // Door on one of the longer sides (z)
    
    for (let y = 0; y <= houseHeight; y++) {
        for (let x = 0; x < houseWidth; x++) {
            for (let z = 0; z < houseLength; z++) {
                const currentX = houseBasePos.x + x; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                const currentY = houseBasePos.y + y; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                const currentZ = houseBasePos.z + z; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    
                const isPerimeter = x === 0 || x === houseWidth - 1 || z === 0 || z === houseLength - 1; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                const isRoofLayer = (y === houseHeight); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    
                if (isRoofLayer) {
                    await skills.placeBlock(bot, roofBlockType, currentX, currentY, currentZ); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                } else if (isPerimeter) {
                    const isDoorSpot = (x === doorOffsetX && z === doorOffsetZ && (y === 0 || y === 1)); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    
                    let isWindowSpot = false; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                    // Simple window placement on second layer, avoiding door spot
                    if (y === 1) {
                        if ((x === 1 || x === houseWidth - 2) && (z === 0 || z === houseLength - 1)) {
                            // Check if it's not the door's exact X, Z
                            if (!(x === doorOffsetX && z === doorOffsetZ)) {
                                isWindowSpot = true; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                            }
                        }
                        if ((z === 1 || z === houseLength - 2) && (x === 0 || x === houseWidth - 1)) {
                             // Check if it's not the door's exact X, Z
                            if (!(x === doorOffsetX && z === doorOffsetZ)) {
                                isWindowSpot = true; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                            }
                        }
                    }
    
                    if (!isDoorSpot && !isWindowSpot) {
                        await skills.placeBlock(bot, wallBlockType, currentX, currentY, currentZ); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                    }
                }
            }
        }
    }
    
    // --- Step 4: Place door ---
    bot.chat("Placing the door."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    const doorPlaceX = houseBasePos.x + doorOffsetX; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    const doorPlaceY = houseBasePos.y; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    const doorPlaceZ = houseBasePos.z + doorOffsetZ; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    
    let oakDoorItem = bot.inventory.items().find(item => item.name === "oak_door"); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    if (!oakDoorItem) {
        bot.chat("No oak door in inventory. Attempting to craft one now."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    
        const arrivedAtCraftingTableForDoor = await skills.goToPosition(bot, mainCraftingTablePos.x, mainCraftingTablePos.y, mainCraftingTablePos.z, 1); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        if (!arrivedAtCraftingTableForDoor) {
            bot.chat("Failed to reach the main crafting table to craft door."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
            throw new Error("Failed to reach crafting table for door crafting."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        }
    
        const craftingTableBlockForDoor = bot.blockAt(mainCraftingTablePos); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        if (craftingTableBlockForDoor && craftingTableBlockForDoor.name === "crafting_table") {
            const oakDoorRecipe = bot.recipesFor("oak_door", null, 1, craftingTableBlockForDoor)[0]; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
            if (oakDoorRecipe) {
                try {
                    await bot.craft.craftItem(oakDoorRecipe, 1, craftingTableBlockForDoor); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                    oakDoorItem = bot.inventory.items().find(item => item.name === "oak_door"); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                    if (!oakDoorItem) {
                        bot.chat("Failed to find oak door in inventory after crafting attempt."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                        throw new Error("Failed to craft oak door."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                    }
                } catch (err) {
                    bot.chat(`Failed to craft oak door: ${err.message}`); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                    throw err; if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                }
            } else {
                bot.chat("No recipe found for oak door. Ensure enough oak planks are available."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
                throw new Error("No recipe for oak door."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
            }
        } else {
            bot.chat("Crafting table not found at expected location for door crafting. Cannot craft door."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
            throw new Error("Crafting table unavailable for door crafting."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        }
    }
    
    if (oakDoorItem) {
        await bot.setQuickBarSlot(oakDoorItem.slot); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        // Move to a position to place the door correctly (e.g., in front of it)
        await skills.goToPosition(bot, doorPlaceX, doorPlaceY, doorPlaceZ + 1, 1); // Stand 1 block in front of the door target
        await skills.placeBlock(bot, "oak_door", doorPlaceX, doorPlaceY, doorPlaceZ); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
        bot.chat("Placed oak door."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    } else {
        bot.chat("Cannot place door: No oak door item available."); if(bot.interrupt_code) {log(bot, "Code interrupted.");return;}
    }
    
    bot.chat("House construction complete!");

log(bot, 'Code finished.');

})