Kagee

Untitled

Apr 11th, 2013
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Based on excavate from the original computercraft distribution
  2. -- written by hildenae
  3. local rubberwood=1
  4. local tool=2
  5. -- electric hat has 200 uses.
  6. -- my size is 2 rows of 6 threes
  7. -- with a maxheight of 7 - this leves 4 uses
  8. local width = 6
  9. local rows = 2
  10. local MAX_USES=200
  11. local uses = 0
  12. local depth = 0
  13. local xPos,zPos = 0,0
  14. local xDir,zDir = 0,1
  15.  
  16. local function turnLeft()
  17.     turtle.turnLeft()
  18.     xDir, zDir = -zDir, xDir
  19. end
  20.  
  21. local function turnRight()
  22.     turtle.turnRight()
  23.     xDir, zDir = zDir, -xDir
  24. end
  25.  
  26. function goTo( x, y, z, xd, zd )
  27.     while depth > y do
  28.         if turtle.up() then
  29.             depth = depth - 1
  30.         else
  31.             return false
  32.         end
  33.     end
  34.  
  35.     if xPos > x then
  36.         while xDir ~= -1 do
  37.             turnLeft()
  38.         end
  39.         while xPos > x do
  40.             if turtle.forward() then
  41.                 xPos = xPos - 1
  42.             else
  43.                 return false
  44.             end
  45.         end
  46.     elseif xPos < x then
  47.         while xDir ~= 1 do
  48.             turnLeft()
  49.         end
  50.         while xPos < x do
  51.             if turtle.forward() then
  52.                 xPos = xPos + 1
  53.             else
  54.                 return false
  55.             end
  56.         end
  57.     end
  58.    
  59.     if zPos > z then
  60.         while zDir ~= -1 do
  61.             turnLeft()
  62.         end
  63.         while zPos > z do
  64.             if turtle.forward() then
  65.                 zPos = zPos - 1
  66.             else
  67.                 return false
  68.             end
  69.         end
  70.     elseif zPos < z then
  71.         while zDir ~= 1 do
  72.             turnLeft()
  73.         end
  74.         while zPos < z do
  75.             if turtle.forward() then
  76.                 zPos = zPos + 1
  77.             else
  78.                 return false
  79.             end
  80.         end
  81.     end
  82.     while depth < y do
  83.         if turtle.down() then
  84.             depth = depth + 1
  85.         else
  86.             return false
  87.         end
  88.     end
  89.     while zDir ~= zd or xDir ~= xd do
  90.         turnLeft()
  91.     end
  92.     return true
  93. end
  94.  
  95. local function forward()
  96.     turtle.forward()
  97.     xPos = xPos + xDir
  98.     zPos = zPos + zDir
  99.     return true
  100. end
  101.  
  102. local function down()
  103.     if turtle.down() then
  104.         depth = depth + 1
  105.         return true
  106.     else
  107.         return false
  108.     end
  109. end
  110.  
  111. local function harvest()
  112.     turtle.select(rubberwood)
  113.     if turtle.compare() then
  114.         turtle.select(tool)
  115.         turtle.place()
  116.         uses = uses + 1
  117.     else
  118.         print("not wood")
  119.     end
  120. end
  121.  
  122. local function downTree()
  123.     local x,y,z,xd,zd = xPos,depth,zPos,xDir,zDir
  124.     repeat
  125.         harvest()
  126.     until not down()
  127.     goTo( x,y,z,xd,zd )
  128. end
  129.  
  130. local function moveRight()
  131.     turnRight()
  132.     forward()
  133.     turnLeft()
  134. end
  135. local function moveLeft()
  136.     turnLeft()
  137.     forward()
  138.     turnRight()
  139. end
  140. local function turn180()
  141.     turnRight()
  142.     turnRight()
  143. end
  144. local function harvestRow()
  145.     local w = width
  146.     while(w > 0) do
  147.         downTree()
  148.         moveRight()
  149.         w = w -1
  150.     end
  151.     forward()
  152.     turnLeft()
  153.     downTree() -- check side for resin
  154.     moveRight()
  155.     turnLeft()
  156.     w = width
  157.     while(w > 0) do
  158.         moveRight()
  159.         downTree()
  160.         w = w -1
  161.     end
  162.     moveRight()
  163.     forward()
  164.     turnLeft()
  165.     downTree() -- check side for resin
  166. end
  167.  
  168. run = true
  169. while run do
  170.    
  171.     local r = rows
  172.     forward()
  173.     while (r > 0) do
  174.         harvestRow()
  175.         moveLeft()
  176.         forward()
  177.         turnLeft()
  178.         r = r -1
  179.     end
  180.  
  181.     moveLeft() -- move out to the side
  182.     turn180()
  183.     for i = 0, rows, 2 do
  184.         print ("moving forward 2")
  185.         forward()
  186.         forward()
  187.     end
  188.     print("uses: ")
  189.     print (uses)
  190.    
  191.     -- go to charge station
  192.     goTo(0,0,0,0,1)
  193.     run = false
  194. end
Advertisement
Add Comment
Please, Sign In to add comment