Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Digger: A simple program to dig a 1 x 2 shaft straight
- Author: Brandon Weaver (keystonelemur / baweaver)
- Notes: I guess you could use this as a bridge builder too,
- but I'll make a better program for that one later.
- Some of the more common functionality such as 180s and
- checking fuel levels really should be an API level concern
- so I'll get to that one later.
- --]]
- local tArgs = { ... }
- if tArgs[1] == 'help' then
- print('Usage:')
- print(' miner [distance] [set safe blocks] [set torches]')
- print('')
- print('setSafeBlock - Whether to set blocks to prevent a fall')
- print('setTorches - Whether to set torches')
- 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
- -- Finds the shortage of fuel for the round trip
- function checkFuelDeficit()
- return (2 * distance - t.getFuelLevel()) + 2
- end
- -- Confirm that we have adequate fuel for the trip
- level = checkFuelDeficit()
- if level > 0 then
- -- Attempt to correct the deficit
- print('Insufficient fuel of'..level..' units, attempting refuel...')
- t.refuel(level)
- -- See if that worked, or end the program
- newLevel = checkFuelDeficit()
- if newLevel > 0 then
- print('Cannot make trip, fuel is short by'..newLevel..' units. Goodbye')
- return
- end
- end
- -- Confirm that we have enough torches to cover the span
- -- TODO - consider increasing the slots, while 320 is large it may
- -- not be enough for some.
- if torches then
- requiredTorches = math.floor(distance / 5)
- currentStock = turtle.getItemCount(3)
- deficit = requiredTorches - currentStock
- if deficit > 0 then
- print('Insufficient torches to cover the distance, '..deficit..' more torches required!')
- return
- end
- end
- print('Mining '..distance..' squares')
- print('')
- function turnAround()
- t.turnRight()
- t.turnRight()
- end
- -- 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(currentLocation)
- if torches and currentLocation % 5 == 0 then
- t.select(3)
- turnAround()
- t.place()
- turnAround()
- end
- end
- -- Clear a forward path
- function clearForward(currentLocation)
- setSafeBlock()
- -- Make sure to deal with sand and friends
- while t.detect() do t.dig() end
- t.forward()
- setTorch(currentLocation)
- t.digUp()
- end
- -- Make it come back to the origin
- function returnHome()
- turnAround()
- t.up()
- for returnLocation = 0, distance do
- -- Make sure to deal with sand and friends
- while t.detect() do t.dig() end
- 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
- clearForward(currentLocation)
- end
- returnHome()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement