Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local prefix = "[Carlos 1.0a] "
- -- Funcao printf
- local function printf(...) print(string.format(...)) end
- -- Funcao combustivel
- local function combustivel()
- local restante = turtle.getFuelLevel() -- Combustivel restante
- local suficiente = false
- while true do
- if restante == 0 then
- suficiente = false
- printf("%sSem combustivel restante, tentando reabastecer.", prefix)
- for i = 1, 16 do
- turtle.select(i)
- if turtle.refuel(0) then
- local halfStack = math.ceil(turtle.getItemCount(i)/2)
- turtle.refuel(halfStack)
- restante = turtle.getFuelLevel()
- suficiente = true
- break
- end
- end
- else
- printf("%sCombustivel restante: %s", prefix, restante)
- suficiente = true
- break
- end
- end
- return suficiente
- end
- -- Funcao minerar
- local function minerar(a, b, c)
- local possivel = combustivel()
- while possivel do
- for i=1, c do
- for i=1, b do
- for i=1 , a-1 do
- turtle.dig()
- turtle.forward()
- possivel = combustivel()
- end
- if (i % 2) == 1 then
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- possivel = combustivel()
- turtle.turnRight()
- else
- turtle.turnLeft()
- turtle.dig()
- turtle.forward()
- possivel = combustivel()
- turtle.turnLeft()
- end
- end
- if (c % 2) ~= 0 then
- turtle.turnRight()
- turtle.forward()
- possivel = combustivel()
- turtle.turnLeft()
- turtle.digDown()
- turtle.down()
- possivel = combustivel()
- end
- if (c % 2) == 0 then
- turtle.digDown()
- turtle.down()
- possivel = combustivel()
- turtle.turnLeft()
- for i=1, b do
- turtle.dig()
- turtle.forward()
- end
- turtle.turnRight()
- end
- end
- break
- end
- end
- -- Codigo
- print(prefix .. "Digite a area para ser minerada: ")
- local a = tonumber(read())
- local b = tonumber(read())
- local c = tonumber(read())
- minerar(a, b, c)
- print(prefix .. "A area foi minerada.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement