Advertisement
Guest User

digout

a guest
May 21st, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.22 KB | None | 0 0
  1. _channel = 7
  2. _dumpRock = true
  3. _stopOnFull = true
  4.  
  5. gravDelay = 0
  6. fuelLimitLow = 1
  7. depth = 0
  8. width = 0
  9. height = 0
  10.  
  11. modem = nil
  12.  
  13. if(peripheral.getType("right") == "modem") then
  14.     modem = peripheral.wrap("right")
  15.     modem.open(_channel)
  16. elseif(peripheral.getType("left") == "modem") then
  17.     modem = peripheral.wrap("left")
  18.     modem.open(_channel)
  19. else
  20.     print("No modem")
  21. end
  22.  
  23. function tx(msg)
  24.     if(modem ~= nil) then
  25.         modem.transmit(_channel, _channel, os.getComputerLabel().."#"..os.getComputerID().." "..msg)
  26.     end
  27. end
  28.  
  29. function ping(currentDepth)
  30.     tx(width.."x"..height.."x"..depth.." Depth:"..currentDepth.."\nFuel: "..turtle.getFuelLevel().."\nSlots empty: "..getEmptySlots())
  31. end
  32.  
  33. function getEmptySlots()
  34.     local num = 16
  35.     for i = 1, 16, 1 do
  36.         if(turtle.getItemCount(i) > 0) then
  37.             num = num-1
  38.         end
  39.     end
  40.     return num
  41. end
  42.  
  43. function dumpRock()
  44.     if(getEmptySlots() > 0 or _dumpRock == false) then
  45.         return false
  46.     end
  47.     for i = 1, 16, 1 do
  48.         if(turtle.getItemCount(i) > 0) then
  49.             local data = turtle.getItemDetail(i)
  50.             if(data.name == "minecraft:cobblestone" or data.name == "minecraft:stone" or data.name == "minecraft:dirt" or data.name == "minecraft:sand" or data.name == "minecraft:gravel" or data.name == "minecraft:netherrack") then
  51.                 turtle.select(i)
  52.                 turtle.drop()
  53.             else
  54.                 --print("Not rock: "..data.name)
  55.             end
  56.         else
  57.             --print("empty")
  58.         end
  59.     end
  60.     if(getEmptySlots() == 0) then
  61.         print("Slots full!")
  62.         if(_stopOnFull == true) then
  63.             print("Stopping on full!")
  64.             while(getEmptySlots() == 0) do
  65.                 tx("FULL!")
  66.                 print("Empty me!")
  67.                 os.sleep(1)
  68.             end
  69.         else
  70.             print("Not stopping!")
  71.         end
  72.     end
  73. end
  74.  
  75. function fDig()
  76.     dumpRock()
  77.     while(turtle.dig()) do
  78.         refuel()
  79.         turtle.dig()
  80.         sleep(gravDelay)
  81.     end
  82. end
  83.  
  84. function uDig()
  85.     dumpRock()
  86.     while(turtle.digUp()) do
  87.         refuel()
  88.         turtle.digUp()
  89.         sleep(gravDelay)
  90.     end
  91. end
  92.  
  93. function dDig()
  94.     while(turtle.digDown()) do
  95.         refuel()
  96.         turtle.digDown()
  97.         sleep(gravDelay)
  98.     end
  99. end
  100.  
  101. function fMove()
  102.     refuel()
  103.     while(turtle.forward() == false) do
  104.         fDig()
  105.     end
  106. end
  107.  
  108. function uMove()
  109.     refuel()
  110.     while(turtle.up() == false) do
  111.         uDig()
  112.     end
  113. end
  114.  
  115. function dMove()
  116.     refuel()
  117.     while(turtle.down() == false) do
  118.         dDig()
  119.     end
  120. end
  121.  
  122. function refuel()
  123. end
  124.  
  125. function disp(w, h, d)
  126.   term.clear()
  127.   term.setCursorPos(1,1)
  128.   print("Width  [x]: ", w)
  129.   print("Height [z]: ", h)
  130.   print("Depth  [y]: ", d)
  131.   print("Fuel      : ", turtle.getFuelLevel())
  132.   print("Pinging on Ch. ", _channel)
  133. end
  134.  
  135. print("Width:")
  136. width = tonumber(read())
  137. print("Height:")
  138. height = tonumber(read())
  139. print("Depth:")
  140. depth = tonumber(read())
  141. print(width, " x ", height, " x ", depth)
  142.  
  143. for d = 1, depth do
  144.     ping(d)
  145.     fDig()
  146.     fMove()
  147.     turtle.turnLeft()
  148.     for h = 1, height do
  149.         for w = 1, width-1 do
  150.           fDig()
  151.           fMove()
  152.           disp(w, h, d)
  153.         end
  154.  
  155.         if(h < height) then
  156.             turtle.turnLeft()
  157.             turtle.turnLeft()
  158.             uDig()
  159.             turtle.up()
  160.         else
  161.             if(height % 2 == 0) then
  162.                 turtle.turnLeft()
  163.                 --print("Waiting for Gravity: ", gravDelay * height)
  164.                 --sleep(gravDelay * height)
  165.                 for i = 2, height do
  166.                     dMove()
  167.                 end
  168.             else
  169.                 turtle.turnLeft()
  170.                 turtle.turnLeft()
  171.                 --print("Waiting for Gravity: ", gravDelay * height)
  172.                 --sleep(gravDelay * height)
  173.                 for i = 2, height do
  174.                     dMove()
  175.                 end
  176.                 for i = 2, width do
  177.                     fMove()
  178.                 end
  179.                 turtle.turnLeft()
  180.             end
  181.         end
  182.     end
  183. end
  184. while(1) do
  185.     print("Done.")
  186.     tx("done")
  187.     os.sleep(1)
  188. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement