Advertisement
MadScience2728

MINECLIENT_2.0

Mar 2nd, 2021 (edited)
1,136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Awake
  2. local Y = 52
  3. print("Mining client awake: Hello World!")
  4.  
  5. -- Setup wireless
  6. local modem = peripheral.wrap("right")
  7. -- 5 Server -> Client
  8. -- 6 Client -> Server
  9. modem.open(11)
  10. modem.open(12)
  11. print("Channel 11 and 12 are open")
  12.  
  13. -- Setup receiving wireless messages
  14. function WaitForMessage(messageCompare)
  15.     while true do
  16.         local a,b,c,d,e,f = os.pullEvent("modem_message")
  17.         print("Message received: ")
  18.         print(e)
  19.         if(e == messageCompare) then
  20.             print("Message accepted")
  21.             break
  22.         end
  23.     end
  24. end
  25.  
  26. -- Setup sending wireless messages
  27. function SendMessage(message)
  28.     modem.transmit(12, 11, message)
  29. end
  30.  
  31. -- Down shortdown
  32. function Down()
  33.     while not turtle.down() do
  34.         if turtle.detectDown() then turtle.digDown() end
  35.         turtle.attackDown()
  36.     end
  37.     turtle.dig()
  38. end
  39.  
  40. -- Up shorthand
  41. function Up()
  42.     while not turtle.up() do
  43.         if turtle.detectUp() then turtle.digUp() end
  44.         turtle.attackUp()
  45.     end
  46.     turtle.dig()
  47. end
  48.  
  49. -- Forward shorthand
  50. function Forward()
  51.     while not turtle.forward() do
  52.         if turtle.detect() then turtle.dig() end
  53.         turtle.attack()
  54.     end
  55. end
  56.  
  57. -- Bedrock shorthand
  58. function IsBedrock()
  59.     local success, data = turtle.inspectDown()
  60.     if success then
  61.         return data.name == "minecraft:bedrock"
  62.     else
  63.         return false
  64.     end
  65. end
  66.  
  67. -- Server handshake
  68. print("Waiting for server awake")
  69. WaitForMessage("_ServerAwake")
  70. print("Replying to server...")
  71. SendMessage("_TurtleRegistered")
  72.  
  73. -- Reset position
  74. print("Waiting for signal to reset Y")
  75. WaitForMessage("_ResetY")
  76. print("Resetting to y 55")
  77. turtle.select(1)
  78. turtle.dig()
  79. while not IsBedrock() do Down() end
  80. for i=0, Y do Up() end
  81.  
  82. print("Letting server know ready...")
  83. SendMessage("_TurtleReadyToMine")
  84.  
  85. print("Waiting to begin")
  86. WaitForMessage("_Begin")
  87.  
  88. -- Mine Routine
  89. function Mine()
  90.     Forward()
  91.     Forward()
  92.     turtle.dig()
  93.     for i=0, Y do Down() end
  94.     Forward()
  95.     Forward()
  96.     turtle.dig()
  97.     for i=0, Y do Up() end
  98.     turtle.select(1)
  99.     while not turtle.place() do
  100.         turtle.dig()
  101.         turtle.attack()
  102.     end
  103.     for i = 16,1,-1 do
  104.         turtle.select(i)
  105.         turtle.drop()
  106.     end
  107.     turtle.dig()
  108. end
  109.  
  110. -- Mine loop
  111. while true do
  112.     print("Waiting to start next cycle")
  113.     WaitForMessage("_StartNextCycle")
  114.     print("Starting next cycle...")
  115.     Mine()
  116.     print("Letting server know ready for next cycle...")
  117.     SendMessage("_ReadyForNextCycle")
  118.     print(">>")
  119.     print(">>")
  120.     print(">>")
  121. end
  122.  
  123. print("Goodbye >>")
  124. read()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement