Advertisement
1lann

cobblegen

Jul 29th, 2012
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. server = 000
  2. side = "top"
  3. chest = false
  4.  
  5. function round(number)
  6. if (number % 1) < 0.5 then
  7. return math.floor(number)
  8. else
  9. return math.ceil(number)
  10. end
  11. end
  12.  
  13. counter = 0
  14. oldclock = os.clock()
  15. dClock = os.clock()
  16. total = 0
  17. if peripheral.getType("top") == "monitor" then
  18. monitor = true
  19. else monitor = false
  20. end
  21. for i = 1, 9 do
  22. total = turtle.getItemCount(i) + total
  23. end
  24. timetil = round((1024 - total)*1.47)
  25. if monitor then
  26. mon = peripheral.wrap("top")
  27. mon.setTextScale(1)
  28. mon.clear()
  29. end
  30. term.clear()
  31. while total < 1024 do
  32. turtle.select(1)
  33. status = "Generating cobble"
  34. if turtle.detect() then
  35. dClock = os.clock()
  36. ret = turtle.dig()
  37. if not ret then
  38. status = "Cannot mine block!"
  39. end
  40. else
  41. if (os.clock() - dClock) > 3 then
  42. status = "Cobble not found!"
  43. end
  44. end
  45. sleep(0.0001)
  46. total = 0
  47. for i = 1, 16 do
  48. total = turtle.getItemCount(i) + total
  49. end
  50. if monitor then
  51. mon.clear()
  52. mon.setCursorPos(1, 1)
  53. end
  54. etime = round(os.clock() - oldclock)
  55. if status ~= "Generating cobble" then
  56. else
  57. if oldtotal == total and oldetime ~= etime then
  58. if counter < 6 then
  59. timetil = timetil-(etime - oldetime)
  60. counter = counter+1
  61. else
  62. counter = 0
  63. timetil = round((1024 - total)*1.47)
  64. end
  65. elseif round((1024 - total)*1.47) < timetil then
  66. counter = 0
  67. timetil = round((1024 - total)*1.47)
  68. end
  69. end
  70. per = round((total/1024)*23)
  71. bar = string.rep("=", per)
  72. if monitor then
  73. mon.setCursorPos(1, 1)
  74. mon.write("Status: " .. status)
  75. mon.setCursorPos(1, 2)
  76. mon.write("Total cobble: " .. total)
  77. mon.setCursorPos(1, 3)
  78. mon.write("Time elapsed: " .. etime .. " seconds")
  79. mon.setCursorPos(1, 4)
  80. mon.write("Time to finish: " .. timetil .. " seconds")
  81. mon.setCursorPos(1, 5)
  82. mon.write("[" .. bar)
  83. mon.setCursorPos(26, 5)
  84. mon.write("]")
  85. end
  86. term.clear()
  87. term.setCursorPos(1, 1)
  88. print("Status: " .. status)
  89. print("Total cobble: " .. total)
  90. print("Time elapsed: " .. etime .. " seconds")
  91. print("Time to finish: " .. timetil .. " seconds")
  92. print("[" .. bar)
  93. term.setCursorPos(26, 5)
  94. print("]")
  95. oldtotal = total
  96. oldetime = etime
  97. end
  98. if monitor then
  99. mon.setCursorPos(1, 1)
  100. mon.clearLine()
  101. mon.write("Status: Full!")
  102. mon.setCursorPos(1, 5)
  103. mon.clearLine()
  104. mon.write("Please empty and reboot!")
  105. end
  106. term.setCursorPos(1, 1)
  107. term.clearLine()
  108. write("Status: Full!")
  109. term.setCursorPos(1, 5)
  110. term.clearLine()
  111. if not chest then
  112. write("Press [CTRL] to empty and reboot!")
  113. while true do
  114.   event, key = os.pullEvent("key")
  115.   if key == 29 then break end
  116. end
  117. end
  118. turtle.turnLeft()
  119. turtle.turnLeft()
  120. for i = 1, 16 do
  121. turtle.select(i)
  122. turtle.drop()
  123. end
  124. turtle.select(1)
  125. turtle.turnLeft()
  126. turtle.turnLeft()
  127. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement