Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. -- Mining Program --
  2. ProgramName='Mine'
  3. Position=1
  4.  
  5. local args={...}
  6. Position=arg[1]
  7. if Position==nil then Position=1 end
  8.  
  9. index=Position
  10. starting=1
  11.  
  12. function progress(I)
  13. fh=io.open('settings/last', 'w')
  14. fh:write(ProgramName..'\n')
  15. fh:write(I..'\n')
  16. fh:write(X..'\n')
  17. fh:write(Y..'\n')
  18. fh:write(Z..'\n')
  19. fh:write(Facing..'\n')
  20. fh:close()
  21. end
  22.  
  23.  
  24. if fs.exists('settings/last') then
  25. fh=io.open('settings/last')
  26. line=fh:read()
  27. index=tonumber(fh:read())
  28. X=tonumber(fh:read())
  29. Y=tonumber(fh:read())
  30. Z=tonumber(fh:read())
  31. Facing=tonumber(fh:read())
  32. fh:close()
  33. else
  34. fs.makeDir('settings')
  35. progress(Position)
  36. end
  37.  
  38.  
  39.  
  40. program='wwwwwwwwwwwwwwwrwwwrwllwllwrwwrrwwrwllwllwrwwrrwwrwllwllwrwwrrwwrwllwllwrwwrrwwrwllwllwrwww'
  41. FuelNeeded=count(program, 'w')
  42.  
  43. if turtle.getFuelLevel()<FuelNeeded then
  44. a=FuelNeeded-turtle.getFuelLevel()
  45. print('fuel too low, feed me '..(a/5)..' sticks.')
  46. while turtle.getFuelLevel()<FuelNeeded do
  47. a=FuelNeeded-turtle.getFuelLevel()
  48. turtle.select(15)
  49. turtle.refuel(a/5)
  50. end
  51. turtle.select(1)
  52. end
  53.  
  54. function count(base, pattern)
  55. return select(2, string.gsub(base, pattern, ''))
  56. end
  57.  
  58. function dig()
  59. turtle.dig()
  60. turtle.digUp()
  61. turtle.attack()
  62. success=turtle.forward()
  63. while success==false do
  64. turtle.dig()
  65. turtle.digUp()
  66. turtle.attack()
  67. success=turtle.forward()
  68. end
  69.  
  70. if Facing==0 then Z=Z-1 end
  71. if Facing==1 then X=X+1 end
  72. if Facing==2 then Z=Z+1 end
  73. if Facing==3 then X=X-1 end
  74. end
  75.  
  76.  
  77. while true do
  78. for i=starting, string.len(program)+1 do
  79. a=string.sub(program, index, index)
  80. index=index+1
  81. progress(index)
  82. print(a)
  83.  
  84. if a=='w' then
  85. dig()
  86. end
  87. if a=='r' then
  88. turtle.turnRight()
  89. Facing=Facing+1
  90. if Facing==4 then Facing=0 end
  91. end
  92. if a=='l' then
  93. turtle.turnLeft()
  94. Facing=Facing-1
  95. if Facing==-1 then Facing=3 end
  96. end
  97. if a=='c' then
  98. turtle.suck(50)
  99. end
  100. 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
  101. turtle.select(tonumber(a))
  102. end
  103. if a=='R' then
  104. turtle.refuel(50)
  105. end
  106. end
  107. index=0
  108. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement