Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ----------------------------------------------------------
- -- Stripmining turtle --
- ----------------------------------------------------------
- -- Version 1.2 --
- ----------------------------------------------------------
- -- Makes the turtle mine straight down to the bedrock. --
- -- Usege: dig <max Y> <length> --
- -- <max Y> - maximum height for mining --
- -- <length> - number of blocks to mine forward --
- ----------------------------------------------------------
- -- Based on a script pastebin.com/JbFMHaNg by Eonsv --
- -- Tested with CC 1.5 --
- -- Don't forget to use chunkloaders! --
- ----------------------------------------------------------
- --Tests wether a file with the filename name exists.
- --Returns true if it does and false if not
- function fileExists(name)
- local f = io.open(name,'r')
- if (f ~= nil) then
- f:close()
- return true
- else
- return false
- end
- end
- local arg = {...}
- --Saves current position to file
- function save()
- local str = ''
- str = str..y..'\n'
- str = str..x..'\n'
- local file = io.open('save', 'w')
- file:write(str)
- file:close()
- end
- --Consumes a stack of fuel from the 2nd enderchest
- local function refuel(fuel)
- if(turtle.getFuelLevel() >= fuel) then
- return true
- end
- while(turtle.detectUp()) do
- turtle.digUp()
- end
- turtle.select(2)
- while(not turtle.placeUp()) do
- turtle.attackUp()
- end
- turtle.select(16)
- while(not turtle.suckUp()) do
- sleep('No fuel found. Sleeping.', 10)
- end
- turtle.refuel(64)
- turtle.select(2)
- turtle.digUp()
- end
- --Dumps all items into the 1st enderchest
- local function dump()
- while(turtle.detectUp()) do
- turtle.digUp()
- end
- turtle.select(1)
- while(not turtle.placeUp()) do
- turtle.attackUp()
- end
- for i = 3, 16 do
- if(turtle.getItemCount(i) > 0) then
- turtle.select(i)
- while(not turtle.dropUp()) do
- sleep('Dropoff chest is full. Sleeping.', 10)
- end
- end
- end
- turtle.select(1)
- turtle.digUp()
- print('Dropoff successful')
- end
- local function dropoff()
- local empty = 0
- --Calculates number of empty slots
- for i = 2, 16 do
- if(turtle.getItemCount(i) == 0) then
- empty = empty + 1
- end
- end
- --Dumps items if the inventory is full
- if(empty == 0) then
- dump()
- end
- end
- --Clears the screen
- function clear()
- term.clear()
- term.setCursorPos(1, 1)
- end
- --Sleeps for %time% seconds, while displaying %text% and counting down
- function sleep(text, time)
- for i = 0, time - 1 do
- clear()
- print(text)
- print('Countdown: '..time - i..'s.')
- os.sleep(1)
- end
- end
- --Returns true if successful, and false if the block is bedrock
- local function bedrockTest()
- local test
- test = turtle.down()
- return test
- end
- --Moves up until reaching initial height
- function moveUp()
- for i = 1, y do
- refuel(200)
- while(not turtle.up()) do
- turtle.attackUp()
- turtle.digUp()
- end
- end
- end
- --Digging down until bedrock
- function digDown()
- local fail = 0
- while(true) do
- dropoff()
- refuel(500)
- turtle.digDown()
- if(not bedrockTest()) then
- os.sleep(0.2)
- fail = fail + 1
- if(fail == 6) then
- break
- end
- end
- end
- end
- --Mining loop
- function loop()
- while(x > 0) do
- print('Chunks left to mine: '..x)
- digDown()
- print('Hit bedrock, moving up '..y..' blocks')
- moveUp()
- while(not turtle.forward()) do
- turtle.attack()
- turtle.dig()
- end
- dump()
- x = x - 1
- save()
- end
- end
- --Init sequence
- function init()
- clear()
- y = tonumber(arg[1])
- y = y - 1
- x = tonumber(arg[2])
- while(turtle.getItemCount(1) ~= 1) do
- sleep('Wrong number of items in slot 1. Place one dropoff ender chest.', 5)
- end
- while(turtle.getItemCount(2) ~= 1) do
- sleep('Wrong number of items in slot 2. Place one fuel ender chest.', 5)
- end
- save()
- -- Creating startup file to continue mining after server restarts
- if(not fileExists('startup')) then
- local file = io.open('startup', 'w')
- file:write("shell.run(\'dig\')")
- file:close()
- end
- loop()
- end
- --------
- --MAIN--
- --------
- if(not fileExists('startup')) then
- for i = 1, 2 do
- if(arg[i] == nil) then
- print('Usage: dig <max Y> <length>')
- print('<max Y> - maximum height for mining (e.g. your Y coordinate).')
- print('<length> - number of blocks to mine forward.')
- do return end
- end
- end
- init()
- else
- clear()
- --Reading save file
- local file = io.open('save', 'r')
- y = tonumber(file:read('*l'))
- x = tonumber(file:read('*l'))
- file:close()
- --If rebooted while dumping items
- if(turtle.getItemCount(1) == 0) then
- turtle.select(1)
- turtle.digUp()
- dump()
- while(turtle.getItemCount(1) == 0) do
- sleep('Missing chest in slot 1.', 10)
- end
- end
- --If rebooted while refueling
- if(turtle.getItemCount(2) == 0) then
- turtle.select(2)
- turtle.digUp()
- refuel()
- while(turtle.getItemCount(1) == 0) do
- sleep('Missing chest in slot 2.', 10)
- end
- end
- loop()
- end
- --Finishing
- shell.run('delete', 'save')
- shell.run('delete', 'startup')
- print('Done!')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement