MadScience2728

MINECHUNKCLIENT

Mar 2nd, 2021 (edited)
641
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Awake
  2. print("Mining client awake: Hello World!")
  3.  
  4. -- Setup wireless
  5. local modem = peripheral.wrap("right")
  6. -- 11 Server -> Client
  7. -- 12 Client -> Server
  8. modem.open(11)
  9. modem.open(12)
  10. print("Channel 11 and 12 are open")
  11.  
  12. -- Setup receiving wireless messages
  13. function WaitForMessage(messageCompare)
  14.     while true do
  15.         local a,b,c,d,e,f = os.pullEvent("modem_message")
  16.         print("Message received: ")
  17.         print(e)
  18.         if(e == messageCompare) then
  19.             print("Message accepted")
  20.             break
  21.         end
  22.     end
  23. end
  24.  
  25. function IsTurtle()
  26.     local success, data = turtle.inspect()
  27.     if success then
  28.         return data.name == "computercraft:turtle_advanced"
  29.     else
  30.         return false
  31.     end
  32. end
  33.  
  34. -- Setup sending wireless messages
  35. function SendMessage(message)
  36.     modem.transmit(12, 11, message)
  37. end
  38.  
  39. -- Main loop
  40. while true do
  41.     print("Waiting to start next cycle")
  42.     WaitForMessage("_StartNextCycle")
  43.     print("Starting next cycle...")
  44.     while not IsTurtle() do
  45.         turtle.forward()
  46.     end
  47.     print(">>")
  48.     print(">>")
  49.     print(">>")
  50. end
  51.  
  52. print("Goodbye >>")
  53. read()
RAW Paste Data