CultistaDeCrocs

farmTrees.lua

Mar 19th, 2024 (edited)
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. brokenTrees = 0
  2.  
  3. function clearMonitor ()
  4. term.clear()
  5. term.setCursorPos(1,1)
  6. end
  7.  
  8. function centerCursor(strSize)
  9. local x, y = term.getCursorPos()
  10. local width, height = term.getSize()
  11. term.setCursorPos(math.floor((width - strSize) / 2) + 1, y)
  12. end
  13.  
  14. function checkTree ()
  15. local has_block, data = turtle.inspect()
  16.  
  17. if data.name == "ars_nouveau:red_archwood_log" then
  18. return true
  19. else
  20. return false
  21. end
  22. end
  23.  
  24. function sendPulse ()
  25. redstone.setOutput("back", true)
  26. os.sleep(0.5)
  27. redstone.setOutput("back", false)
  28. end
  29.  
  30. function getSaplings ()
  31. while (not turtle.suckDown() and not lookForSaplings()) do
  32. clearMonitor()
  33. print("No saplings found. Checking again...")
  34. end
  35.  
  36. updateMonitor()
  37. end
  38.  
  39. function lookForSaplings ()
  40. for i=1, 16 do
  41. turtle.select(i)
  42. local currentItem = turtle.getItemDetail(i)
  43.  
  44. if currentItem ~= nil then
  45. if (currentItem.name == "ars_nouveau:red_archwood_sapling") then
  46. return true
  47. end
  48. end
  49. end
  50.  
  51. return false
  52. end
  53.  
  54. function updateMonitor ()
  55. titleString = "===== Tree Farmer MK I ====="
  56. clearMonitor()
  57. centerCursor(#titleString)
  58. print(titleString)
  59.  
  60. print("\nHi! I'm the Tree Farmer, courtesy of Bongo!\n")
  61. print("Please do not take items from me or the chest under me.\n\n")
  62. print("Trees harvested today: " .. brokenTrees)
  63. end
  64.  
  65. updateMonitor ()
  66. while (true) do
  67. if checkTree() then
  68. brokenTrees = brokenTrees + 1
  69. sendPulse()
  70. os.sleep(3)
  71. getSaplings()
  72. turtle.place()
  73. end
  74. end
Advertisement
Add Comment
Please, Sign In to add comment