Advertisement
asweigart

Untitled

Feb 15th, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.38 KB | None | 0 0
  1. local tArgs = {...}
  2. if #tArgs < 2 or tonumber(tArgs[1]) == nil or tonumber(tArgs[2] == nil) then
  3. print('Usage: wartfarmer <forward> <right>')
  4. print(' The size of the field is relative')
  5. print(' to the turtle\'s start point. Turtle')
  6. print(' should be *above* the netherwart.')
  7. return
  8. end
  9.  
  10. local FORWARD_LEN = tonumber(tArgs[1])
  11. local RIGHT_LEN = tonumber(tArgs[2])
  12. local i
  13.  
  14.  
  15. local function plantWart()
  16. for i=1,16 do
  17. itemData = turtle.getItemDetail(i)
  18. if itemData ~= nil and itemData['name'] == 'minecraft:nether_wart' then
  19. turtle.placeDown() -- plant netherwart
  20. break
  21. end
  22. end
  23. end
  24.  
  25. -- note that "forward" and "right" are relative to the turtle's start
  26. local forwardPos = 1
  27. local rightPos = 1
  28. local movingForward = true
  29. local outOfFuel = false
  30. local wartCount = 0
  31.  
  32. -- quick fuel check
  33. if turtle.getFuelLevel() == 0 then
  34. print('Out of fuel!')
  35. end
  36.  
  37. print('Hold Ctrl-T to stop farmer.')
  38. --main program
  39. while true do
  40. -- check if below is a chest
  41. local exists, block = turtle.inspectDown()
  42.  
  43. if exists and (string.find(block['name'], 'chest') or string.find(block['name'], 'barrel')) then
  44. -- drop off inventory into chest
  45. print('Dropping off inventory into chest...')
  46. for i=1,16 do
  47. turtle.select(i)
  48. itemData = turtle.getItemDetail()
  49. if itemData ~= nil and itemData['name'] == 'minecraft:nether_wart' then
  50. wartCount = wartCount + turtle.getItemCount()
  51. end
  52. turtle.dropDown(64) -- deposit everything into chest, warts and whatever
  53. end
  54. print(' ', wartCount, ' warts deposited.')
  55. wartCount = 0
  56. elseif not exists then
  57. -- nothing is under the turtle, so try to plant netherwart
  58. plantWart()
  59. elseif block['name'] == 'minecraft:nether_wart' and block['metadata'] == 3 then
  60. -- netherart (and fully mature) is below, so harvest it
  61. turtle.digDown()
  62. turtle.suckDown() -- pick up any netherwart
  63. plantWart()
  64. end
  65.  
  66. -- move the turtle along 1 block
  67. if movingForward and forwardPos < FORWARD_LEN then
  68. -- moving forward down the row
  69. moved = turtle.forward()
  70. if not moved then outOfFuel = true end
  71. forwardPos = forwardPos + 1 -- keep track of where we are
  72. elseif movingForward and forwardPos == FORWARD_LEN then
  73. -- at the end of the row
  74. if rightPos < RIGHT_LEN then
  75. -- go to next row
  76. turtle.turnRight()
  77. moved = turtle.forward()
  78. if not moved then outOfFuel = true end
  79. rightPos = rightPos + 1 -- keep track of where we are
  80. turtle.turnRight()
  81. movingForward = false
  82. elseif rightPos == RIGHT_LEN then
  83. -- end of the last row, go back home
  84. turtle.turnRight()
  85. turtle.turnRight()
  86. for i=1,(FORWARD_LEN-1) do
  87. moved = turtle.forward()
  88. if not moved then outOfFuel = true end
  89. end
  90. turtle.turnRight()
  91. for i=1,(RIGHT_LEN-1) do
  92. moved = turtle.forward()
  93. if not moved then outOfFuel = true end
  94. end
  95. turtle.turnRight()
  96. -- should be back at start now in correct orientation
  97. forwardPos = 1
  98. rightPos = 1
  99. movingForward = true
  100. sleep(210) -- wait 3:30 for regrow
  101. end
  102. elseif not movingForward and forwardPos > 1 then
  103. -- moving back down the row
  104. moved = turtle.forward()
  105. if not moved then outOfFuel = true end
  106. forwardPos = forwardPos - 1 -- keep track of where we are
  107. elseif not movingForward and forwardPos == 1 then
  108. -- back at start of row, turn to next row
  109. if rightPos < RIGHT_LEN then
  110. -- go to next row
  111. turtle.turnLeft()
  112. moved = turtle.forward()
  113. if not moved then outOfFuel = true end
  114. rightPos = rightPos + 1 -- keep track of where we are
  115. turtle.turnLeft()
  116. movingForward = true
  117. elseif rightPos == RIGHT_LEN then
  118. -- end of the last row, go back home
  119. turtle.turnRight()
  120. for i=1,(RIGHT_LEN-1) do
  121. moved = turtle.forward()
  122. if not moved then outOfFuel = true end
  123. end
  124. turtle.turnRight()
  125. -- should be back at start now in correct orientation
  126. forwardPos = 1
  127. rightPos = 1
  128. movingForward = true
  129. sleep(210) -- wait 3:30 for regrow
  130. end
  131. end
  132.  
  133. --print('Pos: ', forwardPos, ', ', rightPos)
  134.  
  135. if outOfFuel then
  136. print('Out of fuel (or blocked)! Refuel and')
  137. print('move turtle back to start point.')
  138. return
  139. end
  140. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement