Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Digger2: A simple program to dig a cross pattern
- Author: Brandon Weaver (keystonelemur / baweaver)
- Notes:
- --]]
- local tArgs = { ... }
- if tArgs[1] == 'help' then
- print('Usage:')
- print(' lava [distance] [drop]')
- return
- end
- -- Distance to mine
- local distance = tArgs[1] or 1
- -- Shorten the turtle name
- local t = turtle
- -- Finds the shortage of fuel for the round trip
- local function checkFuelDeficit()
- return (2 * distance - t.getFuelLevel()) + 2
- end
- -- Confirm that we have adequate fuel for the trip
- local level = checkFuelDeficit()
- if level > 0 then
- -- Attempt to correct the deficit
- print('Insufficient fuel of'..level..' units, attempting refuel...')
- t.refuel()
- -- See if that worked, or end the program
- local newLevel = checkFuelDeficit()
- if newLevel > 0 then
- print('Cannot make trip, fuel is short by'..newLevel..' units. Goodbye')
- return
- end
- end
- print('Mining '..distance..' squares')
- print('')
- local function turnAround()
- t.turnRight()
- t.turnRight()
- end
- local function until_clear(checkFn, digFn)
- while checkFn() do
- digFn()
- sleep(0.1)
- end
- end
- -- Clear a forward path
- local function clearDown()
- -- Make sure to deal with sand and friends
- until_clear(t.detect, t.dig)
- until_clear(t.detectDown, t.digDown)
- until_clear(t.detectUp, t.digUp)
- t.turnRight()
- until_clear(t.detect, t.dig)
- turnAround()
- until_clear(t.detect, t.dig)
- t.turnRight()
- t.digDown()
- t.forward()
- end
- -- Make it come back to the origin
- local function returnHome()
- turnAround()
- for returnLocation = 0, distance do
- -- Make sure to deal with sand and friends
- until_clear(t.detect, t.dig)
- t.forward()
- end
- end
- -- Main program loop
- for currentLocation = 0, distance do
- -- Do you REALLY want it every block notifications?
- if currentLocation % 5 == 0 then
- print('Mined '..currentLocation..' blocks')
- end
- clearDown()
- end
- returnHome()
Advertisement
Add Comment
Please, Sign In to add comment