Advertisement
pson

PowaDispenser.lua

Aug 4th, 2020 (edited)
1,598
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.82 KB | None | 0 0
  1. function forward()
  2.     while turtle.detect() do
  3.         turtle.dig()
  4.         sleep(0.5)
  5.     end
  6.     flag = turtle.forward()
  7.     while not flag do
  8.         turtle.attack()
  9.         sleep(0.5)
  10.         flag = turtle.forward()
  11.     end
  12. end
  13.  
  14. function up()
  15.     while turtle.detectUp() do
  16.         turtle.digUp()
  17.         sleep(0.5)
  18.     end
  19.     flag = turtle.up()
  20.     while not flag do
  21.         turtle.attackUp()
  22.         sleep(0.5)
  23.         flag = turtle.up()
  24.     end
  25. end
  26.  
  27. function down()
  28.     while turtle.detectDown() do
  29.         turtle.digDown()
  30.         sleep(0.5)
  31.     end
  32.     flag = turtle.down()
  33.     while not flag do
  34.         turtle.attackDown()
  35.         sleep(0.5)
  36.         flag = turtle.down()
  37.     end
  38. end
  39.  
  40. function restock() -- Try to refill slots 1 to 15
  41.     local i, j
  42.     for i=1,13,1 do
  43.         turtle.select(i)
  44.         for j=i+1,14,1 do
  45.             if turtle.compareTo(j) then
  46.                 turtle.select(j)
  47.                 turtle.transferTo(i)
  48.                 turtle.select(i)
  49.             end            
  50.         end
  51.     end
  52. end
  53.  
  54. function check_front()
  55.     if not turtle.detect() then
  56.         if turtle.getItemCount(2) < 2 then
  57.             restock()
  58.         end
  59.         turtle.select(2)
  60.         turtle.place()
  61.     end
  62. end
  63.  
  64. function check_up()
  65.     if not turtle.detectUp() then
  66.         if turtle.getItemCount(2) < 2 then
  67.             restock()
  68.         end
  69.         turtle.select(2)
  70.         turtle.placeUp()
  71.     end
  72. end
  73.  
  74. function check_down()
  75.     if not turtle.detectDown() then
  76.         if turtle.getItemCount(2) < 2 then
  77.             restock()
  78.         end
  79.         turtle.select(2)
  80.         turtle.placeDown()
  81.     end
  82. end
  83.  
  84. function check()
  85.     turtle.turnLeft()
  86.     check_front()
  87.     turtle.turnRight()
  88.     turtle.turnRight()
  89.     check_front()
  90.     turtle.turnLeft()
  91. end
  92.  
  93. function upAndDown()
  94.     check_down()
  95.     check()
  96.     up()
  97.     check()
  98.     up()
  99.     check()
  100.     check_up()
  101.     forward()
  102.     check_up()
  103.     check()
  104.     down()
  105.     check()
  106.     down()
  107.     check()
  108.     check_down()
  109. end
  110.  
  111. function section()
  112.     local i
  113.  
  114.     while turtle.getFuelLevel() < 30 do
  115.         turtle.select(1)
  116.         turtle.refuel(1)
  117.     end
  118.     upAndDown()
  119.     forward()
  120.     upAndDown()
  121.     forward()
  122.     turtle.select(15)
  123.     turtle.turnLeft()
  124.     turtle.turnLeft()
  125.     turtle.place()
  126.     turtle.turnLeft()
  127.     turtle.turnLeft()    
  128.     upAndDown()
  129.     forward()
  130.     upAndDown()
  131.     if turtle.getItemCount(13) > 0 then
  132.         restock()
  133.         turtle.turnLeft()
  134.         turtle.turnLeft()
  135.         turtle.select(16)
  136.         turtle.place()
  137.         for i=3,14,1 do
  138.             turtle.select(i)
  139.             turtle.drop()
  140.         end
  141.         turtle.turnLeft()
  142.         turtle.turnLeft()    
  143.     end
  144. end
  145.  
  146. function tunnel(...)
  147.     local args = {...}
  148.     if #args ~= 1 then
  149.         print "Usage: tunnel <length of tunnel>"
  150.         print "- Slot  1: Fuel"
  151.         print "- Slot  2: Wall filler"
  152.         print "- Slot 15: Torches"
  153.         print "- Slot 16: Chests"
  154.         error()
  155.     end
  156.  
  157.     local i=0
  158.     local tlen=tonumber(args[1])
  159.     while tlen > 0 do
  160.         section()
  161.         tlen = tlen-8
  162.         if tlen > 0 then
  163.             forward()
  164.         end
  165.         i = i+1
  166.     end
  167.     restock()
  168.     turtle.back()
  169.     turtle.select(2)
  170.     turtle.place()
  171.     turtle.up()
  172.     turtle.place()
  173.     turtle.up()
  174.     turtle.place()
  175.     turtle.down()
  176.     turtle.down()    
  177.     turtle.turnLeft()
  178.     turtle.turnLeft()
  179.     up()
  180.     i = (i*8)-2
  181.     while i > 0 do
  182.         while turtle.getFuelLevel() < 10 do
  183.             turtle.select(1)
  184.             turtle.refuel(1)
  185.         end    
  186.         turtle.forward()
  187.         i = i-1
  188.     end
  189.     turtle.select(16)        
  190.     turtle.placeDown()
  191.     for i=1,16,1 do
  192.         turtle.select(i)
  193.         turtle.dropDown()
  194.     end
  195. end
  196. tunnel(...)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement