Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module(...)
- local U = require "utils"
- local T = require "turtle"
- local mT = require "miningTurtle"
- local wood = {}
- local nextColDir = "up"
- local 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
- mT.invFull("back", 2)
- nextColDir = T.swapColDir(nextColDir)
- T.turn(nextRowDir)
- nextRowDir = T.swapRowDir(nextRowDir)
- for j = 1, 3, 1 do
- if not digCenter(nextColDir) then
- return false
- end
- mT.invFull("back", 2)
- nextColDir = T.swapColDir(nextColDir)
- end
- if not digSide(nextColDir) then
- return false
- end
- mT.invFull("back", 2)
- nextColDir = T.swapColDir(nextColDir)
- T.turn(nextRowDir)
- end
- if not addSupports() then
- return false
- end
- mT.invFull(nextRowDir, 2)
- end
- return true
- end
- function addSupports()
- T.turn(nextRowDir)
- mT.forward()
- T.turn(nextRowDir)
- mT.forward()
- T.turn(nextRowDir)
- if not placeBeams(nextColDir) then
- return false
- end
- nextColDir = T.swapColDir(nextColDir)
- T.turn(nextRowDir)
- T.turn(nextRowDir)
- nextRowDir = T.swapRowDir(nextRowDir)
- mT.forward()
- if nextColDir == "up" then
- mT.digDown()
- if not placeWood("down") then
- return false
- end
- mT.up()
- mT.up()
- if not placeWood("up") then
- return false
- end
- elseif nextColDir == "down" then
- if not placeWood("up") then
- return false
- end
- mT.down()
- mT.down()
- mT.digDown()
- if not placeWood("down") then
- return false
- end
- end
- nextColDir = T.swapColDir(nextColDir)
- mT.forward()
- if not placeBeams(nextColDir) then
- return false
- end
- nextColDir = T.swapColDir(nextColDir)
- T.turn(nextRowDir)
- nextRowDir = T.swapRowDir(nextRowDir)
- mT.forward()
- T.turn(nextRowDir)
- mT.forward()
- nextRowDir = T.swapRowDir(nextRowDir)
- T.turn(nextRowDir)
- return true
- end
- function placeBeams(direction)
- success = true
- if direction == "up" then
- mT.digDown()
- sucess = placeWood("down")
- sucess = placeWood("front")
- mT.up()
- sucess = placeWood("front")
- mT.up()
- sucess = placeWood("front")
- sucess = placeWood("up")
- elseif direction == "down" then
- sucess = placeWood("up")
- sucess = placeWood("front")
- mT.down()
- sucess = placeWood("front")
- mT.down()
- mT.digDown()
- sucess = placeWood("front")
- sucess = placeWood("down")
- end
- return success
- end
- function digSide(direction)
- local success = true
- mT.dig()
- mT.forward()
- if direction == "up" then
- mT.digDown()
- success = placeWood("down")
- for i = 1, 2, 1 do
- mT.digUp()
- mT.up()
- end
- mT.digUp()
- success = placeWood("up")
- else
- mT.digUp()
- success = placeWood("up")
- for i = 1, 2, 1 do
- mT.digDown()
- mT.down()
- end
- mT.digDown()
- success = placeWood("down")
- end
- return success
- end
- function digCenter(direction)
- local success = true
- mT.dig()
- mT.forward()
- if direction == "up" then
- mT.digUp()
- mT.up()
- mT.digUp()
- mT.up()
- mT.digUp()
- else
- mT.digUp()
- for i = 1, 2, 1 do
- mT.digDown()
- mT.down()
- end
- end
- return success
- end
- function placeWood(dir)
- hasWood = true
- if (wood == nil) or (U.sum(wood) == 0) then
- hasWood = findWood()
- end
- if not hasWood then
- return false
- end
- woodSlot = 1
- for i = 1, 14, 1 do
- if wood[i] > 0 then
- woodSlot = i
- end
- end
- turtle.select(woodSlot)
- success = true
- if dir == "front" then
- success = turtle.place()
- elseif dir == "up" then
- success = turtle.placeUp()
- elseif dir == "down" then
- success = turtle.placeDown()
- end
- wood[woodSlot] = turtle.getItemCount(woodSlot)
- return success
- end
- function findWood()
- for i = 1, 14, 1 do
- turtle.select(i)
- wood[i] = turtle.getItemCount(i)
- end
- if not (U.sum(wood) == 0) then
- return true
- else
- return false
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment