daily pastebin goal
77%
SHARE
TWEET

Quarry Receiver 3.0.3 FTB Compatible

a guest May 3rd, 2013 96 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Made for version 3.0.3
  2. tArgs = {...}
  3. sides = {front = "front", back = "back", left = "left", right = "right", top = "top", bottom = "bottom"}
  4. local screenX, screenY = term.getSize()
  5. assert(screenY > 8 and screenX > 35, "Screen too small")
  6. local interval = 1
  7. if not term.isColor() then
  8. term.setTextColor = function() return false end
  9. term.setBackgroundColor = function() return false end; end
  10. local function output(text,xPos,yPos,doClear)
  11. term.setCursorPos(xPos,yPos); if doClear then term.clearLine() end
  12. io.write(text); return #text+2 end
  13. local errorMessage = "Improper Side"
  14. term.clear(); term.setCursorPos(1,1)
  15. if tArgs[1] then
  16. modemSide = assert(sides[tArgs[1]], errorMessage )
  17. else
  18. print("Modem Side?")
  19. modemSide = assert(sides[read()], errorMessage)
  20. end
  21. modem = peripheral.wrap(modemSide)
  22. local sender
  23. if tonumber(tArgs[2]) then
  24. sender = tonumber(tArgs[2])
  25. else
  26. print("Receiving channel? (Check the turtle)")
  27. sender = assert(tonumber(io.read()))
  28. end
  29. assert(sender == math.floor(sender), "Channel cannot be a decimal")
  30. assert(sender < 65535 and sender > 0, "Channel cannot be below 1 or above 65535")
  31. modem.open(sender)
  32.  
  33. local relayMessage = "Confirm"
  34. local origRelayMessage = replyMessage
  35. local replyChannel, startDist
  36. term.clear()
  37. term.setCursorPos(1,1)
  38. print("Welcome to the Quarry Receiver Program!")
  39. print("Waiting for a turtle to send initial message")
  40. repeat
  41. local event, modemSide, sendChannel, repChannel, message, distance = os.pullEvent("modem_message")
  42. startDist = distance
  43. replyChannel = repChannel
  44. until sendChannel == sender and textutils.unserialize(message)
  45. local function sendMsg(message)
  46. modem.transmit(replyChannel, sender, message)
  47. end
  48. sendMsg(relayMessage)
  49. print("Now paired with turtle on Channel ",sender,". Sending back on Channel ",replyChannel)
  50. sleep(0.5)
  51.  
  52. local function pullChar()
  53. while relayMessage ~= "stop" do
  54. --[[repeat
  55. local _, key = os.pullEvent("char")
  56. until key == "a" ]]
  57. sleep(0.5)
  58. output("Type Command\n",1,screenY-1,true)
  59. relayMessage = string.lower(io.read())
  60. end
  61. end
  62.  
  63. local function main()
  64. local message
  65. local timeWaited = 0 --For seconds since last, may fix later
  66. term.clear()
  67. while message ~= "stop" do
  68. repeat
  69. local id = os.startTimer(interval)
  70. local event, idCheck, sendChannel, _, locMessage, distance = os.pullEvent()
  71. message = locMessage
  72. if (event == "timer" and idCheck == id) then timeWaited = timeWaited + interval else timeWaited = 0 end
  73. until (event == "modem_message" and idCheck == modemSide and sendChannel == sender) or (event == "timer" and idCheck == id)
  74. sendMsg(relayMessage)
  75. message = textutils.unserialize(message) or "stop"
  76. relayMessage = origRelayMessage
  77. if message ~= "stop" then
  78. output("Percent Complete: "..message.percent,1,1)
  79. output("Dimensions: ",1,2,true)
  80. output("Length X-"..message.x,1,3); output("Rows-"..message.z,18,3); output("Layers-"..message.y,30,3)
  81. output("Position in Row: "..message.xPos,1,4); output("Row this Layer: "..message.zPos,1,5); output("On Layer: "..math.ceil(message.yPos/3),1,6)
  82. local condition = (message.z == message.zPos) and (message.x == message.xPos)
  83. if  condition then output("Going to next layer",1,7) elseif message.isInPath then output("",1,7,true) end
  84. if message.y == math.ceil(message.yPos/3) and condition then output("Going back to start",1,8) end
  85. if message.xPos == 0 then output("Calculating materials",1,9) end
  86. --output("Time since last message: "..timeWaited.." Seconds",1,7,true) --Broken
  87. output("Type Command\n",1,screenY-1)
  88. end
  89. end
  90. end
  91.  
  92. local order = parallel.waitForAny(main, pullChar)
  93. modem.close(sender)
  94. term.setCursorPos(1,1)
  95. term.clear()
  96. local doneType
  97. if order == 1 then
  98. doneType = "Turtle Finished"
  99. messageT = textutils.unserialize(({os.pullEvent("modem_message")})[5])
  100. for i=1, #messageT do
  101. for a, b in pairs(messageT[i]) do
  102. print(a,b) end
  103. end
  104. else doneType = "Program Aborted" end
  105. error(doneType,0)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top