Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to check if turtle has sufficient fuel --
- function sufficientFuel(vector1,vector2,fuel,remainder)
- local distance = math.abs(vector1.x - vector2.x) + math.abs(vector1.y - vector2.y) + math.abs(vector1.z - vector2.z)
- if(fuel <= distance + remainder) then
- return false
- else
- return true
- end
- end
- -- Function to refuel turtle appropriately --
- function consumeFuel(maxFuel)
- local refuel = false
- for i = 1, 16 do
- turtle.select(i)
- local x = turtle.getItemDetail(i)
- if(x ~= nil) then
- local istr = string.sub(x.name,string.find(x.name,":",0)+1)
- print(istr," t")
- if(istr == "planks" or istr == "stick" or istr == "log") then
- turtle.refuel()
- refuel = true
- end
- if(turtle.getFuelLevel() < maxFuel and istr == "coal") then
- turtle.refuel(1)
- refuel = true
- end
- end
- end
- turtle.select(1)
- print(turtle.getFuelLevel())
- return refuel
- end
- -- Function to check for inv space --
- function invSpace()
- for i = 1, 16 do
- turtle.select(i)
- local x = turtle.getItemDetail(i)
- if(x == nil or turtle.compare()) then
- turtle.select(1)
- return true
- end
- end
- turtle.select(1)
- return false
- end
- -- Function to sort inventory --
- function sortInv()
- for i = 1, 16 do -- loop through the slots
- turtle.select(i)
- if(turtle.getItemDetail(i) ~= nil) then
- for c = i, 16 do
- if(turtle.getItemDetail(c) ~= nil) then
- if(turtle.compareTo(c)) then
- turtle.select(c)
- turtle.transferTo(i)
- turtle.select(i)
- end
- end
- end
- end
- end
- turtle.select(1)
- end
- function mineVein(start,moves,back)
- local current = vector.new(gps.locate())
- if(not sufficientFuel(start,current,turtle.getFuelLevel(),5 + moves)) then
- if(not consumeFuel(400)) then
- return false
- end
- end
- if(not invSpace()) then
- sortInv()
- if(not invSpace()) then
- return false
- end
- end
- local success,data = turtle.inspect()
- if(success) then
- local istr = string.sub(data.name,string.find(data.name,":",0)+1)
- print(istr)
- if(istr == "iron_ore") then
- turtle.dig()
- turtle.forward()
- mineVein(start,moves+1,false)
- turtle.back()
- end
- end
- if(moves < 1) then
- return true
- end
- turtle.turnLeft()
- local success,data = turtle.inspect()
- if(success) then
- local istr = string.sub(data.name,string.find(data.name,":",0)+1)
- print(istr)
- if(istr == "iron_ore") then
- turtle.dig()
- turtle.forward()
- mineVein(start,moves+1,false)
- turtle.back()
- end
- end
- if(back) then
- turtle.turnLeft()
- local success,data = turtle.inspect()
- if(success) then
- local istr = string.sub(data.name,string.find(data.name,":",0)+1)
- print(istr)
- if(istr == "iron_ore") then
- turtle.dig()
- turtle.forward()
- mineVein(start,moves+1,false)
- turtle.back()
- end
- end
- turtle.turnLeft()
- local success,data = turtle.inspect()
- if(success) then
- local istr = string.sub(data.name,string.find(data.name,":",0)+1)
- print(istr)
- if(istr == "iron_ore") then
- turtle.dig()
- turtle.forward()
- mineVein(start,moves+1,false)
- turtle.back()
- end
- end
- turtle.turnLeft()
- local success,data = turtle.inspectUp()
- if(success) then
- local istr = string.sub(data.name,string.find(data.name,":",0)+1)
- print(istr)
- if(istr == "iron_ore") then
- turtle.digUp()
- turtle.up()
- mineVein(start,moves+1,true)
- turtle.down()
- end
- end
- --
- local success,data = turtle.inspectDown()
- if(success) then
- local istr = string.sub(data.name,string.find(data.name,":",0)+1)
- print(istr)
- if(istr == "iron_ore") then
- turtle.digDown()
- turtle.down()
- mineVein(start,moves+1,true)
- turtle.up()
- end
- end
- --
- else
- turtle.turnRight()
- turtle.turnRight()
- local success,data = turtle.inspect()
- if(success) then
- local istr = string.sub(data.name,string.find(data.name,":",0)+1)
- print(istr)
- if(istr == "iron_ore") then
- turtle.dig()
- turtle.forward()
- mineVein(start,moves+1,false)
- turtle.back()
- end
- end
- turtle.turnLeft()
- local success,data = turtle.inspectUp()
- if(success) then
- local istr = string.sub(data.name,string.find(data.name,":",0)+1)
- print(istr)
- if(istr == "iron_ore") then
- turtle.digUp()
- turtle.up()
- mineVein(start,moves+1,true)
- turtle.down()
- end
- end
- --
- local success,data = turtle.inspectDown()
- if(success) then
- local istr = string.sub(data.name,string.find(data.name,":",0)+1)
- print(istr)
- if(istr == "iron_ore") then
- turtle.digDown()
- turtle.down()
- mineVein(start,moves+1,true)
- turtle.up()
- end
- end
- --
- end
- return true
- end
- gpsData = fs.open("GPS_DATA","r")
- local start = vector.new(gps.locate())
- mineVein(start,0,false)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement