Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function hasAnyTag(str, tags)
- for _, tag in ipairs(tags) do
- if string.find(str, tag) ~= nil then
- return true
- end
- end
- return false
- end
- function isBlock(itemName)
- local blockTags = {"cobblestone"}
- return hasAnyTag(itemName, blockTags)
- end
- function isValuable(itemName)
- return hasAnyTag(itemName, {"diamond", "gold", "emerald", "iron"})
- end
- function setToNotValuableBlockSlot()
- for i = 1, 16 do
- local itemName = turtle.getItemDetail(i).name
- if not isValuable(itemName) and isBlock(itemName) then
- turtle.select(i)
- return true
- end
- end
- return false
- end
- function moveInSpiral(targetSize, toOutside, callback)
- local function moveForward(n)
- for _ = 1, n do
- turtle.forward()
- callback()
- end
- end
- moveForward(targetSize)
- turtle.turnLeft()
- for i = targetSize - 1, 1, -1 do
- for _ = 1, 2 do
- moveForward(i)
- turtle.turnLeft()
- end
- end
- end
- function moveZig(forward, left, callback)
- local function moveForward(n)
- for _ = 1, n do
- callback()
- turtle.forward()
- end
- end
- callback()
- for i = 1, left-1 do
- local even = i % 2 == 0
- moveForward(forward-1)
- if not even then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- moveForward(1)
- if not even then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- end
- moveForward(forward-1)
- end
- function repeatFunc(callback, n)
- for i = 1, n do
- callback()
- end
- end
- function move(direction, n)
- local moveFunc
- if "forward" then
- moveFunc = turtle.forward
- elseif "down" then
- moveFunc = turtle.down
- elseif "up" then
- moveFunc = turtle.up
- end
- for i = 1, n do
- moveFunc()
- end
- end
- local width = tonumber(arg[1]) or 4
- local length = tonumber(arg[2]) or 4
- local height = tonumber(arg[3]) or 4
- if height < 2 then
- error("2 is height minimum")
- end
- if turtle.inspectUp() then
- turtle.digUp()
- end
- turtle.up()
- for i = 1, height - 1 do
- local width = tonumber(width)
- moveZig(tonumber(length), width, function()
- if turtle.inspect() then
- while turtle.dig() do end
- end
- turtle.digDown()
- end)
- if width % 2 == 0 then
- turtle.turnLeft()
- else
- turtle.turnLeft()
- turtle.turnLeft()
- end
- if i == 1 then
- turtle.digDown()
- end
- local isLast = i == height - 1
- if not isLast then
- if turtle.inspectUp() then
- turtle.digUp()
- end
- turtle.up()
- else
- repeatFunc(turtle.down, height)
- repeatFunc(turtle.forward, length)
- turtle.turnLeft()
- repeatFunc(turtle.forward, width)
- turtle.turnLeft()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement