Advertisement
Guest User

Quarry Receiver 3.0.4

a guest
May 6th, 2013
1,332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.62 KB | None | 0 0
  1. --Made for version 3.0.4
  2. --Remember to release an FTB compatible version that removes the sendMsg after receives
  3. --In the future, rewrite this all to make it make more sense. As of now the whole scheme does not
  4. --E.g. Keep a record of what line it is on, have different messages for all the items.
  5. --Maybe have each item in a table with a table.display value that changes based on screenX and screenY
  6. --Make multiple colors if supported by the monitor :)
  7. --I'll just put this here: Make a shell program that can automate quarries and start this program automatically. Really cool.
  8. tArgs = {...}
  9. sides = {front = "front", back = "back", left = "left", right = "right", top = "top", bottom = "bottom"}
  10. local xScale, yScale = 0,0
  11. local screenX, screenY = term.getSize()
  12. if screenX >= 7 then xScale = 1 end
  13. if screenX >= 18 then xScale = 2 end
  14. if screenX >= 29 then xScale = 3 end
  15. if screenY >= 5 then yScale = 1 end
  16. if screenY >= 12 then yScale = 2 end
  17. assert(yScale >= 1 and xScale >= 1, "Screen Size too small: "..tostring(screenX).." by "..tostring(screenY))
  18. if screenX >= 35 and screenY >= 10 then local fullscreen = true else local fullscreen = false end
  19. --X scale of 3 and Y scale of 2 is fullscreen
  20.  
  21. local interval = 1
  22. if not term.isColor() then
  23. term.setTextColor = function() return false end
  24. term.setBackgroundColor = function() return false end; end
  25. local function output(text,xPos,yPos,doClear)
  26. term.setCursorPos(xPos,yPos); if doClear then term.clearLine() end
  27. io.write(text); return #text+2 end
  28. local function screenLine(x,y)
  29. term.setCursorPos(x,y); term.clearLine() end
  30. local errorMessage = "Improper Side"
  31. term.clear(); term.setCursorPos(1,1)
  32. if tArgs[1] then
  33. modemSide = assert(sides[tArgs[1]], errorMessage )
  34. else
  35. print("Modem Side?")
  36. modemSide = assert(sides[read()], errorMessage)
  37. end
  38. modem = peripheral.wrap(modemSide)
  39. local sender
  40. if tonumber(tArgs[2]) then
  41. sender = tonumber(tArgs[2])
  42. else
  43. print("Receiving channel? (Check the turtle)")
  44. sender = assert(tonumber(io.read()))
  45. end
  46. assert(sender == math.floor(sender), "Channel cannot be a decimal")
  47. assert(sender < 65535 and sender > 0, "Channel cannot be below 1 or above 65535")
  48. modem.open(sender)
  49.  
  50. local relayMessage = "Confirm"
  51. local origRelayMessage = relayMessage
  52. local replyChannel, startDist
  53. term.clear()
  54. term.setCursorPos(1,1)
  55. print("Welcome to the Quarry Receiver Program!")
  56. print("Waiting for a turtle to send initial message")
  57. repeat
  58. local event, modemSide, sendChannel, repChannel, message, distance = os.pullEvent("modem_message")
  59. startDist = distance
  60. replyChannel = repChannel
  61. until sendChannel == sender and textutils.unserialize(message)
  62. local function sendMsg(message)
  63. modem.transmit(replyChannel, sender, message)
  64. end
  65. sendMsg(relayMessage)
  66. print("Now paired with turtle on Channel ",sender,". Sending back on Channel ",replyChannel)
  67. sleep(0.5)
  68.  
  69. local function pullChar()
  70. while relayMessage ~= "stop" do
  71. sleep(0.5)
  72. output("Type Command\n",1,screenY-1,true)
  73. relayMessage = string.lower(io.read())
  74. end
  75. end
  76.  
  77. local utils = {}
  78. if xScale == 3 then utils.percent = "Percent Complete: "
  79. elseif xScale == 2 then utils.percent = "Percent Done: "
  80. else utils.percent = "% " end
  81. if xScale == 3 then utils.x = "Length X-"; utils.z = "Rows-"; utils.y = "Layers-"
  82. elseif xScale == 2 then utils.x = "X:"; utils.z = "Z:"; utils.y = "Y:"; end
  83.  
  84. local function main()
  85. local message
  86. term.clear()
  87. while message ~= "stop" do
  88. repeat
  89. local event, idCheck, sendChannel, _, locMessage, distance = os.pullEvent()
  90. message = locMessage
  91. until (event == "modem_message" and idCheck == modemSide and sendChannel == sender)
  92. sendMsg(relayMessage)
  93. message = textutils.unserialize(message) or "stop"
  94. relayMessage = origRelayMessage
  95. if message ~= "stop" then
  96. output(utils.percent..message.percent,1,1)
  97. if yScale == 2 then
  98. output("Dimensions: ",1,2,true)
  99. local a,b; if xScale == 1 then a,b = 4, 7 elseif xScale ==2 then a, b = 6, 11 else a,b = 18,30 end --To accomadate smaller screens, pos.
  100. output(utils.x..message.x,1,3,true); output(utils.z..message.z,a,3); output(utils.y..message.y,b,3)
  101. if xScale ==3 then
  102. output("Position in Row: "..message.xPos,1,4,true); output("Row this Layer: "..message.zPos,1,5,true); output("On Layer: "..math.ceil(message.yPos/3),1,6,true)
  103. elseif xScale == 2 then
  104. output("X:"..message.xPos.." Z:"..message.zPos.." Y:"..math.ceil(message.yPos/3),1,4,true)
  105. elseif xScale == 1 then
  106. output(message.xPos.." "..message.zPos.." "..math.ceil(message.yPos/3),1,4,true)
  107. end
  108. else
  109. if xScale >= 2 then
  110. output("X:"..message.xPos.." Z:"..message.zPos.." Y:"..math.ceil(message.yPos/3),1,3,true)
  111. else
  112. output(message.xPos.." "..message.zPos.." "..math.ceil(message.yPos/3),1,3,true)
  113. end
  114. end
  115. local condition = (message.z == message.zPos) and (message.x == message.xPos) --At start of layer
  116. if xScale >= 2 and yScale == 2 then
  117. if condition then output("Going 2 next layer",1,7) elseif message.isInPath then screenLine(1,7) end
  118. if message.y == math.ceil(message.yPos/3) and condition then output("Going back to start",1,8) elseif message.isInPath then screenLine(1,8) end
  119. if message.xPos == 0 then output("Calculating materials",1,9) else screenLine(1,9) end
  120. end
  121. if fullscreen then
  122. output("Type Command\n",1,screenY-1)
  123. end
  124. end
  125. end
  126. end
  127.  
  128. local order
  129. if fullscreen then order = parallel.waitForAny(main, pullChar)
  130. else main(); order = 1 end
  131. modem.close(sender)
  132. term.setCursorPos(1,1)
  133. term.clear()
  134. local doneType
  135. if order == 1 then
  136. doneType = "Turtle Finished"
  137. messageT = textutils.unserialize(({os.pullEvent("modem_message")})[5])
  138. for i=1, #messageT do
  139. for a, b in pairs(messageT[i]) do
  140. print(a,b) end
  141. end
  142. else doneType = "Program Aborted" end
  143. error(doneType,0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement