Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Ground-standing Menril tree farmer, v3
- -- Place a chest directly behind the turtle and a dirt block one space ahead.
- --------------------------------------------------
- -- Constants
- --------------------------------------------------
- local SAPLING = "integrateddynamics:menril_sapling"
- local MIN_FUEL = 500 -- refuel floor
- local MENRIL_LOG = { -- any of these count as wood
- ["integrateddynamics:menril_log"] = true,
- ["integrateddynamics:menril_wood"] = true,
- ["integrateddynamics:menril_log_filled"] = true, -- enriched/filled variant
- }
- --------------------------------------------------
- -- Helpers
- --------------------------------------------------
- local function isMenril(name) return MENRIL_LOG[name] end
- local function refuel()
- if turtle.getFuelLevel() == "unlimited" or turtle.getFuelLevel() >= MIN_FUEL then return end
- for slot = 1, 16 do
- local item = turtle.getItemDetail(slot)
- if item and item.name ~= SAPLING then -- never burn saplings
- turtle.select(slot)
- if turtle.refuel(0) then -- probe burnability
- turtle.refuel()
- if turtle.getFuelLevel() >= MIN_FUEL then break end
- end
- end
- end
- end
- local function selectSapling()
- for slot = 1, 16 do
- local d = turtle.getItemDetail(slot)
- if d and d.name == SAPLING then turtle.select(slot); return true end
- end
- return false
- end
- local function suckFromChest()
- turtle.turnLeft(); turtle.turnLeft()
- for slot = 1, 16 do
- if turtle.getItemCount(slot) == 0 then turtle.select(slot); turtle.suck() end
- end
- turtle.turnRight(); turtle.turnRight()
- end
- local function dumpToChest()
- turtle.turnLeft(); turtle.turnLeft()
- for slot = 1, 16 do turtle.select(slot); turtle.drop() end
- turtle.turnRight(); turtle.turnRight()
- end
- -- dig the four horizontal arms of a “plus” at the current level
- local function spinDigHorizontal()
- for _ = 1, 4 do
- turtle.turnRight()
- if turtle.detect() then
- local ok, blk = turtle.inspect()
- if ok and isMenril(blk.name) then turtle.dig() end
- end
- end
- end
- --------------------------------------------------
- -- Core farming steps
- --------------------------------------------------
- local function plantSapling()
- if not selectSapling() then suckFromChest() end
- assert(selectSapling(), "No Menril saplings available!")
- if turtle.detect() then turtle.dig() end
- turtle.place() -- plant on dirt
- end
- local function waitForGrowth()
- while true do
- local ok, info = turtle.inspect() -- block in front
- if ok and isMenril(info.name) then return end
- os.sleep(5)
- end
- end
- local function harvestTree()
- ----------------------------------------------------------
- -- a. Enter the trunk and clear the bottom “root” cross
- ----------------------------------------------------------
- turtle.dig(); turtle.forward()
- spinDigHorizontal()
- ----------------------------------------------------------
- -- b. Climb the trunk, clearing every thick section
- ----------------------------------------------------------
- while true do
- -- Is there a log above?
- local okUp, blkUp = turtle.inspectUp()
- if not (okUp and isMenril(blkUp.name)) then break end
- turtle.digUp()
- turtle.up()
- -- After moving up, check if the trunk thickens here
- local okFront, blkFront = turtle.inspect()
- if okFront and isMenril(blkFront.name) then
- spinDigHorizontal() -- clear arms
- end
- end
- ----------------------------------------------------------
- -- c. Ensure the crown cross is gone (harmless if already clear)
- ----------------------------------------------------------
- spinDigHorizontal()
- ----------------------------------------------------------
- -- d. Return to start position
- ----------------------------------------------------------
- while turtle.down() do end
- turtle.back()
- end
- --------------------------------------------------
- -- Main loop
- --------------------------------------------------
- while true do
- refuel()
- plantSapling()
- waitForGrowth()
- harvestTree()
- dumpToChest()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement