Advertisement
Rot256

Logger

Nov 1st, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.15 KB | None | 0 0
  1. -- Static variables (Settings)
  2.  
  3. leaves = {"minecraft:leaves"}
  4. log = {"minecraft:log"}
  5. dirt = {"minecraft:dirt", "minecraft:grass"}
  6. sapling = {"minecraft:sapling"}
  7. chest = {"minecraft:chest"}
  8.  
  9. turnLeft = {"minecraft:planks"}
  10. turnRight = {"minecraft:double_wooden_slab"}
  11. goUp = {"minecraft:cobblestone"}
  12.  
  13. inventory_size = 16
  14. fuel_level = 5000
  15. sapling_slots = 1
  16.  
  17. -- Functions
  18.  
  19. function isType(e, t)
  20. if e == nil then
  21. return false
  22. end
  23. i = 1
  24. while(t[i] ~= nil) do
  25. if(e.name == t[i]) then
  26. return true
  27. end
  28. i = i + 1
  29. end
  30. return false
  31. end
  32.  
  33. function PlaceSapling()
  34. for i = 1, inventory_size, 1 do
  35. item = turtle.getItemDetail(i)
  36. if isType(item, sapling) then
  37. turtle.select(i)
  38. turtle.placeDown()
  39. return true
  40. end
  41. end
  42.  
  43. return false
  44. end
  45.  
  46. function turtleMove(dir)
  47. check = {forward = turtle.inspect, up = turtle.inspectUp, down = turtle.inspectDown}
  48. move = {forward = turtle.forward, up = turtle.up, down = turtle.down}
  49. dig = {forward = turtle.dig, up = turtle.digUp, down = turtle.digDown}
  50. attack = {forward = turtle.attack, up = turtle.attackUp, down = turtle.attackDown}
  51. while attack[dir]() do
  52. os.sleep(0.05)
  53. end
  54. _, block = check[dir]()
  55. if isType(block, leaves) then
  56. dig[dir]()
  57. end
  58. return move[dir]()
  59. end
  60.  
  61. function unload()
  62. -- Clear sapling spaces
  63. for i = 1, sapling_slots, 1 do
  64. turtle.select(i)
  65. item = turtle.getItemDetail()
  66. if isType(item, sapling) == false then
  67. turtle.dropDown()
  68. end
  69. end
  70.  
  71. -- Clear remaining inventory
  72. for i = sapling_slots + 1, inventory_size, 1 do
  73. turtle.select(i)
  74. item = turtle.getItemDetail()
  75. if isType(item, sapling) then
  76. for n = 1, sapling_slots, 1 do
  77. turtle.transferTo(n)
  78. end
  79. end
  80. turtle.dropDown()
  81. end
  82. end
  83.  
  84. function refuel()
  85. turtle.select(inventory_size)
  86. turtle.drop()
  87. while turtle.getFuelLevel() < fuel_level do
  88. turtle.suckUp(1)
  89. turtle.refuel()
  90. end
  91. turtle.suck()
  92. end
  93.  
  94. function checkChests()
  95. chests_found = false
  96. -- Unload
  97. _, block = turtle.inspectDown()
  98. if isType(block, chest) then
  99. unload()
  100. chests_found = true
  101. end
  102.  
  103. -- Refuel
  104. _, block = turtle.inspectUp()
  105. if isType(block, chest) then
  106. refuel()
  107. chests_found = true
  108. end
  109. return chests_found
  110. end
  111.  
  112. -- Do startup
  113.  
  114. turtleMove("up")
  115.  
  116. -- Main loop
  117.  
  118. while (1) do
  119. turtle.suck()
  120. _, block = turtle.inspect()
  121.  
  122. -- Handle trees
  123. if isType(block, log) then
  124. while turtle.dig() == false do
  125. os.sleep(0.05)
  126. end
  127. turtleMove("up")
  128.  
  129. elseif isType(block, sapling) then
  130. turtleMove("up")
  131. turtleMove("forward")
  132.  
  133. -- Handle control blocks
  134. elseif isType(block, turnLeft) then
  135. turtle.turnLeft()
  136.  
  137. elseif isType(block, turnRight) then
  138. turtle.turnRight()
  139.  
  140. elseif isType(block, goUp) then
  141. while (isType(block, goUp)) do
  142. turtleMove("up")
  143. _, block = turtle.inspect()
  144. end
  145. turtleMove("forward")
  146.  
  147. -- Handle chests
  148. elseif checkChests() then
  149. turtleMove("forward")
  150.  
  151. else
  152. -- Check ground
  153. if turtleMove("down") == false then
  154. _, block = turtle.inspectDown()
  155. if isType(block, dirt) then
  156. turtleMove("up")
  157. PlaceSapling()
  158. end
  159. turtleMove("forward")
  160. end
  161. end
  162. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement