Computer Craft – Using a turtle to spot mine! or How do I get that glowstone?

I created a command that allows you to spot mine with a turtle. It gives you direct access to the turtle.dig() function via a program called “dig”. You can dig forwards, down, and up for any amount of distance. The parameters can also be specified in any order.

You can get the program from I created a command that allows you to spot mine with a turtle. It gives you direct access to the turtle.dig() function via a program called “dig”. You can dig forwards, down, and up for any amount of distance. The parameters can also be specified in any order.

You can get the program from http://adfoc.us/27013355689086 or copy and paste below:

--[[
======================= A KreezCo Production =============================
== Written by: Kreezxil ==
== Orignal Code by: M_I_Z_E ==
== Many Parts of this code was barrowed from the original turtle ==
== programs that come with computer craft. ==
== http://www.computercraft.info/ ==
== YouTube channel Name: Adventures in Casual Gaming ==
== URL: http://www.youtube.com/user/kreezxil ==
== Original URL: http://www.youtube.com/user/MIZ3craft ==
== Please link to my channel and give proper credit if using my code. ==
== Thanks for watching! ==
==========================================================================
--]]

--[[ Begin Library 
 Libary by Kreezxil 7/29/2013
--]]

function refuel()
 --Check fuel and refuel if necessary
 --Code source: sethbling http://www.youtube.com/watch?v=DSsx4VSe-Uk&feature=share&list=SP2Qvl4gaBge02Eh4AqtDSWg3sojt3jeRO
 if turtle.getFuelLevel() < 200 then
 turtle.select(1)
 turtle.refuel(1)
 end
end

function dig(direction, distance)
 travel = 0
 repeat
 --[[ do we have fuel? --]]
 refuel()
 travel = travel + 1
 if direction == "f" then
 if turtle.dig() then 
 turtle.suck()
 end
 if distance > 0 then 
 turtle.forward() 
 end 
 elseif direction == "u" then
 if turtle.digUp() then 
 turtle.suckUp()
 end
 if distance > 0 then 
 turtle.up() 
 end 
 elseif direction == "d" then
 if turtle.digDown() then 
 turtle.suckDown()
 end
 if distance > 0 then 
 turtle.down() 
 end 
 elseif direction == "b" then
 turtle.back()
 end
 until travel == distance
end

--[[ End Library --]]

local tArgs = { ... }
local dist = 1
--[[ test how many args were passed, if none set dist to 0 and assume
forward facing. --]]
if #tArgs < 1 then
 --[[ print usage --]]
 print("Usage: dig [direction] ")
 print()
 print("Place fuel in slot 1")
 print("Give command to dig")
 return
else
 --[[ dist = tonumber( tArgs[1] ) --]]
 --[[ parses passed parameters and sets variables despite order of values --]]
 print("Args Present: "..#tArgs)
 for n=1,#tArgs do
 if n == 3 then
 --[[ in the future subsequent arguments will be accepted
 as command line mapping instructions
 --]]
 break
 end
 test = string.sub( tArgs[n], 1, 1)
 test = string.lower( test )
 if string.find("fdub",test) ~= nil then
 direction = test
 else
 dist = tonumber(tArgs[n])
 end
 end
end

--[[ Process command directives --]]
paramError = 0
if dist == nil or tonumber(dist) < 0 then
 print("Distance must be a number from 0 on up.")
 paramError = paramError + 1
end
if string.find("fdub",direction) == nil then
 print("Direction must be one of: forward, down, up, back, f, d, u, b")
 paramError = paramError + 1
end

if paramError > 0 then
 print("Number of parameter errors are " .. paramError)
 print("Please think about your options.")
 return
end

dig(direction,dist)