Advertisement
Voxxel

Stripmine v2.1

Dec 24th, 2017
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.72 KB | None | 0 0
  1.  
  2. local robot = require("robot")
  3. local computer = require("computer")
  4. local sides = require("sides")
  5. local component = require("component")
  6. local ic = component.inventory_controller
  7.  
  8. --the length of the tunnels
  9. local distance = 0
  10. --spacing between the tunnels
  11. local width = 0
  12. --from startingpoint to the left or right
  13. local direction = 0
  14. --how often is the process repeated
  15. local multi = 0
  16. --how often has the process repeated YET
  17. local multiCounter = 0
  18.  
  19. --distance traveled since the last torch
  20. local torchCounter = 0
  21.  
  22. --local xcord = 0
  23. --local ycord = 0
  24. --local zcord = 0
  25.  
  26. --error check
  27. local error = 0
  28.  
  29.  
  30. --local minEnergy = 0.25
  31. local torchDist = 11
  32. local dropChecker = 1
  33.  
  34. --Lets the robot dig up and forward until everything is cleared. Then moves it forward
  35. function forward(a, b, c)
  36.     local i = 0
  37.     while i < a do
  38.         if robot.detectUp() then
  39.             repeat
  40.                 robot.swingUp()
  41.             until not robot.detectUp()
  42.         end
  43.         if robot.detect() then
  44.             repeat
  45.                 robot.swing()
  46.             until not robot.detect()
  47.         end
  48.         robot.forward()
  49.         i = i+1
  50.         if b == true then
  51.             if robot.detectDown() == false then
  52.                 robot.select(2)
  53.                 robot.placeDown()
  54.             end
  55.         end
  56.         if c == true then
  57.             torchCounter = torchCounter+1
  58.             lightCheck()
  59.         end
  60.     end
  61. end
  62.  
  63. --Executes the turn-manouver
  64. function turn()
  65.     if direction == 0 then
  66.         robot.turnLeft()
  67.         forward(width+1, true, true)
  68.         robot.turnLeft()
  69.         direction = 1
  70.     elseif direction == 1 then
  71.         robot.turnRight()
  72.         forward(width+1, true, true)
  73.         robot.turnRight()
  74.         direction = 0
  75.     end
  76. end
  77.  
  78. --Checks if it is time to place a torch
  79. function lightCheck()
  80.     if torchCounter >= torchDist then
  81.         placeTorch()
  82.     end
  83. end
  84.  
  85. --Places a torch behind the robot
  86. function placeTorch()
  87.     if robot.count(1) > 1 then
  88.         local slot1 = ic.getStackInInternalSlot(1)
  89.         if slot1.name == "minecraft:torch" then
  90.             robot.turnAround()
  91.             robot.select(1)
  92.             robot.place(sides.down)
  93.             robot.turnAround()
  94.             torchCounter = 0
  95.         end
  96.     end
  97. end
  98.  
  99. --Checks remaining space in the inventory and starts the unload and restock process if applicable
  100. function inventoryCheck()
  101.     if robot.count(robot.inventorySize()-2) > 0 then
  102.         returnToChest((multiCounter*(width+1))+(width+1))
  103.         unload()
  104.         restock()
  105.         returnToMine()
  106.     end
  107.     if robot.count(1) < 2 then
  108.         returnToChest((multiCounter*(width+1))+(width+1))
  109.         unload()
  110.         restock()
  111.         returnToMine()
  112.     end
  113. end
  114.  
  115. --Moves the robot back to the starting point
  116. function returnToChest(length)
  117.     if direction == 0 then
  118.         robot.turnRight()
  119.     elseif direction == 1 then
  120.         robot.turnLeft()
  121.     end
  122.     if robot.detectUp() then
  123.             repeat
  124.                 robot.swingUp()
  125.             until not robot.detectUp()
  126.         end
  127.     robot.up()
  128.     local a = 0
  129.     while a < length do
  130.         if robot.detect() then
  131.             repeat
  132.                 robot.swing()
  133.             until not robot.detect()
  134.         end
  135.         robot.forward()
  136.         a = a+1
  137.     end
  138.     if robot.detectDown() then
  139.             repeat
  140.                 robot.swingDown()
  141.             until not robot.detectDown()
  142.         end
  143.     robot.down()
  144.     if direction == 0 then
  145.         robot.turnRight()
  146.     elseif direction == 1 then
  147.         robot.turnLeft()
  148.     end
  149. end
  150.  
  151. --Drops all Items into to chest. Does NOT drop Slot 1 and leaves 20 Items in Slot 2
  152. function unload()
  153.     local i = robot.inventorySize()
  154.     while i > 2 do
  155.         robot.select(i)
  156.         if robot.count(i) == 0 then
  157.        
  158.         else
  159.             robot.drop()
  160.         end
  161.         i = i-1
  162.     end
  163.     robot.select(2)
  164.     robot.drop(44)
  165. end
  166.  
  167. --Refills the first slot with torches from a chest in front of it
  168. function restock()
  169.     local chestSize, chestSizeAdd = ic.getInventorySize(3)
  170.     local i = 1
  171.     if chestSize == nil then
  172.        
  173.     else
  174.         while i <= chestSize do
  175.             local info = ic.getStackInSlot(3, i)
  176.             if info == nil then
  177.                
  178.             else
  179.                 if info.name == "minecraft:torch" then
  180.                     robot.select(1)
  181.                     if robot.space(1)>0 then
  182.                         ic.suckFromSlot(3,i,robot.space(1))
  183.                     end
  184.                 end
  185.             end
  186.             i = i+1
  187.         end
  188.     end
  189.    
  190. end
  191.  
  192. --Moves the Robot to the last position in the Mine
  193. function returnToMine()
  194.     if direction == 0 then
  195.         robot.turnRight()
  196.     elseif direction == 1 then
  197.         robot.turnLeft()
  198.     end
  199.     if robot.detectUp() then
  200.             repeat
  201.                 robot.swingUp()
  202.             until not robot.detectUp()
  203.         end
  204.     robot.up()
  205.     local a = 0
  206.     while a < ((multiCounter*(width+1))+(width+1)) do
  207.         if robot.detect() then
  208.             repeat
  209.                 robot.swing()
  210.             until not robot.detect()
  211.         end
  212.         robot.forward()
  213.         a = a+1
  214.     end
  215.     if robot.detectDown() then
  216.             repeat
  217.                 robot.swingDown()
  218.             until not robot.detectDown()
  219.         end
  220.     robot.down()
  221.     if direction == 0 then
  222.         robot.turnRight()
  223.     elseif direction == 1 then
  224.         robot.turnLeft()
  225.     end
  226. end
  227.  
  228. --Basic systemcheck
  229. function iCheck()
  230.     if robot.count(1) < 1 then
  231.         print("No torches in Slot 1!")
  232.         print("")
  233.         error = 1  
  234.     end
  235.     if distance < 1 then
  236.         print("Tunnel lenght is less than 1! Enter a valid distance.")
  237.         print("")
  238.         error = 2
  239.     end
  240.     if width < 1 then
  241.         print("Space between tunnels is less than 1! Enter valid width.")
  242.         print("")
  243.         error = 2
  244.     end
  245.     --if (computer.energy() >= (minEnergy*computer.maxEnergy())) then
  246.     --  print("Energylevel is too low. Please recharge first.")
  247.     --  print("")
  248.     --  error = 3
  249.     --end
  250.     if (direction < 0 or direction > 1) then
  251.         print("A invalid direction was entered.")
  252.         print("")
  253.         error = 2
  254.     end
  255.    
  256.     os.sleep(3)
  257.    
  258.     if error == 0 then
  259.         print("Check complete. Starting to mine.")
  260.         print("")
  261.     elseif error == 1 then
  262.         reCheck()
  263.     elseif error == 2 then
  264.         print("Please restart the program.")
  265.         print("")
  266.         computer.shutdown(true)
  267.     elseif error == 3 then
  268.         print("Shutting down.")
  269.         print("")
  270.         computer.shutdown(false)
  271.     end
  272. end
  273.  
  274. --Recheck if only torches are missing
  275. function reCheck()
  276.     print("Please put some torches in the first inventory-slot.")
  277.     while robot.count(1) == 0 do
  278.         print("Standing by...")
  279.         print("")
  280.         os.sleep(5)
  281.     end
  282.     error = 0
  283.     iCheck()
  284. end
  285.  
  286. --To change basic parameters
  287. function admin()
  288.     print("minEnergy in %")
  289.     input5 = io.read()
  290.     minEnergy = (tonumber(input5)/100)
  291.     print("torchDist?")
  292.     input6 = io.read()
  293.     torchDist = tonumber(input6)
  294.     print("dropChecker?")
  295.     input7 = io.read()
  296.     dropChecker = tonumber(input7)
  297.     print("End of Admin()")
  298.     print("")
  299.     os.sleep(2)
  300. end
  301.  
  302. --Starts the process
  303. function start()
  304.    
  305.     while multiCounter < multi do
  306.         forward(distance, true, true)
  307.         turn()
  308.         if (multiCounter % 2 == 0) then
  309.             --Robot is on the wrong wide of the mine. No good path to the unloading-box
  310.         else
  311.             inventoryCheck()
  312.         end
  313.         multiCounter = multiCounter+1
  314.     end
  315.     if (multi % 2 == 0) then
  316.         returnToChest(((multiCounter-1)*(width+1))+(width+1))
  317.         unload()
  318.     else
  319.         returnToChest(((multiCounter-1)*(width+1))+(width+1))
  320.         robot.turnAround()
  321.         robot.up()
  322.         torchDist = 99999
  323.         forward(distance, false, false)
  324.         robot.down()
  325.         unload()
  326.     end
  327.     print("")
  328.     print("-----------------------")
  329.     print("ALL DONE! SHUTTING DOWN IN 10s")
  330.     print("-----------------------")
  331.     print("")
  332.     os.sleep(10)
  333.     computer.shutdown(false)
  334. end
  335.  
  336. print("Welcome to Voxxels Stripmining program")
  337. print("-----------------------------------")
  338. print("How far do you want to go?")
  339. input1 = io.read()
  340. distance = tonumber(input1)
  341.  
  342. if distance == 1234 then
  343.     admin()
  344. end
  345.  
  346. print("-----------------------------------")
  347. print("How many blocks between the tunnels?")
  348. input2 = io.read()
  349. width = tonumber(input2)
  350.  
  351. print("----------------------------------")
  352. print("Left or Right?")
  353. print("(0 = Left ; 1 = Right)")
  354. input3 = io.read()
  355. direction = tonumber(input3)
  356.  
  357. print("----------------------------------")
  358. print("Ok almost done.")
  359. print("How often should I repeat that?")
  360. input4 = io.read()
  361. multi = tonumber(input4)
  362.  
  363. print("")
  364. print("Well done. Now let me do a quick system check...")
  365. os.sleep(1)
  366. print(".")
  367. os.sleep(1)
  368. print("..")
  369. os.sleep(1)
  370. print("...")
  371. print("")
  372. iCheck()
  373.  
  374. os.sleep(2)
  375. start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement