Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Mining Program --
- ProgramName='Mine'
- Position=1
- local args={...}
- Position=arg[1]
- if Position==nil then Position=1 end
- index=Position
- starting=1
- function progress(I)
- fh=io.open('settings/last', 'w')
- fh:write(ProgramName..'\n')
- fh:write(I..'\n')
- fh:write(X..'\n')
- fh:write(Y..'\n')
- fh:write(Z..'\n')
- fh:write(Facing..'\n')
- fh:close()
- end
- if fs.exists('settings/last') then
- fh=io.open('settings/last')
- line=fh:read()
- index=tonumber(fh:read())
- X=tonumber(fh:read())
- Y=tonumber(fh:read())
- Z=tonumber(fh:read())
- Facing=tonumber(fh:read())
- fh:close()
- else
- fs.makeDir('settings')
- progress(Position)
- end
- program='wwwwwwwwwwwwwwwrwwwrwllwllwrwwrrwwrwllwllwrwwrrwwrwllwllwrwwrrwwrwllwllwrwwrrwwrwllwllwrwww'
- FuelNeeded=count(program, 'w')
- if turtle.getFuelLevel()<FuelNeeded then
- a=FuelNeeded-turtle.getFuelLevel()
- print('fuel too low, feed me '..(a/5)..' sticks.')
- while turtle.getFuelLevel()<FuelNeeded do
- a=FuelNeeded-turtle.getFuelLevel()
- turtle.select(15)
- turtle.refuel(a/5)
- end
- turtle.select(1)
- end
- function count(base, pattern)
- return select(2, string.gsub(base, pattern, ''))
- end
- function dig()
- turtle.dig()
- turtle.digUp()
- turtle.attack()
- success=turtle.forward()
- while success==false do
- turtle.dig()
- turtle.digUp()
- turtle.attack()
- success=turtle.forward()
- end
- if Facing==0 then Z=Z-1 end
- if Facing==1 then X=X+1 end
- if Facing==2 then Z=Z+1 end
- if Facing==3 then X=X-1 end
- end
- while true do
- for i=starting, string.len(program)+1 do
- a=string.sub(program, index, index)
- index=index+1
- progress(index)
- print(a)
- if a=='w' then
- dig()
- end
- if a=='r' then
- turtle.turnRight()
- Facing=Facing+1
- if Facing==4 then Facing=0 end
- end
- if a=='l' then
- turtle.turnLeft()
- Facing=Facing-1
- if Facing==-1 then Facing=3 end
- end
- if a=='c' then
- turtle.suck(50)
- end
- if a=='1' or a=='2' or a=='3' or a=='4' or a=='5' or a=='6' or a=='7' or a=='8' or a=='9' then
- turtle.select(tonumber(a))
- end
- if a=='R' then
- turtle.refuel(50)
- end
- end
- index=0
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement