andrelisboa1

tiller.lua

Jul 2nd, 2025 (edited)
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local monitor = peripheral.wrap("right")
  2. local blockName = "minecraft:coarse_dirt"
  3.  
  4. function getCoarseDirtAmount()
  5.     local total = 0
  6.     for slot = 1, 16 do
  7.         local item = turtle.getItemDetail(slot)
  8.         if item and item.name == blockName then
  9.             total = total + item.count
  10.         end
  11.     end
  12.     return total
  13. end
  14.  
  15. function doDig()
  16.     for i = 2, 15 do
  17.         local item = turtle.getItemDetail(i)
  18.         if item and item.name == blockName then
  19.             turtle.select(i)
  20.             turtle.place()
  21.             turtle.dig()
  22.             turtle.select(16)
  23.             turtle.equipRight()
  24.             turtle.dig()
  25.             turtle.equipRight()
  26.             return true
  27.         end
  28.     end
  29.     return false
  30. end
  31.  
  32.  
  33.  
  34. -- Initialize
  35. local total = getCoarseDirtAmount()
  36. local progress = 0
  37. local dropBuffer = 0
  38. local DROP_EVERY = 5  -- Drop after every 5 tilled blocks
  39.  
  40. -- Main loop
  41. while doDig() do
  42.     progress = progress + 1
  43.     dropBuffer = dropBuffer + 1
  44.  
  45.     -- Display update
  46.     monitor.clear()
  47.     monitor.setCursorPos(1, 1)
  48.     monitor.setTextColor(colors.lime)
  49.     monitor.write("TILLER_d")
  50.     monitor.setCursorPos(1, 2)
  51.     monitor.setTextColor(colors.white)
  52.     monitor.write("At")
  53.     monitor.setCursorPos(1, 3)
  54.     monitor.write(progress .. "/" .. total)
  55.  
  56.     -- Drop when buffer reaches threshold
  57.     if dropBuffer >= DROP_EVERY then
  58.         turtle.select(1)
  59.         turtle.dropUp()
  60.         dropBuffer = 0
  61.     end
  62. end
  63.  
  64. -- Final drop (in case leftovers weren't dumped)
  65. if dropBuffer > 0 then
  66.     turtle.select(1)
  67.     turtle.dropUp()
  68. end
  69.  
  70. -- Done message
  71. monitor.clear()
  72. monitor.setCursorPos(1, 1)
  73. monitor.setTextColor(colors.lime)
  74. monitor.write("--------")
  75. monitor.setCursorPos(1, 2)
  76. monitor.write("Tilling")
  77. monitor.setCursorPos(1, 3)
  78. monitor.write("complete")
  79.  
Advertisement
Add Comment
Please, Sign In to add comment