Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.clear()
- term.setCursorPos(1,1)
- sel = 0
- fuelThreshold = 300
- if turtle.getFuelLevel() == "unlimited" then
- turtle.getFuelLevel = function()
- return 2 + fuelThreshold
- end
- end
- if fs.exists("coords") == false then
- print("Hi, I am your mining robot!\n\nI will need to ask you a couple of questions before I start mining:\n\nWhat diameter would you like me to mine?\n")
- setSize =read()
- print("\nCool! Now insert the turtles current y coordinate\n")
- input = read()
- setDepth = input-5
- print("\nJust one more thing- put any blocks you don't want me to mine in slots 1-4 and press enter.. or just leave it empty to mine everything (I will be slower the more you put there)\n")
- temp=read()
- setJunkSlots = 0
- for i = 1,4 do
- if turtle.getItemCount(i) ~= 0 then
- setJunkSlots = setJunkSlots + 1
- end
- end
- print("\nOkay, I will start mining now :D")
- w = fs.open("coords","w")
- w.write(setSize.."\n"..setDepth.."\n1\n1\n1\n0\n"..setJunkSlots)
- w.close()
- w = fs.open("startup","w")
- w.write('shell.run("dig")')
- w.close()
- sleep(3)
- term.clear()
- term.setCursorPos(1,1)
- end
- h = fs.open("coords","r")
- size = tonumber(h.readLine(1))
- depth = tonumber(h.readLine(2))
- x = tonumber(h.readLine(3))
- y = tonumber(h.readLine(4))
- z = tonumber(h.readLine(5))
- facing = tonumber(h.readLine(6))
- junkSlots = tonumber(h.readLine(7))
- h.close()
- --Gets the necessary variables from the file coords
- function drop(fslot,lslot)
- for i=fslot,lslot do
- turtle.select(i)
- while turtle.drop() == false and turtle.getItemCount(i) ~= 0 do
- print("Can't drop items- full?")
- sleep(2)
- end
- end
- end
- function save()
- os.queueEvent("test")
- coroutine.yield()
- s = fs.open("coords","w")
- s.writeLine(size)
- s.writeLine(depth)
- s.writeLine(x)
- s.writeLine(y)
- s.writeLine(z)
- s.writeLine(facing)
- s.writeLine(junkSlots)
- s.close()
- end
- --save function, prints the turtles orientation and coords to a file
- function rflforw()
- if turtle.forward() == true then
- if facing == 0 then
- x = x+1
- save()
- elseif facing == 1 then
- y= y-1
- save()
- elseif facing == 2 then
- x = x - 1
- save()
- elseif facing == 3 then
- y = y + 1
- save()
- else
- error("Invalid facing variable")
- end
- else
- print("Can't move forward, trying again...")
- while turtle.forward() == false do
- turtle.dig()
- sleep(0.3)
- end
- if facing == 0 then
- x = x+1
- save()
- elseif facing == 1 then
- y= y-1
- save()
- elseif facing == 2 then
- x = x - 1
- save()
- elseif facing == 3 then
- y = y + 1
- save()
- end
- end
- end
- --refuel-less forward function
- function dig()
- turtle.dig()
- end
- function digdown()
- turtle.digDown()
- end
- function digup()
- turtle.digUp()
- end
- function refuel()
- local char = ""
- if turtle.getFuelLevel() < fuelThreshold then
- if turtle.getItemCount(16) == 0 then
- oldfacing = facing
- oldx = x
- oldy = y
- oldz = z
- while facing ~= 1 do
- left()
- end
- while y ~= 1 do
- rflforw()
- end
- while facing ~= 2 do
- left()
- end
- while x ~= 1 do
- rflforw()
- end
- while z ~= 1 do
- up()
- end
- drop(junkSlots + 1, 15)
- while facing ~= 1 do
- left()
- end
- turtle.select(16)
- turtle.drop()
- turtle.suck()
- while turtle.getItemCount(16) < 16 do
- print('Not enough fuel, Refill the chest and press enter')
- temp=read()
- turtle.drop()
- turtle.suck()
- turtle.refuel(1)
- end
- while facing ~= 0 do
- left()
- end
- while z ~= oldz do
- down()
- end
- while x ~= oldx do
- rflforw()
- end
- while facing ~= 3 do
- left()
- end
- while y ~= oldy do
- forw()
- end
- while facing ~= oldfacing do
- left()
- end
- else
- while true do
- turtle.select(16)
- turtle.refuel(1)
- turtle.select(1)
- if turtle.getFuelLevel() > fuelThreshold then
- break
- elseif turtle.getItemCount(16) == 0 then
- refuel()
- end
- end
- end
- end
- end
- function forw()
- refuel()
- if turtle.forward() == true then
- if facing == 0 then
- x = x+1
- save()
- elseif facing == 1 then
- y= y-1
- save()
- elseif facing == 2 then
- x = x - 1
- save()
- elseif facing == 3 then
- y = y + 1
- save()
- else
- error("Invalid facing variable")
- end
- else
- print("Can't move forward, trying again...")
- while turtle.forward() == false do
- turtle.dig()
- sleep(0.3)
- end
- if facing == 0 then
- x = x+1
- save()
- elseif facing == 1 then
- y= y-1
- save()
- elseif facing == 2 then
- x = x - 1
- save()
- elseif facing == 3 then
- y = y + 1
- save()
- end
- end
- end
- function down()
- if turtle.down() == true then
- z = z + 1
- else
- print("Something is blocking my way down, trying again!")
- while turtle.down() == false do
- sleep(0.3)
- digdown()
- end
- z= z + 1
- end
- end
- function up()
- if turtle.up() == true then
- z = z - 1
- else
- print("Something is blocking my way up, trying again!")
- while turtle.up() == false do
- sleep(0.3)
- digup()
- end
- z= z - 1
- end
- end
- function left()
- turtle.turnLeft()
- facing = facing - 1
- facing = facing % 4
- save()
- end
- function right()
- turtle.turnRight()
- facing = facing + 1
- facing = facing % 4
- save()
- end
- function comine()
- local isJunkd = false
- local isJunku = false
- sel = sel + 1
- if junkSlots == 0 then
- sel = 0
- else
- sel = sel % junkSlots
- end
- if sel == 0 then
- for i = 1 , junkSlots do
- turtle.select(i)
- if turtle.compareUp()== true then
- isJunku = true
- end
- if turtle.compareDown()== true then
- isJunkd = true
- end
- end
- else
- for i = junkSlots , 1, -1 do
- turtle.select(i)
- if turtle.compareUp()== true then
- isJunku = true
- end
- if turtle.compareDown()== true then
- isJunkd = true
- end
- end
- end
- if isJunku == false then
- digup()
- end
- if isJunkd == false then
- digdown()
- end
- end
- function diglayer()
- for j = 1,size - 1 do
- comine()
- dig()
- forw()
- if turtle.getItemCount(15) > 0 then
- oldfacing = facing
- oldx = x
- oldy = y
- oldz = z
- while facing ~= 1 do
- left()
- end
- while y ~= 1 do
- forw()
- end
- while facing ~= 2 do
- left()
- end
- while x ~= 1 do
- forw()
- end
- while z ~= 1 do
- up()
- end
- drop(junkSlots + 1, 15)
- turtle.select(sel + 1)
- while facing ~= 0 do
- left()
- end
- while z ~= oldz do
- down()
- end
- while x ~= oldx do
- forw()
- end
- while facing ~= 3 do
- left()
- end
- while y ~= oldy do
- forw()
- end
- while facing ~= oldfacing do
- left()
- end
- end
- end
- end
- function program()
- if size % 2 == 0 then
- for i = 1 , size / 2 - 1 do
- diglayer()
- comine()
- left()
- dig()
- forw()
- left()
- diglayer()
- comine()
- right()
- dig()
- forw()
- right()
- end
- diglayer()
- comine()
- left()
- dig()
- forw()
- left()
- diglayer()
- comine()
- left()
- for i = 1, size-1 do
- forw()
- end
- left()
- else
- for i = 1, (size - 1)/2 do
- diglayer()
- comine()
- left()
- dig()
- forw()
- left()
- diglayer()
- comine()
- right()
- dig()
- forw()
- right()
- end
- diglayer()
- comine()
- right()
- while y ~= 1 do
- forw()
- end
- right()
- while x ~= 1 do
- forw()
- end
- left()
- left()
- end
- end
- refuel()
- refuel()
- if x ~= 1 or y ~= 1 or facing ~= 0 then
- while facing ~= 1 do
- left()
- end
- while y ~= 1 do
- forw()
- end
- while facing ~= 2 do
- right()
- end
- while x ~= 1 do
- forw()
- end
- while facing ~= 0 do
- left()
- end
- end
- while z ~= depth do
- program()
- for i = 1, 3 do
- if z == depth then
- break
- end
- digdown()
- down()
- end
- end
- program()
- while facing ~=2 do
- left()
- end
- while z ~= 1 do
- up()
- end
- drop(1,16)
- fs.delete("startup")
- fs.delete("coords")
- print("I am done now :D")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement