Skip to content

Instantly share code, notes, and snippets.

@baweaver
Last active August 29, 2015 14:06
Show Gist options
  • Save baweaver/f5be6ee6b75b58f9221f to your computer and use it in GitHub Desktop.
Save baweaver/f5be6ee6b75b58f9221f to your computer and use it in GitHub Desktop.
--[[
# Digger: A simple program to dig a 1 x 2 shaft straight
## Author: Brandon Weaver (keystonelemur / baweaver)
--]]
local tArgs = { ... }
if tArgs[1] == 'help' then
print('Usage:')
print('')
return
end
-- Distance to mine
local distance = tArgs[1] or 1
-- Whether or not to set blocks on an imminent fall
local safeBlock = tArgs[2]
-- Whether or not to set torches from slot 2
local torches = tArgs[3]
-- Shorten the turtle name
local t = turtle
function checkFuelLevel()
return distance - t.getFuelLevel()
end
-- Confirm that we have adequate fuel for the trip
level = checkFuelLevel()
if level > 0 then
print('Insufficient fuel of '..level..' units, attempting refuel...')
t.refuel(level)
newLevel = checkFuelLevel()
if newLevel > 0 then
print('Cannot make trip, fuel is short by '..newLevel..' units. Goodbye')
return
end
end
print('Mining '..distance..' squares')
-- Set a safety block to keep from a nasty fall
function setSafeBlock()
if safeBlock then
t.select(2)
t.placeDown()
end
end
-- Set a torch for visibility
function setTorch()
if torches then
t.select(3)
t.placeDown()
end
end
-- Clear a forward path
-- Use detection to deal with sand and gravel
function clearForward()
while t.detect() do t.dig() end
t.forward()
t.digUp()
setSafeBlock()
setTorch()
end
for i = 0, distance do
print('Mined '..i..' blocks')
clearForward()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment