Advertisement
hyndgrinder

LJ

Aug 6th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.46 KB | None | 0 0
  1. dSlot=1
  2. -----------Ground Leveller------------
  3. function level()
  4.   print"Begin Levelling"
  5.  print ("slot:  "..  dSlot)
  6.     if not turtle.detectDown() then
  7.     flooring = turtle.getItemCount(dSlot)
  8.     while not flooring do
  9.         if dSlot==16 then
  10.             dSlot=1
  11.             print ("slot:  ".. dslot)
  12.         else
  13.             dSlot=dSlot+1
  14.             print ("slot: ".. dslot)
  15.         end
  16.     flooring = turtle.getItemCount(dSlot)
  17.     sleep(0.2)
  18.     end
  19.     turtle.placeDown()
  20.   end
  21.   print"End levelling"
  22. end
  23.  
  24. ---------Tree Chop---------------
  25. function tree_chop()
  26. print "Beginning tree chop"
  27. blocks=0
  28.   while turtle.detect() do
  29.       turtle.dig()
  30.      if turtle.detectUp() then
  31.       turtle.digUp()
  32.      end
  33.      turtle.up()
  34.      blocks=blocks+1
  35.   end
  36. --print ("Top of tree reached" .. blocks .. " found.")
  37.    
  38.       while blocks>0 do
  39.         turtle.down()
  40.         blocks=blocks-1
  41.       end
  42.  
  43.  
  44. --print("Back down")
  45.   level()
  46.   --print "Levelling landscape"
  47.  
  48.   print "End tree chop"
  49.  
  50. end
  51.  
  52. ---------Steps-------------------  
  53. function steps(g)
  54. print("Begin steps")
  55. s=0
  56. repeat
  57.   level()
  58.   --print ("Before Chop step:  ".. s)
  59.   tree_chop()
  60.   turtle.forward()
  61.   s=s+1
  62.   --print("Updated step = "..s)
  63. until s==g
  64. --print "stepping forward"
  65. print ("End steps")
  66. end
  67.  
  68. ----------Lateral Move Manager---------------------
  69. function latMan(g)
  70. print("Begin lateral moves")
  71.  
  72. l=0
  73. repeat
  74.   if l%2==0 then
  75.     turndir="right"
  76.   else
  77.     turndir="left"
  78.  
  79.   end
  80. print("Lateral step:  " .. l ..", " .. g-l .." steps to go.")
  81. --print( "Next turn, I will go " .. turndir)
  82. level()
  83. steps(g)
  84.   if turndir=="right" then
  85.     turtle.turnRight()
  86.     tree_chop()
  87.     turtle.forward()
  88.     level()
  89.     turtle.turnRight()
  90.     l=l+1
  91.     else
  92.       if turndir=="left" then
  93.         turtle.turnLeft()
  94.         tree_chop()
  95.         turtle.forward()
  96.         level()
  97.         turtle.turnLeft()
  98.         l=l+1
  99.        
  100.       else
  101.         print ("latMan direction error")
  102.       end
  103.   end
  104. print( "I've turned the corner starting lateral #" .. l .. " out of".. g)
  105. until l==g
  106. print"End lateral moves"
  107. end
  108. ----------------Program Code-----------------------
  109.  
  110. -- The Turtle Lumberjack Program--------
  111. print ("1 for clear cutting, 2 for specific # of logs")
  112. t=0
  113. t=io.read()
  114. -- Clearing Logs  
  115.   --Set Grid Size to 'g'
  116.  
  117.   if t=="1" then
  118.   print "Enter a grid size:"
  119.   g=0
  120.   g=tonumber(io.read())
  121.  
  122.   print("clearing " .. g*g .. " blocks")
  123.   end
  124. --tree_chop()
  125. --steps()
  126. latMan(g)
  127.  
  128. vector.new(home)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement