Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if not turtle then
- printError( "Requires a Turtle" )
- return
- end
- local tArgs = { ... }
- if #tArgs ~= 2 then
- print( "Usage: gh <length> <width>" )
- return
- end
- -- Mine in a quarry pattern until we hit something we can't dig
- local length = tonumber( tArgs[1] )
- local width = tonumber( tArgs[2] )
- if length < 1 then
- print( "Length must be natural number" )
- return
- end
- if width < 1 then
- print( "Width must be natural number" )
- return
- end
- local depth = 0
- local item = 1
- local function refuel()
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel == "unlimited" or fuelLevel > 0 then
- return
- end
- local function tryRefuel()
- for n=1,16 do
- if turtle.getItemCount(n) > 0 then
- turtle.select(n)
- if turtle.refuel(1) then
- turtle.select(1)
- return true
- end
- end
- end
- turtle.select(1)
- return false
- end
- if not tryRefuel() then
- print( "Add more fuel to continue." )
- while not tryRefuel() do
- os.pullEvent( "turtle_inventory" )
- end
- print( "Resuming floor building..." )
- end
- end
- local function charge()
- local function tryCharge()
- for n=1,16 do
- if turtle.getItemCount(n) > 0 then
- if turtle.getItemDetail(n).name == "chisel:glass" then
- turtle.select(n)
- return true
- end
- end
- end
- turtle.select(2)
- return false
- end
- if not tryCharge() then
- print( "Add more material to continue." )
- while not tryCharge() do
- os.pullEvent( "turtle_inventory" )
- end
- print( "Resuming floor building..." )
- end
- end
- local function tryForward()
- refuel()
- while not turtle.forward() do
- if turtle.detect() then
- if not tryDig() then
- return false
- end
- elseif turtle.attack() then
- else
- sleep( 0.1 )
- end
- end
- return true
- end
- local function tryUp()
- refuel()
- while not turtle.up() do
- if turtle.detectUp() then
- if not tryDigUp() then
- return false
- end
- elseif turtle.attackUp() then
- else
- sleep( 0.1 )
- end
- end
- return true
- end
- local function tryDigDown()
- while turtle.detectDown() do
- if turtle.digDown() then
- sleep(0.1)
- else
- return false
- end
- end
- return true
- end
- local function tryDown()
- refuel()
- while not turtle.down() do
- if turtle.detectDown() then
- if not tryDigDown() then
- return false
- end
- elseif turtle.attackDown() then
- else
- sleep( 0.1 )
- end
- end
- return true
- end
- local function tryPlaceDown()
- refuel()
- charge()
- while not turtle.detectDown() do
- if turtle.placeDown() then
- sleep(0.1)
- else
- return false
- end
- end
- return true
- end
- print( "Building the floor..." )
- local function buildForward(dir)
- for n=1,dir do
- for x=1,6 do
- tryForward()
- end
- tryDown()
- tryDigDown()
- tryUp()
- tryPlaceDown()
- end
- end
- local frwDir = true;
- tryDown()
- tryDigDown()
- tryUp()
- tryPlaceDown()
- length = length - 1
- width = width - 1
- while (length > 0 or width > 0) do
- if frwDir == true then
- buildForward(length)
- width = width - 1
- frwDir = false
- else
- buildForward(width)
- length = length - 1
- frwDir = true
- end
- turtle.turnRight()
- end
- print( "Floor building complete" )
Add Comment
Please, Sign In to add comment