Guest User

farm

a guest
Aug 24th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 18.49 KB | None | 0 0
  1.  
  2. --Fichier de sauvegarde des variables utiles au reboot :
  3. -- turtle.farm.dir: Orientation de la turtle 0,1,2,3 (N-E-S-W)
  4. -- turtle.farm.fuel: Niveau de fuel au d?part d'une boucle
  5. -- Si le fichier n'existe pas il sera cr??
  6. local settingsFile = "/settings/TurtleFarm"
  7.  
  8. --Fichier contenant les donn?es ? inscrire sur le moniteur
  9. -- N?cessairement sur un disk
  10. -- Si le mountPath est modifi?, il sera corrig? au premier disk drive trouv?
  11. local dataFile = "/disk/FarmData"
  12.  
  13. --Delai appliqu? ? chaque pas
  14. local delay=.1
  15.  
  16. --Dur?e de la pause entre deux tours
  17. local pause=900 --15min
  18.  
  19. --Multiplicateur
  20. -- pass? ? 10, la turtle pr?voira asez de fuel pour 10 tours
  21. local fuelSupply=4 -- minimum 2 par s?curit?
  22.  
  23. --Soupape : nombre d'?checs successifs tol?r?s dans une boucle while
  24. local limit=32
  25.  
  26. -- D?lai d'attente de confirmation pour r?initialiser au reboot
  27. -- Hard reboot: Placer un bloc de redstone sur le parcours de la turtle
  28. -- La turtle stoppe. Retirer le bloc, la turtle demande confirmation pour r?initialiser
  29. -- Sans confirmation pass? le d?lai hardRebootCountDown, elle reprend sa course
  30. local hardRebootCountDown = 10
  31.  
  32. --Liste des items bons ? jeter (ne seront pas stock?s)
  33. unwanted = {
  34. ["minecraft:poisonous_potato"]=1,
  35. --["minecraft:wheat_seeds"]=1, --NB: un stack de graines sera tout de m?me conserv? par la turtle pour replanter
  36. }
  37.  
  38. --
  39. -- API
  40. --
  41. if not os.loadAPI("/apis/dbFarm") then
  42.     error("Missing API: dbFarm\n> pastebin get k0bi24gr /apis/dbFarm")
  43.     return
  44. end
  45. if not os.loadAPI("/apis/dbFuel") then
  46.     error("Missing API: dbFuel\n> pastebin get 5g2DntXx /apis/dbFuel")
  47.     return
  48. end
  49.  
  50. --
  51. -- CONSTANTS
  52. --
  53. NORTH=0
  54. EAST=1
  55. SOUTH=2
  56. WEST=3
  57. sDir={"North","East","South","West"}
  58.  
  59. plantAges = {
  60. ["minecraft:wheat"]      =7,    
  61. ["minecraft:carrots"]    =7,  
  62. ["minecraft:potatoes"]   =7,  
  63. ["minecraft:melon_block"]=7,
  64. ["minecraft:pumpkin"]    =7,  
  65. ["minecraft:reeds"]      =7,    
  66. ["minecraft:nether_wart"]=3, --/!\
  67. ["minecraft:beetroots"]  =3, --/!\
  68. }
  69.  
  70. --Bloc reference (see function walk() 263)
  71. --sBlockType = "minecraft:stained_hardened_clay"
  72. sBlockType = "minecraft:stained_glass"
  73. local function blockType_north(data)
  74.     return data.name==sBlockType
  75.     and data.state
  76.     and data.state.color=="red"
  77. end
  78. local function blockType_east(data)
  79.     return data.name==sBlockType
  80.     and data.state
  81.     and data.state.color=="orange"
  82. end
  83. local function blockType_south(data)
  84.     return data.name==sBlockType
  85.     and data.state
  86.     and data.state.color=="yellow"
  87. end
  88. local function blockType_west(data)
  89.     return data.name==sBlockType
  90.     and data.state
  91.     and data.state.color=="white"
  92. end
  93.  
  94. --
  95. -- GLOBALS
  96. --
  97. fuelSupply = math.max(2,fuelSupply)
  98. fuelUsed=0
  99. block={up={},down={}}
  100. tick = os.startTimer(.1)
  101. tFarmCrops,tFarmSeeds,tFarmBlocks = {},{},{}
  102. local _,v
  103. local _,_cropsList = dbFarm.query("crop")
  104. local _,_seedsList = dbFarm.query("seed")
  105. local _,_blocksList = dbFarm.query("block")
  106. for _,v in pairs(_cropsList)  do tFarmCrops[v]=1 end
  107. for _,v in pairs(_seedsList)  do tFarmSeeds[v]=1 end
  108. for _,v in pairs(_blocksList) do tFarmBlocks[v]=1 end
  109.  
  110.  
  111. --Demande l'orientation de la turtle (N-E-S-W)
  112. --Initialise le fichier de dsauvegarde des settings
  113. init=function()
  114.     local msg = ""
  115.     local confirm=false
  116.     while not confirm do
  117.         term.setCursorPos(1,1)
  118.         term.clear()
  119.         print([[TurtleFarming
  120. Set Turtle current orientation
  121.   0:North
  122.   1:East
  123.   2:South
  124.   3:West]])
  125.         print(msg)
  126.         local d = read()
  127.         if not tonumber(d) or (d~="0" and d~="1" and d~="2" and d~="3") then
  128.             msg="Number: 0, 1, 2 ort 3"
  129.         else
  130.             settings.set("turtle.farm.dir",tonumber(d))
  131.             settings.save(settingsFile)
  132.             confirm=true
  133.             break
  134.         end
  135.     end
  136. end
  137.  
  138. --Charge les donn?es stock?es dans le fichier settings
  139. if not fs.exists(settingsFile) then init()
  140. else settings.load(settingsFile) end
  141. local dir = settings.get("turtle.farm.dir",init)
  142. --Statistiques par tour
  143. lap = {
  144.     loop=0,
  145.     chrono=0,
  146.     crops=settings.get("turtle.farm.crops",0),
  147.     fuel=settings.get("turtle.farm.fuel",turtle.getFuelLevel())
  148. }
  149.  
  150. --Ecrit sur le terminal ? une ligne donn?e
  151. local function printLine(str,y)
  152.     term.setCursorPos(1,y)
  153.     term.clearLine()
  154.     print(str)
  155. end
  156.  
  157. --Hard reboot
  158. if rs.getInput("back") or rs.getInput("front")
  159. or rs.getInput("top")  or rs.getInput("bottom")
  160. or rs.getInput("left") or rs.getInput("right") then
  161.     print("Hard Reboot")
  162.     os.pullEvent("redstone")
  163.     local x,y = term.getCursorPos()
  164.     local confirm,countdown,countdownTimer = false,hardRebootCountDown,os.startTimer(1)
  165.     while not confirm and countdown>0 do
  166.         printLine("Reset Turtle orientation ("..sDir[dir+1]..") ?",y)
  167.         printLine("Press Y/N ("..countdown..")", y+1)
  168.         local e,k = os.pullEvent()
  169.         if e=="key" and k==keys.y then
  170.             sleep(.3)
  171.             init()
  172.             confirm=true
  173.             break
  174.         elseif e=="key" and k==keys.n then
  175.             sleep(.3)
  176.             confirm=true
  177.             break
  178.         elseif e=="timer" then
  179.             countdown=countdown-1
  180.             countdownTimer = os.startTimer(1)
  181.         end
  182.     end
  183. end
  184.  
  185. -- Panne de Fuel
  186. -- interrompt la turtle, en l'attente de ravitaillement en fuel
  187. local function waitManualyRefuel()
  188.     printLine("Give some Fuel then press any key",8)
  189.     while turtle.getFuelLevel()==0 do
  190.         os.pullEvent("key")
  191.         term.setCursorPos(1,9)
  192.         term.clearLine()
  193.         shell.run("refuel all")
  194.     end
  195.     printLine("",8)
  196. end
  197.  
  198. -- Avance la turtle d'une case
  199. -- R?colte la canne ? surcre si elle bloque le passage
  200. local function forward()
  201.     local test = turtle.forward()
  202.     if not test and turtle.detect() then
  203.         local test,data=turtle.inspect()
  204.         if test and data.name=="minecraft:reeds" then
  205.             if turtle.dig() and turtle.forward() then
  206.                 lap.crops = lap.crops+1
  207.                 settings.set("turtle.farm.crops",lap.crops)
  208.                 settings.save(settingsFile)
  209.                 turtle.suckUp()
  210.                 turtle.suck()
  211.                 turtle.suckDown()
  212.                 return true
  213.             end
  214.         end
  215.         error("Program stopped by a block forward\n"..textutils.serialize(data),-1) exit()
  216.     end
  217.     local count=1
  218.     while not test and not turtle.detect() and turtle.getFuelLevel()>0 and count<limit do
  219.         sleep(delay)
  220.         count = count+1
  221.         test = turtle.forward()
  222.     end
  223.     if not test then
  224.         if turtle.getFuelLevel()==0 then
  225.             waitManualyRefuel()
  226.         else
  227.             error("Program stopped. Can't go forward (tries:"..count..")",-1)
  228.             exit()
  229.         end
  230.     end
  231. end
  232.  
  233. -- Rel?ve les donn?es des blocs dessus/dessous
  234. local function inspect()
  235.     local test,data
  236.     test,data = turtle.inspectUp()
  237.     block.up = test and data or false
  238.     test,data = turtle.inspectDown()
  239.     block.down = test and data or false
  240. end
  241.  
  242. -- Aligne la turtle dans la direction indiqu?e
  243. -- Sauvegarde de la nouvelle direction dans le fichier settings
  244. local function turn(d)
  245.     if dir ~= d then
  246.         if d == NORTH then
  247.                 if dir==EAST  then turtle.turnLeft()
  248.             elseif dir==SOUTH then turtle.turnLeft() turtle.turnLeft()
  249.             elseif dir==WEST  then turtle.turnRight()
  250.             end                    
  251.         elseif d == EAST then      
  252.                 if dir==NORTH then turtle.turnRight()
  253.             elseif dir==SOUTH then turtle.turnLeft()
  254.             elseif dir==WEST  then turtle.turnLeft() turtle.turnLeft()
  255.             end                    
  256.         elseif d == SOUTH then    
  257.                 if dir==NORTH then turtle.turnLeft() turtle.turnLeft()
  258.             elseif dir==EAST  then turtle.turnRight()
  259.             elseif dir==WEST  then turtle.turnLeft()
  260.             end                    
  261.         elseif d == WEST then      
  262.                 if dir==NORTH then turtle.turnLeft()
  263.             elseif dir==EAST  then turtle.turnLeft() turtle.turnLeft()
  264.             elseif dir==SOUTH then turtle.turnRight()
  265.             end
  266.         end
  267.         dir = d
  268.         settings.set("turtle.farm.dir",d)
  269.         settings.save(settingsFile)
  270.     end
  271. end
  272.  
  273. -- G?re le mouvement de la turtle
  274. local function walk()
  275.     printLine("",7)
  276.     if block.up then
  277.         if blockType_north(block.up) then
  278.             printLine("North",7) turn(NORTH) forward()
  279.         elseif blockType_east(block.up) then
  280.             printLine("East",7)  turn(EAST)  forward()
  281.         elseif blockType_south(block.up) then
  282.             printLine("South",7) turn(SOUTH) forward()
  283.         elseif blockType_west(block.up) then
  284.             printLine("West",7)  turn(WEST)  forward()
  285.         elseif isContainer(block.up.name) then
  286.             printLine("Container",7) forward()
  287.         else
  288.             printLine(block.up.name,7)
  289.         end
  290.     end
  291. end
  292.  
  293. -- Formate un nombre de secondes en dur?e lisible
  294. local function timeStr(sec)
  295.     local d = math.floor(sec/86400) --24*60*60 sec
  296.     local h = math.floor(sec/3600)%24 -- 60x60 sec
  297.     local m = math.floor(sec/60)%60 -- 60sec
  298.     local s = math.floor(sec%60) --Reste
  299.     local str = ""
  300.     if d>0 then str = d>1 and d.. "days " or "1 day " end
  301.     if h>0 then str = str..h.."h" end
  302.     if m>0 then str = str..(m>9 and m or "0"..m) end
  303.     if h==0 then str = m>0 and str..":"..(s>9 and s or "0"..s) or s.."s" end
  304.     return str
  305. end
  306.  
  307. -- V?rifie que le r?pertoire racine de la disquette est bien pr?sent
  308. -- Sinon la variable est corrig?e (au premier disk drive trouv?)
  309. local function getMountedDisk()
  310.     if fs.exists(dataFile) then return true end
  311.     local _,name
  312.     for _,name in pairs(peripheral.getNames()) do
  313.         if peripheral.getType(name) == "drive" then
  314.             if disk.hasData(name) then
  315.                 local mount = disk.getMountPath(name)
  316.                 local pattern = "^/?disk%d*/(.+)$"
  317.                 dataFile = string.gsub(dataFile, pattern, "/"..mount.."/%1")
  318.                 return true
  319.             end
  320.         end
  321.     end
  322.     return false
  323. end
  324.  
  325. -- Sauvegarde les donn?es statistiques dans une disquette
  326. -- ? fin d'affichage sur un moniteur
  327. local function storeData()
  328.     lap.loop=lap.loop+1
  329.     if getMountedDisk() then --S'il y a bien une disquette disponible
  330.         local sChrono,sFuel="",""
  331.         if lap.chrono>0 then
  332.             sChrono = " / "..math.floor(os.clock()-lap.chrono)
  333.         end
  334.         if lap.fuel>0 then
  335.             sFuel = " / used: "..(lap.fuel - turtle.getFuelLevel())
  336.         end
  337.         local report = string.format([[Loops: %d
  338. Running until: %s%s
  339. Fuel level: %d%s
  340. Crops: %d]],
  341.             lap.loop,
  342.             timeStr(os.clock()), sChrono,
  343.             turtle.getFuelLevel(),sFuel,
  344.             lap.crops)
  345.         local fh = fs.open(dataFile,"w")
  346.         fh.write(report)
  347.         fh.close()
  348.     end
  349.     lap.chrono = os.clock()
  350.     lap.fuel = turtle.getFuelLevel()
  351.     settings.set("turtle.farm.fuel",lap.fuel)
  352.     settings.save(settingsFile)
  353. end
  354.  
  355. -- Regroupe les items identiques dans l'inventaire
  356. local function compactInventory()
  357.     printLine("Compact inventory",8)
  358.     local i,j,d1,d2
  359.     for i=1,16 do
  360.         d1 = turtle.getItemDetail(i)
  361.         if d1~=nil and turtle.getItemSpace(i)>0 then
  362.             for j=i+1,16 do
  363.                 d2 = turtle.getItemDetail(j)
  364.                 if d2~=nil and d1.name==d2.name then
  365.                     turtle.select(j)
  366.                     turtle.transferTo(i)
  367.                 end
  368.             end
  369.         end
  370.     end
  371. end
  372.  
  373. --Renvoi le premier slot vide trouv?
  374. --Renvoi false si linventaire est plein
  375. local function findFreeSlot()
  376.     local i
  377.     for i=1,16 do
  378.         if turtle.getItemCount(i)==0 then
  379.             return i
  380.         end
  381.     end
  382.     return false
  383. end
  384.  
  385. --Renvoi le premier slot contenant un combustible compatible
  386. --Renvoi false si aucun combustible n'est trouv?
  387. local function findFuelSlot()
  388.     local i
  389.     for i=1,16 do
  390.         local data = turtle.getItemDetail(i)
  391.         if data and dbFuel.isFuel(data.name) then
  392.             return i
  393.         end
  394.     end
  395.     return false
  396. end
  397.  
  398. -- https://github.com/garrynewman/garrysmod/blob/master/garrysmod/lua/includes/extensions/table.lua#L93
  399. local function tableHasValue( t, val )
  400.     for k, v in pairs( t ) do
  401.         if ( v == val ) then return true end
  402.     end
  403.     return false
  404. end
  405.  
  406. --Compare les quantit?s de chaque slot indiqu?s par slotList
  407. --_v: Retourne le num?ro du slot le moins fourni
  408. --_k: Retourne la cl? correspondante de la table slotList
  409. local function getMinQtySlot(slotList)
  410.     slotList = slotList or {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16}
  411.     local _min,k,v,_k,_v=64
  412.     for k,v in pairs(fuelSlots) do
  413.         if _min >= turtle.getItemCount(v) then
  414.             _min = turtle.getItemCount(v)
  415.             _k = k
  416.             _v = v
  417.         end
  418.     end
  419.     return _v,_k
  420. end
  421.  
  422. --Vide les slots contenant des items inutiles
  423. -- drop : function (turtle.drop, turtle.dropUp, turtle.dropDown)
  424. -- n : nombre de slot ? lib?rer
  425. local function dumpUnwanted(drop,n)
  426.     n = n or 16
  427.     compactInventory()
  428.     printLine("Dump unwanted",8)
  429.     local i,farmSlots,fuelSlots=1,{},{},{}
  430. -- >global  local tFarmCrops = dbFarm.query("crop")
  431. -- >global  local tFarmSeeds = dbFarm.query("seed")
  432.     for i=1,16 do
  433.         local data = turtle.getItemDetail(i)
  434.         if not data then
  435.             n=n-1
  436.         elseif dbFuel.isFuel(data.name) then
  437.             table.insert(fuelSlots,i)
  438.         elseif tFarmSeeds[data.name]~=nil then
  439.             table.insert(farmSlots,i)
  440.         elseif tFarmCrops[data.name]~=nil then
  441.             table.insert(farmSlots,i)
  442.         else
  443.             turtle.select(i)
  444.             drop(64)
  445.             n=n-1
  446.         end
  447.         if n<=0 then return true end
  448.     end
  449.     while n>1 do
  450.         if #fuelSlots > 0 then
  451.             local slot,key = getMinQtySlot(fuelSlots)
  452.             table.remove (fuelSlots, key)
  453.         else
  454.             local slot,key = getMinQtySlot(farmSlots)
  455.             table.remove (farmSlots, key)
  456.         end
  457.         turtle.select(s)
  458.         drop(64)
  459.         n=n-1
  460.     end
  461.     return not n>1
  462. end
  463.  
  464. -- Gestion automatique du fuel ? la station
  465. local function autoRefuel()
  466.     printLine("Auto refuel",8)
  467.     if turtle.getFuelLevel()<fuelUsed*fuelSupply then
  468.         compactInventory()
  469.         slot = findFreeSlot()
  470.         if not slot then slot=findFuelSlot() end
  471.         if slot then
  472.             turtle.select(slot)
  473.             while turtle.getFuelLevel()<fuelUsed*fuelSupply do
  474.                 if not turtle.suckUp(1) then
  475.                     error("Fuel tank is empty...",-1)
  476.                     exit()
  477.                 end
  478.                 turtle.refuel()
  479.                 lap.fuel = turtle.getFuelLevel()+1 -- diff de la distance entre les stations storeData et autorefuel
  480.                 settings.set("turtle.farm.fuel",lap.fuel)
  481.                 settings.save(settingsFile)
  482.             end
  483.         end
  484.     end
  485. end
  486.  
  487. -- Trouve un slot contenant l'item indiqu?
  488. -- Renvoi false s'il ne trouve rien
  489. local function findSlotItem(refName)
  490.     local slot=1
  491.     for slot=1,16 do
  492.         local data = turtle.getItemDetail(slot)
  493.         if data and data.name==refName then return slot end
  494.     end
  495.     return false
  496. end
  497.  
  498. -- Ramasse et replante, dans la mesure du possible
  499. -- Renvoi false si la manoeuvre n'est pas parfaitement execut?e.
  500. local function crop()
  501.     printLine("Crop manager",8)
  502.     if block.down and block.down.state and block.down.state.age then
  503.         local requiredAge = plantAges[block.down.name]
  504.         printLine(block.down.name.." "..block.down.state.age.."/"..requiredAge,5)
  505.         if block.down.state.age>=requiredAge then
  506.             local test,result = dbFarm.query("block",block.down.name)
  507.             if test and result["seed"] then
  508.                 local slot = findSlotItem(result["seed"])
  509.                 if not slot then slot = findFreeSlot() end
  510.                 if not slot and dumpUnwanted(turtle.dropDown,1) then slot = findFreeSlot() end
  511.                 if not slot  then error("Inventory saturation..",-1) exit() end
  512.                 turtle.select(slot)
  513.                 if turtle.digDown() then
  514.                     lap.crops=lap.crops+1
  515.                     settings.set("turtle.farm.crops",lap.crops)
  516.                     settings.save(settingsFile)
  517.                     turtle.select(findSlotItem(result["seed"]))
  518.                     return turtle.placeDown()
  519.                 end
  520.             end
  521.         end
  522.     end
  523.     return false
  524. end
  525.  
  526. local function isContainer(name)
  527.     return name=="minecraft:chest"
  528.     or name=="minecraft:trapped_chest"
  529.     or name=="minecraft:dispenser"
  530.     or name=="minecraft:hopper"
  531.     or name=="minecraft:dropper"
  532.     or name=="computercraft:CC-Turtle"
  533.  or name=="computercraft:CC-TurtleExpanded"
  534.     or name=="computercraft:CC-TurtleAdvanced"
  535.     or name=="ironchest:BlockIronChest"
  536. end
  537.  
  538. local function storeCrops()
  539.     if lap.crops>0 and isContainer(block.up.name) then
  540.         local skip = {
  541.             wheat_seeds =    findSlotItem("minecraft:wheat_seeds"),
  542.             potato =         findSlotItem("minecraft:potato"),
  543.             carrot =         findSlotItem("minecraft:carrot"),
  544.             nether_wart =    findSlotItem("minecraft:nether_wart"),
  545.             beetroot_seeds = findSlotItem("minecraft:beetroot_seeds"),
  546.         }
  547.         local slot
  548.         for slot=1,16 do
  549.             if  slot ~= skip.wheat_seeds
  550.             and slot ~= skip.potato
  551.             and slot ~= skip.carrot
  552.             and slot ~= skip.nether_wart
  553.             and slot ~= skip.beetroot_seeds
  554.             and turtle.getItemCount(slot)>0
  555.             then
  556.                 turtle.select(slot)
  557.                 local data = turtle.getItemDetail(slot)
  558.                 if unwanted[data.name]~=nil then turtle.drop(64)
  559.                 else turtle.dropUp(64) end
  560.             end
  561.         end
  562.         lap.crops = 0
  563.         settings.set("turtle.farm.crops",lap.crops)
  564.         settings.save(settingsFile)
  565.     end
  566. end
  567.  
  568. -- G?re les op?rations de la turtle
  569. local function step()
  570.     printLine("",5)
  571.     if block.down then
  572.         --End loop
  573.         if block.down.name=="computercraft:CC-Peripheral" then
  574.             compactInventory()
  575.             fuelUsed = lap.fuel - turtle.getFuelLevel()
  576.             if block.down.state.variant=="disk_drive_full" then
  577.                 printLine("Disk-Drive",5)
  578.                 storeData()
  579.                 storeCrops()
  580.             else
  581.                 printLine(block.down.name.." / "..block.down.state.variant,5)
  582.             end
  583.             --init pause delay
  584.             settings.set("turtle.farm.pause",pause)
  585.             settings.save(settingsFile)
  586.         --Start Loop
  587.         elseif block.down.name=="computercraft:CC-Computer" then
  588.             autoRefuel()
  589.             local computer = peripheral.wrap("bottom")
  590.             if computer.isOn() then computer.reboot()
  591.             else computer.turnOn() end
  592.             --Pause
  593.             settings.load(settingsFile)
  594.             local pauseDelay = settings.get("turtle.farm.pause",pause)
  595.             while pauseDelay>0 do
  596.                 printLine("Pause : "..timeStr(pauseDelay),5)
  597.                 --Sauvegarde le temps ?coul? toutes les secondes
  598.                 local pauseTimer = os.startTimer(1)
  599.                 local e = os.pullEvent("timer")
  600.                 pauseDelay=pauseDelay-1
  601.                 settings.set("turtle.farm.pause",pauseDelay)
  602.                 settings.save(settingsFile)
  603.             end
  604.         --Crops
  605.         elseif block.down.name=="minecraft:pumpkin"
  606.         or block.down.name=="minecraft:melon_block"
  607.   or block.down.name=="minecraft:reeds" then
  608.             local cropName = (block.down.name == "minecraft:pumpkin") and "minecraft:pumpkin" or "minecraft:melon"
  609.    if block.down.name=="minecraft:reeds" then cropName="minecraft:reeds" end
  610.             local slot = findSlotItem(cropName)
  611.             if slot then turtle.select(slot) end
  612.             if turtle.digDown() then
  613.                 lap.crops = lap.crops+1
  614.                 settings.set("turtle.farm.crops",lap.crops)
  615.                 settings.save(settingsFile)
  616.             end
  617.         elseif tFarmBlocks[block.down.name]==1 and block.down.name~="minecraft:reeds" then
  618.             printLine(block.down.name,5)
  619.             crop()
  620.         else
  621.             printLine(block.down.name.."*",5)
  622.         end
  623.     end
  624.     printLine("Crops: "..lap.crops,3)
  625.     printLine("",8)
  626. end
  627.  
  628. -- S?quence des manoeuvres
  629. local function process()
  630.     printLine("Reading blocks",2)
  631.     inspect()
  632.     printLine("Process step",4)
  633.     step()
  634.     printLine("Process walk",6)
  635.     walk()
  636. end
  637.  
  638. --Gestionaire principal
  639. function main()
  640.     term.clear()
  641.     term.setCursorPos(1,1)
  642.     local continue=true
  643.     tick=os.startTimer(delay)
  644.     while continue do
  645.         local e,k=os.pullEvent()
  646.         if e=="redstone" then
  647.             os.reboot()
  648.             continue=false
  649.         elseif e=="key" and k==keys.t then
  650.             continue=false
  651.             os.cancelTimer(tick)
  652.         elseif e=="timer" then
  653.             printLine("Process new step "..os.clock(),1)
  654.             printLine("Fuel level is  "..turtle.getFuelLevel(),9)
  655.             process()
  656.             tick=os.startTimer(delay)
  657.         end
  658.     end
  659.     print("Terminate")
  660.     ignoreReboot = false
  661.     sleep(delay)
  662. end
  663.  
  664. main()
Advertisement
Add Comment
Please, Sign In to add comment