Advertisement
Guest User

granjero3

a guest
Apr 24th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.63 KB | None | 0 0
  1. --Wheat recolector v1.6.1 Recovered!
  2. --Made by elhuevoman
  3. --No rights reserved
  4. --Enjoy it!
  5.  
  6.  
  7. --Detecta si hay semillas seleccionadas
  8. function detector(slot)
  9.  
  10.   local item = turtle.getItemDetail(slot)
  11.  
  12.   if item then
  13.  
  14.     if item.name == "minecraft:wheat_seeds" then
  15.  
  16.       return 0
  17.     else
  18.    
  19.       return 1
  20.     end
  21.   end
  22. end
  23.  
  24. --Busca semillas en el inventario
  25. function selector(iSlot)
  26.  
  27.   if turtle.getSelectedSlot() == 16 and detector(turtle.getSelectedSlot()) == 1 then
  28.     turtle.select(1)
  29.   end
  30.   while detector(iSlot) ~= 0 and iSlot < 16 do
  31.     iSlot = iSlot + 1
  32.     turtle.select(iSlot)
  33.   end
  34.  
  35.  
  36.   if detector(iSlot) == 0 then
  37.     return true
  38.   else  
  39.     return false
  40.   end
  41.  
  42. end
  43.  
  44. --Crecio ya el cultivo?
  45. function isGrown()
  46.   local success, data = turtle.inspectDown()
  47.  
  48.   if success then
  49.     if data.metadata == 7 then    
  50.     return true    
  51.     end
  52.   else
  53.     return false
  54.   end
  55.  
  56. end
  57.  
  58. function recolectar(contador)
  59.    
  60.   local i = 0
  61.   local slotActual = turtle.getSelectedSlot()
  62.  
  63.   if contador < 8 then  
  64.     if isGrown() == true then
  65.       turtle.digDown()
  66.      
  67.       --El slot actual tiene semillas?
  68.       if detector(slotActual) == 0 then
  69.         selector(slotActual)
  70.        
  71.       else      
  72.         selector(1)
  73.        
  74.       end
  75.       turtle.placeDown()
  76.      end
  77.    end  
  78.    
  79. end
  80.  
  81. --Cuantas semillas hay en el slot?
  82. function contSem(slot)
  83.  
  84.   turtle.select(slot)
  85.   local espacio = turtle.getItemSpace(slot)
  86.   local data = turtle.getItemDetail(slot)
  87.  
  88.   if data then
  89.     if data.name == "minecraft:wheat_seeds" then
  90.      
  91.        return espacio
  92.     else
  93.       return 0
  94.      
  95.     end
  96.   end
  97.  
  98.   return 64
  99. end
  100.  
  101. --Cuanto trigo hay en el slot?
  102. function contTrigo(slot)
  103.  
  104.   turtle.select(slot)
  105.   local espacio = turtle.getItemSpace(slot)
  106.   local data = turtle.getItemDetail(slot)
  107.  
  108.   if data then
  109.     if data.name == "minecraft:wheat" then    
  110.       return espacio
  111.      
  112.     else
  113.       return 0
  114.      
  115.     end
  116.   else
  117.     return 64
  118.   end
  119.  
  120.  
  121. end
  122. --Cuantas semillas caben?
  123. function semillasRestantes()
  124.  
  125.   local total = 0 --Valor a retornar
  126.   local i = 1 --Variable contadora for
  127.   turtle.select(1)
  128.  
  129.   for i = 1, 16 do
  130.     total = total + contSem(i)
  131.   end
  132.  
  133.   return total
  134. end  
  135.  
  136. --Cuanto trigo cabe?
  137. function trigoRestante()
  138.  
  139.   local total = 0 --Valor a retornar
  140.   local i = 1 --Variable contadora for
  141.   turtle.select(1)
  142.  
  143.   for i = 1, 16 do
  144.     total = total + contTrigo(i)
  145.   end
  146.  
  147.   return total
  148. end
  149.  
  150. --Comprueba si el fuel esta lleno
  151. function isFuelFull()
  152.  
  153.   print("Comprobando niveles de combustible...")
  154.   if turtle.getFuelLevel() > 10000 then
  155.     return true
  156.   else
  157.     return false    
  158.   end
  159. end
  160.  
  161. function movimiento(valor)
  162.  
  163.   if valor%2 == 0 then
  164.     turtle.turnRight()
  165.     turtle.forward()
  166.     turtle.turnRight()
  167.   else
  168.     turtle.turnLeft()
  169.     turtle.forward()
  170.     turtle.turnLeft()
  171.   end
  172. end
  173. function recolectarNivel()
  174.  
  175.   local contador = 0 --Impedir recolectar el ultimo
  176.   local i = 1 --Variable contadora for
  177.   local j = 1 --Variable contadora anidada
  178.  
  179.   recolectar(contador)  
  180.   for i = 1, 9 do
  181.  
  182.     for j = 1, 8 do
  183.     turtle.forward()
  184.     recolectar(1)
  185.    
  186.     end
  187.    
  188.    
  189.     movimiento(i-1)
  190.     recolectar(contador)
  191.     contador = contador + 1
  192.    
  193.   end
  194. end
  195.  
  196. function hayEspacio()
  197.  
  198.   local semillasRestantes = semillasRestantes()
  199.   local trigoRestante = trigoRestante()
  200.  
  201.   if  semillasRestantes > 120 and trigoRestante > 80 then
  202.     return true
  203.   else
  204.     return false
  205.   end
  206.  
  207. end
  208.  
  209. --Loop de movimiento
  210. function moverse(bloques)
  211.  
  212.   local i = 0 --Variable contadora for
  213.  
  214.   for i = 0, bloques do
  215.     turtle.forward()
  216.   end
  217. end
  218.  
  219. --Funcion que devuelve al punto en que se quedo
  220. function volver(pos)
  221.  
  222.   local bloquesAMover = pos*9
  223.   local i = 0 --Variable contadora for
  224.   if pos < 7 then
  225.     turtle.turnLeft()
  226.     turtle.turnLeft()
  227.    
  228.     moverse(bloquesAMover - 1)    
  229.   elseif pos < 14 then
  230.     turtle.turnRight()
  231.     moverse(8)
  232.     turtle.turnRight()
  233.     moverse(((pos - 7)*9)-1)
  234.   elseif pos < 21 then
  235.     turtle.turnRight()
  236.     moverse(17)
  237.     turtle.turnRight()
  238.     moverse(((pos - 14)*9)-1)
  239.   elseif pos < 28 then
  240.     turtle.turnRight()
  241.     moverse(26)
  242.     turtle.turnRight()
  243.     moverse(((pos - 21)*9)-1)
  244.   elseif pos < 35 then
  245.     turtle.turnRight()
  246.     moverse(35)
  247.     turtle.turnRight()
  248.     moverse(((pos - 28)*9) - 1)
  249.   elseif pos < 42 then
  250.     turtle.turnRight()
  251.     moverse(44)
  252.     turtle.turnRight()
  253.     moverse(((pos - 35)*9) - 1)
  254.   else
  255.     turtle.turnRight()
  256.     moverse(53)
  257.     turtle.turnRight()
  258.     moverse(((pos - 42)*9) - 1)
  259.   end
  260.  
  261. end
  262.  
  263. function volverCofre()
  264.   turtle.turnRight()
  265.  
  266.   while not turtle.detect() do
  267.     turtle.forward()
  268.   end
  269.  
  270.   turtle.turnRight()
  271.   while not turtle.detect() do
  272.     turtle.forward()
  273.   end
  274. end
  275.  
  276. function vaciarInv()
  277.  
  278.   selector(1)
  279.  
  280.   local slotActual = turtle.getSelectedSlot()
  281.   for i = 1, 16 do
  282.     if slotActual ~= i then
  283.       turtle.select(i)
  284.       turtle.drop()
  285.     end
  286.   end
  287.  
  288.   turtle.select(slotActual)
  289.  
  290.   while turtle.getItemCount() > 32 do
  291.     if turtle.getItemCount() == 64 then
  292.       turtle.drop(32)
  293.     elseif (turtle.getItemCount()%2) == 0 then
  294.       turtle.drop(2)
  295.     else
  296.       turtle.drop(1)
  297.     end
  298.   end
  299.  
  300.   turtle.transferTo(1)
  301.   turtle.select(1)
  302. end
  303.  
  304. function recoleccionTotal()
  305.  
  306.   local contadorPosicion = 0
  307.  
  308.   while contadorPosicion < 48 do
  309.  
  310.     turtle.turnLeft()
  311.     recolectarNivel()
  312.     contadorPosicion = contadorPosicion + 1
  313.    
  314.     if contadorPosicion == 7 or contadorPosicion == 14 or contadorPosicion == 21 or contadorPosicion == 28 or contadorPosicion == 35 or contadorPosicion == 42 then
  315.       turtle.turnLeft()
  316.       turtle.turnLeft()
  317.       turtle.forward()
  318.       turtle.turnLeft()      
  319.       moverse(62)
  320.       turtle.turnRight()
  321.       turtle.turnRight()
  322.     else
  323.       moverse(7)
  324.       turtle.turnLeft()
  325.     end
  326.    
  327.     if not hayEspacio() then
  328.  
  329.       volverCofre()
  330.            
  331.       vaciarInv()
  332.            
  333.       volver(contadorPosicion)
  334.      
  335.       turtle.select(1)
  336.     end
  337.  
  338.   end
  339.  
  340.   volverCofre()
  341.  
  342.   vaciarInv()
  343.  
  344.   print("Recoleccion finalizada con exito")
  345. end
  346.  
  347. print("Bienvenido al Software de recoleccion <<Granjero 2k17>>")
  348.  
  349. if isFuelFull() then
  350.   print("Niveles de combustible correctos, inicializando")
  351.   recoleccionTotal()
  352.   turtle.turnLeft()
  353.   turtle.turnLeft()
  354.   print("Recoleccion de trigo finalizada.")
  355.   print("Gracias por usar el Software <<Granjero 2k17>>")
  356. else
  357.   print("Error. Niveles de combustible insuficientes")
  358. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement