Sectly_Playz

Untitled

Mar 20th, 2021 (edited)
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- NOTE: 8 x 8 x 60
  2.  
  3.  
  4. -- Quarry script by: Sectly.
  5. -- EDIT VARIABLES IN HERE
  6.  
  7.  -- slot numbers are
  8.  -- 1  2  3  4
  9.  -- 5  6  7  8
  10.  -- 9 10 11 12
  11.  -- 13 14 15 16
  12.  
  13.   -- inventory slot number for fuel.
  14.   local SLOT_FUEL = 1
  15.  
  16.   -- default digging size X, Y, Z
  17.   local dDS = { 8, 20, 8 }
  18.  
  19. -- DONT EDIT FROM HERE
  20.  
  21. -- (script local) global variables
  22.   -- argument
  23.   local tArgs = { ... }
  24.  
  25.   -- local coordinate
  26.   -- X, Y, Z, Orientation
  27.   local LC = { 0, 0, 0, 1 }
  28.  
  29.   -- internal table for coordinate system
  30.   -- 1N, 2E, 3S, 4W
  31.   -- X, Z
  32.   local cAdd = { { 0, 1 }, { 1, 0 }, { 0, -1 }, { -1, 0 } }
  33.  
  34.   local td = false
  35.  
  36.   function splitstring(inputstr, sep)
  37.         if sep == nil then
  38.              sep = "%s"
  39.         end
  40.  
  41.         local t={}
  42.  
  43.         for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
  44.                 table.insert(t, str)
  45.         end
  46.  
  47.         return t
  48.   end
  49.  
  50. local turtlestartupdone = false
  51. shell.run('clear') -- Clears Screen For Start
  52. os.setComputerLabel("TEC_NO's Turtle Quarry Script!")
  53. label = ("TEC_NO's Turtle Quarry Script!")
  54. sleep(1)
  55. print("Starting program...")
  56. sleep(1)
  57. print("--------------------------")
  58. print("Version 0.4 release, build/test 14")
  59. print("--------------------------")
  60. print("Welcome To TEC_NO's Turtle Quarry Script")
  61. print("--------------------------")
  62. print("Hello I'm Ready To Start!")
  63. print("--------------------------")
  64. print("Fuel goes to slot 1")
  65. print("--------------------------")
  66. print("What will my name be?")
  67. local setname = read()
  68. print("--------------------------")
  69. print("Please wait a sec!")
  70. sleep(1)
  71. os.setComputerLabel(setname)
  72. label = (setname)
  73. print("--------------------------")
  74. print("Dig area? (X,Y,Z | Default: 8,20,8)")
  75. local digarea = read()
  76. print("--------------------------")
  77. print("Please wait!")
  78. sleep(1)
  79. if digarea then
  80.   local cords = splitstring(digarea, ",")
  81.  
  82.   if cords then
  83.     tArgs[1] = cords[1] or 8
  84.     tArgs[2] = cords[2] or 20
  85.     tArgs[3] = cords[3] or 8
  86.   end
  87. end
  88. sleep(1)
  89. turtlestartupdone = true
  90. print("Alright Starting...")
  91. shell.run('clear') -- Cleans the screen again
  92. sleep(1)
  93. -- fuel thingy
  94. function rFuel()
  95.   if turtle.getFuelLevel() < 1 then
  96.     turtle.select(SLOT_FUEL)
  97.     while not turtle.refuel(1) do
  98.       print("OUT OF FUEL!!")
  99.       print("Put fuel to slot"..SLOT_FUEL.." then press enter.")
  100.       i = read()
  101.     end
  102.     print("REFUELED")
  103.     print("Fuel level = "..turtle.getFuelLevel())
  104.     print("Remaining fuel = "..turtle.getItemCount(SLOT_FUEL))
  105.   end
  106. end
  107.  
  108. -- turn
  109. function turn(d)
  110.   if d == "left" then
  111.     turtle.turnLeft()
  112.     LC[4] = LC[4]  - 1
  113.   elseif d == "right" then
  114.     turtle.turnRight()
  115.     LC[4] = LC[4] + 1
  116.   end
  117.  
  118.   if LC[4] > 4 then
  119.     LC[4] = 1
  120.   elseif LC[4] < 1 then
  121.     LC[4] = 4
  122.   end
  123.  
  124.   -- debug
  125.   -- print(LC[4])
  126. end
  127.  
  128. -- flip
  129. function flip()
  130.   turn("right")
  131.   turn("right")
  132. end
  133.  
  134. -- move safely, and calculate the local coordinate (amount, direction)
  135. function move(a, d)
  136.   local i = 1
  137.   local s = false
  138.  
  139.   for i = 1, a do
  140.     rFuel()
  141.     repeat
  142.       if d == "forward" then
  143.         s = turtle.forward()
  144.         if s then
  145.           LC[1] = LC[1] + cAdd[LC[4]][1]
  146.           LC[3] = LC[3] + cAdd[LC[4]][2]
  147.         end
  148.       elseif d == "back" then
  149.         s = turtle.back()
  150.         if s then
  151.           LC[1] = LC[1] - cAdd[LC[4]][1]
  152.           LC[3] = LC[3] - cAdd[LC[4]][2]
  153.         end
  154.       elseif d == "up" then
  155.         s = turtle.up()
  156.         if s then
  157.           LC[2] = LC[2] - 1
  158.         end
  159.       elseif d == "down" then
  160.         s = turtle.down()
  161.         if s then
  162.           LC[2] = LC[2] + 1
  163.         end
  164.       end
  165.     until s == true
  166.   end
  167.   -- debug
  168.   -- print(LC[1] .. ", " .. LC[2] .. ", " .. LC[3])
  169. end
  170.  
  171. -- check if inventory is full(true) or not(false)
  172. function chkInventory()
  173.   local ret = true
  174.   for i = 1, 16 do
  175.     if turtle.getItemSpace(i) == 64 then
  176.       ret = false
  177.     end
  178.   end
  179.   return ret
  180. end
  181.  
  182. -- count slot amount
  183. function slotSpace(fromSlot, toSlot)
  184.    local maxItems = turtle.getItemSpace(toSlot)
  185.    local hasItems = turtle.getItemCount(fromSlot)
  186.  
  187.    if hasItems >= maxItems then
  188.      return maxItems
  189.    end
  190.  
  191.    return hasItems
  192. end
  193.  
  194. -- drop off
  195. function dropoff()
  196.   print("dropping off items")
  197.   local oLC = { LC[1], LC[2], LC[3], LC[4] }
  198.  
  199.   move(oLC[2], "up")
  200.   while LC[4] ~= 4 do
  201.     turn("right")
  202.   end
  203.   move(oLC[1], "forward")
  204.   while LC[4] ~= 3 do
  205.     turn("right")
  206.   end
  207.   move(oLC[3], "forward")
  208.  
  209.   for i = 1, 16 do
  210.     if i ~= SLOT_FUEL then
  211.       turtle.select(i)
  212.      
  213.       if turtle.getItemDetail(i).name == turtle.getItemDetail(SLOT_FUEL).name then
  214.         if slotSpace(i, SLOT_FUEL) >= 1 then
  215.           turtle.transferTo(SLOT_FUEL, slotSpace(i, SLOT_FUEL))
  216.         end
  217.       end
  218.  
  219.       turtle.drop()
  220.     end
  221.   end
  222.  
  223.   while LC[4] ~= 1 do
  224.     turn("right")
  225.   end
  226.   move(oLC[3], "forward")
  227.   while LC[4] ~= 2 do
  228.     turn("right")
  229.   end
  230.   move(oLC[1], "forward")
  231.   move(oLC[2], "down")
  232.   while LC[4] ~= oLC[4] do
  233.     turn("right")
  234.   end
  235.  
  236.   LC = { oLC[1], oLC[2], oLC[3], oLC[4] }
  237. end
  238.  
  239. -- dig a block in front
  240. function digFront()
  241.   if chkInventory() then
  242.     -- Go back and dump shit
  243.     dropoff()
  244.     return turtle.dig()
  245.   else
  246.     return turtle.dig()
  247.   end
  248. end
  249.  
  250. -- dig a block in bottom
  251. function digDown()
  252.   if chkInventory() then
  253.     dropoff()
  254.     return turtle.digDown()
  255.   else
  256.     return turtle.digDown()
  257.   end
  258. end
  259.  
  260. -- mining turn
  261. function turning()
  262.   if LC[4] == 1 then
  263.     if td then
  264.       d = "left"
  265.     else
  266.       d = "right"
  267.     end
  268.   else
  269.     if td then
  270.       d = "right"
  271.     else
  272.       d = "left"
  273.     end
  274.   end
  275.  
  276.   turn(d)
  277.   digFront()
  278.   move(1, "forward")
  279.   turn(d)
  280. end
  281.  
  282. -- main program
  283.  
  284. -- check arguments. if not set, then use default
  285. if #tArgs == 3 then
  286.   dDS[1] = tonumber(tArgs[1])
  287.   dDS[2] = tonumber(tArgs[2])
  288.   dDS[3] = tonumber(tArgs[3])
  289.   print("digging area is set to")
  290.   print("X:"..dDS[1]..", Y:"..dDS[2]..", Z:"..dDS[3])
  291. else
  292.   print("No arguments given, using default size.")
  293.   print("X:"..dDS[1]..", Y:"..dDS[2]..", Z:"..dDS[3])
  294.   print("You can change dig area on script (re)start.")
  295. end
  296.  
  297. for y = 1, dDS[2] do
  298.   for x = 1, dDS[1] do
  299.     if x > 1 then
  300.       turning()
  301.     end
  302.     for z = 1, dDS[3] - 1 do
  303.       while turtle.detect() do
  304.         digFront()
  305.         os.sleep(0.5)
  306.       end
  307.       move(1, "forward")
  308.     end
  309.   end
  310.   while turtle.detectDown() do
  311.     digDown()
  312.   end
  313.   move(1, "down")
  314.   flip()
  315.   td = not td
  316. end
  317.  
  318. move(LC[2], "up")
  319. while LC[4] ~= 4 do
  320.   turn("right")
  321. end
  322. move(LC[1], "forward")
  323. while LC[4] ~= 3 do
  324.   turn("right")
  325. end
  326. move(LC[3], "forward")
  327. for i = 1, 16 do
  328.   if i ~= SLOT_FUEL then
  329.     turtle.select(i)
  330.     turtle.drop()
  331.   end
  332. end
  333. while LC[4] ~= 1 do
  334.   turn("right")
  335. end
  336.  
  337. print("Successfully completed operation!")
Advertisement
Add Comment
Please, Sign In to add comment