Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- wood = 0
- nextColDir = "up"
- nextRowDir = "right"
- function digTunnel(length)
- for i = 1, length, 1 do
- for k = 1, 4, 1 do
- if not digSide(nextColDir) then
- return false
- end
- swapColDirection()
- turn(nextRowDir)
- swapRowDirection()
- for j = 1, 3, 1 do
- if not digCenter(nextColDir) then
- return false
- end
- swapColDirection()
- end
- if not digSide(nextColDir) then
- return false
- end
- swapColDirection()
- turn(nextRowDir)
- end
- if not addSupports() then
- return false
- end
- end
- return true
- end
- function addSupports()
- success = true
- turn(nextRowDir)
- forward()
- turn(nextRowDir)
- forward()
- turn(nextRowDir)
- success = placeBeams(nextColDir)
- swapColDirection()
- turn(nextRowDir)
- turn(nextRowDir)
- swapRowDirection()
- forward()
- if nextColDir == "up" then
- digDown()
- success = placeWood("down")
- up()
- up()
- success = placeWood("up")
- elseif nextColDir == "down" then
- success = placeWood("up")
- down()
- down()
- digDown()
- success = placeWood("down")
- end
- swapColDirection()
- forward()
- success = placeBeams(nextColDir)
- swapColDirection()
- turn(nextRowDir)
- swapRowDirection()
- forward()
- turn(nextRowDir)
- forward()
- swapRowDirection()
- turn(nextRowDir)
- return success
- end
- function placeBeams(direction)
- success = true
- if direction == "up" then
- digDown()
- sucess = placeWood("down")
- sucess = placeWood("front")
- up()
- sucess = placeWood("front")
- up()
- sucess = placeWood("front")
- sucess = placeWood("up")
- elseif direction == "down" then
- sucess = placeWood("up")
- sucess = placeWood("front")
- down()
- sucess = placeWood("front")
- down()
- digDown()
- sucess = placeWood("front")
- sucess = placeWood("down")
- end
- return success
- end
- function turn(direction)
- if direction == "right" then
- turtle.turnRight()
- elseif direction == "left" then
- turtle.turnLeft()
- end
- end
- function swapRowDirection()
- if nextRowDir == "right" then
- nextRowDir = "left"
- else
- nextRowDir = "right"
- end
- end
- function swapColDirection()
- if nextColDir == "up" then
- nextColDir = "down"
- else
- nextColDir = "up"
- end
- end
- function digSide(direction)
- success = true
- dig()
- forward()
- if direction == "up" then
- digDown()
- success = placeWood("down")
- for i = 1, 2, 1 do
- digUp()
- up()
- end
- digUp()
- success = placeWood("up")
- else
- digUp()
- success = placeWood("up")
- for i = 1, 2, 1 do
- digDown()
- down()
- end
- digDown()
- success = placeWood("down")
- end
- return success
- end
- function digCenter(direction)
- success = true
- dig()
- forward()
- if direction == "up" then
- digUp()
- up()
- digUp()
- up()
- digUp()
- else
- digUp()
- for i = 1, 2, 1 do
- digDown()
- down()
- end
- end
- return success
- end
- function placeWood(direction)
- if wood > 0 then
- wood = wood - 1
- else
- wood = findWood()
- if wood == 0 then
- print("Out of wood! Please refill!")
- return false
- end
- end
- if direction == "front" then
- return turtle.place()
- elseif direction == "up" then
- return turtle.placeUp()
- elseif direction == "down" then
- return turtle.placeDown()
- end
- end
- function findWood()
- for i = 1, 15, 1 do
- turtle.select(i)
- if turtle.compareTo(16) then
- return turtle.getItemCount(i)
- end
- end
- return 0
- end
- function digUp()
- while turtle.detectUp() do
- turtle.digUp()
- end
- end
- function dig()
- while turtle.detect() do
- turtle.dig()
- end
- end
- function digDown()
- while turtle.detectDown() do
- turtle.digDown()
- end
- end
- function forward()
- dig()
- turtle.forward()
- end
- function up()
- digUp()
- turtle.up()
- end
- function down()
- digDown()
- turtle.down()
- end
Advertisement
Add Comment
Please, Sign In to add comment