Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Wheat recolector v1.6.1 Recovered!
- --Made by elhuevoman
- --No rights reserved
- --Enjoy it!
- --Detecta si hay semillas seleccionadas
- function detector(slot)
- local item = turtle.getItemDetail(slot)
- if item then
- if item.name == "minecraft:wheat_seeds" then
- return 0
- else
- return 1
- end
- end
- end
- --Busca semillas en el inventario
- function selector(iSlot)
- if turtle.getSelectedSlot() == 16 and detector(turtle.getSelectedSlot()) == 1 then
- turtle.select(1)
- end
- while detector(iSlot) ~= 0 and iSlot < 16 do
- iSlot = iSlot + 1
- turtle.select(iSlot)
- end
- if detector(iSlot) == 0 then
- return true
- else
- return false
- end
- end
- --Crecio ya el cultivo?
- function isGrown()
- local success, data = turtle.inspectDown()
- if success then
- if data.metadata == 7 then
- return true
- end
- else
- return false
- end
- end
- function recolectar(contador)
- local i = 0
- local slotActual = turtle.getSelectedSlot()
- if contador < 8 then
- if isGrown() == true then
- turtle.digDown()
- --El slot actual tiene semillas?
- if detector(slotActual) == 0 then
- selector(slotActual)
- else
- selector(1)
- end
- turtle.placeDown()
- end
- end
- end
- --Cuantas semillas hay en el slot?
- function contSem(slot)
- turtle.select(slot)
- local espacio = turtle.getItemSpace(slot)
- local data = turtle.getItemDetail(slot)
- if data then
- if data.name == "minecraft:wheat_seeds" then
- return espacio
- else
- return 0
- end
- end
- return 64
- end
- --Cuanto trigo hay en el slot?
- function contTrigo(slot)
- turtle.select(slot)
- local espacio = turtle.getItemSpace(slot)
- local data = turtle.getItemDetail(slot)
- if data then
- if data.name == "minecraft:wheat" then
- return espacio
- else
- return 0
- end
- else
- return 64
- end
- end
- --Cuantas semillas caben?
- function semillasRestantes()
- local total = 0 --Valor a retornar
- local i = 1 --Variable contadora for
- turtle.select(1)
- for i = 1, 16 do
- total = total + contSem(i)
- end
- return total
- end
- --Cuanto trigo cabe?
- function trigoRestante()
- local total = 0 --Valor a retornar
- local i = 1 --Variable contadora for
- turtle.select(1)
- for i = 1, 16 do
- total = total + contTrigo(i)
- end
- return total
- end
- --Comprueba si el fuel esta lleno
- function isFuelFull()
- print("Comprobando niveles de combustible...")
- if turtle.getFuelLevel() > 10000 then
- return true
- else
- return false
- end
- end
- function movimiento(valor)
- if valor%2 == 0 then
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- else
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- end
- end
- function recolectarNivel()
- local contador = 0 --Impedir recolectar el ultimo
- local i = 1 --Variable contadora for
- local j = 1 --Variable contadora anidada
- recolectar(contador)
- for i = 1, 9 do
- for j = 1, 8 do
- turtle.forward()
- recolectar(1)
- end
- movimiento(i-1)
- recolectar(contador)
- contador = contador + 1
- end
- end
- function hayEspacio()
- local semillasRestantes = semillasRestantes()
- local trigoRestante = trigoRestante()
- if semillasRestantes > 120 and trigoRestante > 80 then
- return true
- else
- return false
- end
- end
- --Loop de movimiento
- function moverse(bloques)
- local i = 0 --Variable contadora for
- for i = 0, bloques do
- turtle.forward()
- end
- end
- --Funcion que devuelve al punto en que se quedo
- function volver(pos)
- local bloquesAMover = pos*9
- local i = 0 --Variable contadora for
- if pos < 7 then
- turtle.turnLeft()
- turtle.turnLeft()
- moverse(bloquesAMover - 1)
- elseif pos < 14 then
- turtle.turnRight()
- moverse(8)
- turtle.turnRight()
- moverse(((pos - 7)*9)-1)
- elseif pos < 21 then
- turtle.turnRight()
- moverse(17)
- turtle.turnRight()
- moverse(((pos - 14)*9)-1)
- elseif pos < 28 then
- turtle.turnRight()
- moverse(26)
- turtle.turnRight()
- moverse(((pos - 21)*9)-1)
- elseif pos < 35 then
- turtle.turnRight()
- moverse(35)
- turtle.turnRight()
- moverse(((pos - 28)*9) - 1)
- elseif pos < 42 then
- turtle.turnRight()
- moverse(44)
- turtle.turnRight()
- moverse(((pos - 35)*9) - 1)
- else
- turtle.turnRight()
- moverse(53)
- turtle.turnRight()
- moverse(((pos - 42)*9) - 1)
- end
- end
- function volverCofre()
- turtle.turnRight()
- while not turtle.detect() do
- turtle.forward()
- end
- turtle.turnRight()
- while not turtle.detect() do
- turtle.forward()
- end
- end
- function vaciarInv()
- selector(1)
- local slotActual = turtle.getSelectedSlot()
- for i = 1, 16 do
- if slotActual ~= i then
- turtle.select(i)
- turtle.drop()
- end
- end
- turtle.select(slotActual)
- while turtle.getItemCount() > 32 do
- if turtle.getItemCount() == 64 then
- turtle.drop(32)
- elseif (turtle.getItemCount()%2) == 0 then
- turtle.drop(2)
- else
- turtle.drop(1)
- end
- end
- turtle.transferTo(1)
- turtle.select(1)
- end
- function recoleccionTotal()
- local contadorPosicion = 0
- while contadorPosicion < 48 do
- turtle.turnLeft()
- recolectarNivel()
- contadorPosicion = contadorPosicion + 1
- if contadorPosicion == 7 or contadorPosicion == 14 or contadorPosicion == 21 or contadorPosicion == 28 or contadorPosicion == 35 or contadorPosicion == 42 then
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.forward()
- turtle.turnLeft()
- moverse(62)
- turtle.turnRight()
- turtle.turnRight()
- else
- moverse(7)
- turtle.turnLeft()
- end
- if not hayEspacio() then
- volverCofre()
- vaciarInv()
- volver(contadorPosicion)
- turtle.select(1)
- end
- end
- volverCofre()
- vaciarInv()
- print("Recoleccion finalizada con exito")
- end
- print("Bienvenido al Software de recoleccion <<Granjero 2k17>>")
- if isFuelFull() then
- print("Niveles de combustible correctos, inicializando")
- recoleccionTotal()
- turtle.turnLeft()
- turtle.turnLeft()
- print("Recoleccion de trigo finalizada.")
- print("Gracias por usar el Software <<Granjero 2k17>>")
- else
- print("Error. Niveles de combustible insuficientes")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement