Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Program to mine out several layers. Definable length, width, and depth.
- -- config
- local width = 0
- local length = 0
- local depth = 0
- local linecount = 0 -- number times completed a length
- local layercount = 0 -- number of times completed a layer
- local lblocks = 0 -- total blocks in layer
- local cblocks = 0 -- total blocks moved
- local dblocks = 0 -- blocks dug so far minus air
- local tblocks = 0 -- total blocks in area
- local mblocks = 0 -- current line progress
- local goneleft = false -- has turtle gone left yet
- --functions start
- --clear
- function clear()
- term.clear()
- term.setCursorPos(1,1)
- end
- --dig line
- local function line()
- mblocks = 0
- while mblocks < length do
- if turtle.dig() == true then
- dblocks = dblocks+1
- end
- while turtle.forward() ~= true do
- os.sleep(0.5)
- end
- mblocks = mblocks+1
- cblocks = cblocks+1
- end
- print("dug " .. dblocks .. "/" .. lblocks .. "(" .. tblocks .. ")" .. " blocks, turtle.")
- linecount = linecount+1
- print("Line function complete")
- end
- -- turn left and dig a line
- local function lineleft()
- turtle.turnLeft()
- if turtle.dig() == true then
- dblocks = dblocks+1
- end
- while turtle.forward() ~= true do
- os.sleep(0.5)
- end
- cblocks = cblocks+1
- turtle.turnLeft()
- line()
- end
- -- turn right and dig a line
- local function lineright()
- turtle.turnRight()
- if turtle.dig() == true then
- dblocks = dblocks+1
- end
- while turtle.forward() ~= true do
- os.sleep(0.5)
- end
- cblocks = cblocks+1
- turtle.turnRight()
- line()
- end
- -- does it go left or right?
- local function alternate()
- if goneleft == true then
- lineright()
- goneleft = false
- else
- lineleft()
- goneleft = true
- end
- end
- -- go down
- local function linestart()
- if turtle.digDown() == true then
- dblocks = dblocks+1
- end
- turtle.down()
- cblocks = cblocks+1
- print("Line function time")
- line()
- end
- -- do 180 and dig down to start another layer
- local function nextlayer()
- print("Layer complete, starting next layer, turtle.")
- print("Cleared " .. lblocks .. "/" .. tblocks)
- turtle.turnLeft()
- turtle.turnLeft()
- linecount = 0
- print("Linestart function time")
- linestart()
- end
- --begin code
- clear()
- print("Place me above block at bottom right of area, turtle.")
- write("Enter Width: ")
- width = tonumber(read())
- write("Enter Length: ")
- length = tonumber(read()-1)
- write("Enter Depth: ")
- depth = tonumber(read())
- tblocks = ((length+1)*(width)*(depth))
- lblocks = ((length+1)*(width))
- linestart()
- while (cblocks < tblocks) do
- while linecount < width do
- print("alternate function time")
- alternate()
- end
- layercount = layercount+1
- if layercount < depth then
- print("nextlayer function time")
- nextlayer()
- print("nextlayer function complete, loop to alternate")
- end
- print("returning to loop cblocks")
- end
- print("Done. Mined " .. dblocks .. " out of " .. tblocks .. " blocks total, turtle.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement