LazyNub

SmallTreeFarmBuilder v0.3

May 7th, 2013
1,258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.29 KB | None | 0 0
  1. -- Small Tree Farm Builder v0.3
  2. -- BY: LazyNub
  3. --
  4. -- Modified version of
  5. -- Robust Turtle API by SpeedR
  6. -- integrated into code in v0.3
  7. --
  8. -- Works well with Andy Logger Deluxe Felling Turtle program
  9. -- Located at:  pastebin get HanjL7Mz logger
  10. -- Suggest fir trees in a 4x4 formation
  11. -- You will need a water bucket and 17 saplings and 17 dirt minimum
  12. --
  13. -- Place the mining turtle at the lower left hand corner of the
  14. -- construction site you have planned. You will need an area 17x18 (Width x Length)
  15. -- open to the sky or tall enough for your trees plus 6 vertical blocks.
  16. --
  17. -- Items needed:
  18. -- Building blocks: 325 placed in first 5 slots (any solid block)
  19. -- Optional Furnace: 1 Placed in Slot 15
  20. -- Needed Wooden Chests: 4 Placed in Slot 14
  21. -- Needed Obsidian Transport Pipe: 1 Placed in slot 12
  22. -- Needed Stone Transport Pipes: 5 Placed in Slot 13
  23. -- Fuel needed ~400: Placed in Slot 16 (5 coal ore)
  24. -- ~7 min build time
  25. --
  26. local NeededBlocks = 324
  27. local NeededFuel = 400
  28. local blockslot = 1
  29. local blockslotcur = 1
  30.  
  31. function checkfuellevel()
  32.     if turtle.getFuelLevel() >= NeededFuel then
  33.         print ("Plenty Fuel, Thanks!")
  34.         return true
  35.     else
  36.         print ("Refueling...")
  37.         while turtle.getFuelLevel() < NeededFuel do
  38.             turtle.select(16)
  39.             turtle.refuel(1)
  40.         end
  41.         return true
  42.     end
  43. end
  44.  
  45. function selectfullslot()
  46.     for blockslot = blockslotcur,10 do
  47.         if turtle.getItemCount(blockslot) >= 1 then
  48.             turtle.select(blockslot)
  49.             blockslotcur=blockslot
  50.             break
  51.         end
  52.     end
  53. end
  54.  
  55. function enoughblocks()
  56.     t = 0
  57.     for i = 1,11 do
  58.     t = t + turtle.getItemCount(i)
  59.     end
  60.     if t >= NeededBlocks then
  61.         print ("Plenty Building Blocks, Thanks!")
  62.         return true
  63.     else
  64.         return false
  65.     end
  66. end
  67.  
  68.  
  69. --[[
  70.  
  71.  
  72.  
  73.         Robust Turtle API by SpeedR
  74.  
  75.  
  76.        
  77. ]]--
  78. --Traveling: Goes in the direction no matter what (almost)
  79. --Will not be stopped by blocks or mobs
  80.  
  81. function forward(l)
  82.   l=l or 1
  83.   for i=1,l do
  84.     local tries = 0
  85.     while turtle.forward() ~= true do
  86.       turtle.dig()
  87.       turtle.attack()
  88.       sleep(0.2)
  89.       tries = tries + 1
  90.       if tries>500 then
  91.         print("Error: can't move forward.")
  92.         return false
  93.       end
  94.     end
  95.   end
  96.   return true
  97. end
  98.  
  99. function up(l)
  100.   l=l or 1
  101.   for i=1,l do
  102.     local tries = 0
  103.     while turtle.up() ~= true do
  104.       turtle.digUp()
  105.       turtle.attackUp()
  106.       sleep(0.2)
  107.       tries = tries + 1
  108.       if tries>500 then
  109.         print("Error: can't move up.")
  110.         return false
  111.       end
  112.     end
  113.   end
  114.   return true
  115. end
  116.  
  117. --Turning
  118. function turnAround()
  119.   turtle.turnRight()
  120.   turtle.turnRight()
  121. end
  122.  
  123. function right()
  124.   turtle.turnRight()
  125. end
  126.  
  127. function left()
  128.   turtle.turnLeft()
  129. end
  130.  
  131. function goRight(l)
  132.   l=l or 1
  133.   turtle.turnRight()
  134.   forward(l)
  135. end
  136.  
  137. function goLeft(l)
  138.   l=l or 1
  139.   turtle.turnLeft()
  140.   forward(l)
  141. end
  142.  
  143. function strafeRight(l)
  144.   l=l or 1
  145.   goRight(l)
  146.   turtle.turnLeft()
  147. end
  148.  
  149. function strafeLeft(l)
  150.   l=l or 1
  151.   goLeft(l)
  152.   turtle.turnRight()
  153. end
  154.  
  155. --Digging with gravel/sand detection
  156. function dig()
  157.   local tries = 0
  158.   while turtle.detect() do
  159.     turtle.select(11)
  160.     turtle.dig()
  161.     turtle.drop()
  162.     selectfullslot()
  163.     sleep(0.3)
  164.     tries = tries + 1
  165.     if tries>500 then
  166.       print("Error: dug for too long.")
  167.       return false
  168.     end
  169.   end
  170.   return true
  171. end
  172.  
  173. function digUp()
  174.   local tries = 0
  175.   while turtle.detectUp() do
  176.     turtle.select(11)
  177.     turtle.digUp()
  178.     turtle.drop()
  179.     selectfullslot()
  180.     sleep(0.3)
  181.     tries = tries + 1
  182.     if tries>500 then
  183.       print("Error: dug up for too long.")
  184.       return false
  185.     end
  186.   end
  187.   return true
  188. end
  189.  
  190. function digDown()
  191.   local tries = 0
  192.   while turtle.detectDown() do
  193.     turtle.select(11)
  194.     turtle.digDown()
  195.     turtle.drop()
  196.     selectfullslot()
  197.     sleep(0.3)
  198.     tries = tries + 1
  199.     if tries>500 then
  200.       print("Error: dug down for too long.")
  201.       return false
  202.     end
  203.   end
  204.   return true
  205. end
  206.  
  207.  
  208. --
  209.  
  210.  
  211. function down(l)
  212.   l=l or 1
  213.   for i=1,l do
  214.     local tries = 0
  215.     while turtle.down() ~= true do
  216.       turtle.digDown()
  217.       turtle.attackDown()
  218.       sleep(0.2)
  219.       tries = tries + 1
  220.       if tries>500 then
  221.         print("Error: can't move down.")
  222.         return false
  223.       end
  224.     end
  225.   end
  226.   return true
  227. end
  228.  
  229. function back(l)
  230.   l=l or 1
  231.   for i=1,l do
  232.     if turtle.back() ~= true then
  233.       turnAround()
  234.       forward()
  235.       turnAround()
  236.     end
  237.   end
  238. end
  239.  
  240.  
  241. --Place blocks
  242. --Does not place when there's already the right block.
  243. function place()
  244.   selectfullslot()
  245.   if turtle.compare()== false then
  246.     dig()
  247.     turtle.place()
  248.   end
  249. end
  250.  
  251. function placeUp()
  252.   selectfullslot()
  253.   if turtle.compareUp()==false then
  254.     digUp()
  255.     turtle.placeUp()
  256.   end
  257. end
  258.  
  259. function placeDown()
  260.   selectfullslot()
  261.   if turtle.compareDown()==false then
  262.     digDown()
  263.     turtle.placeDown()
  264.   end
  265. end
  266.  
  267. local function outOfResource()
  268.   print("Ran out of a resource. Block: ",blockslot , ".")
  269.   print("Refill, then say something to proceed.")
  270.   read()
  271. end
  272.  
  273. function placeRight()
  274.   turtle.turnRight()
  275.   place()
  276.   turtle.turnLeft()
  277. end
  278.  
  279. function placeLeft()
  280.   turtle.turnLeft()
  281.   place()
  282.   turtle.turnRight()
  283. end
  284.  
  285. function placeBack()
  286.   turnAround()
  287.   place()
  288.   turnAround()
  289. end
  290.  
  291. --place row     e.g. placeRow(up, forward, 15)
  292. function placeRow(placeDir, travelDir, l)
  293.   l=l or 1
  294.   for i=1,l do
  295.     if placeDir == "forward" then
  296.       place()
  297.     elseif placeDir == "up" then
  298.       placeUp()
  299.     elseif placeDir == "down" then
  300.       placeDown()
  301.     elseif placeDir == "right" then
  302.       placeRight()
  303.     elseif placeDir == "left" then
  304.       placeLeft()
  305.     elseif placeDir == "back" then
  306.       placeBack()
  307.     else
  308.       print('"', placeDir, '" is not a valid direction!')
  309.       return false
  310.     end
  311.     if travelDir == "forward" then
  312.       if i < l then
  313.         forward()
  314.       end
  315.     elseif travelDir == "up" then
  316.       up()
  317.     elseif travelDir == "down" then
  318.       down()
  319.     elseif travelDir == "right" then
  320.       strafeRight()
  321.     elseif travelDir == "left" then
  322.       strafeLeft()
  323.     elseif travelDir == "back" then
  324.       back()
  325.     else
  326.       print('"', travelDir, '" is not a valid direction!')
  327.       return false
  328.     end
  329.   end
  330.   return true
  331. end
  332.  
  333.  
  334.  
  335. --[[
  336.        
  337.        
  338.        
  339.         Robust Turtle API by SpeedR
  340.        
  341.        
  342.        
  343. ]]--
  344.  
  345.  
  346.  
  347.  
  348. function BuildWall(h,l)
  349.     for lt= 1,l do
  350.         for ht= 1,h do
  351.             selectfullslot()
  352.             turtle.place()
  353.             turtle.up()
  354.         end
  355.         for i=1,h do
  356.             turtle.down()
  357.         end
  358.         if lt < l then
  359.             turtle.turnRight()
  360.             turtle.forward()
  361.             turtle.turnLeft()
  362.         end
  363.     end
  364. end
  365.  
  366. function Buildslab(w,d)
  367.     -- Slab will be built lower left to upper right with finish at right bottom
  368.     for wt=1,w do
  369.         placeRow("down","forward",d)
  370.         if wt < w then
  371.             if wt%2==0 then
  372.                 turtle.turnLeft()
  373.                 forward()
  374.                 turtle.turnLeft()
  375.             else
  376.                 turtle.turnRight()
  377.                 forward()
  378.                 turtle.turnRight()
  379.             end
  380.         end
  381.     end
  382.     if w%2==0 then
  383.         turtle.turnLeft()
  384.         turtle.turnLeft()
  385.     else
  386.         back(d-1)
  387.     end
  388. end
  389.  
  390. -- Main Program
  391. --
  392. --
  393. if enoughblocks() and checkfuellevel() then
  394.  
  395.     up()
  396.     Buildslab(15,8)
  397.     forward(8)
  398.     turtle.turnLeft()
  399.     forward(14)
  400.     turtle.turnRight()
  401.     up()
  402.     Buildslab(15,7)
  403.     strafeRight()
  404.     up()
  405.     placeRow("down","forward",8)
  406.     left()
  407.     forward()
  408.     placeRow("down","forward",15)
  409.     forward()
  410.     left()
  411.     placeRow("down","forward",8)
  412.     forward()
  413.     down()
  414.     placeRow("down","forward",8)
  415.     forward()
  416.     goLeft()
  417.     down(3)
  418.     for i = 1,8 do
  419.         placeLeft()
  420.         placeDown()
  421.         placeRight()
  422.         forward()
  423.     end
  424.     up()
  425.     for i = 1,7 do
  426.         placeDown()
  427.         placeRight()
  428.         forward()
  429.     end
  430.     up()
  431.     left()
  432.     placeDown()
  433.     forward()
  434.     up()
  435.     placeRow("down","forward",8)
  436.     left()
  437.     forward(15)
  438.     left()
  439.     forward(8)
  440.     down(2)
  441.     turtle.select(12)
  442.     turtle.placeDown()
  443.     turtle.select(13)
  444.     for i = 1,5 do
  445.         up()
  446.         turtle.placeDown()
  447.     end
  448.     left()
  449.     forward()
  450.     turtle.select(14)
  451.     turtle.placeDown()
  452.     forward()
  453.     turtle.placeDown()
  454.     forward(2)
  455.     turtle.placeDown()
  456.     forward()
  457.     turtle.placeDown()
  458.     back(2)
  459.     down()
  460.     turtle.select(15)
  461.     turtle.placeUp()
  462.     down(2)
  463.     back(2)
  464.     placeRow("up","forward",5)
  465.     place()
  466.     strafeRight()
  467.     place()
  468.     placeRow("up","back",5)
  469.     down()
  470.     forward(6)
  471.     place()
  472.     strafeRight()
  473.     up(3)
  474.     back(3)
  475.     left()
  476.     forward(2)
  477.    
  478. else
  479.     print("Not Enough Blocks. You need: " .. NeededBlocks)
  480. end
Advertisement
Add Comment
Please, Sign In to add comment