Advertisement
AkaZombie

WoodChop

Dec 27th, 2012
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.51 KB | None | 0 0
  1. local function moveForward()
  2.  for i = 1,6,1 do
  3.   turtle.forward()
  4.  end
  5. end
  6.  
  7. local function checkFuel()
  8.  if turtle.getFuelLevel() < 96 then
  9.   turtle.select(1)
  10.   turtle.refuel(1)
  11.  end
  12. end
  13.  
  14. local function getCoal()
  15.  turtle.select(1)
  16.  while turtle.getItemCount(1) < 16 do
  17.   os.sleep(3)
  18.   turtle.drop()
  19.   turtle.suck()
  20.  end
  21. end
  22.  
  23. local function getSaplings()
  24. turtle.select(2)
  25.  while turtle.getItemCount(2) < 16 do
  26.   os.sleep(3)
  27.   turtle.drop()
  28.   turtle.suck()
  29.  end
  30. end
  31.  
  32. local function getBonemeal()
  33.  turtle.select(3)
  34.  while turtle.getItemCount(3) < 4 do
  35.   os.sleep(3)
  36.   turtle.dropUp()
  37.   turtle.suckUp()
  38.  end
  39. end
  40.  
  41. local function storeWood()
  42.  chestfull = true
  43.  while chestfull == true do
  44.   for i=4,16,1 do
  45.    if turtle.getItemCount(i) > 1 then
  46.     turtle.select(i)
  47.     items = turtle.getItemCount(i) - 1
  48.     chestfull = turtle.drop(items)
  49.    end
  50.   end
  51.  
  52.   chestfull = not chestfull
  53.    
  54.   if chestfull == true and turtle.detectUp() == false then
  55.    turtle.up()
  56.   end
  57.    
  58.   if chestfull == true and turtle.detectUp() == true then
  59.    print("Wood! Wood everywhere!!!")
  60.    print("Try to add more vertical chests or take wood out of them.")
  61.    if turtle.detectDown() == false then
  62.     turtle.down()
  63.    end
  64.    os.shutdown()
  65.   end
  66.  end
  67.  if turtle.detectDown() == false then
  68.   turtle.down()
  69.  end
  70. end
  71.  
  72. local function plantTree()
  73.  turtle.forward()
  74.  turtle.forward()
  75.  turtle.turnRight()
  76.  turtle.select(2)
  77.  turtle.place()
  78.  turtle.turnLeft()
  79.  turtle.back()
  80.  turtle.place()
  81.  turtle.turnRight()
  82.  turtle.place()
  83.  turtle.turnLeft()
  84.  turtle.back()
  85.  turtle.place()
  86.  turtle.select(3)
  87.  turtle.place()
  88. end
  89.  
  90. local function getMaterials()
  91.  turtle.turnRight()
  92.  turtle.turnRight()
  93.  moveForward()
  94.  turtle.turnLeft()
  95.  
  96.  getSaplings()
  97.  getBonemeal()
  98.  
  99.  turtle.turnRight()
  100.  turtle.forward()
  101.  turtle.select(4)
  102.  items = turtle.getItemCount(4) - 1
  103.  turtle.dropDown(items)
  104.  
  105.  storeWood()
  106.  
  107.  turtle.turnRight()
  108.  getCoal()
  109.    
  110.  if redstone.getInput("back") == true then
  111.   turtle.turnRight()
  112.   moveForward()
  113.   turtle.forward()
  114.  else
  115.   print("Shutdown by redstone signal!")
  116.   os.shutdown()
  117.  end
  118. end
  119.  
  120. local function cutWood()
  121.  local height = 0
  122.  turtle.select(2)
  123.  turtle.dig()
  124.  turtle.forward()
  125.  turtle.dig()
  126.  while turtle.detectUp() do
  127.   turtle.digUp()
  128.   turtle.up()
  129.   turtle.dig()
  130.   height = height + 1
  131.  end
  132.  checkFuel()
  133.  turtle.turnRight()
  134.  turtle.dig()
  135.  turtle.forward()
  136.  turtle.turnLeft()
  137.  turtle.dig()
  138.  while height > 0 do
  139.   turtle.digDown()
  140.   turtle.down()
  141.   turtle.dig()
  142.   height = height - 1
  143.  end
  144.  turtle.back()
  145.  turtle.turnLeft()
  146.  turtle.forward()
  147.  turtle.turnRight()
  148. end
  149.  
  150.  
  151.  
  152.  
  153. if redstone.getInput("back") == true then
  154.  getCoal()
  155.  checkFuel()
  156.  if turtle.getItemCount(4) > 1 then
  157.   turtle.turnLeft()
  158.   storeWood()
  159.   turtle.turnRight()
  160.  end
  161.  if turtle.getItemCount(2) < 16 then
  162.   turtle.turnRight()
  163.   turtle.forward()
  164.   turtle.turnRight()
  165.   getSaplings()
  166.   turtle.turnRight()
  167.   if turtle.getItemCount(3) < 4 then
  168.    getBonemeal()
  169.   end
  170.   turtle.forward()
  171.   turtle.turnRight()
  172.  end
  173.  turtle.turnRight()
  174.  turtle.forward()
  175.  moveForward()
  176.  
  177.  while true do
  178.   checkFuel()
  179.   local needMaterials = false
  180.   if turtle.getItemCount(1) < 4 or turtle.getItemCount(2) < 4 then
  181.    needMaterials = true
  182.   end
  183.   if turtle.getItemCount(3) == 0 or turtle.getItemCount(14) > 1 then
  184.    needMaterials = true
  185.   end
  186.   if needMaterials == true then
  187.    getMaterials()
  188.   end
  189.   plantTree()
  190.   checkFuel()
  191.   cutWood()
  192.  end
  193. else
  194.  print("No redstone signal, no wood!")
  195. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement