Jameelo

Up Quarry

Feb 21st, 2023 (edited)
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.33 KB | Gaming | 0 0
  1. --[[
  2.     Not much wbu
  3.     Same as my normal quarry code but it digs up
  4. ]]
  5.  
  6. print("Enter quarry depth")
  7. DEPTH = string.lower(tostring(read()))
  8.  
  9. print("Enter quarry width")
  10. WIDTH = string.lower(tostring(read()))
  11.  
  12. print("Shall I return to the original height?")
  13. returnResponse = string.lower(tostring(read()))
  14.  
  15. acceptedConditions = {"yes","no","true","false","1","0","y","n"}
  16. RETURNCOND = 0
  17.  
  18. for k,v in pairs(acceptedConditions) do
  19.     if returnResponse == v then
  20.         if k%2==1 then
  21.             RETURNCOND = 1
  22.             break
  23.         else
  24.             RETURNCOND = 0
  25.         end
  26.     end
  27. end
  28.  
  29. function dumpItems()
  30.     eSlot = findEChest()
  31.     if eSlot ~= false then
  32.         turtle.refuel()
  33.         turtle.select(eSlot)
  34.         turtle.placeDown()
  35.         emptyInv()
  36.         turtle.digDown()  
  37.     else
  38.         print("No E-Chest detected, skill issue")  
  39.     end
  40. end
  41.  
  42. function emptyInv()
  43.     for n = 1,16,1 do
  44.         turtle.select(n)
  45.         if turtle.getItemCount(n) ~= 0 then
  46.             turtle.dropDown()
  47.         end        
  48.     end
  49. end
  50.  
  51. function findEChest()
  52.     for n = 1,16,1 do
  53.         if turtle.getItemDetail(n).name == "enderstorage:ender_chest" then
  54.             return n
  55.         end
  56.     end
  57.     return false
  58. end
  59.  
  60. function existsTable(tableIn, element)
  61.     for _, value in pairs(tableIn) do
  62.       if value == element then
  63.         return true
  64.       end
  65.     end
  66.     return false
  67. end
  68.  
  69. function calculateFuelExpenditure()
  70.     local distance
  71.     if WIDTH%2 == 0 then
  72.         distance = DEPTH*((WIDTH*WIDTH)+(WIDTH-1)) + DEPTH
  73.     else
  74.         distance = DEPTH*((WIDTH*WIDTH)+2*(WIDTH-1)) + DEPTH
  75.     end
  76.     if turtle.getFuelLevel() > distance then
  77.         return true
  78.     else
  79.         return false
  80.     end
  81. end
  82.  
  83. function minesquare() --assumes the square is untouched and level
  84.     turtle.digUp()
  85.     turtle.up()
  86.  
  87.     if WIDTH%2 == 0 then
  88.         for count = 1,WIDTH/2,1 do
  89.             digForward(WIDTH-1)
  90.             turtle.turnRight()
  91.             digForward()
  92.             turtle.turnRight()
  93.             digForward(WIDTH-1)
  94.             if count == WIDTH/2 then
  95.                 turtle.turnRight()
  96.                 digForward(WIDTH-1)
  97.                 turtle.turnRight()
  98.                 break
  99.             end
  100.             turtle.turnLeft()
  101.             digForward()
  102.             turtle.turnLeft()
  103.         end
  104.     else
  105.         for count = 1,math.floor(WIDTH/2),1 do
  106.             digForward(WIDTH-1)
  107.             turtle.turnRight()
  108.             digForward()
  109.             turtle.turnRight()
  110.             digForward(WIDTH-1)
  111.             if count == math.floor(WIDTH/2) then
  112.                 turtle.turnLeft()
  113.                 digForward()
  114.                 turtle.turnLeft()
  115.                 digForward(WIDTH-1)
  116.                 turtle.turnLeft()
  117.                 digForward(WIDTH-1)
  118.                 turtle.turnLeft()
  119.                 digForward(WIDTH-1)
  120.                 turtle.turnLeft()
  121.                 turtle.turnLeft()
  122.                 break
  123.             end
  124.             turtle.turnLeft()
  125.             digForward()
  126.             turtle.turnLeft()
  127.         end
  128.     end
  129. end
  130.  
  131. function digForward(length)
  132.     if length == nil then
  133.         length = 1 -- default
  134.     end
  135.     for _ = 1,length,1 do
  136.         if everySlotTaken() == true then
  137.             print("Storage full")
  138.             dumpItems()
  139.         end
  140.         turtle.dig()
  141.         turtle.forward()
  142.     end
  143. end
  144.  
  145. function getCoords()
  146.     local coords = vector.new(gps.locate())
  147.     return coords
  148. end
  149.  
  150. function everySlotTaken()
  151.     --Cycle through all the slots and get the inventory size
  152.     local takenSlots = 0
  153.  
  154.     for n = 1,16,1 do
  155.         if turtle.getItemCount(n) > 0 then
  156.             takenSlots = takenSlots + 1
  157.         end
  158.     end
  159.     if takenSlots == 16 then
  160.         return true
  161.     else
  162.         return false
  163.     end
  164. end
  165.  
  166. function main()
  167.     for count = 1,DEPTH,1 do
  168.         minesquare()
  169.     end
  170.  
  171.     if RETURNCOND == 1 then
  172.         for i = 1, DEPTH, 1 do
  173.             turtle.down()
  174.         end
  175.     end
  176.     dumpItems()
  177. end
  178.  
  179. if calculateFuelExpenditure() then
  180.     main()
  181. else
  182.     if turtle.refuel() then
  183.         if calculateFuelExpenditure() then
  184.             main()
  185.         else
  186.             print("Failed refuel attempt, skill issue ig")
  187.         end
  188.     else
  189.         print("Not enough fuel!")
  190.     end
  191. end
Add Comment
Please, Sign In to add comment