Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Quarry Program
- --@author: dlks
- --@version: 2.1a
- local movef = turtle.forward
- local moved = turtle.down
- local digf = turtle.dig
- local digd = turtle.digDown
- local canmovef = turtle.detect
- local canmoved = turtle.detectDown
- local lookr = turtle.turnRight
- local lookl = turtle.turnLeft
- local prefix = "[Carlos 2.1a] "
- -- 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
- local function walk()
- if canmovef ~= true then digf() end
- movef()
- combustivel()
- end
- local function godown()
- if canmoved ~= true then digd() end
- moved()
- combustivel()
- end
- local function walkline(x)
- for i=1, x do walk() end
- end
- local function turnline(direction)
- if direction == 1 then
- lookr()
- walk()
- lookr()
- end
- if direction == 2 then
- lookl()
- walk()
- lookl()
- end
- end
- local function walk2d(x, y, layersmoved)
- local linesmoved = 1
- for i=2, y do
- if linesmoved == 1 then
- walkline(x)
- linesmoved = linesmoved + 1
- end
- if (y % 2) ~= 0 then
- if (linesmoved % 2) == 0 then
- turnline(1)
- walkline(x - 1)
- linesmoved = linesmoved + 1
- else
- turnline(2)
- walkline(x - 1)
- linesmoved = linesmoved + 1
- end
- end
- if (y % 2) == 0 then
- if layersmoved == 1 then
- if (linesmoved % 2) == 0 then
- turnline(1)
- walkline(x - 1)
- linesmoved = linesmoved + 1
- else
- turnline(2)
- walkline(x - 1)
- linesmoved = linesmoved + 1
- end
- end
- if (layersmoved % 2) == 0 then
- if (linesmoved % 2) == 0 then
- turnline(2)
- walkline(x - 1)
- linesmoved = linesmoved + 1
- else
- turnline(1)
- walkline(x - 1)
- linesmoved = linesmoved + 1
- end
- end
- end
- end
- end
- local function walk3d(x, y, z)
- local layersmoved = 1
- for i=1, z do
- walk2d(x, y, layersmoved)
- layersmoved = layersmoved + 1
- walk()
- lookl()
- lookl()
- godown()
- end
- end
- print(prefix .. "Digite a area para ser minerada: ")
- local a = tonumber(read())
- local b = tonumber(read())
- local c = tonumber(read())
- walk3d(a, b, c)
- print(prefix .. "A area foi minerada.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement