Guest User

Untitled

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