Advertisement
McBaron

Untitled

Jun 29th, 2025 (edited)
521
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.75 KB | Gaming | 0 0
  1. -- Dark Oak Turtle Farm: Centered Cube Chopper + 2x2 Planting
  2.  
  3. local saplingSlot = 1
  4. local fuelSlot = 16
  5. local cubeX, cubeY, cubeZ = 4, 10, 4    -- Make X and Z EVEN for perfect centering
  6. local dumpToChest = false
  7.  
  8. posX, posY, posZ = 0, 0, 0
  9. heading = 0 -- 0=fwd, 1=right, 2=back, 3=left
  10.  
  11. function turnRight() turtle.turnRight(); heading=(heading+1)%4 end
  12. function turnLeft() turtle.turnLeft(); heading=(heading+3)%4 end
  13. function face(dir)
  14.     local turns = (dir-heading)%4
  15.     if turns==1 then turnRight()
  16.     elseif turns==2 then turnRight(); turnRight()
  17.     elseif turns==3 then turnLeft() end
  18. end
  19. function forward()
  20.     while true do
  21.         if turtle.forward() then
  22.             if heading==0 then posZ=posZ+1
  23.             elseif heading==1 then posX=posX+1
  24.             elseif heading==2 then posZ=posZ-1
  25.             else posX=posX-1 end
  26.             break
  27.         else
  28.             turtle.dig()
  29.             sleep(0.1)
  30.         end
  31.     end
  32. end
  33. function moveUp() while true do if turtle.up() then posY=posY+1; break else turtle.digUp(); sleep(0.1) end end end
  34. function moveDown() while true do if turtle.down() then posY=posY-1; break else turtle.digDown(); sleep(0.1) end end end
  35.  
  36. function goTo(tx,ty,tz,th)
  37.     while posY<ty do moveUp() end
  38.     while posY>ty do moveDown() end
  39.     if posX<tx then face(1) while posX<tx do forward() end
  40.     elseif posX>tx then face(3) while posX>tx do forward() end end
  41.     if posZ<tz then face(0) while posZ<tz do forward() end
  42.     elseif posZ>tz then face(2) while posZ>tz do forward() end end
  43.     face(th)
  44. end
  45.  
  46. function refuel()
  47.     if not fuelSlot then return true end
  48.     if turtle.getFuelLevel()=="unlimited" then return true end
  49.     if turtle.getFuelLevel()<200 then
  50.         turtle.select(fuelSlot)
  51.         if not turtle.refuel(1) then print("⚠️ Out of fuel!"); return false end
  52.     end
  53.     return true
  54. end
  55.  
  56. function dumpItems()
  57.     if not dumpToChest then return end
  58.     print("Dumping items...")
  59.     turnLeft(); turnLeft()
  60.     for i=2,16 do
  61.         turtle.select(i)
  62.         local itm=turtle.getItemDetail()
  63.         if itm and not itm.name:find("sapling") then turtle.drop() end
  64.     end
  65.     turnLeft(); turnLeft()
  66. end
  67.  
  68. -- Centered Cube: covers everything left/right/forward/back
  69. function chopCube()
  70.     local offX = math.floor(cubeX/2)
  71.     local offZ = math.floor(cubeZ/2)
  72.     for y=1,cubeY-1 do
  73.         for x=-offX,offX+1 do
  74.             for z=-offZ,offZ+1 do
  75.                 goTo(x, y, z, 0)
  76.                 turtle.dig()
  77.                 turtle.digUp()
  78.                 turtle.digDown()
  79.             end
  80.         end
  81.     end
  82.     goTo(0,0,0,0)
  83. end
  84.  
  85. function plantSaplings()
  86.     print("Planting dark oak saplings...")
  87.     -- Move up to clear the 2x2 patch, so turtle isn't in the way
  88.     goTo(0, 2, 0, 0) -- Go 2 blocks above home (for clearance)
  89.  
  90.     local spots = {
  91.         {0,0},
  92.         {1,0},
  93.         {0,1},
  94.         {1,1},
  95.     }
  96.     for i,spot in ipairs(spots) do
  97.         goTo(spot[1], 2, spot[2], 0)  -- always 2 above the patch
  98.         turtle.select(saplingSlot)
  99.         -- Try to plant on the block below
  100.         if not turtle.detectDown() then
  101.             if turtle.placeDown() then print("Sapling planted at "..spot[1]..","..spot[2]) end
  102.         end
  103.     end
  104.     goTo(0,0,0,0)
  105. end
  106.  
  107. while true do
  108.     print("Waiting for tree...")
  109.     while true do
  110.         local ok, data = turtle.inspect()
  111.         if ok and (data.name:find("log") or data.name:find("leaves") or data.name:find("wood")) then break end
  112.         sleep(5)
  113.         refuel()
  114.     end
  115.  
  116.     print("Tree detected! Chopping centered cube...")
  117.     chopCube()
  118.     goTo(0,0,0,0)
  119.     dumpItems()
  120.     print("Planting saplings...")
  121.     plantSaplings()
  122.     print("Cycle complete. Waiting for new tree...")
  123.     sleep(10)
  124. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement