Guest User

digv4.lua

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