zed_com

Robot Chank

Jul 7th, 2016
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.42 KB | None | 0 0
  1. local robot = require('robot')
  2. local api = {}
  3. local chest_robot = 16
  4.  
  5. function api.forward()
  6.     while true do
  7.         if robot.forward() then break else robot.swing() end
  8.     end
  9. end
  10.  
  11. function api.kop()
  12.     for i = 1, 16 do
  13.         if robot.detectUp() then robot.swingUp() end
  14.         if robot.detect() and i ~=16 then robot.swing()end
  15.         if robot.detectDown() then robot.swingDown() end
  16.         if i ~= 16 then
  17.             api.forward()
  18.         end
  19.     end
  20. end
  21.  
  22. function api.down()
  23.     for i = 1, 3 do
  24.         if robot.detectDown() then robot.swingDown() end
  25.         robot.down()
  26.         if i ~= 3 then robot.turnLeft() end
  27.     end
  28. end
  29.  
  30. function api.turn(info, n)
  31.     if info == n then
  32.         robot.turnRight()
  33.         if robot.detect() then api.forward() end
  34.         robot.forward()
  35.         robot.turnRight()
  36.     else
  37.         robot.turnLeft()
  38.         if robot.detect() then api.forward() end
  39.         robot.forward()
  40.         robot.turnLeft()
  41.     end
  42. end
  43.  
  44. function api.drop()
  45.     robot.select(chest_robot)
  46.     if robot.count() ~= 0 then
  47.         robot.select(1)
  48.         robot.swing()
  49.         robot.up()
  50.         robot.swing()
  51.         robot.down()
  52.         if robot.place(1) then         
  53.             for i = 2, chest_robot do
  54.                 robot.select(i)
  55.                 robot.drop()
  56.             end
  57.         end
  58.     end
  59.     robot.select(1)
  60. end
  61.  
  62. function api.mine(y)
  63.     local n = 0,5
  64.     for i = 1, y / 3 do
  65.         for j = 1, 16 do
  66.             api.kop()
  67.             api.drop()
  68.             _, info = math.modf(j / 2)
  69.             if j ~= 16 then api.turn(info, n) end
  70.         end
  71.         if n == 0.5 then n = 0 else n = 0.5 end
  72.         api.down()
  73.     end
  74. end
  75.  
  76. return api
Advertisement
Add Comment
Please, Sign In to add comment