Advertisement
Guest User

lumber.lua

a guest
Jul 29th, 2015
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.53 KB | None | 0 0
  1. local com = require("component")
  2. local robot = require("robot")
  3. local exp = com.experience
  4. local gen = com.generator
  5. local magnet = com.tractor_beam
  6. local inv = com.inventory_controller
  7. local X, Y = 7, 17
  8. local LOGS, SAPS = 2, 1
  9. local DELAYNIGHT = 60
  10. local DELAYDAY = 10
  11.  
  12. local EXP = exp.level()
  13.  
  14. local function suck() end --further declaration...
  15.  
  16. local function detect()
  17.   _, detected = robot.detect()
  18.   if detected == "entity" or detected == "solid" or detected == "passable" then
  19.     robot.swing()
  20.   end
  21. end
  22.  
  23. local function forward()
  24.   detect()
  25.   while not robot.forward() do
  26.     detect()
  27.     os.sleep(0.5)
  28.   end
  29.   suck()
  30. end
  31.  
  32. local function back()
  33.   detect()
  34.   while not robot.back() do
  35.     os.sleep(0.5)
  36.   end
  37.   suck()
  38. end
  39.  
  40. local function up()
  41.   detect()
  42.   while not robot.up() do
  43.     os.sleep(0.5)
  44.   end
  45.   suck()
  46. end
  47.  
  48. local function down()
  49.   detect()
  50.   while not robot.down() do
  51.     os.sleep(0.5)
  52.   end
  53.   suck()
  54. end
  55.  
  56. function suck()
  57.   while not magnet.suck() == false do end
  58. end
  59.  
  60. local function nextRow(start)
  61.   local repeats = start and 1 or 4
  62.   if not start == true then
  63.     robot.turnLeft()
  64.   end
  65.   for i = 1, repeats, 1 do
  66.     forward()
  67.   end
  68.   robot.turnRight()
  69. end
  70.  
  71. local function checkAndFall()
  72.   robot.select(LOGS)
  73.   if robot.compare() == true then
  74.     robot.swing()
  75.   end
  76.   os.sleep(0.25)
  77.   if robot.detect() == false then
  78.     robot.select(SAPS)
  79.     robot.place()
  80.   end
  81.   suck()
  82. end
  83.  
  84. -- === MAIN === ---
  85. while true do
  86.   nextRow(true)
  87.   for i = 1, X, 1 do
  88.     for j = 1, Y, 1 do
  89.       forward()
  90.       robot.turnLeft()
  91.       checkAndFall()
  92.       robot.turnAround()
  93.       checkAndFall()
  94.       robot.turnLeft()
  95.       if j ~= Y then
  96.         forward()
  97.       else
  98.         for k = 1, Y * 2 - 1, 1 do
  99.           back()
  100.         end
  101.       end
  102.     end
  103.     if i ~= X then
  104.       nextRow(false)
  105.     else
  106.       robot.turnRight()
  107.       for l = 1, (X - 1) * 4 + 1, 1 do
  108.         forward()
  109.       end
  110.       for l = 1, robot.inventorySize(), 1 do
  111.         robot.select(l)
  112.         if l ~= LOGS and l ~= SAPS then
  113.           if not exp.consume() then
  114.             gen.insert()
  115.             robot.drop()
  116.           end
  117.         end
  118.       end
  119.       robot.turnAround()
  120.     end
  121.   end
  122.   robot.turnLeft()
  123.   robot.select(robot.inventorySize())
  124.   inv.equip()
  125.   robot.drop()
  126.   if tonumber(os.date("%H")) > 5 and tonumber(os.date("%H")) < 19 then
  127.     DELAY = DELAYDAY
  128.   else
  129.     DELAY = DELAYNIGHT
  130.   end
  131.   for i = 1, DELAY, 1 do
  132.     print(i.."/"..DELAY)
  133.     print("Exp: " .. EXP .. " -> " .. exp.level() .. "L")
  134.     os.sleep(1)
  135.   end
  136.   EXP = exp.level()
  137.   inv.suckFromSlot(3, 1)
  138.   inv.equip()
  139.   robot.turnRight()
  140. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement