Advertisement
fzed51

[lua] [CC] Turtle - Ferme à bois / logging

Aug 23rd, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.76 KB | None | 0 0
  1. --[[
  2. +----------------------------------------------------------------------------+
  3. | logging
  4. | version : 1.3
  5. | Auteur : fzed51
  6. | git : https://github.com/fzed51/CC_Script/blob/master/disk/logging.lua
  7. | pastebin : http://pastebin.com/bE6pBfsB
  8. +----------------------------------------------------------------------------+
  9. | tag : [lua] [MC] [MineCraft] [CC] [ComputerCraft] [Turtle]
  10. | Descript :
  11. | script de ferme à bois.
  12. | le script est actif avec un signal de redstone.
  13. +----------------------------------------------------------------------------+
  14. ]]--
  15. dofile('advTurtle') -- pastebin.com/7mLzefhQ
  16.  
  17. item.add('coal', 1, 64)
  18. item.add('sapling', 2, 64)
  19. item.add('wood', 3, 1)
  20.  
  21. local function timber()
  22.     local hauteur = 0
  23.     trySelect(item.wood)
  24.     while turtle.compare(item.wood) do
  25.         tryDig()
  26.         if tryUp() then hauteur = hauteur + 1 end
  27.     end
  28.     while hauteur > 0 do
  29.         if tryDown() then hauteur = hauteur - 1 end    
  30.     end
  31. end
  32.  
  33. local function control()
  34.     turnLeft()
  35.     if not turtle.detect() then
  36.         tryPlace(item.sapling)
  37.     end
  38.     timber()
  39.     turnBack()
  40.     if not turtle.detect() then
  41.         tryPlace(item.sapling)
  42.     end
  43.     timber()
  44.     turnLeft()
  45. end
  46.  
  47. local function recuperreSapling()
  48.     turnRight()
  49.     turtle.suck()
  50.     turnBack()
  51.     turtle.suck()
  52.     turnRight()
  53. end
  54.  
  55. local function isOn()
  56.     local on = false
  57.     for _,side in pairs(redstone.getSides()) do
  58.         on = on or redstone.getInput(side)
  59.     end
  60.     return on
  61. end
  62.  
  63. local n, nb = 0, 4
  64.  
  65. while true do
  66.     if isOn() then
  67.         for _ = 1,4 do
  68.             while n < nb do
  69.                 tryForward()
  70.                 tryForward()
  71.                 control()
  72.                 n=n+1
  73.             end
  74.             turnBack()
  75.             while n > 0 do
  76.                 tryForward()
  77.                 recuperreSapling()
  78.                 tryForward()
  79.                 n=n-1
  80.             end
  81.             turnRight()
  82.         end
  83.         os.sleep(200)
  84.     else
  85.         print('Pause ...')
  86.         os.sleep(25)
  87.     end
  88. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement