Base8

Untitled

Dec 26th, 2020 (edited)
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.91 KB | None | 0 0
  1. local r = require("robot")
  2. local component = require("component")
  3. local sides = require("sides")
  4. local computer = require("computer")
  5. local inv = component.inventory_controller
  6. local minDurability=0.1
  7. local minTourches=1
  8. local minEnergy=1000
  9. local torchDistance=11
  10. local torchSlot=1
  11.  
  12. function turnAround()
  13.     r.turnRight()
  14.     r.turnRight()
  15. end
  16.  
  17. function forward()
  18.     while not r.forward() do
  19.         r.swing()
  20.     end
  21. end
  22.  
  23. function up()
  24.     while not r.up() do
  25.         r.swingUp()
  26.     end
  27. end
  28.  
  29. function down()
  30.     while not r.down() do
  31.         r.swingDown()
  32.     end
  33. end
  34.  
  35. function back()
  36.     while not r.back() do
  37.         turnAround()
  38.         dig()
  39.         turnAround()
  40.     end
  41. end
  42.  
  43. function dig()
  44.     r.swing()
  45.     while r.detect() do
  46.         r.swing()
  47.     end
  48. end
  49.  
  50. function digUp()
  51.     r.swingUp()
  52.     while r.detectUp() do
  53.         r.swingUp()
  54.     end
  55. end
  56.  
  57. function digDown()
  58.     r.swingDown()
  59.     while r.detectDown() do
  60.         r.swingDown()
  61.     end
  62. end
  63.  
  64. function checkFull()
  65.     for i=1,16 do
  66.         if r.count(i)==0 then
  67.             return false
  68.         end
  69.     end
  70.     return true
  71. end
  72.  
  73. function digLayer()
  74.     dig()
  75.     forward()
  76.     digUp()
  77.     digDown()
  78.    
  79.     r.turnRight()
  80.     dig()
  81.     forward()
  82.     digUp()
  83.     digDown()
  84.    
  85.     turnAround()
  86.     forward()
  87.     dig()
  88.     forward()
  89.     digUp()
  90.     digDown()
  91.     back()
  92.    
  93.     r.turnRight()
  94. end
  95.  
  96. --Dumps entire inv down
  97. --Returns False if inv full
  98. function dumpDown()
  99.     for i=2,16 do
  100.         r.select(i)
  101.         r.dropDown()
  102.     end
  103.    
  104.     for i=1,54 do
  105.         if inv.getSlotStackSize(sides.down,i)==0 then
  106.             return true
  107.         end
  108.     end
  109.    
  110.     return false
  111. end
  112.  
  113. --Returns false if the robot needs to return
  114. function checkStatus()
  115.     if r.durability()==nil or r.durability()<minDurability then
  116.         print("-Durability Ran Out")
  117.         return false
  118.     elseif checkFull() then
  119.         print("-INV Filled Up")
  120.         return false
  121.     elseif r.count(torchSlot)<=minTourches then
  122.         print("-Ran Out Of Torches")
  123.         return false
  124.     elseif computer.energy()<minEnergy then
  125.         print("-Low On Energy")
  126.         return false
  127.     end
  128.     return true
  129. end
  130.  
  131. function placeTorch()
  132.     r.select(torchSlot)
  133.     r.placeDown()
  134. end
  135.  
  136. function pitStop()
  137.     if not dumpDown() then
  138.         os.exit()
  139.     end
  140.     r.turnRight()
  141.     r.select(torchSlot)
  142.     r.suck()
  143.     if r.count(torchSlot)<0 then
  144.         os.exit()
  145.     end
  146.     turnAround()
  147.     if r.durability()<minDurability then
  148.         r.select(2)
  149.         r.suck()
  150.         inv.equip()
  151.         r.dropUp()
  152.         if r.durability==nil or r.durability()<minDurability then
  153.             os.exit()
  154.         end
  155.     end
  156.     r.turnRight()
  157.     if computer.energy()<minEnergy then
  158.         os.exit()
  159.     end
  160. end
  161.  
  162. function mine()
  163.     local depth=0
  164.     up()
  165.     back()
  166.     r.turnLeft()
  167.     r.select(1)
  168.     r.suck()
  169.     inv.equip()
  170.     turnAround()
  171.     r.select(torchSlot)
  172.     r.suck()
  173.     r.turnLeft()
  174.     forward()
  175.     while true do
  176.         while checkStatus() do
  177.             print("Depth: "..depth)
  178.             dig()
  179.             forward()
  180.             if depth%torchDistance==0 then
  181.                 placeTorch()
  182.             end
  183.             depth=depth+1
  184.         end
  185.         turnAround()
  186.         for i = 0,depth do
  187.             forward()
  188.         end
  189.         turnAround()
  190.         pitStop()
  191.         for i=0,depth do
  192.             forward()
  193.         end
  194.     end
  195. end
  196.  
  197. mine()
Add Comment
Please, Sign In to add comment