Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.63 KB | None | 0 0
  1. -- JC magical crops farming script for 7x7 areas
  2.  
  3. farmsize = 7
  4. requiredFuel = 64 --how much fuel you need for a run 7x7+7x2 plus some extra
  5. inverted = false --if you want to start on the right corner instead
  6.  
  7. fullyGrown = 7 --the meta data value when the plant is fully grown
  8. cropType = "magicalcrops"
  9. seedType = "MinicioSee"
  10.  
  11. function getFreeSlot()
  12. local cacheSlot = turtle.getSelectedSlot() --so we can jump back to it afterwards
  13. for i=1,16 do
  14. turtle.select(i)
  15. if turtle.getItemDetail() == nil then
  16. print("GetFreeSlot Returned " .. i)
  17. turtle.select(cacheSlot)
  18. return i
  19. end
  20. end
  21. turtle.select(cacheSlot)
  22. return false
  23. end
  24.  
  25. function getSeeds()
  26. turtle.select(1)
  27. if turtle.getItemDetail() ~= nil then
  28. if string.find(turtle.getItemDetail().name, seedType) then
  29. return
  30. else
  31. local slo = getFreeSlot()
  32. turtle.select(1)
  33. print("moving " .. turtle.getSelectedSlot() .. "to:" .. slo)
  34. turtle.transferTo(tonumber(slo))
  35. end
  36. end
  37.  
  38. for i=1,16 do
  39. turtle.select(i)
  40. if turtle.getItemDetail() ~= nil then
  41. print(turtle.getItemDetail().name)
  42. if string.find(turtle.getItemDetail().name, seedType) then
  43. turtle.transferTo(1)
  44. turtle.select(1)
  45. break
  46. end
  47. end
  48. end
  49. turtle.select(1)
  50. end
  51.  
  52. function checkDig()
  53. found, data = turtle.inspectDown()
  54. if found then
  55. if string.find(data.name, cropType) then --if its the right kind of plant
  56. if data.metadata == fullyGrown then --if it's fully grown
  57. turtle.digDown() --dig it up
  58. getSeeds()
  59. turtle.placeDown()
  60. end
  61. --if its the right kind of crop but its not fully grown then dont do anything
  62. else
  63. --if its not the right kind of plant
  64. turtle.digDown()
  65. getSeeds()
  66. turtle.placeDown()
  67. end
  68. else
  69. --if there is nothing under us
  70. turtle.digDown()
  71. getSeeds()
  72. turtle.placeDown()
  73. end
  74.  
  75. end
  76.  
  77. function moveAndHarvest(num)
  78. for i=1,num do
  79. checkDig()
  80. turtle.forward()
  81. checkDig()
  82. end
  83. end
  84.  
  85. function rightTurn()
  86. turtle.turnRight()
  87. turtle.forward()
  88. turtle.turnRight()
  89. end
  90.  
  91. function leftTurn()
  92. turtle.turnLeft()
  93. turtle.forward()
  94. turtle.turnLeft()
  95. end
  96.  
  97. function run(lenght)
  98. local switch = true
  99. for i=1,lenght do
  100. moveAndHarvest(lenght-1)
  101. if i == lenght then break end --dont countinu after this point if its the last row
  102.  
  103. if switch then
  104. if inverted then
  105. leftTurn()
  106. else
  107. rightTurn()
  108. end
  109. switch = false
  110. else
  111. if inverted then
  112. rightTurn()
  113. else
  114. leftTurn()
  115. end
  116. switch = true
  117. end
  118.  
  119. end
  120. if switch then
  121. turtle.turnRight()
  122. turtle.turnRight()
  123. for i=1,lenght-1 do
  124. turtle.forward()
  125. end
  126. end
  127. if inverted then
  128. turtle.turnLeft()
  129. else
  130. turtle.turnRight()
  131. end
  132.  
  133.  
  134. for i=1,lenght-1 do
  135. turtle.forward()
  136. end
  137.  
  138. if inverted then
  139. turtle.turnLeft()
  140. else
  141. turtle.turnRight()
  142. end
  143. end
  144.  
  145. function dumpThings()
  146. for i=2,16 do
  147. turtle.select(i)
  148. turtle.dropDown()
  149. end
  150.  
  151. end
  152.  
  153. function reFuel()
  154. turtle.select(16)
  155. turtle.suckUp()
  156. turtle.refuel()
  157. turtle.select(1)
  158. end
  159.  
  160. if turtle.getFuelLevel() < requiredFuel then
  161. print("trying to refuel")
  162. reFuel()
  163. end
  164.  
  165.  
  166. if turtle.getFuelLevel() > requiredFuel then
  167. print("Starting")
  168. while turtle.getFuelLevel() > requiredFuel do
  169. getSeeds()
  170. turtle.forward()
  171. run(farmsize)
  172. turtle.back()
  173. dumpThings()
  174. print("Current Fuel:" .. turtle.getFuelLevel())
  175. if turtle.getFuelLevel() < requiredFuel then
  176. print("Trying to refuel")
  177. reFuel()
  178. end
  179. end
  180. print("ran out of fuel")
  181. else
  182. print("I dont have enough fuel")
  183. print("I need: " .. tostring(requiredFuel))
  184. print("I have: " .. tostring(turtle.getFuelLevel()))
  185. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement