Advertisement
augustclear

TreeFarm

Dec 20th, 2017
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.89 KB | None | 0 0
  1. local treeSpace=3
  2. local rowNum=7
  3. local colNum=7
  4.  
  5. local x = 0
  6. local y = 0
  7. local z = 0
  8. local facing = 1
  9.  
  10. numLogs = 1
  11. numSaps = 63
  12.  
  13. logSlot = 1
  14. sapSlot = 3
  15. fuelSlot = 2
  16.  
  17. ---------------------------------------
  18. -- BASIC FUNCTIONS FOR TURTLE CONTROL -
  19. ---------------------------------------
  20. local function gf(n)
  21.   if n==nil then
  22.     n=1
  23.   end
  24.   for i=1,n,1 do
  25.     turtle.forward()
  26.   end
  27. end
  28. local function gb(n)
  29.   if n==nil then
  30.     n=1
  31.   end
  32.   for i=1,n,1 do
  33.     turtle.back()
  34.   end
  35. end
  36. local function gu(n)
  37.   if n==nil then
  38.     n=1
  39.   end
  40.   for i=1,n,1 do
  41.     turtle.up()
  42.   end
  43. end
  44. local function gd(n)
  45.   if n==nil then
  46.     n=1
  47.   end
  48.   for i=1,n,1 do
  49.     turtle.down()
  50.   end
  51. end
  52. local function tl()
  53.   turtle.turnLeft()
  54.   if facing == 1 then
  55.     facing = 4
  56.   else
  57.     facing = facing - 1
  58.   end
  59. end
  60. local function tr()
  61.   turtle.turnRight()
  62.   if facing == 4 then
  63.     facing = 1
  64.   else
  65.     facing = facing + 1
  66.   end
  67. end
  68. local function pf()  turtle.place()       end
  69. local function pu()  turtle.placeUp()     end
  70. local function pd()  turtle.placeDown()   end
  71. local function df()  return turtle.dig()  end
  72. local function du()  turtle.digUp()       end
  73. local function dd()  turtle.digDown()     end
  74. local function sf()  turtle.suck()        end
  75. local function su(n)
  76.   if n==nil then
  77.     while turtle.suckUp() do end
  78.   else
  79.     for i=1,n do
  80.       turtle.suckUp()
  81.     end
  82.   end
  83. end
  84. local function sd(n)
  85.   if n==nil then
  86.     while turtle.suckDown() do end
  87.   else
  88.     for i=1,n do
  89.       turtle.suckDown()
  90.     end
  91.   end
  92. end
  93. local function Df()  turtle.drop()       end
  94. local function Du()  turtle.dropUp()     end
  95. local function Dd(n)
  96.   if n==nil then n=64 end
  97.   turtle.dropDown(n)
  98. end
  99. local function ss(s) turtle.select(s)    end
  100. local function cf() turtle.compare()     end
  101. local function cu() turtle.compareUp()   end
  102.  
  103. ---------------------------------------
  104. --          Building Blocks          --
  105. ---------------------------------------
  106.  
  107. function home()
  108.   -- Orient
  109.   if facing == 1 then
  110.     tl()
  111.   elseif facing == 2 then
  112.     tl()
  113.     tl()
  114.   elseif facing == 3 then
  115.     tr()
  116.   end
  117.  
  118.   -- Travel Home
  119.   gf()
  120.   x = x - 1
  121.   tl()
  122.   if z>0 then
  123.     gd(z)
  124.     z = 0
  125.   end
  126.   if y>0 then
  127.     gf(y)
  128.     y = 0
  129.   end
  130.   tr()
  131.   if x>0 then
  132.     gf(x)
  133.   end
  134. end
  135.  
  136. function refuel()
  137.   if turtle.getFuelLevel()<80 then
  138.     ss(fuelSlot)
  139.     turtle.refuel(1)
  140.   end
  141. end
  142.  
  143. function chopTree()
  144.   refuel()
  145.   ss(logSlot)
  146.   if turtle.compare() then
  147.     df()
  148.     numLogs = numLogs + 1
  149.     gf()
  150.     dd()
  151.     numLogs = numLogs + 1
  152.     ss(logSlot)
  153.     while turtle.compareUp() do
  154.       du()
  155.       numLogs = numLogs + 1
  156.       gu()
  157.       z = z + 1
  158.     end
  159.     for i=1,z do
  160.       gd()
  161.     end
  162.     z = 0
  163.     ss(sapSlot)
  164.     pd()
  165.     numSap = numSaps - 1
  166.   else
  167.     gf()
  168.   end
  169. end
  170.  
  171. function btwTree()
  172.   for j=1,3 do
  173.     if turtle.detect() then
  174.       df()
  175.     end
  176.     gf()
  177.     --sd(5)
  178.   end
  179. end
  180.  
  181. function chopRow()
  182.   for i=1,rowNum - 1 do
  183.     btwTree()
  184.     chopTree()
  185.   end
  186. end
  187.  
  188. function chopFarm()
  189.   btwTree()
  190.   chopTree()
  191.   for i=1,colNum-1 do
  192.     chopRow()
  193.     if i%2 == 1 then
  194.       tr()
  195.       btwTree()
  196.       chopTree()
  197.       tr()
  198.     else
  199.       tl()
  200.       btwTree()
  201.       chopTree()
  202.       tl()
  203.     end
  204.   end
  205.   chopRow()
  206.   x = 24
  207.   y = 28
  208.   home()
  209. end
  210.  
  211. function dropOffFuel ()
  212.   gf()
  213.   gd()
  214.   ss(fuelSlot)
  215.   Dd()
  216.   gu()
  217.   gb()
  218. end
  219.  
  220. function dropOffLoot ()
  221.   tl()
  222.   gf()
  223.   gd()
  224.   ss(logSlot)
  225.   Dd(turtle.getItemCount(logSlot)-17)
  226.   ss(sapSlot)
  227.   Dd()
  228.   for i = 4,16 do
  229.     ss(i)
  230.     Dd()
  231.   end
  232.   numLogs = 1
  233.   ss(fuelSlot)
  234.   turtle.craft(64)
  235.   turtle.suckDown(63)
  236.   numSaps = 63
  237.   gu()
  238.   gb()
  239.   tl()
  240.   tl()
  241. end
  242.  
  243. ---------------------------------------
  244. ---------         MAIN        ---------
  245. ---------------------------------------
  246.  
  247. refuel()
  248. chopFarm()
  249. dropOffFuel()
  250. dropOffLoot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement