Guest User

digv3.lua

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