MihaMi

Excavate3.lua

Jan 21st, 2021
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.97 KB | None | 0 0
  1. --[[
  2. local tArgs = { ... }
  3. if #tArgs ~= 1 then
  4.     print( "Usage: excavate3 <diameter>" )
  5.     return
  6. end
  7.  
  8. -- Mine in a quarry pattern until we hit something we can't dig
  9. local size = tonumber( tArgs[1] )
  10. if size < 1 then
  11.     print( "Excavate diameter must be positive" )
  12.     return
  13. end
  14.  
  15. local depth = 0
  16. local unloaded = 0
  17. local collected = 0
  18.  
  19. local xPos,zPos = 0,0
  20. local xDir,zDir = 0,1
  21.  
  22. local goTo -- Filled in further down
  23. local refuel -- Filled in further down
  24.  
  25.  
  26. local function moveDown()    
  27.     for i=0,1 do   
  28.         if turtle.digDown() then
  29.             turtle.down()          
  30.         end
  31.     end
  32. end
  33.  
  34. local function moveUp()    
  35.     for i=0,1 do   
  36.         if turtle.digUp() then
  37.             turtle.up()        
  38.         end
  39.     end
  40. end
  41.  
  42. --]]
  43.  
  44. --[[
  45. TO-DO:
  46. - return back to chest
  47. - up/down dig
  48. - quarry(x,y,z)
  49. - throw items
  50. - print out location and reset monitor
  51.  
  52. --]]
  53.  
  54. local xPos = 0
  55. local yPos = 0
  56. local zPos = 0
  57. local dir = 0
  58. local fuelLevel = 0
  59.  
  60. -- Movement
  61. local function moveDown()
  62.     print("Moving down")
  63.     if turtle.down() then
  64.         yPos = yPos+1
  65.     else
  66.         print("Reason: ",turtle.down())
  67.         return false
  68.     end
  69.     print("Moved down. yPos: ",yPos)
  70.     return true
  71. end
  72.  
  73. local function moveUp()
  74.     print("Moving up")  
  75.     if turtle.up() then
  76.         yPos = yPos+1
  77.     else
  78.         print("Reason: ",turtle.up())
  79.         return false
  80.     end
  81.     print("Moved up. yPos: ",yPos)
  82.     return true
  83. end
  84.  
  85. local function left()
  86.     print("Turning left")
  87.     if turtle.turnLeft() then
  88.         dir = dir + 1
  89.         if dir == 4 then
  90.             dir = 0
  91.         end
  92.         print("Turned left. Dir: ",dir)
  93.     else
  94.         print("Reason: ",turtle.turnLeft())
  95.         return false
  96.     end
  97.     return true
  98. end
  99.  
  100. local function right()
  101.     print("Turning right")  
  102.     if turtle.turnRight() then      
  103.         dir = dir - 1
  104.         if dir == -1 then
  105.             dir = 3
  106.         end
  107.         print("Turned right. Dir: ",dir)
  108.     else
  109.         print("Reason: ",turtle.turnRight())
  110.         return false
  111.     end
  112.     return true
  113. end
  114.  
  115. -- Fueling
  116.  
  117. local function fuel()
  118.     local hasFuel = false  
  119.     if turtle.getFuelLevel() ~= "unlimited" and turtle.getFuelLevel() < 1 then     
  120.         for i = 1, 16 do -- loop through the slots
  121.             turtle.select(i) -- change to the slot
  122.             if turtle.refuel(0) then -- if it's valid fuel
  123.                 hasFuel = true
  124.             end
  125.             if hasFuel == true then
  126.                 for j=1,turtle.getItemCount() do
  127.                     if turtle.getFuelLevel() ~= "unlimited" and turtle.getFuelLevel() < 1 then
  128.                         turtle.refuel(1)
  129.                     end
  130.                 end
  131.             end
  132.         end    
  133.     end
  134. end
  135.  
  136.  
  137. local function goBack()
  138.     local oldXPos = xPos
  139.     local oldYPos = yPos
  140.     local oldZPos = zPos
  141.     local oldXDir = xDir
  142.     local oldZDir = zDir
  143. end
  144.  
  145.  
  146. local function test()
  147.     shell.run("label","set","Zmiskol")
  148.     term.clear()   
  149.  
  150.     for i=0,1 do
  151.         moveUp()
  152.     end
  153.     sleep(5)
  154.     term.clear()
  155.  
  156.     for i=0,1 do
  157.         moveDown()
  158.     end
  159.     sleep(5)
  160.     term.clear()    
  161. end
  162.  
  163. test()
Add Comment
Please, Sign In to add comment