Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Lazy Nub Tunneller v0.03
- Will tell your turtle how to build
- an amazingly wonderful tunnel for you,
- with torch and chest placement if requested.
- Chest(s) slot = 14
- Fuel slot = 15
- Torch(s) slot = 16
- Minimum Length = 1
- Width = 1
- Height = 3
- If you wish to skip the UI and start tunneller with commands directly
- the format is:
- <program name> <Length> <Width> <Height> [Torch Distance]
- ie: lnt 16 1 3 6
- This would start the tunnel with a length of 16 width of 1
- height of 3 and torches spaced 6 apart. The torches can be
- omitted from the line and none will be placed.
- With this option tunneller assumes you have enough fuel and torches in place.
- If you use the command line method it will assume you wish to use chests if the
- chest slot is occupied.
- If any of your numbers fail the limits of the program it will
- default to normal UI operation.
- ComputerCraft Posting: http://www.computercraft.info/forums2/index.php?/topic/13224-lazy-nub-tunneller/
- PasteBin: http://pastebin.com/xjsLsCZ9
- YouTube: http://youtu.be/DVF4VAfNfio
- Load into turtle with:
- pastebin get xjsLsCZ9 lnt
- Then start it with:
- lnt
- Changes:
- June 2 - Released v0.01
- June 3 - UI fixes command line option added v0.02
- June 4 - Added inventory drop-off
- ]]--
- local running = true
- local tunnelLength = 0
- local tunnelWidth = 0
- local tunnelHeight = 0
- local tunnel = 0
- local chestSlot = 14
- local fuelSlot = 15
- local torchSlot = 16
- local placeChest = false
- local placeTorch = false
- local torchDistance = 0
- local lastEmptySlot = 13
- local neededFuel = 0
- local args = { ... }
- local params = false
- local block = 1
- --[[ Robust Turtle
- Modified version of
- Robust Turtle API by SpeedR
- integrated
- ]]--
- local digDelay = .7
- local digTries = 25
- local function outOfResource()
- print("Ran out of a resource. Block: ",block , ".")
- print("Refill, then say something to proceed.")
- read()
- end
- --Digging with gravel/sand detection
- function dig()
- local tries = 0
- while turtle.detect() do
- turtle.dig()
- sleep(digDelay)
- tries = tries + 1
- if tries>digTries then
- print("Error: dug for too long.")
- return false
- end
- end
- return true
- end
- function digUp()
- local tries = 0
- while turtle.detectUp() do
- turtle.digUp()
- sleep(digDelay)
- tries = tries + 1
- if tries>digTries then
- print("Error: dug up for too long.")
- return false
- end
- end
- return true
- end
- function digDown()
- local tries = 0
- while turtle.detectDown() do
- turtle.digDown()
- sleep(digDelay)
- tries = tries + 1
- if tries>digTries then
- print("Error: dug down for too long.")
- return false
- end
- end
- return true
- end
- --Traveling: Goes in the direction no matter what (almost)
- --Will not be stopped by blocks or mobs
- function forward(l)
- l=l or 1
- for i=1,l do
- local tries = 0
- while turtle.forward() ~= true do
- turtle.dig()
- turtle.attack()
- sleep(digDelay)
- tries = tries + 1
- if tries>digTries then
- print("Error: can't move forward.")
- return false
- end
- end
- end
- return true
- end
- function up(l)
- l=l or 1
- for i=1,l do
- local tries = 0
- while turtle.up() ~= true do
- turtle.digUp()
- turtle.attackUp()
- sleep(digDelay)
- tries = tries + 1
- if tries>digTries then
- print("Error: can't move up.")
- return false
- end
- end
- end
- return true
- end
- function down(l)
- l=l or 1
- for i=1,l do
- local tries = 0
- while turtle.down() ~= true do
- turtle.digDown()
- turtle.attackDown()
- sleep(digDelay)
- tries = tries + 1
- if tries>digTries then
- print("Error: can't move down.")
- return false
- end
- end
- end
- return true
- end
- function back(l)
- l=l or 1
- for i=1,l do
- if turtle.back() ~= true then
- turnAround()
- forward()
- turnAround()
- end
- end
- end
- --Place blocks
- --Does not place when there's already the right block.
- function place(block)
- turtle.select(block)
- if turtle.compare()==false then
- if turtle.getItemCount(block)==0 then
- outOfResource(block)
- end
- dig()
- turtle.place()
- end
- end
- function placeUp(block)
- turtle.select(block)
- if turtle.compareUp()==false then
- if turtle.getItemCount(block)==0 then
- outOfResource(block)
- end
- digUp()
- turtle.placeUp()
- end
- end
- function placeDown(block)
- turtle.select(block)
- if turtle.compareDown()== false then
- if turtle.getItemCount(block)== 0 then
- outOfResource(block)
- end
- digDown()
- turtle.placeDown()
- end
- end
- function placeRight(block)
- turtle.turnRight()
- place(block)
- turtle.turnLeft()
- end
- function placeLeft(block)
- turtle.turnLeft()
- place(block)
- turtle.turnRight()
- end
- function placeBack(block)
- turnAround()
- place(block)
- turnAround()
- end
- --place row e.g. placeRow(up, marble, forward, 15)
- function placeRow(placeDir, block, travelDir, l)
- l=l or 1
- for i=1,l do
- if placeDir == "forward" then
- place(block)
- elseif placeDir == "up" then
- placeUp(block)
- elseif placeDir == "down" then
- placeDown(block)
- elseif placeDir == "right" then
- placeRight(block)
- elseif placeDir == "left" then
- placeLeft(block)
- elseif placeDir == "back" then
- placeBack(block)
- else
- print('"', placeDir, '" is not a valid direction!')
- return false
- end
- if travelDir == "forward" then
- forward()
- elseif travelDir == "up" then
- up()
- elseif travelDir == "down" then
- down()
- elseif travelDir == "right" then
- strafeRight()
- elseif travelDir == "left" then
- strafeLeft()
- elseif travelDir == "back" then
- back()
- else
- print('"', travelDir, '" is not a valid direction!')
- return false
- end
- end
- return true
- end
- --Turning
- function turnAround()
- turtle.turnRight()
- turtle.turnRight()
- end
- function right()
- turtle.turnRight()
- end
- function left()
- turtle.turnLeft()
- end
- function goRight(l)
- l=l or 1
- turtle.turnRight()
- forward(l)
- end
- function goLeft(l)
- l=l or 1
- turtle.turnLeft()
- forward(l)
- end
- function strafeRight(l)
- l=l or 1
- goRight(l)
- turtle.turnLeft()
- end
- function strafeLeft(l)
- l=l or 1
- goLeft(l)
- turtle.turnRight()
- end
- --[[ End of Robust Turtle
- ]]--
- function dumpInv() --Dumps inventory to chest
- print("Placing chest..")
- placeDown(chestSlot)
- for i = 1,lastEmptySlot do
- turtle.select(i)
- turtle.dropDown()
- end
- print("Emptied into chest..")
- turtle.select(1)
- end
- function checkSpace()
- --[[
- will remove noiseblocks and compress in future version maybe
- if turtle.getItemCount(lastEmptySlot) > 0 then
- print("Trying to make room...")
- for i = 2,lastEmptySlot,1 do
- if turtle.getItemCount(i)> 0 then
- for j = i-1,1,-1 do
- turtle.select(i-j)
- turtle.transferTo(j)
- ut = read()
- end
- end
- end
- ]]--
- if turtle.getItemCount(lastEmptySlot) > 0 then
- dumpInv()
- end
- end
- --[[ MAIN START ]]--
- if (#args < 3 or #args > 4) then -- Parse command line arguments if found
- params = false
- print("Command Line Option Skipped...")
- print("program name <Length> <Width> <Height> [Torch Distance]")
- else
- params = true
- tunnelLength = tonumber(args[1])
- tunnelWidth = tonumber(args[2])
- tunnelHeight = tonumber(args[3])
- if #args == 4 then
- torchDistance = tonumber(args[4])
- placeTorch = true
- if type( torchDistance ) ~= "number" or torchDistance < 1 then
- params = false
- end
- end
- if turtle.getItemCount(chestSlot) > 0 then
- placeChest = true
- end
- if type(tunnelLength) ~= "number" or tunnelLength < 1 or
- type(tunnelWidth) ~= "number" or tunnelWidth < 1 or
- type(tunnelHeight) ~= "number" or tunnelHeight < 3 or
- turtle.getFuelLevel() < ((tunnelLength*tunnelWidth)+((tunnelHeight-3)*(tunnelLength*tunnelWidth)))+1 then
- params = false
- end
- end
- if params == false then -- Start UI if invalid or no command line
- term.clear()
- term.setCursorPos (1, 1)
- print("Lazy Nub Tunneller v0.03")
- print("=====================")
- while tunnelLength < 1 do
- print("What length of tunnel (min = 1): ")
- tunnelLength = tonumber(read())
- if type( tunnelLength ) ~= "number" or tunnelLength == 0 then
- print ("I was expecting a number 1 or higher...")
- print ("Lets try that again.")
- tunnelLength = 0
- end
- end
- while tunnelWidth < 1 do
- print("What width of tunnel (min = 1): ")
- tunnelWidth = tonumber(read())
- if type( tunnelWidth ) ~= "number" or tunnelWidth == 0 then
- print ("I was expecting a number 1 or higher...")
- print ("Lets try that again.")
- tunnelWidth = 0
- end
- end
- while tunnelHeight < 3 do
- print("What height of tunnel (min = 3): ")
- tunnelHeight = tonumber(read())
- if type( tunnelHeight ) ~= "number" or tunnelHeight < 3 then
- print ("I was expecting a number 3 or higher...")
- print ("Lets try that again.")
- tunnelHeight = 0
- end
- end
- print("Use Torches (y/n): ")
- ut = read()
- if ut == "y" or ut == "Y" then
- placeTorch = true
- while torchDistance < 1 do
- print("Place How Far Apart (suggest 6): ")
- torchDistance = tonumber(read())
- if type( torchDistance ) ~= "number" or torchDistance < 1 then
- print ("I was expecting a number 1 or higher...")
- print ("Lets try that again.")
- torchDistance = 0
- end
- end
- -- check if enough torches.. still need to verify this check total
- if ((tunnelLength/torchDistance)*(tunnelWidth/torchDistance)) > (turtle.getItemCount(torchSlot)) then
- turtle.select(torchSlot)
- print("Place about "..((math.ceil(tunnelLength/torchDistance)*math.ceil(tunnelWidth/torchDistance))+2).." in slot "..torchSlot.." <ENTER>")
- ut = read()
- turtle.select(1)
- end
- end
- print("Use Chests (y/n): ")
- ut = read()
- if ut == "y" or ut == "Y" then
- placeChest = true
- turtle.select(chestSlot)
- while turtle.getItemCount(chestSlot) < 1 do
- print("Place at least 1 chest in slot "..chestSlot)
- print("Press <ENTER> when done.")
- ut = read()
- end
- turtle.select(1)
- end
- -- check for fuel in turtle at start matches needed level
- neededFuel = ((tunnelLength*tunnelWidth)+((tunnelHeight-3)*(tunnelLength*tunnelWidth)))+1
- if turtle.getFuelLevel() < neededFuel then
- turtle.select(fuelSlot)
- turtle.refuel(1)
- turtle.select(1)
- end
- if turtle.getFuelLevel() < neededFuel then
- print("Fuel Level at: "..turtle.getFuelLevel())
- while turtle.getFuelLevel() < neededFuel do
- turtle.select(fuelSlot)
- print ("Place fuel item into slot "..fuelSlot.." and press <Enter>")
- ut = read()
- turtle.refuel(1)
- print("Fuel Level at: "..turtle.getFuelLevel())
- end
- turtle.select(1)
- end
- end
- -- Main loop
- while running do
- up()
- for tunnel = 1,tunnelLength do
- forward()
- digUp()
- digDown()
- if placeChest == true then
- checkSpace()
- end
- if tunnel%torchDistance == 0 then
- placeDown(torchSlot)
- end
- if tunnelHeight > 3 then
- for Height = 4,tunnelHeight,1 do
- up()
- digUp()
- end
- for Height = tunnelHeight,4,-1 do
- down()
- end
- end
- if tunnelWidth > 1 then
- if tunnel%2 == 0 then
- left()
- else
- right()
- end
- for width = 2,tunnelWidth do
- forward()
- digUp()
- digDown()
- if placeChest == true then
- checkSpace()
- end
- if ((width%torchDistance == 0) and (tunnel%torchDistance == 0)) then
- placeDown(torchSlot)
- end
- if tunnelHeight > 3 then
- for Height = 4,tunnelHeight,1 do
- up()
- digUp()
- end
- for Height = tunnelHeight,4,-1 do
- down()
- end
- end
- end
- if tunnel%2 == 0 then
- right()
- else
- left()
- end
- end
- end
- down()
- if placeTorch == true then
- turnAround()
- place(torchSlot)
- turnAround()
- end
- if placeChest then
- if tunnelLength%2==0 then
- left()
- else
- right()
- end
- back()
- up()
- dumpInv()
- forward()
- if tunnelLength%2==0 then
- right()
- else
- left()
- end
- down()
- end
- running = false
- end
Add Comment
Please, Sign In to add comment