Advertisement
viggo99

quarry

May 7th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.01 KB | None | 0 0
  1. -- NOTE: This is not my script, it was made by HomicidalRiceCake (http://www.youtube.com/user/HomicidalRiceCake) All credits to him
  2.  
  3.  
  4. -- quarry like mining script ver2.0
  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 = { 16, 60, 16 }
  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. -- fuel thingy
  37. function rFuel()
  38.   if turtle.getFuelLevel() < 1 then
  39.     turtle.select(SLOT_FUEL)
  40.     while not turtle.refuel(1) do
  41.       print("OUT OF FUEL!!")
  42.       print("put fuel to slot"..SLOT_FUEL.." then press enter.")
  43.       i = read()
  44.     end
  45.     print("REFUELED")
  46.     print("fuel level = "..turtle.getFuelLevel())
  47.     print("remaining fuel = "..turtle.getItemCount(SLOT_FUEL))
  48.   end
  49. end
  50.  
  51. -- turn
  52. function turn(d)
  53.   if d == "left" then
  54.     turtle.turnLeft()
  55.     LC[4] = LC[4]  - 1
  56.   elseif d == "right" then
  57.     turtle.turnRight()
  58.     LC[4] = LC[4] + 1
  59.   end
  60.  
  61.   if LC[4] > 4 then
  62.     LC[4] = 1
  63.   elseif LC[4] < 1 then
  64.     LC[4] = 4
  65.   end
  66.  
  67.   -- debug
  68.   -- print(LC[4])
  69. end
  70.  
  71. -- flip
  72. function flip()
  73.   turn("right")
  74.   turn("right")
  75. end
  76.  
  77. -- move safely, and calculate the local coordinate (amount, direction)
  78. function move(a, d)
  79.   local i = 1
  80.   local s = false
  81.  
  82.   for i = 1, a do
  83.     rFuel()
  84.     repeat
  85.       if d == "forward" then
  86.         s = turtle.forward()
  87.         if s then
  88.           LC[1] = LC[1] + cAdd[LC[4]][1]
  89.           LC[3] = LC[3] + cAdd[LC[4]][2]
  90.         end
  91.       elseif d == "back" then
  92.         s = turtle.back()
  93.         if s then
  94.           LC[1] = LC[1] - cAdd[LC[4]][1]
  95.           LC[3] = LC[3] - cAdd[LC[4]][2]
  96.         end
  97.       elseif d == "up" then
  98.         s = turtle.up()
  99.         if s then
  100.           LC[2] = LC[2] - 1
  101.         end
  102.       elseif d == "down" then
  103.         s = turtle.down()
  104.         if s then
  105.           LC[2] = LC[2] + 1
  106.         end
  107.       end
  108.     until s == true
  109.   end
  110.   -- debug
  111.   -- print(LC[1] .. ", " .. LC[2] .. ", " .. LC[3])
  112. end
  113.  
  114. -- check if inventory is full(true) or not(false)
  115. function chkInventory()
  116.   local ret = true
  117.   for i = 1, 16 do
  118.     if turtle.getItemSpace(i) == 64 then
  119.       ret = false
  120.     end
  121.   end
  122.   return ret
  123. end
  124.  
  125. -- drop off
  126. function dropoff()
  127.   print("dropping off items")
  128.   local oLC = { LC[1], LC[2], LC[3], LC[4] }
  129.  
  130.   move(oLC[2], "up")
  131.   while LC[4] ~= 4 do
  132.     turn("right")
  133.   end
  134.   move(oLC[1], "forward")
  135.   while LC[4] ~= 3 do
  136.     turn("right")
  137.   end
  138.   move(oLC[3], "forward")
  139.  
  140.   for i = 1, 16 do
  141.     if i ~= SLOT_FUEL then
  142.       turtle.select(i)
  143.       turtle.drop()
  144.     end
  145.   end
  146.  
  147.   while LC[4] ~= 1 do
  148.     turn("right")
  149.   end
  150.   move(oLC[3], "forward")
  151.   while LC[4] ~= 2 do
  152.     turn("right")
  153.   end
  154.   move(oLC[1], "forward")
  155.   move(oLC[2], "down")
  156.   while LC[4] ~= oLC[4] do
  157.     turn("right")
  158.   end
  159.  
  160.   LC = { oLC[1], oLC[2], oLC[3], oLC[4] }
  161. end
  162.  
  163. -- dig a block in front
  164. function digFront()
  165.   if chkInventory() then
  166.     -- Go back and dump shit
  167.     dropoff()
  168.     return turtle.dig()
  169.   else
  170.     return turtle.dig()
  171.   end
  172. end
  173.  
  174. -- dig a block in bottom
  175. function digDown()
  176.   if chkInventory() then
  177.     dropoff()
  178.     return turtle.digDown()
  179.   else
  180.     return turtle.digDown()
  181.   end
  182. end
  183.  
  184. -- mining turn
  185. function turning()
  186.   if LC[4] == 1 then
  187.     if td then
  188.       d = "left"
  189.     else
  190.       d = "right"
  191.     end
  192.   else
  193.     if td then
  194.       d = "right"
  195.     else
  196.       d = "left"
  197.     end
  198.   end
  199.  
  200.   turn(d)
  201.   digFront()
  202.   move(1, "forward")
  203.   turn(d)
  204. end
  205.  
  206. -- main program
  207.  
  208. -- check arguments. if not set, then use default
  209. if #tArgs == 3 then
  210.   dDS[1] = tonumber(tArgs[1])
  211.   dDS[2] = tonumber(tArgs[2])
  212.   dDS[3] = tonumber(tArgs[3])
  213.   print("digging area is set to")
  214.   print("X:"..dDS[1]..", Y:"..dDS[2]..", Z:"..dDS[3])
  215. else
  216.   print("no arguments given. using default size.")
  217.   print("X:"..dDS[1]..", Y:"..dDS[2]..", Z:"..dDS[3])
  218.   print("you can change default by editing the script.")
  219. end
  220.  
  221. for y = 1, dDS[2] do
  222.   for x = 1, dDS[1] do
  223.     if x > 1 then
  224.       turning()
  225.     end
  226.     for z = 1, dDS[3] - 1 do
  227.       while turtle.detect() do
  228.         digFront()
  229.         os.sleep(0.5)
  230.       end
  231.       move(1, "forward")
  232.     end
  233.   end
  234.   while turtle.detectDown() do
  235.     digDown()
  236.   end
  237.   move(1, "down")
  238.   flip()
  239.   td = not td
  240. end
  241.  
  242. move(LC[2], "up")
  243. while LC[4] ~= 4 do
  244.   turn("right")
  245. end
  246. move(LC[1], "forward")
  247. while LC[4] ~= 3 do
  248.   turn("right")
  249. end
  250. move(LC[3], "forward")
  251. for i = 1, 16 do
  252.   if i ~= SLOT_FUEL then
  253.     turtle.select(i)
  254.     turtle.drop()
  255.   end
  256. end
  257. while LC[4] ~= 1 do
  258.   turn("right")
  259. end
  260.  
  261. print("successfully completed operation.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement