Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.66 KB | None | 0 0
  1. rednet.open("left")
  2.  
  3. local frameCoords = {}
  4. frameCoords["x"] = 0
  5. frameCoords["y"] = 0
  6. frameCoords["z"] = 0
  7.  
  8. local directions = {}
  9.  
  10. local seaLevelY = 80
  11. local frameCompID = 6
  12. local moveDelay = 0.5
  13. local stop = false
  14.  
  15. local autoMode = false
  16. local domeActive = false
  17. local cycleActive = false
  18. local rsColor = 0
  19.  
  20.  
  21. local currentFunction = ""
  22.  
  23. function setDirections()
  24. directions["Forward"] = colors.brown
  25. directions["Backward"] = colors.blue
  26. directions["Up"] = colors.green
  27. directions["Down"] = colors.red
  28. end
  29.  
  30. function getFrameLoc()
  31. local data = {}
  32. local id,msg,proto
  33. repeat
  34. rednet.send(frameCompID, "GPS")
  35. id,msg,proto = rednet.receive(0.1)
  36. if msg then
  37. data = textutils.unserialize(msg)
  38. if data[0] == "CurrentFunction" then
  39. sendCurrentFunction(id)
  40. elseif data[0] == "STOP" then
  41. print("GetLoc - Stopping")
  42. stop = true
  43. end
  44. end
  45. until data["x"]
  46.  
  47. return data["x"], data["y"], data["z"]
  48. end
  49.  
  50. function setFrameCoords()
  51. frameCoords["x"], frameCoords["y"], frameCoords["z"] = getFrameLoc()
  52. end
  53.  
  54. function checkMove()
  55. local x,y,z = getFrameLoc()
  56. if frameCoords["x"] == x and frameCoords["y"] == y and frameCoords["z"] == z then
  57. return false
  58. else
  59. return true
  60. end
  61. end
  62.  
  63. function sendItems()
  64. currentFunction = "SendItems"
  65. pulseWire(colors.purple, 2)
  66. currentFunction = ""
  67. end
  68.  
  69. function pulseWire(color, delay)
  70. rsColor = rsColor+color
  71. rs.setBundledOutput("right", rsColor)
  72. checkMessageStop(delay)
  73. rsColor = rsColor-color
  74. rs.setBundledOutput("right", rsColor)
  75. end
  76.  
  77. function moveFrame(direction)
  78. currentFunction = direction
  79. repeat
  80. pulseWire(directions[direction], 0.5)
  81. until checkMove()
  82. setFrameCoords()
  83. currentFunction = ""
  84. end
  85.  
  86. function moveFrameNoCheck(direction)
  87. pulseWire(directions[direction], 0.5)
  88. end
  89.  
  90. function checkMessageStop(delay)
  91. local timerCode = os.startTimer(delay)
  92. local event,id,msg,proto
  93. repeat
  94. event,id,msg,proto = os.pullEvent()
  95. if event=="rednet_message" then
  96. data = textutils.unserialize(msg)
  97. if data[0] == "STOP" then
  98. print("checkStop - Stopping")
  99. stop = true
  100. elseif data[0] == "CurrentFunction" then
  101. sendCurrentFunction(id)
  102. end
  103. end
  104. until id == timerCode
  105. return false
  106. end
  107.  
  108. function sendCurrentFunction(id)
  109. local data = {}
  110. print("Current Function: "..currentFunction)
  111. data[0] = currentFunction
  112. data[1] = autoMode
  113. data[2] = cycleActive
  114. rednet.send(id,textutils.serialize(data))
  115. end
  116.  
  117. function toY(level)
  118. while frameCoords["y"] ~= level do
  119. if stop then
  120. autoMode = false
  121. break
  122. end
  123. print(frameCoords["y"])
  124. if level < frameCoords["y"] then
  125. moveFrameNoCheck("Down")
  126. else
  127. moveFrameNoCheck("Up")
  128. end
  129. setFrameCoords()
  130. end
  131.  
  132. end
  133.  
  134. function toBedrock()
  135. currentFunction = "Bedrock"
  136. toY(6)
  137. currentFunction = ""
  138. end
  139.  
  140. function toSky()
  141. currentFunction = "SeaLevel"
  142. toY(seaLevelY)
  143. currentFunction = ""
  144. end
  145.  
  146. function mineCycle()
  147. cycleActive = true
  148. toBedrock()
  149. sleep(2)
  150. toSky()
  151. cycleActive = false
  152. end
  153.  
  154. function nextCycle()
  155. cycleActive = true
  156. toSky()
  157. sendItems()
  158. moveAhead(8)
  159. cycleActive = false
  160. end
  161.  
  162. function moveAhead(times)
  163. if stop then
  164. autoMode = false
  165. return false
  166. end
  167. for i = 1,times do
  168. moveFrame("Forward")
  169. end
  170. end
  171.  
  172. function printCoords()
  173. setFrameCoords()
  174. print(frameCoords["x"]..", "..frameCoords["y"]..", "..frameCoords["z"])
  175. end
  176.  
  177. function sendComplete(id)
  178. rednet.send(id, "Complete")
  179. end
  180.  
  181. function autoMine()
  182. mineCycle()
  183. sendItems()
  184. moveAhead(8)
  185. end
  186.  
  187. function dome()
  188. if domeActive then
  189. rsColor = 0
  190. else
  191. rsColor = colors.cyan
  192. end
  193. rs.setBundledOutput("right", rsColor)
  194. end
  195.  
  196. function setDomeActive(active)
  197. domeActive = active
  198. end
  199.  
  200. function setAutoMode(mode)
  201. autoMode = mode
  202. end
  203.  
  204. function getmsg()
  205. --dome()
  206. setFrameCoords()
  207. stop = false
  208. if autoMode then
  209. autoMine()
  210. else
  211. local data = {}
  212. local id, message, distance, protocol = rednet.receive()
  213. print("MainFunct: "..message)
  214. data = textutils.unserialize(message)
  215. if data[0] == "moveFrame" then
  216. moveFrame(data[1])
  217. setFrameCoords()
  218. currentFunction = ""
  219. --sendComplete(id)
  220. elseif data[0] == "Bedrock" then
  221. toBedrock()
  222. elseif data[0] == "SeaLevel" then
  223. toSky()
  224. elseif data[0] == "SendItems" then
  225. sendItems()
  226. elseif data[0] == "CurrentFunction" then
  227. sendCurrentFunction(id)
  228. elseif data[0] == "AutoMode" then
  229. setAutoMode(true)
  230. elseif data[0] == "Dome" then
  231. setDomeActive(not domeActive)
  232. elseif data[0] == "Cycle" then
  233. autoMine()
  234. elseif data[0] == "NextCycle" then
  235. nextCycle()
  236. end
  237. end
  238. end
  239.  
  240.  
  241. printCoords()
  242. setDirections()
  243. while true do
  244. getmsg()
  245. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement