Advertisement
makmoud98

Untitled

Feb 25th, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. SAPLING = "minecraft:sapling"--always be slot 2
  2. LOG = "minecraft:log"
  3. FUEL = "minecraft:coal"
  4. --charcoal always slot 1
  5. WIDTH = 2
  6. LENGTH = 11
  7.  
  8. DELAY = 60 -- seconds
  9.  
  10. move = 3
  11.  
  12. function dropLoot()
  13. local data = turtle.getItemDetail(1)
  14. if data and data.name ~= FUEL then
  15. turtle.dropDown(1)
  16. end
  17. for i=3,16 do
  18. turtle.dropDown(i)
  19. end
  20. end
  21.  
  22. function refuel()
  23. local data = turtle.getItemDetail(1)
  24. if data and data.name == FUEL then
  25. turtle.select(1)
  26. turtle.suckDown(64-data.count)
  27. turtle.refuel()
  28. else
  29. turtle.select(1)
  30. turtle.suckDown(64)
  31. turtle.refuel()
  32. end
  33. end
  34.  
  35. function estimateFuelNeed()
  36. return WIDTH * LENGTH * 5 * 5
  37. end
  38.  
  39. function fell()
  40. refuel()
  41. if turtle.getFuelLevel() < estimateFuelNeed() then
  42. return false
  43. end
  44. for w=1,WIDTH do
  45. x = LENGTH
  46. if w ~= 1 then
  47. x = x - 1
  48. end
  49. for i=1,x do
  50. for j=1,move do
  51. while not turtle.forward() do
  52. turtle.dig()
  53. end
  54. end
  55. local s,d = turtle.inspectDown()
  56. local saplinginfo = turtle.getItemDetail(2)
  57. if s then
  58. if d.name == SAPLING then
  59. --keep moving, it aint done yet
  60. elseif d.name == LOG then
  61. --break all the logs and replant
  62. turtle.digDown()
  63. local count = 0
  64. local s_, d_ = turtle.inspectUp()
  65. while s_ and d_.name == LOG do
  66. turtle.digUp()
  67. turtle.up()
  68. count = count + 1
  69. s_, d_ = turtle.inspectUp()
  70. end
  71. for j=1,count do
  72. turtle.down()
  73. end
  74. turtle.select(2)
  75. turtle.placeDown()
  76. end
  77. os.sleep(3)
  78. turtle.suck()
  79. else
  80. --there should be a sapling or a log here..
  81. --replanting anyway
  82. turtle.select(2)
  83. turtle.placeDown()
  84. end
  85. if i ~= LENGTH then
  86. move = 5
  87. elseif w == WIDTH then
  88. for j=1, 3 do
  89. while not turtle.forward() do
  90. turtle.dig()
  91. end
  92. end
  93. turtle.turnRight()
  94. for j=1, 3 do
  95. while not turtle.forward() do
  96. turtle.dig()
  97. end
  98. end
  99. dropLoot()
  100. for j=1, 2 do
  101. while not turtle.forward() do
  102. turtle.dig()
  103. end
  104. end
  105. turtle.turnRight()
  106. else
  107. move = 5
  108. turtle.turnRight()
  109. for j=1, 5 do
  110. while not turtle.forward() do
  111. turtle.dig()
  112. end
  113. end
  114. turtle.turnRight()
  115. end
  116. end
  117. end
  118. return true
  119. end
  120.  
  121. while true do
  122. if not fell() then
  123. print('couldnt start, not enough fuel. need at least ' .. estimateFuelNeed())
  124. end
  125. os.sleep(DELAY)
  126. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement