Advertisement
eduinus

railer.lua

Oct 23rd, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 29.20 KB | None | 0 0
  1. local robot = require("robot")
  2. local term = require("term")
  3. local os = require("os")
  4. local component = require("component")
  5. local sides = require("sides")
  6. local keyboard = require("keyboard")
  7. local computer = require("computer")
  8.  
  9. function tableLength(table)
  10.   count = 1
  11.   while table[count] ~= nil do
  12.     count=count+1
  13.   end
  14.   return count-1
  15. end
  16.  
  17. function move()
  18.     swung = false
  19.     while robot.detect() do
  20.         robot.select(1) robot.swing()
  21.     swung = true
  22.     invCount = robot.inventorySize() -- check if need to dump garbage
  23.     if component.inventory_controller.getStackInInternalSlot(1) ~= nil then
  24.       robot.select(1)
  25.       while component.inventory_controller.getStackInInternalSlot(invCount) ~= nil and (robot.compareTo(invCount) == false or component.inventory_controller.getStackInInternalSlot(invCount).size == component.inventory_controller.getStackInInternalSlot(invCount).maxSize) do
  26.         if invCount == itemArray[tableLength(itemArray)][1]+1 then
  27.           robot.select(3) robot.place()
  28.             for x=itemArray[tableLength(itemArray)][1]+1, robot.inventorySize() do
  29.               robot.select(x)
  30.               while robot.drop() == false do end
  31.             end
  32.           robot.select(3) robot.swing()
  33.           invCount = robot.inventorySize()
  34.         else invCount = invCount - 1
  35.         end
  36.       end
  37.       robot.select(1)
  38.       robot.transferTo(invCount)
  39.     end
  40.     end
  41.  
  42.     if computer.energy() / computer.maxEnergy() <= 0.025 then
  43.         while computer.energy() / computer.maxEnergy() <= 0.975 do
  44.             if component.generator.count() < 1 then -- refuel
  45.                 print("Refueling!")
  46.                 robot.select(3) robot.place() robot.select(1)
  47.             while component.generator.count() < 64 do robot.suck(64-component.generator.count()) component.generator.insert() end
  48.             robot.select(3) robot.swing()
  49.             end
  50.             print("Charging... "..computer.energy())
  51.             os.sleep(10)
  52.         end
  53.         print("Charged: "..computer.energy())
  54.     end
  55.  
  56.     while robot.forward() ~= true do end
  57.   return swung
  58. end
  59.  
  60. function moveUp()
  61.     swung = false
  62.     while robot.detectUp() do
  63.         robot.select(1) robot.swingUp()
  64.     swung = true
  65.     invCount = robot.inventorySize() -- check if need to dump garbage
  66.     if component.inventory_controller.getStackInInternalSlot(1) ~= nil then
  67.       robot.select(1)
  68.       while component.inventory_controller.getStackInInternalSlot(invCount) ~= nil and (robot.compareTo(invCount) == false or component.inventory_controller.getStackInInternalSlot(invCount).size == component.inventory_controller.getStackInInternalSlot(invCount).maxSize) do
  69.         if invCount == itemArray[tableLength(itemArray)][1]+1 then
  70.           robot.select(3) robot.placeUp()
  71.             for x=itemArray[tableLength(itemArray)][1]+1, robot.inventorySize() do
  72.               robot.select(x)
  73.               while robot.dropUp() == false do end
  74.             end
  75.           robot.select(3) robot.swingUp()
  76.           invCount = robot.inventorySize()
  77.         else invCount = invCount - 1
  78.         end
  79.       end
  80.       robot.select(1)
  81.       robot.transferTo(invCount)
  82.     end
  83.     end
  84.  
  85.     if computer.energy() / computer.maxEnergy() <= 0.025 then
  86.         while computer.energy() / computer.maxEnergy() <= 0.975 do
  87.             if component.generator.count() < 1 then -- refuel
  88.                 print("Refueling!")
  89.                 robot.select(3) robot.placeUp() robot.select(1)
  90.             while component.generator.count() < 64 do robot.suckUp(64-component.generator.count()) component.generator.insert() end
  91.             robot.select(3) robot.swingUp()
  92.             end
  93.             print("Charging... "..computer.energy())
  94.             os.sleep(10)
  95.         end
  96.         print("Charged: "..computer.energy())
  97.     end
  98.  
  99.     while robot.up() ~= true do end
  100.   return swung
  101. end
  102.  
  103. function moveDown()
  104.     swung = false
  105.     while robot.detectDown() do
  106.         robot.select(1) robot.swingDown()
  107.     swung = true
  108.     invCount = robot.inventorySize() -- check if need to dump garbage
  109.     if component.inventory_controller.getStackInInternalSlot(1) ~= nil then
  110.       robot.select(1)
  111.       while component.inventory_controller.getStackInInternalSlot(invCount) ~= nil and (robot.compareTo(invCount) == false or component.inventory_controller.getStackInInternalSlot(invCount).size == component.inventory_controller.getStackInInternalSlot(invCount).maxSize) do
  112.         if invCount == itemArray[tableLength(itemArray)][1]+1 then
  113.           robot.select(3) robot.placeDown()
  114.             for x=itemArray[tableLength(itemArray)][1]+1, robot.inventorySize() do
  115.               robot.select(x)
  116.               while robot.dropDown() == false do end
  117.             end
  118.           robot.select(3) robot.swingDown()
  119.           invCount = robot.inventorySize()
  120.         else invCount = invCount - 1
  121.         end
  122.       end
  123.       robot.select(1)
  124.       robot.transferTo(invCount)
  125.     end
  126.     end
  127.  
  128.     if computer.energy() / computer.maxEnergy() <= 0.025 then
  129.         while computer.energy() / computer.maxEnergy() <= 0.975 do
  130.             if component.generator.count() < 1 then -- refuel
  131.                 print("Refueling!")
  132.                 robot.select(3) robot.placeDown() robot.select(1)
  133.             while component.generator.count() < 64 do robot.suckDown(64-component.generator.count()) component.generator.insert() end
  134.             robot.select(3) robot.swingDown()
  135.             end
  136.             print("Charging... "..computer.energy())
  137.             os.sleep(10)
  138.         end
  139.         print("Charged: "..computer.energy())
  140.     end
  141.  
  142.     while robot.down() ~= true do end
  143.   return swung
  144. end
  145.  
  146. function moveBack()
  147.     swung = false
  148.     if robot.back() ~= true then
  149.         robot.turnAround()
  150.         swung = true
  151.         robot.select(1)
  152.         while robot.detect() do
  153.             robot.swing()
  154.             os.sleep(0.2)
  155.         invCount = robot.inventorySize() -- check if need to dump garbage
  156.         if component.inventory_controller.getStackInInternalSlot(1) ~= nil then
  157.             robot.select(1)
  158.             while component.inventory_controller.getStackInInternalSlot(invCount) ~= nil and (robot.compareTo(invCount) == false or component.inventory_controller.getStackInInternalSlot(invCount).size == component.inventory_controller.getStackInInternalSlot(invCount).maxSize) do
  159.                 if invCount == itemArray[tableLength(itemArray)][1]+1 then
  160.                     robot.select(3) robot.place()
  161.                     for x=itemArray[tableLength(itemArray)][1]+1, robot.inventorySize() do
  162.                         robot.select(x)
  163.                         while robot.drop() == false do end
  164.                     end
  165.                     robot.select(3) robot.swing()
  166.                     invCount = robot.inventorySize()
  167.                 else
  168.                     invCount = invCount - 1
  169.                 end
  170.             end
  171.             robot.select(1)
  172.             robot.transferTo(invCount)
  173.         end
  174.         end
  175.     end
  176.  
  177.     if computer.energy() / computer.maxEnergy() <= 0.025 then
  178.         while computer.energy() / computer.maxEnergy() <= 0.975 do
  179.             if component.generator.count() < 1 then -- refuel
  180.                 print("Refueling!")
  181.                 robot.select(3) robot.place() robot.select(1)
  182.             while component.generator.count() < 64 do robot.suck(64-component.generator.count()) component.generator.insert() end
  183.             robot.select(3) robot.swing()
  184.             end
  185.             print("Charging... "..computer.energy())
  186.             os.sleep(10)
  187.         end
  188.         print("Charged: "..computer.energy())
  189.     end
  190.  
  191.     if swung == true then
  192.         robot.turnAround()
  193.         while robot.back() ~= true do end
  194.     end
  195.     return swung
  196. end
  197.  
  198. function dig()
  199.   while robot.detect() do
  200.         robot.select(1) robot.swing()
  201.     invCount = robot.inventorySize() -- check if need to dump garbage
  202.     if component.inventory_controller.getStackInInternalSlot(1) ~= nil then
  203.       while component.inventory_controller.getStackInInternalSlot(invCount) ~= nil and (robot.compareTo(invCount) == false or component.inventory_controller.getStackInInternalSlot(invCount).size == component.inventory_controller.getStackInInternalSlot(invCount).maxSize) do
  204.         if invCount == itemArray[tableLength(itemArray)][1]+1 then
  205.           robot.select(3) robot.place()
  206.             for x=itemArray[tableLength(itemArray)][1]+1, robot.inventorySize() do
  207.               robot.select(x)
  208.               while robot.drop() == false do end
  209.             end
  210.           robot.select(3) robot.swing()
  211.           invCount = robot.inventorySize()
  212.         else invCount = invCount - 1
  213.         end
  214.       end
  215.       robot.select(1)
  216.       robot.transferTo(invCount)
  217.     end
  218.     end
  219.  
  220.     if computer.energy() / computer.maxEnergy() <= 0.025 then
  221.         while computer.energy() / computer.maxEnergy() <= 0.975 do
  222.             if component.generator.count() < 1 then -- refuel
  223.                 print("Refueling!")
  224.                 robot.select(3) robot.place() robot.select(1)
  225.             while component.generator.count() < 64 do robot.suck(64-component.generator.count()) component.generator.insert() end
  226.             robot.select(3) robot.swing()
  227.             end
  228.             term.clearLine()
  229.             print("Charging... "..computer.energy())
  230.             os.sleep(10)
  231.         end
  232.         print("Charged: "..computer.energy())
  233.     end
  234. end
  235.  
  236. function digDown()
  237.     while robot.detectDown() do
  238.         robot.select(1) robot.swingDown()
  239.     invCount = robot.inventorySize() -- check if need to dump garbage
  240.     if component.inventory_controller.getStackInInternalSlot(1) ~= nil then
  241.       while component.inventory_controller.getStackInInternalSlot(invCount) ~= nil and (robot.compareTo(invCount) == false or component.inventory_controller.getStackInInternalSlot(invCount).size == component.inventory_controller.getStackInInternalSlot(invCount).maxSize) do
  242.         if invCount == itemArray[tableLength(itemArray)][1]+1 then
  243.           robot.select(3) robot.placeDown()
  244.             for x=itemArray[tableLength(itemArray)][1]+1, robot.inventorySize() do
  245.               robot.select(x)
  246.               while robot.dropDown() == false do end
  247.             end
  248.           robot.select(3) robot.swingDown()
  249.           invCount = robot.inventorySize()
  250.         else invCount = invCount - 1
  251.         end
  252.       end
  253.       robot.select(1)
  254.       robot.transferTo(invCount)
  255.     end
  256.     end
  257.  
  258.     if computer.energy() / computer.maxEnergy() <= 0.025 then
  259.         while computer.energy() / computer.maxEnergy() <= 0.975 do
  260.             if component.generator.count() < 1 then -- refuel
  261.                 print("Refueling!")
  262.                 robot.select(3) robot.placeDown() robot.select(1)
  263.             while component.generator.count() < 64 do robot.suckDown(64-component.generator.count()) component.generator.insert() end
  264.             robot.select(3) robot.swingDown()
  265.             end
  266.             print("Charging... "..computer.energy())
  267.             os.sleep(10)
  268.         end
  269.         print("Charged: "..computer.energy())
  270.     end
  271. end
  272.  
  273. function digUp()
  274.     while robot.detectUp() do
  275.         robot.select(1) robot.swingUp()
  276.     invCount = robot.inventorySize() -- check if need to dump garbage
  277.     if component.inventory_controller.getStackInInternalSlot(1) ~= nil then
  278.       while component.inventory_controller.getStackInInternalSlot(invCount) ~= nil and (robot.compareTo(invCount) == false or component.inventory_controller.getStackInInternalSlot(invCount).size == component.inventory_controller.getStackInInternalSlot(invCount).maxSize) do
  279.         if invCount == itemArray[tableLength(itemArray)][1]+1 then
  280.           robot.select(3) robot.placeUp()
  281.             for x=itemArray[tableLength(itemArray)][1]+1, robot.inventorySize() do
  282.               robot.select(x)
  283.               while robot.dropUp() == false do end
  284.             end
  285.           robot.select(3) robot.swingUp()
  286.           invCount = robot.inventorySize()
  287.         else invCount = invCount - 1
  288.         end
  289.       end
  290.       robot.select(1)
  291.       robot.transferTo(invCount)
  292.     end
  293.     end
  294.  
  295.     if computer.energy() / computer.maxEnergy() <= 0.025 then
  296.         while computer.energy() / computer.maxEnergy() <= 0.975 do
  297.             if component.generator.count() < 1 then -- refuel
  298.                 print("Refueling!")
  299.                 robot.select(3) robot.placeUp() robot.select(1)
  300.             while component.generator.count() < 64 do robot.suckUp(64-component.generator.count()) component.generator.insert() end
  301.             robot.select(3) robot.swingUp()
  302.             end
  303.             print("Charging... "..computer.energy())
  304.             os.sleep(10)
  305.         end
  306.         print("Charged: "..computer.energy())
  307.     end
  308. end
  309.  
  310. itemArray = {}
  311.     -- SLOT 1 FOR PICK (ideally infinipick)
  312.     itemArray[1] = {} itemArray[1][1] = 4 itemArray[1][2] = 2 itemArray[1][3] = 9 itemArray[1][4] = "bricks" -- misc tesseract 1
  313.     itemArray[2] = {} itemArray[2][1] = 5 itemArray[2][2] = 2 itemArray[2][3] = 10 itemArray[2][4] = "smoothBricks" -- misc tesseract 2
  314.     itemArray[3] = {} itemArray[3][1] = 6 itemArray[3][2] = 2 itemArray[3][3] = 11 itemArray[3][4] = "lantern" -- misc tesseract 3
  315.     itemArray[4] = {} itemArray[4][1] = 7 itemArray[4][2] = 2 itemArray[4][3] = 12 itemArray[4][4] = "glass" -- misc tesseract 4
  316.     itemArray[5] = {} itemArray[5][1] = 8 itemArray[5][2] = 2 itemArray[5][3] = 13 itemArray[5][4] = "fence" -- misc tesseract 5
  317.     -- NB SLOT 3 FOR FUEL AND TRASH TELE
  318.  
  319. function place(blockName)
  320.     swung = false
  321.     while robot.detect() do -- check for blockage
  322.         robot.select(1) robot.swing()
  323.         swung = true
  324.     invCount = robot.inventorySize() -- check if need to dump garbage
  325.     if component.inventory_controller.getStackInInternalSlot(1) ~= nil then
  326.       while component.inventory_controller.getStackInInternalSlot(invCount) ~= nil and (robot.compareTo(invCount) == false or component.inventory_controller.getStackInInternalSlot(invCount).size == component.inventory_controller.getStackInInternalSlot(invCount).maxSize) do
  327.         if invCount == itemArray[tableLength(itemArray)][1]+1 then
  328.           robot.select(3) robot.place()
  329.             for x=itemArray[tableLength(itemArray)][1]+1, robot.inventorySize() do
  330.               robot.select(x)
  331.               while robot.drop() == false do end
  332.             end
  333.           robot.select(3) robot.swing()
  334.           invCount = robot.inventorySize()
  335.         else invCount = invCount - 1
  336.         end
  337.       end
  338.       robot.select(1)
  339.       robot.transferTo(invCount)
  340.     end
  341.     end
  342.  
  343.     for blocki=1, tableLength(itemArray) do -- need to restock?
  344.         if itemArray[blocki][4] == blockName then
  345.             if component.inventory_controller.getStackInInternalSlot(itemArray[blocki][1]) == nil then
  346.                 if blockName ~= "stoneBrick" then
  347.                     robot.select(itemArray[blocki][2])
  348.                     robot.place()
  349.                     print("Restocking "..itemArray[blocki][4]..".")
  350.                     robot.select(itemArray[blocki][1])
  351.                     component.inventory_controller.suckFromSlot(3,itemArray[blocki][3],(component.inventory_controller.getSlotMaxStackSize(3,itemArray[blocki][3])-1))
  352.                     robot.select(itemArray[blocki][2]) robot.swing() os.sleep(0.2)
  353.                 else
  354.                     if itemArray[blocki][1]<16 then
  355.                         while component.inventory_controller.getStackInInternalSlot(itemArray[blocki][1]) == nil and itemArray[blocki][1]<16 do
  356.                             itemArray[blocki][1] = itemArray[blocki][1] + 1
  357.                         end
  358.                     else
  359.                         itemArray[blocki][1] = 6
  360.                         robot.select(itemArray[blocki][2])
  361.                         robot.place()
  362.                         print("Restocking "..itemArray[blocki][4]..".")
  363.                         for stonei=itemArray[blocki][1], 16 do
  364.                             robot.select(stonei)
  365.                             component.inventory_controller.suckFromSlot(3,9,64)
  366.                             while component.inventory_controller.getSlotStackSize(3,9)<component.inventory_controller.getSlotMaxStackSize(3,9) do os.sleep(1) end
  367.                         end
  368.                         robot.select(itemArray[blocki][2]) robot.swing() os.sleep(0.2)
  369.                     end
  370.                 end
  371.             end
  372.             robot.select(itemArray[blocki][1])
  373.         end
  374.     end
  375.  
  376.     if blockName == "ladder" then
  377.         if robot.place(3) == false then robot.place() end
  378.     else
  379.         if robot.place(0) == false then robot.place() end
  380.     end
  381.  
  382.     return swung
  383. end
  384.  
  385. function placeUp(blockName)
  386.     swung = false
  387.     while robot.detectUp() do -- check for blockage
  388.         robot.select(1) robot.swingUp()
  389.         swung = true
  390.     invCount = robot.inventorySize() -- check if need to dump garbage
  391.     if component.inventory_controller.getStackInInternalSlot(1) ~= nil then
  392.       while component.inventory_controller.getStackInInternalSlot(invCount) ~= nil and (robot.compareTo(invCount) == false or component.inventory_controller.getStackInInternalSlot(invCount).size == component.inventory_controller.getStackInInternalSlot(invCount).maxSize) do
  393.         if invCount == itemArray[tableLength(itemArray)][1]+1 then
  394.           robot.select(3) robot.placeUp()
  395.             for x=itemArray[tableLength(itemArray)][1]+1, robot.inventorySize() do
  396.               robot.select(x)
  397.               while robot.dropUp() == false do end
  398.             end
  399.           robot.select(3) robot.swingUp()
  400.           invCount = robot.inventorySize()
  401.         else invCount = invCount - 1
  402.         end
  403.       end
  404.       robot.select(1)
  405.       robot.transferTo(invCount)
  406.     end
  407.     end
  408.  
  409.     for blocki=1, tableLength(itemArray) do -- need to restock?
  410.       if itemArray[blocki][4] == blockName then
  411.         if component.inventory_controller.getStackInInternalSlot(itemArray[blocki][1]) == nil then
  412.           if blockName ~= "stoneBrick" then
  413.           robot.select(itemArray[blocki][2])
  414.           robot.placeUp()
  415.           print("Restocking "..itemArray[blocki][4]..".")
  416.           robot.select(itemArray[blocki][1])
  417.           component.inventory_controller.suckFromSlot(1,itemArray[blocki][3],(component.inventory_controller.getSlotMaxStackSize(1,itemArray[blocki][3])-1))
  418.           robot.select(itemArray[blocki][2]) robot.swingUp() os.sleep(0.2)
  419.         else
  420.           if itemArray[blocki][1]<16 then
  421.             while component.inventory_controller.getStackInInternalSlot(itemArray[blocki][1]) == nil and itemArray[blocki][1]<16 do
  422.               itemArray[blocki][1] = itemArray[blocki][1] + 1
  423.             end
  424.           else
  425.             itemArray[blocki][1] = 6
  426.             robot.select(itemArray[blocki][2])
  427.             robot.placeUp()
  428.             print("Restocking "..itemArray[blocki][4]..".")
  429.             for stonei=itemArray[blocki][1], 16 do
  430.               robot.select(stonei)
  431.               while component.inventory_controller.getSlotStackSize(1,9)<component.inventory_controller.getSlotMaxStackSize(1,9) do os.sleep(1) end
  432.               component.inventory_controller.suckFromSlot(1,9,64)
  433.             end
  434.           robot.select(itemArray[blocki][2]) robot.swingUp() os.sleep(0.2)
  435.           end
  436.         end
  437.         end
  438.       robot.select(itemArray[blocki][1])
  439.       end
  440.     end
  441.     if robot.placeUp(1) == false then robot.placeUp() end
  442.     return swung
  443. end
  444.  
  445. function placeDown(blockName)
  446.     swung = false
  447.     while robot.detectDown() do -- check for blockage
  448.         robot.select(1) robot.swingDown()
  449.         swung = true
  450.     invCount = robot.inventorySize() -- check if need to dump garbage
  451.     if component.inventory_controller.getStackInInternalSlot(1) ~= nil then
  452.       while component.inventory_controller.getStackInInternalSlot(invCount) ~= nil and (robot.compareTo(invCount) == false or component.inventory_controller.getStackInInternalSlot(invCount).size == component.inventory_controller.getStackInInternalSlot(invCount).maxSize) do
  453.         if invCount == itemArray[tableLength(itemArray)][1]+1 then
  454.           robot.select(3) robot.placeDown()
  455.             for x=itemArray[tableLength(itemArray)][1]+1, robot.inventorySize() do
  456.               robot.select(x)
  457.               while robot.dropDown() == false do end
  458.             end
  459.           robot.select(3) robot.swingDown()
  460.           invCount = robot.inventorySize()
  461.         else invCount = invCount - 1
  462.         end
  463.       end
  464.       robot.select(1)
  465.       robot.transferTo(invCount)
  466.     end
  467.     end
  468.  
  469.     for blocki=1, tableLength(itemArray) do -- need to restock?
  470.       if itemArray[blocki][4] == blockName then
  471.         if component.inventory_controller.getStackInInternalSlot(itemArray[blocki][1]) == nil then
  472.           if blockName ~= "stoneBrick" then
  473.           robot.select(itemArray[blocki][2])
  474.           robot.placeDown()
  475.           print("Restocking "..itemArray[blocki][4]..".")
  476.           robot.select(itemArray[blocki][1])
  477.           component.inventory_controller.suckFromSlot(0,itemArray[blocki][3],(component.inventory_controller.getSlotMaxStackSize(0,itemArray[blocki][3])-1))
  478.           robot.select(itemArray[blocki][2]) robot.swingDown() os.sleep(0.2)
  479.         else
  480.           if itemArray[blocki][1]<16 then
  481.             while component.inventory_controller.getStackInInternalSlot(itemArray[blocki][1]) == nil and itemArray[blocki][1]<16 do
  482.               itemArray[blocki][1] = itemArray[blocki][1] + 1
  483.             end
  484.           else
  485.             itemArray[blocki][1] = 6
  486.             robot.select(itemArray[blocki][2])
  487.             robot.placeDown()
  488.             print("Restocking "..itemArray[blocki][4]..".")
  489.             for stonei=itemArray[blocki][1], 16 do
  490.               robot.select(stonei)
  491.               while component.inventory_controller.getSlotStackSize(0,9)<component.inventory_controller.getSlotMaxStackSize(0,9) do os.sleep(1) end
  492.               component.inventory_controller.suckFromSlot(0,9,64)
  493.             end
  494.           robot.select(itemArray[blocki][2]) robot.swingDown() os.sleep(0.2)
  495.           end
  496.         end
  497.         end
  498.       robot.select(itemArray[blocki][1])
  499.       end
  500.     end
  501.     if blockName == "log" then
  502.         if robot.placeDown(3) == false then
  503.             if robot.placeDown(2) == false then
  504.                 robot.placeDown()
  505.             end
  506.         end
  507.     elseif blockName == "torch" then
  508.         torchI = 2
  509.         while torchI <=5 and robot.placeDown(torchI) == false do
  510.             torchI = torchI + 1
  511.         end
  512.         if torchI == 6 then
  513.             robot.placeDown()
  514.         end
  515.     else
  516.         if robot.placeDown(0) == false then
  517.             robot.placeDown()
  518.         end
  519.     end
  520.     return swung
  521. end
  522.  
  523. function checkGlass() -- moves robot into chunk, checks if it should be glassed
  524.     for i=1, 2 do move() end
  525.     moveUp()
  526.     robot.turnRight()
  527.     move()
  528.     rwGlass = true
  529.     for checker=1, 7 do -- right window
  530.         if robot.detect() then rwGlass = false end
  531.         moveUp()
  532.         if robot.detect() then rWGlass = false end
  533.         robot.turnLeft()
  534.         move()
  535.         robot.turnRight()
  536.         if robot.detect() then rwGlass = false end
  537.         moveDown()
  538.         if robot.detect() then rwGlass = false end
  539.         if checker < 7 then
  540.             robot.turnLeft()
  541.             move()
  542.             robot.turnRight()
  543.         end
  544.     end
  545.     for i=1, 3 do moveBack() end
  546.     for i=1, 2 do moveDown() end
  547.     robot.turnAround()
  548.     bwGlass = true
  549.     for checker=1, 7 do -- bottom window
  550.         if robot.detectDown() then bwGlass = false end
  551.         move()
  552.         if robot.detectDown() then bwGlass = false end
  553.         robot.turnLeft()
  554.         move()
  555.         robot.turnRight()
  556.         if robot.detectDown() then bwGlass = false end
  557.         moveBack()
  558.         if robot.detectDown() then bwGlass = false end
  559.         if checker < 7 then
  560.             robot.turnLeft()
  561.             move()
  562.             robot.turnRight()
  563.         end
  564.     end
  565.     for i=1, 2 do moveUp() end
  566.     for i=1, 4 do move() end
  567.     lwGlass = true
  568.     for checker=1, 7 do -- left window
  569.         if robot.detect() then lwGlass = false end
  570.         moveUp()
  571.         if robot.detect() then lwGlass = false end
  572.         robot.turnRight()
  573.         move()
  574.         robot.turnLeft()
  575.         if robot.detect() then lwGlass = false end
  576.         moveDown()
  577.         if robot.detect() then lwGlass = false end
  578.         if checker < 7 then
  579.             robot.turnRight()
  580.             move()
  581.             robot.turnLeft()
  582.         end
  583.     end
  584.     robot.turnAround()
  585.     for i=1, 3 do move() end
  586.     for i=1, 4 do moveUp() end
  587.     twGlass = true
  588.     for checker=1, 7 do -- top window
  589.         if robot.detectUp() then twGlass = false end
  590.         move()
  591.         if robot.detectUp() then twGlass = false end
  592.         robot.turnRight()
  593.         move()
  594.         robot.turnRight()
  595.         if robot.detectUp() then twGlass = false end
  596.         move()
  597.         if robot.detectUp() then twGlass = false end
  598.         if checker < 7 then
  599.             robot.turnLeft()
  600.             move()
  601.             robot.turnLeft()
  602.         end
  603.     end
  604.     robot.turnAround()
  605.     for i=1, 5 do moveDown() end
  606.     for i=1, 3 do move() end
  607.     robot.turnRight()
  608.     move()
  609.     robot.turnAround()
  610.     return rwGlass, bwGlass, lwGlass, twGlass
  611. end
  612.  
  613. function endBitUp()
  614.     placeDown("smoothBricks")
  615.     place("smoothBricks")
  616.     for i=1, 3 do
  617.         moveUp()
  618.         place("smoothBricks")
  619.     end
  620.     placeUp("smoothBricks")
  621. end
  622.  
  623. function endBitDown()
  624.     placeUp("smoothBricks")
  625.     for i=1, 3 do
  626.         place("smoothBricks")
  627.         moveDown()
  628.     end
  629.     place("smoothBricks")
  630.     placeDown("smoothBricks")
  631. end
  632.  
  633. function wallBitUp(win)
  634.     placeDown("bricks")
  635.     place("smoothBricks")
  636.     for i=1, 2 do
  637.         moveUp()
  638.         if win then
  639.             place("glass")
  640.         else
  641.             place("bricks")
  642.         end
  643.     end
  644.     moveUp()
  645.     place("smoothBricks")
  646.     placeUp("smoothBricks")
  647. end
  648.  
  649. function wallBitDown(win)
  650.     placeUp("smoothBricks")
  651.     place("smoothBricks")
  652.     moveDown()
  653.     for i=1, 2 do
  654.         if win then
  655.             place("glass")
  656.         else
  657.             place("bricks")
  658.         end
  659.         moveDown()
  660.     end
  661.     place("smoothBricks")
  662.     placeDown("bricks")
  663. end
  664.  
  665. function midBitUp(topWin, botWin, lamp)
  666.     if botWin then
  667.         placeDown("glass")
  668.     else
  669.         placeDown("bricks")
  670.     end
  671.     move()
  672.     if lamp then
  673.         placeDown("lantern")
  674.     else
  675.         placeDown("smoothBricks")
  676.     end
  677.     robot.turnAround()
  678.     for i=1, 4 do
  679.         moveUp()
  680.         if robot.detect() then
  681.             dig()
  682.         end
  683.     end
  684.     if lamp then
  685.         placeUp("lantern")
  686.     else
  687.         placeUp("smoothBricks")
  688.     end
  689.     move()
  690.     if topWin then
  691.         placeUp("glass")
  692.     else
  693.         placeUp("bricks")
  694.     end
  695.     robot.turnAround()
  696. end
  697.  
  698. function midBitDown(topWin, botWin, lamp)
  699.     if topWin then
  700.         placeUp("glass")
  701.     else
  702.         placeUp("bricks")
  703.     end
  704.     move()
  705.     if lamp then
  706.         placeUp("lantern")
  707.     else
  708.         placeUp("smoothBricks")
  709.     end
  710.     robot.turnAround()
  711.     for i=1, 4 do
  712.         moveDown()
  713.         if robot.detect() then
  714.             dig()
  715.         end
  716.     end
  717.     if lamp then
  718.         placeDown("lantern")
  719.     else
  720.         placeDown("smoothBricks")
  721.     end
  722.     move()
  723.     if botWin then
  724.         placeDown("glass")
  725.     else
  726.         placeDown("bricks")
  727.     end
  728.     robot.turnAround()
  729. end
  730.  
  731. function endMidBitUp()
  732.     placeDown("smoothBricks")
  733.     move()
  734.     placeDown("smoothBricks")
  735.     robot.turnAround()
  736.     for i=1, 4 do
  737.         moveUp()
  738.         if robot.detect() then
  739.             dig()
  740.         end
  741.     end
  742.     placeUp("smoothBricks")
  743.     move()
  744.     placeUp("smoothBricks")
  745.     robot.turnAround()
  746. end
  747.  
  748. function endMidBitDown()
  749.     placeUp("smoothBricks")
  750.     move()
  751.     placeUp("smoothBricks")
  752.     robot.turnAround()
  753.     for i=1, 4 do
  754.         moveDown()
  755.         if robot.detect() then
  756.             dig()
  757.         end
  758.     end
  759.     placeDown("smoothBricks")
  760.     move()
  761.     placeDown("smoothBricks")
  762.     robot.turnAround()
  763. end
  764.  
  765. function light(test)
  766.   if test == 1 or test == 4 or test == 7 or test == 8 or test == 11 or test == 14 then
  767.     return true
  768.   else
  769.     return false
  770.   end
  771. end
  772.  
  773. function fence(glassBottom)
  774.     for fenceI=1, 15 do
  775.         moveBack()
  776.         if fenceI == 1 or fenceI == 3 or fenceI == 4 or fenceI == 6 or fenceI == 7 or fenceI == 10 or fenceI == 11 or fenceI == 13 or fenceI == 14 then
  777.             place("fence") 
  778.         end
  779.     end
  780.         robot.turnRight()
  781.         moveBack()
  782.         place("fence")
  783.         moveBack()
  784.         if glassBottom then
  785.             moveBack()
  786.             place("fence")
  787.             moveBack()
  788.             place("fence")
  789.             moveBack()
  790.         else
  791.             robot.turnRight()
  792.             for i=1, 15 do
  793.                 moveBack()
  794.                 if fenceI == 1 or fenceI == 3 or fenceI == 4 or fenceI == 6 or fenceI == 7 or fenceI == 10 or fenceI == 11 or fenceI == 13 or fenceI == 14 then
  795.                     place("fence") 
  796.                 end
  797.             end
  798.             robot.turnLeft()
  799.             moveBack()
  800.             robot.turnLeft()
  801.             for i=1, 15 do
  802.                 moveBack()
  803.                 if fenceI == 1 or fenceI == 3 or fenceI == 4 or fenceI == 6 or fenceI == 7 or fenceI == 10 or fenceI == 11 or fenceI == 13 or fenceI == 14 then
  804.                     place("fence") 
  805.                 end
  806.             end
  807.             robot.turnRight()
  808.             moveBack()
  809.             place("fence")
  810.             moveBack()
  811.         end
  812.     robot.turnRight()
  813.     for fenceI=1, 15 do
  814.         moveBack()
  815.         if fenceI == 1 or fenceI == 3 or fenceI == 4 or fenceI == 6 or fenceI == 7 or fenceI == 10 or fenceI == 11 or fenceI == 13 or fenceI == 14 then
  816.             place("fence") 
  817.         end
  818.     end
  819.     robot.turnRight()
  820.     moveBack()
  821.     place("fence")
  822.     moveBack()
  823.     moveBack()
  824.     place("fence")
  825.     moveBack()
  826.     place("fence")
  827.     moveBack()
  828.     robot.turnRight()
  829. end
  830.  
  831. -- Begin
  832. term.clear()
  833. print("Press space to confirm that robot is facing in the direction of the wall, on the block before the first iteration, on the rightmost side.")
  834. while not keyboard.isKeyDown(keyboard.keys.space) do os.sleep(0.1) end
  835. term.clear()
  836.  
  837. print("How many chunks do you want to build for?")
  838. tunnelLengthChunks = io.read()
  839.  
  840. os.sleep(1)
  841. term.clear()
  842.  
  843. print("Robot Inventory Instructions:")
  844. print("1 - Pickaxe (Preferably w/o Durability)")
  845. print("2 - Item Transceiver")
  846. print("3 - Trash/Fuel Transceiver")
  847. print("4+ - No need to load!")
  848.  
  849. print(" ")
  850. print("--- Press Enter When Ready to Begin ---")
  851. while not keyboard.isKeyDown(keyboard.keys.enter) do os.sleep(0.1) end
  852. term.clear()
  853. robot.select(1)
  854. component.inventory_controller.equip()
  855. print("Building...")
  856.  
  857. -- Begin walling sequence
  858.  
  859. for iterate=1, tunnelLengthChunks do
  860.   rWindow, bWindow, lWindow, tWindow = checkGlass()
  861.   print("Chunk 1: ".."rWindow: "..tostring(rWindow).." ".."bWindow: "..tostring(bWindow).." ".."lWindow: "..tostring(lWindow).." ".."tWindow: "..tostring(tWindow))
  862.   robot.turnRight()
  863.  
  864.   endBitUp()
  865.   robot.turnLeft()
  866.   move()
  867.   robot.turnRight()
  868.   for i=1, 7 do
  869.     wallBitDown(rWindow)
  870.     robot.turnLeft()
  871.     move()
  872.     robot.turnRight()
  873.     wallBitUp(rWindow)
  874.     robot.turnLeft()
  875.     move()
  876.     robot.turnRight()
  877.   end
  878.   endBitDown()
  879.  
  880.   for i=1, 2 do moveBack() end
  881.   endMidBitUp()
  882.   robot.turnRight()
  883.   move()
  884.   robot.turnLeft()
  885.   for aye=1, 14 do
  886.     if aye % 2 ~= 0 then
  887.       midBitDown(tWindow,bWindow,light(aye))
  888.       robot.turnRight()
  889.       move()
  890.       robot.turnLeft()
  891.     else
  892.       midBitUp(tWindow,bWindow,light(aye))
  893.       robot.turnRight()
  894.       move()
  895.       robot.turnLeft()
  896.     end
  897.   end
  898.   endMidBitDown()
  899.  
  900.   robot.turnAround()
  901.   move()
  902.   endMidBitUp()
  903.   robot.turnRight()
  904.   move()
  905.   robot.turnLeft()
  906.   for aye=1, 14 do
  907.     if aye % 2 ~= 0 then
  908.       midBitDown(tWindow,bWindow,light(aye))
  909.       robot.turnRight()
  910.       move()
  911.       robot.turnLeft()
  912.     else
  913.       midBitUp(tWindow,bWindow,light(aye))
  914.       robot.turnRight()
  915.       move()
  916.       robot.turnLeft()
  917.     end
  918.   end
  919.   endMidBitDown()
  920.  
  921.   for i=1, 2 do move() end
  922.   endBitUp()
  923.   robot.turnLeft()
  924.   move()
  925.   robot.turnRight()
  926.   for i=1, 7 do
  927.     wallBitDown(lWindow)
  928.     robot.turnLeft()
  929.     move()
  930.     robot.turnRight()
  931.     wallBitUp(lWindow)
  932.     robot.turnLeft()
  933.     move()
  934.     robot.turnRight()
  935.   end
  936.   endBitDown()
  937.  
  938.   robot.turnAround()
  939.   for i=1, 5 do move() end
  940.   robot.turnLeft()
  941.   for i=1, 15 do move() end
  942.   fence(bWindow)
  943. end
  944.  
  945. computer.shutdown()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement