Here, for question #1. Place the turtle so it faces the leftmost part of the hole, give it a bunch of dirt, put this program in a file, and run the file.
It "feels" it's way around the hole (no pun intended) so it figures out the size of it, so you don't need to input anything or wall it off or such.
If there's some nearby cavity it's not supposed to fill (like a moat or a cliff) you might need to wall that off, though.
If it misses part of the hole, either fill it in manually or re-position the turtle and run the program again.
-- Select the first non-empty slot in the inventory.
function selectBlock()
for i=1, 9 do
if turtle.getItemCount(i) ~= 0 then
turtle.select(i)
break
end
end
end
-- Fill all blocks below the turtle.
-- Returns true if at least one block was filled, false otherwise.
function fillColumn()
local depth = 0
while turtle.down() do
depth = depth+1
end
if depth == 0 then
return false
end
for i=1, depth do
turtle.up()
selectBlock()
turtle.placeDown()
end
return true
end
-- Fill a line of columns.
-- Returns true if at least one column was filled, false otherwise.
function fillLine()
local patience = 8
local filledAny = false
while patience > 0 do
patience = patience-1
if fillColumn() then
filledAny = true
patience = 3
end
turtle.forward()
end
return filledAny
end
-- Fill a line of lines, a.k.a. a grid.
function fillGrid()
local goingBack = false
while fillLine() do
if goingBack then
turtle.turnLeft()
turtle.forward()
turtle.turnLeft()
else
turtle.turnRight()
turtle.forward()
turtle.turnRight()
end
goingBack = not goingBack
end
end
-- Run program.
fillGrid()