Guest User

Untitled

a guest
May 4th, 2020
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.73 KB | None | 0 0
  1. local robot = require("robot")
  2. local computer = require("computer")
  3. local sides = require("sides")
  4. local component = require("component")
  5.  
  6. local c = component.crafting
  7. local inventory = component.inventory_controller
  8. local g = component.generator
  9. local passable, state = robot.detect() -- return values for robot.detect()
  10. local args = {...} -- ... gets the program's arguments somehow
  11. local rowsToDig = args[1] -- getting the first argument in the argument table
  12.  
  13.  
  14. local function checkEnergy()
  15.  
  16.         if     computer.energy() <= 200 then
  17.               robot.select(15)
  18.               g.insert()
  19.               robot.select(2)
  20.               robot.drop()
  21.               robot.select(3)
  22.               robot.drop()
  23.               robot.select(4)
  24.               robot.drop()
  25.               robot.select(5)
  26.               robot.drop()
  27.               robot.select(6)
  28.               robot.drop()
  29.               robot.select(7)
  30.               robot.drop()
  31.               robot.select(8)
  32.               robot.drop()
  33.               robot.select(9)
  34.               robot.drop()
  35.               robot.select(10)
  36.               robot.drop()
  37.               robot.select(11)
  38.               robot.drop()
  39.               robot.select(14)
  40.               robot.turnLeft()
  41.               robot.place()
  42.               robot.select(15)
  43.               inventory.suckFromSlot(3, 1)
  44.               g.insert()
  45.               inventory.suckFromSlot(3, 1)
  46.               robot.select(2)
  47.               robot.transferTo(14)
  48.               os.sleep(20)
  49.               robot.swing()
  50.               robot.turnRight()
  51.               os.sleep(60)
  52.         until computer.energy() >= 201
  53.           else  computer.shutdown()
  54.             end    
  55.  
  56.  
  57.  
  58.  
  59.  
  60. local function checkTool()
  61.         if not robot.durability() <= 0.2 and robot.count(1) <= 0 then
  62.           repeat
  63.               robot.select(2)
  64.               robot.drop()
  65.               robot.select(3)
  66.               robot.drop()
  67.               robot.select(4)
  68.               robot.drop()
  69.               robot.select(5)
  70.               robot.drop()
  71.               robot.select(6)
  72.               robot.drop()
  73.               robot.select(7)
  74.               robot.drop()
  75.               robot.select(8)
  76.               robot.drop()
  77.               robot.select(9)
  78.               robot.drop()
  79.               robot.select(10)
  80.               robot.drop()
  81.               robot.select(11)
  82.               robot.drop()
  83.               robot.select(17)
  84.               robot.transferTo(2)
  85.               c.craft(1)
  86.               robot.select(2)
  87.               robot.transferTo(17)
  88.       until    robot.durability() == 1 or robot.count(1) <= 0 and robot.durability() >= 0.2
  89.         else  computer.shutdown()
  90.       end
  91.    
  92.  
  93. local function digHollow3x3()
  94.  
  95.       for i = 1, rowsToDig do
  96.  
  97.        
  98.           checkEnergy()
  99.           checkTool()
  100.  
  101.        
  102.           robot.detectDown()
  103.         if state == "liquid" or "air" then robot.select(13) -- dev/ null
  104.           robot.placeDown()
  105.         end
  106.  
  107.           robot.select(4) -- rails
  108.           robot.placeDown()
  109.  
  110.           robot.detect()
  111.         if state == "solid" then robot.swing() -- swing at block 2
  112.           checkTool()
  113.         end
  114.          
  115.           robot.forward()      
  116.           robot.turnLeft() -- face left
  117.  
  118.           robot.detect() -- check for solid block
  119.         if state == "solid" then robot.swing() -- swing at block 1
  120.           checkTool()
  121.         end
  122.  
  123.           robot.forward() -- under block 4
  124.  
  125.           robot.detectDown() -- detect under block 1
  126.         if state == "liquid" or "air" then robot.select(13) -- dev/ null
  127.           robot.placeDown()
  128.         end
  129.  
  130.           robot.detect() -- detect left side of block 1
  131.         if state == "liquid" or "air" then robot.select(13) -- dev/ null
  132.           robot.place()
  133.         end
  134.  
  135.           robot.turnAround() -- face right
  136.           robot.forward() -- under block 5
  137.  
  138.           robot.detect()
  139.         if state == "solid" then robot.swing()-- swing at block 3
  140.           checkTool()
  141.         end
  142.  
  143.           robot.forward() -- under block 6
  144.  
  145.           robot.detect() -- detect right side of block 3
  146.         if state == "liquid" or "air" then robot.select(13) -- dev/ null
  147.           robot.place()
  148.         end
  149.  
  150.           robot.detectDown() -- detect under block block 3
  151.         if state == "liquid" or "air" then robot.select(13) -- dev/ null
  152.           robot.place()
  153.         end
  154.  
  155.           robot.detectUp()
  156.         if state == "solid" then robot.swing()-- swing at block 6
  157.           checkTool()
  158.         end
  159.  
  160.           robot.up() -- under block 9
  161.  
  162.           robot.detect() -- detect block right of block 6
  163.         if state == "liquid" or "air" then robot.select(13) -- dev/ null
  164.           robot.place()
  165.         end
  166.  
  167.           robot.turnAround() -- face left
  168.  
  169.           robot.detect()
  170.         if state == "solid" then robot.swing() -- swing at block 5
  171.           checkTool()
  172.         end
  173.  
  174.           robot.forward() -- under block 8
  175.  
  176.           robot.detect()
  177.         if state == "solid" then robot.swing()          -- swing at block 4
  178.           checkTool()
  179.         end
  180.  
  181.           robot.forward() -- under block 7
  182.  
  183.           robot.detect() -- detect block at right of block 4
  184.         if state == "liquid" or "air" then robot.select(13) -- dev/ null
  185.           robot.place()
  186.         end
  187.  
  188.           robot.detectUp()
  189.         if state == "solid" then robot.swing() -- swing at block 7
  190.           checkTool()
  191.         end
  192.  
  193.           robot.up() -- at block 7 position
  194.  
  195.           robot.detect() -- detect block on left side of block 7
  196.         if state == "liquid" or "air" then robot.select(13) -- dev/ null
  197.           robot.place()
  198.         end
  199.  
  200.           robot.detectUp() -- detect block above block 7
  201.         if state == "liquid" or "air" then robot.select(13) -- dev/null
  202.           robot.placeUp()
  203.         end
  204.  
  205.           robot.turnAround() -- face right
  206.  
  207.           robot.detect()
  208.         if state == "solid" then robot.swing() -- swing at block 8
  209.           checkTool()
  210.         end
  211.  
  212.           robot.forward() -- at block 8 position
  213.  
  214.           robot.detectUp() -- detect block above block 8
  215.         if state == "liquid" or "air" then robot.select(13)
  216.           robot.placeUp()
  217.         end
  218.  
  219.           robot.forward() -- at block 9 position
  220.          
  221.           robot.detectUp() -- detect block above block 9
  222.         if state == "liquid" or "air" then robot.select(13)
  223.           robot.placeUp()
  224.         end
  225.  
  226.           robot.detect() -- detect block on the right of block 9
  227.         if state == "liquid" or "air" then robot.select(13)
  228.           robot.place()
  229.         end
  230.  
  231.           robot.back()
  232.           robot.turnLeft() -- face toward next layer
  233.           robot.down(2)
  234.   end
  235.  
  236. digHollow3x3()
Add Comment
Please, Sign In to add comment