Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dist_param = 256
- step = 0
- --Movements custom functions
- function dig()
- while turtle.detect() do
- turtle.dig()
- end
- end
- --utility functions
- function tryRefuel()
- turtle.select(1)
- fcount = turtle.getItemCount()
- if fcount > 1 then
- turtle.refuel(fcount-1)
- end
- end
- function homing_or_resume()
- turtle.turnLeft()
- turtle.turnLeft()
- for i=1,step do
- turtle.forward()
- end
- end
- function unload()
- for i=4,16 do
- turtle.select(i)
- turtle.drop()
- end
- end
- function diag()
- if turtle.getFuelLevel() < 1000 then
- tryRefuel()
- end
- if turtle.getFuelLevel() < dist_param+20 or turtle.getItemCount(2) < 2 then
- homing_or_resume()
- turtle.select(1)
- turtle.suckUp(turtle.getItemSpace())
- turtle.select(2)
- turtle.suckUp(turtle.getItemSpace())
- tryRefuel()
- unload()
- homing_or_resume()
- end
- if turtle.getItemCount(16) > 0 then
- homing_or_resume()
- unload()
- homing_or_resume()
- end
- end
- function follow()
- for i=1,4 do
- turtle.turnRight()
- _,id = turtle.inspect()
- if id ~= "No block to inspect" and string.find(id["name"],"ore") ~= nil then
- dig()
- turtle.forward()
- follow()
- turtle.back()
- end
- end
- _,id = turtle.inspectUp()
- if id ~= "No block to inspect" and string.find(id["name"],"ore") ~= nil then
- turtle.digUp()
- turtle.up()
- follow()
- turtle.down()
- end
- _,id = turtle.inspectDown()
- if id ~= "No block to inspect" and string.find(id["name"],"ore") ~= nil then
- turtle.digDown()
- turtle.down()
- follow()
- turtle.up()
- end
- end
- --Scan functions
- function scan()
- for j=1,4 do
- _,id = turtle.inspect()
- if id ~= "No block to inspect" and string.find(id["name"],"ore") ~= nil then
- dig()
- turtle.forward()
- follow()
- turtle.back()
- end
- turtle.turnRight()
- end
- end
- function scanDown()
- _,id = turtle.inspectDown()
- if id ~= "No block to inspect" and string.find(id["name"],"ore") ~= nil then
- turtle.digDown()
- turtle.down()
- follow()
- turtle.up()
- end
- end
- function scanUp()
- _,id = turtle.inspectUp()
- if id ~= "No block to inspect" and string.find(id["name"],"ore") ~= nil then
- turtle.digUp()
- turtle.up()
- follow()
- turtle.down()
- end
- end
- --main function
- function mining(dist)
- for i=1,dist do
- step = step+1
- if turtle.detect() then
- dig()
- turtle.forward()
- scanDown()
- scan()
- turtle.digUp()
- turtle.up()
- scan()
- scanUp()
- turtle.down()
- else
- turtle.forward()
- turtle.digUp()
- end
- if not turtle.detectDown() then
- turtle.select(3)
- turtle.placeDown()
- end
- if i%8 == 0 then
- turtle.select(2)
- turtle.back()
- turtle.placeUp()
- turtle.forward()
- end
- diag()
- end
- end
- mining(dist_param)
Add Comment
Please, Sign In to add comment