Guest User

Untitled

a guest
May 7th, 2020
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.86 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.  
  10. local passable, state = robot.detect() -- return values for robot.detect()
  11.  
  12.  
  13. local args = {...} -- ... gets the program's arguments somehow
  14. local rowsToDig = args[1] -- getting the first argument in the argument table
  15.  
  16.  
  17.  
  18. local function checkEnergy()
  19.  
  20.         if     computer.energy() <= 200 then
  21.               robot.select(15)
  22.               g.insert()
  23.               robot.select(2)
  24.               robot.drop()
  25.               robot.select(3)
  26.               robot.drop()
  27.               robot.select(5)
  28.               robot.drop()
  29.               robot.select(6)
  30.               robot.drop()
  31.               robot.select(7)
  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.swing()
  47.               robot.select(2)
  48.               robot.transferTo(14)
  49.               os.sleep(20)
  50.               robot.turnRight()
  51.               os.sleep(60)
  52.             end    
  53.           end
  54.  
  55.  
  56. local function placeRails()
  57.   local hasRails = inventory.getStackInInternalSlot(4)
  58.               robot.select(4)
  59.            if robot.count() <=2 then
  60.               robot.select(8)
  61.               robot.turnRight()
  62.               robot.place()
  63.               robot.select(2)
  64.               robot.drop()
  65.               robot.select(3)
  66.               robot.drop()
  67.               robot.select(5)
  68.               robot.drop()
  69.               robot.select(6)
  70.               robot.drop()
  71.               robot.select(7)
  72.               robot.drop()
  73.               robot.select(9)
  74.               robot.drop()
  75.               robot.select(10)
  76.               robot.drop()
  77.               robot.select(11)
  78.               robot.drop()
  79.     for slot = 1, inventory.getInventorySize(3) do
  80.            if hasRails = inventory.getStackInSlot(slot) then
  81.               repeat
  82.               inventory.suckFromSlot(3, slot)
  83.               until robot.count(4) >= 3
  84.           return slot
  85.               robot.swing()
  86.               robot.select(2)
  87.               robot.transferTo(8)
  88.               robot.select(4)
  89.               robot.turnLeft()
  90.             end
  91.           end
  92.         end
  93.               robot.turnAround()
  94.               robot.place()
  95.               robot.turnAround()
  96. end
  97.              
  98.  
  99.  
  100.  
  101. --[[local function checkTool()
  102.         if not robot.durability(0.2) and robot.count(1) <= 0 then
  103.               robot.select(2)
  104.               robot.drop()
  105.               robot.select(3)
  106.               robot.drop()
  107.               robot.select(4)
  108.               robot.drop()
  109.               robot.select(5)
  110.               robot.drop()
  111.               robot.select(6)
  112.               robot.drop()
  113.               robot.select(7)
  114.               robot.drop()
  115.               robot.select(8)
  116.               robot.drop()
  117.               robot.select(9)
  118.               robot.drop()
  119.               robot.select(10)
  120.               robot.drop()
  121.               robot.select(11)
  122.               robot.drop()
  123.               robot.select(17)
  124.               robot.transferTo(2)
  125.               c.craft(1)
  126.               robot.select(2)
  127.               robot.transferTo(17)
  128.            end
  129.         end --]]
  130.  
  131. local function digHollow3x3()
  132.  
  133.       for i = 1, rowsToDig do
  134.  
  135.        
  136.           checkEnergy()
  137.          -- checkTool()
  138.  
  139.        
  140.           robot.detectDown()
  141.         if state == "liquid" or "air" then robot.select(13) -- dev/ null
  142.           robot.placeDown()
  143.         end
  144.  
  145.  
  146.           placeRails()
  147.  
  148.           robot.detect()
  149.         if state == "solid" then robot.swing() -- swing at block 2
  150.           -- checkTool()
  151.         end
  152.          
  153.           repeat
  154.           robot.detect()
  155.           if state == "solid" then robot.swing()
  156.           until state == "liquid" or "air" then robot.forward() -- moving forward
  157.           end
  158.  
  159.  
  160.           robot.turnLeft() -- face left
  161.  
  162.           robot.detect() -- check for solid block
  163.         if state == "solid" then robot.swing() -- swing at block 1
  164.          end
  165.           -- checkTool()
  166.      
  167.  
  168.           repeat
  169.           robot.detect()
  170.           if state == "solid" then robot.swing()
  171.           until state == "liquid" or "air" then robot.forward() -- moving forward under block 4
  172.           end
  173.  
  174.           robot.detectDown() -- detect under block 1
  175.         if state == "liquid" or "air" then robot.select(13) -- dev/ null
  176.           robot.placeDown()
  177.         end
  178.  
  179.           robot.detect() -- detect left side of block 1
  180.         if state == "liquid" or "air" then robot.select(13) -- dev/ null
  181.           robot.place()
  182.         end
  183.  
  184.           robot.turnAround() -- face right
  185.  
  186.           repeat
  187.           robot.detect()
  188.           if state == "solid" then robot.swing()
  189.           until state == "liquid" or "air" then robot.forward() -- moving forward under block 5
  190.           end
  191.  
  192.           robot.detect()
  193.         if state == "solid" then robot.swing()-- swing at block 3
  194.           end        
  195.         -- checkTool()
  196.        
  197.           repeat
  198.           robot.detect()
  199.           if state == "solid" then robot.swing()
  200.           until state == "liquid" or "air" then robot.forward() -- moving forward under block 6
  201.           end
  202.  
  203.           robot.detect() -- detect right side of block 3
  204.         if state == "liquid" or "air" then robot.select(13) -- dev/ null
  205.           robot.place()
  206.         end
  207.  
  208.           robot.detectDown() -- detect under block block 3
  209.         if state == "liquid" or "air" then robot.select(13) -- dev/ null
  210.           robot.place()
  211.         end
  212.  
  213.           robot.detectUp()
  214.         if state == "solid" then robot.swingUp()-- swing at block 6
  215.         end        
  216.         --  checkTool()
  217.        
  218.  
  219.         repeat
  220.         robot.detectUp()
  221.         if state == "solid" then robot.swing()
  222.         until state == "liquid" or "air" then robot.up() -- moving up under block 9
  223.         end
  224.  
  225.           robot.detect() -- detect block right of block 6
  226.         if state == "liquid" or "air" then robot.select(13) -- dev/ null
  227.           robot.place()
  228.         end
  229.  
  230.           robot.turnAround() -- face left
  231.  
  232.           robot.detect()
  233.         if state == "solid" then robot.swing() -- swing at block 5
  234.           end
  235.  
  236.           repeat
  237.           robot.detect()
  238.           if state == "solid" then robot.swing()
  239.           until state == "liquid" or "air" then robot.forward() -- moving forward under block 8
  240.           end
  241.  
  242.           robot.detect()
  243.         if state == "solid" then robot.swing()          -- swing at block 4
  244.          end
  245.          --  checkTool()
  246.  
  247.           repeat
  248.           robot.detect()
  249.           if state == "solid" then robot.swing()
  250.           until state == "liquid" or "air" then robot.forward() -- moving forward under block 7
  251.           end
  252.  
  253.           robot.detect() -- detect block at right of block 4
  254.         if state == "liquid" or "air" then robot.select(13) -- dev/ null
  255.           robot.place()
  256.         end
  257.  
  258.           robot.detectUp()
  259.         if state == "solid" then robot.swingUp() -- swing at block 7
  260.           checkTool()
  261.         end
  262.  
  263.           repeat
  264.         robot.detectUp()
  265.         if state == "solid" then robot.swing()
  266.         until state == "liquid" or "air" then robot.up() -- moving up at block 7 position
  267.         end
  268.  
  269.           robot.detect() -- detect block on left side of block 7
  270.         if state == "liquid" or "air" then robot.select(13) -- dev/ null
  271.           robot.place()
  272.         end
  273.  
  274.           robot.detectUp() -- detect block above block 7
  275.         if state == "liquid" or "air" then robot.select(13) -- dev/null
  276.           robot.placeUp()
  277.         end
  278.  
  279.           robot.turnAround() -- face right
  280.  
  281.           robot.detect()
  282.         if state == "solid" then robot.swing() -- swing at block 8
  283.         --  checkTool()
  284.         end
  285.  
  286.           repeat
  287.           robot.detect()
  288.           if state == "solid" then robot.swing()
  289.           until state == "liquid" or "air" then robot.forward() -- moving forward at block 8 position
  290.           end
  291.  
  292.           robot.detectUp() -- detect block above block 8
  293.         if state == "liquid" or "air" then robot.select(13)
  294.           robot.placeUp()
  295.         end
  296.  
  297.           robot.detect()
  298.         if state == "solid" then robot.swing()
  299.          end
  300.  
  301.           repeat
  302.           robot.detect()
  303.           if state == "solid" then robot.swing()
  304.           until state == "liquid" or "air" then robot.forward() -- moving forward at block 9 position
  305.           end
  306.  
  307.           robot.detectUp() -- detect block above block 9
  308.         if state == "liquid" or "air" then robot.select(13)
  309.           robot.placeUp()
  310.         end
  311.  
  312.           robot.detect() -- detect block on the right of block 9
  313.         if state == "liquid" or "air" then robot.select(13)
  314.           robot.place()
  315.         end
  316.  
  317.           robot.turnAround()
  318.  
  319.           repeat
  320.           robot.detect()
  321.           if state == "solid" then robot.swing()
  322.           until state == "liquid" or "air" then robot.forward() -- moving forward
  323.           end
  324.  
  325.           robot.turnRight() -- face toward next layer
  326.  
  327.           repeat
  328.           robot.detectDown()
  329.           if state == "solid" then robot.swing()
  330.           until state == "liquid" or "air" then robot.down()
  331.           end
  332.  
  333.           repeat
  334.           robot.detectDown()
  335.           if state == "solid" then robot.swing()
  336.           until state == "liquid" or "air" then robot.down()
  337.           end
  338.  
  339.  
  340. digHollow3x3()
Add Comment
Please, Sign In to add comment