Advertisement
Guest User

Quarry Receiver 3.0.4 FTB Compatible

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