Advertisement
ThSchm

Mining Turtle - Intelligent Quarry

Sep 16th, 2014
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.63 KB | None | 0 0
  1. --[[
  2. Quarry programm for a turtle.
  3. Features:
  4. - finds adjacent chest
  5. - checks refuel and makes its way back to the chest if out of fuel
  6. - empties its inventory to chest
  7. - some minor intelligence stuff
  8.  
  9. Note:
  10. - the first argument you pass will determine the start height of the quarry
  11.  
  12. Copyright Thorsten Schmiedel 2014
  13. Do NOT post this without noticing me! (schmiedel.thorsten@gmail.com)
  14. --]]
  15.  
  16. -- Variables and constants
  17. -- Constants
  18. local FuelSlot = 1
  19. local ChestSlot = 2
  20.  
  21. -- Variables
  22. local tArgs = { ... }
  23.  
  24. local startHeightDiff = 0
  25. local sizeXZ = 16
  26. local debug = true
  27.  
  28. local dX, dY, dZ;
  29.  
  30. -- Arguments
  31. if (#tArgs >= 1) then
  32.   startHeightDiff = tonumber(tArgs[1])
  33.   if (#tArgs >= 2) then
  34.     sizeXZ = tonumber(tArgs[2])
  35.   end
  36. end
  37. -- end Arguments
  38.  
  39. -- FUNCTIONS
  40.  
  41. -- HELPER FUNCTIONS
  42. local function ForceMoveDown()
  43.   while not turtle.down() do
  44.     turtle.digDown()
  45.     turtle.attackDown()
  46.     sleep(0.2)
  47.   end
  48. end
  49.  
  50. local function ForceMoveUp()
  51.   while not turtle.up() do
  52.     turtle.digUp()
  53.     turtle.attackUp()
  54.     sleep(0.2)
  55.   end
  56. end
  57.  
  58. local function CheckFuel()
  59.   local lengthOfWay = startHeightDiff + dX + dY + dZ
  60.  
  61.   if (lengthOfWay <= turtle.getFuelLevel()) then
  62.     return false
  63.   else
  64.     return true
  65.   end
  66. end
  67.  
  68.  
  69. -- Finds a chest adjacent to the turtle
  70. local function FindChest()
  71.   for i = 1, 4 do
  72.     if turtle.detect() then
  73.       if debug then
  74.         print("Chest found!")
  75.       end
  76.       return
  77.     else
  78.     turtle.turnRight()
  79.     end
  80.   end
  81.   if debug then
  82.     print("No adjacent chest found! New attempt in 3 secs")
  83.   end
  84.   return
  85. end
  86.  
  87. -- Pick up the chest
  88. local function PickUp(slot)
  89.   local tmp = turtle.getSelectedSlot()
  90.   turtle.select(slot)  
  91.   if not turtle.dig() and debug then
  92.     print("Error in picking up the chest! Aborting programm!")
  93.   end
  94.   turtle.select(tmp)
  95. end
  96.  
  97. -- Dig to the begin of the quarry
  98. local function GoToStartHeight()
  99.   if (startHeightDiff == 0) then
  100.     if debug then
  101.     print("Reached startheight! Mining begins...")
  102.     end
  103.     return
  104.   end
  105.  
  106.   for i = 1, startHeightDiff do
  107.     ForceMoveDown()
  108.   end
  109.   if debug then
  110.     print("Reached startheight! Mining begins...")
  111.   end
  112. end
  113.  
  114. -- Go back to the chest
  115. local function GoUpToChest()
  116.   if (startHeightDiff == 0) then
  117.     if debug then
  118.       print("Reached chest! Inventory empty begins...")
  119.     end
  120.     return
  121.   end
  122.  
  123.   for i = 1, startHeightDiff do
  124.     ForceMoveUp()
  125.   end
  126.   if debug then
  127.     print("Reached chest! Inventory empty begins...")
  128.   end
  129. end
  130.  
  131. -- Mines one column
  132. local function MineColumn(amount)
  133.  
  134. end
  135.  
  136.  
  137. FindChest()
  138. GoToStartHeight()
  139. GoUpToChest()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement