Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Dark Oak Turtle Farm: Centered Cube Chopper + 2x2 Planting
- local saplingSlot = 1
- local fuelSlot = 16
- local cubeX, cubeY, cubeZ = 4, 10, 4 -- Make X and Z EVEN for perfect centering
- local dumpToChest = false
- posX, posY, posZ = 0, 0, 0
- heading = 0 -- 0=fwd, 1=right, 2=back, 3=left
- function turnRight() turtle.turnRight(); heading=(heading+1)%4 end
- function turnLeft() turtle.turnLeft(); heading=(heading+3)%4 end
- function face(dir)
- local turns = (dir-heading)%4
- if turns==1 then turnRight()
- elseif turns==2 then turnRight(); turnRight()
- elseif turns==3 then turnLeft() end
- end
- function forward()
- while true do
- if turtle.forward() then
- if heading==0 then posZ=posZ+1
- elseif heading==1 then posX=posX+1
- elseif heading==2 then posZ=posZ-1
- else posX=posX-1 end
- break
- else
- turtle.dig()
- sleep(0.1)
- end
- end
- end
- function moveUp() while true do if turtle.up() then posY=posY+1; break else turtle.digUp(); sleep(0.1) end end end
- function moveDown() while true do if turtle.down() then posY=posY-1; break else turtle.digDown(); sleep(0.1) end end end
- function goTo(tx,ty,tz,th)
- while posY<ty do moveUp() end
- while posY>ty do moveDown() end
- if posX<tx then face(1) while posX<tx do forward() end
- elseif posX>tx then face(3) while posX>tx do forward() end end
- if posZ<tz then face(0) while posZ<tz do forward() end
- elseif posZ>tz then face(2) while posZ>tz do forward() end end
- face(th)
- end
- function refuel()
- if not fuelSlot then return true end
- if turtle.getFuelLevel()=="unlimited" then return true end
- if turtle.getFuelLevel()<200 then
- turtle.select(fuelSlot)
- if not turtle.refuel(1) then print("⚠️ Out of fuel!"); return false end
- end
- return true
- end
- function dumpItems()
- if not dumpToChest then return end
- print("Dumping items...")
- turnLeft(); turnLeft()
- for i=2,16 do
- turtle.select(i)
- local itm=turtle.getItemDetail()
- if itm and not itm.name:find("sapling") then turtle.drop() end
- end
- turnLeft(); turnLeft()
- end
- -- Centered Cube: covers everything left/right/forward/back
- function chopCube()
- local offX = math.floor(cubeX/2)
- local offZ = math.floor(cubeZ/2)
- for y=1,cubeY-1 do
- for x=-offX,offX+1 do
- for z=-offZ,offZ+1 do
- goTo(x, y, z, 0)
- turtle.dig()
- turtle.digUp()
- turtle.digDown()
- end
- end
- end
- goTo(0,0,0,0)
- end
- function plantSaplings()
- print("Planting dark oak saplings...")
- -- Move up to clear the 2x2 patch, so turtle isn't in the way
- goTo(0, 2, 0, 0) -- Go 2 blocks above home (for clearance)
- local spots = {
- {0,0},
- {1,0},
- {0,1},
- {1,1},
- }
- for i,spot in ipairs(spots) do
- goTo(spot[1], 2, spot[2], 0) -- always 2 above the patch
- turtle.select(saplingSlot)
- -- Try to plant on the block below
- if not turtle.detectDown() then
- if turtle.placeDown() then print("Sapling planted at "..spot[1]..","..spot[2]) end
- end
- end
- goTo(0,0,0,0)
- end
- while true do
- print("Waiting for tree...")
- while true do
- local ok, data = turtle.inspect()
- if ok and (data.name:find("log") or data.name:find("leaves") or data.name:find("wood")) then break end
- sleep(5)
- refuel()
- end
- print("Tree detected! Chopping centered cube...")
- chopCube()
- goTo(0,0,0,0)
- dumpItems()
- print("Planting saplings...")
- plantSaplings()
- print("Cycle complete. Waiting for new tree...")
- sleep(10)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement