Advertisement
FrozenSpring

OC wood chopper

Jan 21st, 2017
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.47 KB | None | 0 0
  1. --[[
  2. Go forward 7 spaces, wait until the saplings are
  3. grown, go to the left and start cutting a 4x4
  4. tree, both at that level and the one above,
  5. then go up two levels and do it again for 5
  6. more times, then come down, plant the 4 saplings,
  7. return teh 7 spaces to the chest, drop the wood
  8. off, pick up enough coal from the furnace in
  9. front to have a full stack in the last slot,
  10. go to the next cest and get another 4 saplings,
  11. and restart the program
  12. ]]--
  13.  
  14. local robot = require("robot")
  15. local c = require("computer")
  16. local o = require("os")
  17. -- wait in seconds for the sapling to grow
  18. local wait = 60
  19. -- height to chop to /2
  20. local height = 6
  21. -- distance from chest to island
  22. local distance = 7
  23. -- total diameter of the tree (width or depth)
  24. local width = 6
  25.  
  26.  
  27. -- chop forward
  28. local function forward()
  29.  robot.swing()
  30.  robot.forward()
  31.  robot.swingUp()
  32. end
  33.  
  34. -- chop a line
  35. local function chopLine(turn)
  36.  for v = 1, width do forward() end
  37.  if turn then
  38.   robot.turnRight() forward() robot.turnRight()
  39.  else
  40.   robot.turnLeft() forward() robot.turnLeft()
  41.  end
  42. end
  43.  
  44. -- chop down this and the next level of the tree
  45. local function chopLevel()
  46.  local turnRight = true
  47.  for w = 1, width do
  48.   chopLine(turnRight)
  49.   turnRight = not turnRight
  50.  end
  51.  robot.turnLeft()
  52.  for w = 1, width do robot.forward() end
  53.  robot.turnRight()
  54. end
  55.  
  56.  
  57. -- Where the main program starts running
  58. while true do
  59.  
  60. -- move from chest to saplings and wait
  61. robot.select(2)
  62. robot.suckDown(4)
  63. for i = 1, distance do robot.forward() end
  64. robot.select(1)
  65. while not robot.compare(false) do o.sleep(wait) end
  66.  
  67. -- move into position
  68. robot.back()
  69. robot.back()
  70. robot.turnLeft()
  71. robot.forward()
  72. robot.forward()
  73. robot.turnRight()
  74.  
  75. -- chop the tree
  76. for i = 1, height do
  77.  chopLevel()
  78.  robot.up()
  79.  robot.swingUp()
  80.  robot.up()
  81. end
  82.  
  83. -- plant the saplings
  84. robot.turnRight()
  85. robot.forward()
  86. robot.forward()
  87. robot.turnLeft()
  88. robot.forward()
  89. robot.forward()
  90. robot.forward()
  91. while robot.down() do end
  92. robot.up()
  93. robot.select(2)
  94. robot.placeDown()
  95. robot.forward()
  96. robot.placeDown()
  97. robot.turnRight()
  98. robot.forward()
  99. robot.turnRight()
  100. robot.placeDown()
  101. robot.forward()
  102. robot.placeDown()
  103. -- go back to chests
  104. for i = 0, distance do robot.forward() end
  105. robot.down()
  106. for i = 2, 16 do
  107.  robot.select(i)
  108.  robot.dropDown()
  109. end
  110. robot.turnRight()
  111. robot.forward()
  112. robot.turnRight()
  113. while c.maxEnergy()-c.energy() > 200 do
  114.  os.sleep(60)
  115. end
  116. -- point where the program starts over again
  117. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement