MaxPKjj

cobble with move

Oct 22nd, 2021 (edited)
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.38 KB | None | 0 0
  1. local robot = require("robot")
  2. local com = require("component")
  3. local sides = require("sides")
  4. local comp = require("computer")
  5. local os = require("os")
  6. local craft = com.crafting
  7.  
  8. bat = comp.energy()
  9. slots = {1, 2, 5, 6}
  10.  
  11. home = {0, 5, 10}
  12.  
  13.  
  14.  
  15.  
  16.  
  17. function goHome()
  18.         cleanUp()
  19.         robot.up()
  20.         robot.up()
  21.         robot.turnRight()
  22.         robot.forward()
  23.         robot.forward()
  24.         robot.forward()
  25.         robot.forward()
  26.         robot.forward()
  27.         robot.forward()
  28.         robot.forward()
  29.         robot.forward()
  30.         robot.turnRight()
  31.         robot.forward()
  32.         robot.forward()
  33.         robot.forward()
  34.         robot.forward()
  35.         robot.forward()
  36.         robot.forward()
  37.         robot.forward()
  38.         robot.forward()
  39.         robot.forward()
  40.         robot.forward()
  41.         robot.forward()
  42.         robot.forward()
  43.         robot.forward()
  44.         robot.turnRight()
  45.         robot.turnRight()
  46.         robot.down()
  47.         robot.down()
  48.         robot.down()
  49.        
  50.     end
  51. function pullStone(i)
  52.     robot.select(i)
  53.     return robot.suck(16)
  54. end
  55.  
  56. function cleanUp()
  57.     for i, slot in ipairs(slots) do
  58.         robot.select(slot)
  59.         robot.drop()
  60.     end
  61. end
  62. function charge()
  63.     com.redstone.setOutput(sides.back, 15)
  64.     while(bat < 19800) do
  65.         print("battery: ", bat)
  66.         bat = comp.energy()
  67.     end
  68.     com.redstone.setOutput(sides.back, 0)
  69. end
  70. function work()
  71.         robot.up()
  72.         robot.up()
  73.         robot.up()
  74.         robot.forward()
  75.         robot.forward()
  76.         robot.forward()
  77.         robot.forward()
  78.         robot.forward()
  79.         robot.forward()
  80.         robot.forward()
  81.         robot.forward()
  82.         robot.forward()
  83.         robot.forward()
  84.         robot.forward()
  85.         robot.forward()
  86.         robot.forward()
  87.         robot.turnLeft()
  88.         robot.forward()
  89.         robot.forward()
  90.         robot.forward()
  91.         robot.forward()
  92.         robot.forward()
  93.         robot.forward()
  94.         robot.forward()
  95.         robot.forward()
  96.         robot.down()
  97.         robot.down()
  98.         robot.turnRight()
  99. end
  100.  
  101. charge()
  102. work()
  103. while(true) do
  104.     valid = true
  105.     bat = comp.energy()
  106.     if(bat < 10000 ) then
  107.         os.execute("cls")
  108.         goHome()
  109.         charge()
  110.         work()
  111.     end
  112.     red = com.redstone.getInput(sides.back)
  113.     if(red > 1 ) then
  114.         goHome()
  115.         os.exit()
  116.     end
  117.     for i, slot in ipairs(slots) do
  118.         if (pullStone(slot) ~= 16) then
  119.             cleanUp()
  120.             goHome()
  121.             os.execute("cls")
  122.             os.sleep(60)
  123.             work()
  124.             valid = false
  125.             break
  126.         end
  127.     end
  128.  
  129.     if (valid) then
  130.         robot.select(4)
  131.         craft.craft(64)
  132.         robot.dropDown()
  133.     end
  134. end
Add Comment
Please, Sign In to add comment