Advertisement
cfl3

menril

May 12th, 2025 (edited)
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.29 KB | None | 0 0
  1. -- Ground-standing Menril tree farmer, v3
  2. -- Place a chest directly behind the turtle and a dirt block one space ahead.
  3.  
  4. --------------------------------------------------
  5. -- Constants
  6. --------------------------------------------------
  7. local SAPLING   = "integrateddynamics:menril_sapling"
  8. local MIN_FUEL  = 500                                -- refuel floor
  9.  
  10. local MENRIL_LOG = {                                -- any of these count as wood
  11.   ["integrateddynamics:menril_log"]         = true,
  12.   ["integrateddynamics:menril_wood"]        = true,
  13.   ["integrateddynamics:menril_log_filled"]  = true, -- enriched/filled variant
  14. }
  15.  
  16. --------------------------------------------------
  17. -- Helpers
  18. --------------------------------------------------
  19. local function isMenril(name) return MENRIL_LOG[name] end
  20.  
  21. local function refuel()
  22.   if turtle.getFuelLevel() == "unlimited" or turtle.getFuelLevel() >= MIN_FUEL then return end
  23.   for slot = 1, 16 do
  24.     local item = turtle.getItemDetail(slot)
  25.     if item and item.name ~= SAPLING then                    -- never burn saplings
  26.       turtle.select(slot)
  27.       if turtle.refuel(0) then                               -- probe burnability
  28.         turtle.refuel()
  29.         if turtle.getFuelLevel() >= MIN_FUEL then break end
  30.       end
  31.     end
  32.   end
  33. end
  34.  
  35. local function selectSapling()
  36.   for slot = 1, 16 do
  37.     local d = turtle.getItemDetail(slot)
  38.     if d and d.name == SAPLING then turtle.select(slot); return true end
  39.   end
  40.   return false
  41. end
  42.  
  43. local function suckFromChest()
  44.   turtle.turnLeft(); turtle.turnLeft()
  45.   for slot = 1, 16 do
  46.     if turtle.getItemCount(slot) == 0 then turtle.select(slot); turtle.suck() end
  47.   end
  48.   turtle.turnRight(); turtle.turnRight()
  49. end
  50.  
  51. local function dumpToChest()
  52.   turtle.turnLeft(); turtle.turnLeft()
  53.   for slot = 1, 16 do turtle.select(slot); turtle.drop() end
  54.   turtle.turnRight(); turtle.turnRight()
  55. end
  56.  
  57. -- dig the four horizontal arms of a “plus” at the current level
  58. local function spinDigHorizontal()
  59.   for _ = 1, 4 do
  60.     turtle.turnRight()
  61.     if turtle.detect() then
  62.       local ok, blk = turtle.inspect()
  63.       if ok and isMenril(blk.name) then turtle.dig() end
  64.     end
  65.   end
  66. end
  67.  
  68. --------------------------------------------------
  69. -- Core farming steps
  70. --------------------------------------------------
  71. local function plantSapling()
  72.   if not selectSapling() then suckFromChest() end
  73.   assert(selectSapling(), "No Menril saplings available!")
  74.  
  75.   if turtle.detect() then turtle.dig() end
  76.   turtle.place()                                             -- plant on dirt
  77. end
  78.  
  79. local function waitForGrowth()
  80.   while true do
  81.     local ok, info = turtle.inspect()                        -- block in front
  82.     if ok and isMenril(info.name) then return end
  83.     os.sleep(5)
  84.   end
  85. end
  86.  
  87. local function harvestTree()
  88.   ----------------------------------------------------------
  89.   -- a. Enter the trunk and clear the bottom “root” cross
  90.   ----------------------------------------------------------
  91.   turtle.dig(); turtle.forward()
  92.   spinDigHorizontal()
  93.  
  94.   ----------------------------------------------------------
  95.   -- b. Climb the trunk, clearing every thick section
  96.   ----------------------------------------------------------
  97.   while true do
  98.     -- Is there a log above?
  99.     local okUp, blkUp = turtle.inspectUp()
  100.     if not (okUp and isMenril(blkUp.name)) then break end
  101.  
  102.     turtle.digUp()
  103.     turtle.up()
  104.  
  105.     -- After moving up, check if the trunk thickens here
  106.     local okFront, blkFront = turtle.inspect()
  107.     if okFront and isMenril(blkFront.name) then
  108.       spinDigHorizontal()                                   -- clear arms
  109.     end
  110.   end
  111.  
  112.   ----------------------------------------------------------
  113.   -- c. Ensure the crown cross is gone (harmless if already clear)
  114.   ----------------------------------------------------------
  115.   spinDigHorizontal()
  116.  
  117.   ----------------------------------------------------------
  118.   -- d. Return to start position
  119.   ----------------------------------------------------------
  120.   while turtle.down() do end
  121.   turtle.back()
  122. end
  123.  
  124. --------------------------------------------------
  125. -- Main loop
  126. --------------------------------------------------
  127. while true do
  128.   refuel()
  129.   plantSapling()
  130.   waitForGrowth()
  131.   harvestTree()
  132.   dumpToChest()
  133. end
  134.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement