Advertisement
Ubidibity

Random public turtle quarry (untested)

Jun 7th, 2023 (edited)
1,053
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.81 KB | Gaming | 0 0
  1. -- though this was written to dig up, it isn't going down far enough to need to...adding more depth between passes to utilize that.
  2. -- WIP!! there's also a quadrant error I haven't located yet.
  3. turtle.digDown()
  4. turtle.down()
  5. turtle.digDown()
  6. turtle.down()
  7.  
  8. local tArgs = {...}
  9. local size = tonumber(tArgs[1])
  10. local meter = tonumber(tArgs[2])
  11.  
  12. local stepSize = size - 1
  13. local area = size * size
  14. local diggedLevel = 0
  15.  
  16. function frwd(steps)
  17.     for i = 1, steps do
  18.         local success,blockInfo = turtle.inspectUp()
  19.         if success then
  20.           local blockName=blockInfo.name
  21.           if blockName~="minecraft:stone" and blockName~="minecraft:dirt" then
  22.             turtle.digUp()
  23.           end
  24.         end
  25.         local success,blockInfo = turtle.inspectDown()
  26.         if success then
  27.           local blockName=blockInfo.name
  28.           if blockName~="minecraft:stone" and blockName~="minecraft:dirt" then
  29.             turtle.digDown()
  30.           end
  31.         end
  32.  
  33.         while not turtle.forward() do
  34.             turtle.dig()
  35.         end
  36.     end
  37. end
  38.  
  39. function turnRight()
  40.     turtle.turnRight()
  41.     frwd(1)
  42.     turtle.turnRight()
  43. end
  44.  
  45. function turnLeft()
  46.     turtle.turnLeft()
  47.     frwd(1)
  48.     turtle.turnLeft()
  49. end
  50.  
  51. function refuel(limit)
  52.     local fuel = turtle.getFuelLevel()
  53.     local refueled = false
  54.  
  55.     for i = 1, 16 do
  56.         turtle.select(i)
  57.  
  58.         if turtle.getFuelLevel() <= limit and turtle.refuel(0) then
  59.             local fuelNeeded = limit - turtle.getFuelLevel()
  60.             local fuelAmount = math.min(fuelNeeded, turtle.getItemCount(i))
  61.             turtle.refuel(fuelAmount)
  62.             print("Turtle> Fuel: " .. turtle.getFuelLevel())
  63.  
  64.             if turtle.getFuelLevel() >= limit then
  65.                 refueled = true
  66.                 break
  67.             end
  68.         end
  69.     end
  70.  
  71.     turtle.select(1)
  72.  
  73.     return refueled
  74. end
  75.  
  76. function ejectUnwantedItems()
  77.     local unwantedItems = {
  78.         "minecraft:cobblestone",
  79.         "minecraft:gravel",
  80.         "minecraft:dirt"
  81.     }
  82.  
  83.     turtle.turnLeft()
  84.     turtle.turnLeft()
  85.  
  86.     for i = 1, 16 do
  87.         turtle.select(i)
  88.  
  89.         if turtle.getItemCount(i) > 0 then
  90.             local itemDetail = turtle.getItemDetail()
  91.             itemName = itemDetail.name
  92.  
  93.             for _, unwantedItem in ipairs(unwantedItems) do
  94.                 if itemName == unwantedItem then
  95.                     turtle.dropUp()
  96.                     break
  97.                 end
  98.             end
  99.         end
  100.     end
  101.  
  102.     turtle.turnRight()
  103.     turtle.turnRight()
  104.     turtle.select(1)
  105. end
  106.  
  107. function emptySlots()
  108.     local empty = 16
  109.  
  110.     for i = 1, 16 do
  111.         if turtle.getItemCount(i) ~= 0 then
  112.             empty = empty - 1
  113.         end
  114.     end
  115.  
  116.     return empty
  117. end
  118.  
  119. function mineLevel()
  120.     for i = 1, size do
  121.         frwd(stepSize)
  122.  
  123.         if i == size then
  124.         --    turtle.turnRight()
  125.         --    turtle.turnRight()
  126.             ejectUnwantedItems()
  127.         --    turtle.turnRight()
  128.         --    turtle.turnRight()
  129.         end
  130.         -- end of first row, output 1 error("Checkpiont: diggedLevel%2.."..diggedLevel % 2)
  131.         if diggedLevel % 2 ~= 0 then
  132.             if i ~= size then
  133.                 if i % 2 == 0 then
  134.                     turnRight()
  135.                 else
  136.                     turnLeft()
  137.                 end
  138.             end
  139.         else
  140.             if i ~= size then
  141.                 if i % 2 == 0 then
  142.                     turnLeft()
  143.                 else
  144.                     turnRight()
  145.                 end
  146.             end
  147.         end
  148.     end
  149. end
  150.  
  151. -- Main program
  152. refuel(6)
  153.  
  154. -- Main loop
  155. while diggedLevel < meter do
  156.     local startLevel = diggedLevel
  157. levelsToDig=meter -- this doesn't seem to make sense to me...    local levelsToDig = math.min(2, meter - startLevel)
  158.  
  159.     for level = 1, levelsToDig do
  160.         diggedLevel = diggedLevel + 1
  161.         mineLevel()
  162. turtle.digUp()
  163.         if level ~= levelsToDig then
  164.  
  165. --            turtle.digUp()
  166.             turtle.digDown()
  167.             turtle.down()
  168.             turtle.digDown()
  169.             turtle.down()
  170.             turtle.digDown()
  171.             turtle.down()
  172.        end
  173. --      error("checkpoint")
  174.      if diggedLevel %2 ~= 0 then
  175.        turtle.turnLeft()
  176.        turtle.turnLeft()
  177.      else
  178.       turtle.turnRight()
  179.       turtle.turnRight()
  180. -- error("level.."..level..", levelsToDig"..levelsToDig)
  181.      end
  182.     end
  183.  
  184. --    turtle.turnRight()
  185.   --  turtle.turnRight()
  186.     turtle.digUp()
  187.     turtle.digDown()
  188.  
  189.     if emptySlots() == 0 then
  190.         print("\nTurtle> Inventory full! Ejecting unwanted items.")
  191.         ejectUnwantedItems()
  192.     else
  193.         refuel(area + 3)
  194.     end
  195.  
  196.     print("\nTurtle> Dug: " .. diggedLevel .. " / " .. meter .. " levels")
  197. end
  198.  
  199. print("\nTurtle> Mining complete! Terminating!")
  200.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement