Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- to install/reinstall:
- -- pastebin run YmWZcV0e WarrX8Nh pillars.lua
- placedBlocks = 0
- function fillArray(x, n)
- arr = {}
- for i = 1, n do
- arr[i] = x
- end
- return arr
- end
- function tryToExecute(actions, autoDig)
- for i = 1, #actions do
- print(i)
- action = actions[i]
- if autoDig then
- flag, e = nil, nil
- if action == turtle.forward then
- flag, e = turtle.dig()
- elseif action == turtle.back then
- flag, e = tryToExecute({turtle.turnLeft, turtle.turnLeft, turtle.dig, turtle.turnLeft, turtle.turnLeft}, false)
- elseif action == turtle.up then
- flag, e = turtle.digUp()
- elseif action == turtle.down then
- flag, e = turtle.digDown()
- end
- if not flag and not e == "Nothing to dig here" then
- return false, e
- end
- end
- flag, e = action()
- ignore = action == turtle.digDown or action == turtle.dig or action == turtle.digUp
- if not ignore then
- if action == turtle.place or action == turtle.placeDown or action == turtle.placeUp then
- ignore = true
- end
- end
- if not ignore and not flag then
- return false, e
- end
- end
- return true
- end
- function findBlock(name)
- item = turtle.getItemDetail()
- if item and item.name == name then
- return true
- end
- for i = 1, 16 do
- item = turtle.getItemDetail(i)
- if item and item.name == name then
- turtle.select(i)
- return true
- end
- end
- return false
- end
- local forwardActions = fillArray(turtle.forward, 20)
- local blockName = "minecraft:cobblestone"
- function placeBlock()
- suc, par = turtle.inspect()
- if suc then
- if par.name == blockName then
- return true
- else
- s, e = turtle.dig()
- if not s and not e == "Nothing to dig here" then
- return false, e
- end
- end
- end
- if not findBlock(blockName) then
- return false, "No blocks"
- end
- if turtle.place() then
- placedBlocks = placedBlocks + 1
- return true
- else
- return false
- end
- end
- function placeBlockDown()
- suc, par = turtle.inspectDown()
- if suc then
- if par.name == blockName then
- return true
- else
- s, e = turtle.digDown()
- if not s then
- return false, e
- end
- end
- end
- if not findBlock(blockName) then
- return false, "No blocks"
- end
- if turtle.placeDown() then
- placedBlocks = placedBlocks + 1
- return true
- else
- return false
- end
- end
- local pillarBase = {
- turtle.down,
- turtle.forward, placeBlock, turtle.turnLeft, placeBlock, turtle.turnLeft, turtle.forward, turtle.turnLeft,
- turtle.forward, placeBlock, turtle.turnLeft, placeBlock, turtle.turnLeft, turtle.forward, turtle.turnLeft,
- turtle.forward, placeBlock, turtle.turnLeft, placeBlock, turtle.turnLeft, turtle.forward, turtle.turnLeft,
- turtle.forward, placeBlock, turtle.turnLeft, placeBlock, turtle.turnLeft, turtle.forward, turtle.turnLeft,
- placeBlock, turtle.turnLeft, placeBlock, turtle.turnLeft, placeBlock, turtle.turnLeft, placeBlock, turtle.turnLeft,
- turtle.up, placeBlockDown,
- turtle.forward, placeBlock, turtle.turnLeft, placeBlock, turtle.turnLeft, turtle.forward, turtle.turnLeft,
- turtle.forward, placeBlock, turtle.turnLeft, placeBlock, turtle.turnLeft, turtle.forward, turtle.turnLeft,
- turtle.forward, placeBlock, turtle.turnLeft, placeBlock, turtle.turnLeft, turtle.forward, turtle.turnLeft,
- turtle.forward, placeBlock, turtle.turnLeft, placeBlock, turtle.turnLeft, turtle.forward, turtle.turnLeft,
- placeBlock, turtle.turnLeft, placeBlock, turtle.turnLeft, placeBlock, turtle.turnLeft, placeBlock, turtle.turnLeft,
- turtle.up, placeBlockDown
- }
- local pillarPart = {
- placeBlock, turtle.turnLeft, placeBlock, turtle.turnLeft, placeBlock, turtle.turnLeft, placeBlock, turtle.turnLeft,
- turtle.up, placeBlockDown
- }
- function goToNext()
- return tryToExecute(forwardActions, false)
- end
- pillarHeight = 0
- function goDownAndCount()
- run = true
- pillarHeight = 0
- while run do
- if turtle.down() then
- pillarHeight = pillarHeight + 1
- else
- run = false
- end
- end
- print("Height: " .. pillarHeight)
- return true
- end
- tryToExecute({goToNext, goDownAndCount}, false)
- function pillarBaseFunc()
- print("Pillar base")
- return tryToExecute(pillarBase, true)
- end
- function pillarPartsFunc()
- print("Pillar parts")
- for i = 1, pillarHeight - 2 do
- s, e = tryToExecute(pillarPart, true)
- if not s then
- return s, e
- end
- end
- return true
- end
- if pillarHeight > 0 then
- s, e = tryToExecute({pillarBaseFunc, pillarPartsFunc, turtle.up})
- if not s then
- print(e)
- end
- end
- print("Placed blocks " .. placedBlocks)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement