SHOW:
|
|
- or go back to the newest paste.
1 | --pastebin get p8QcFC8H startup | |
2 | - | print("Mining server awake: Hello World!") |
2 | + | |
3 | -- Awake | |
4 | print("Tunnel Server Alive: Hello World!") | |
5 | - | local modemSide = "left" |
5 | + | |
6 | - | local modem = peripheral.wrap(modemSide) |
6 | + | |
7 | - | -- 5 Server -> Client |
7 | + | local modem = peripheral.wrap("right") |
8 | - | -- 6 Client -> Server |
8 | + | -- 210 Server -> Client |
9 | - | -- 7 Server -> Pocket Computer |
9 | + | -- 220 Client -> Server |
10 | - | modem.open(110) |
10 | + | modem.open(210) |
11 | - | modem.open(120) |
11 | + | modem.open(220) |
12 | - | modem.open(130) |
12 | + | print("Channel 210 and 220 are open") |
13 | - | modem.open(140) |
13 | + | |
14 | - | print("Channel 110 and 120 are open, as well as 130 and 140") |
14 | + | |
15 | function SendMessage(message) | |
16 | modem.transmit(210, 220, message) | |
17 | end | |
18 | - | modem.transmit(110, 120, message) |
18 | + | |
19 | -- Setup receiving wireless messages | |
20 | - | function SendMessageToPocketComputer(message) |
20 | + | |
21 | - | modem.transmit(130, 130, message) |
21 | + | |
22 | local | |
23 | a,b,c,d,e,f = os.pullEvent("modem_message") | |
24 | - | --Pocket computer helper |
24 | + | print("Message received: " .. tostring(e)) |
25 | - | function printf(m) |
25 | + | |
26 | - | print(m) |
26 | + | |
27 | - | SendMessageToPocketComputer(m) |
27 | + | |
28 | end | |
29 | - | printf("Link to pocket computer established. Hello") |
29 | + | |
30 | ||
31 | -- Get turtle amount from user | |
32 | print("How many turtles are mining? >>") | |
33 | local desiredTurtleCount = tonumber(read()) | |
34 | ||
35 | -- Get skip checks from user | |
36 | - | printf("Message received: " .. tostring(e)) |
36 | + | print("Skip handshake? (y/n) >>") |
37 | local skipHandshake = read() | |
38 | ||
39 | if skipHandshake == "n" then | |
40 | -- Send awake signal | |
41 | print("Sending awake signal to all turtles...") | |
42 | SendMessage("_ServerAwake") | |
43 | - | -- Get turtle amount from users |
43 | + | |
44 | - | printf("How many turtles are mining? >>") |
44 | + | -- Wait for all turtles to register |
45 | print("Waiting for turtles to register...") | |
46 | local turtleCount = 0 | |
47 | - | -- Get cycle amount from users |
47 | + | while true do |
48 | - | printf("How many cycles should they mine for? >>") |
48 | + | WaitForMessage("_TurtleRegistered") |
49 | - | local desiredCycleCount = tonumber(read()) |
49 | + | turtleCount = turtleCount + 1 |
50 | print("Turtle registered. Count is " .. tostring(turtleCount)) | |
51 | - | -- Send awake signal |
51 | + | if(turtleCount == desiredTurtleCount) then break end |
52 | - | printf("Sending awake signal to all turtles...") |
52 | + | |
53 | - | SendMessage("_ServerAwake") |
53 | + | print("All turtles registered") |
54 | ||
55 | - | -- Wait for all turtles to register |
55 | + | -- Wait for all turtles to reset their y pos |
56 | - | -- Accept and continue from user |
56 | + | print("Waiting for turtles to be ready to mine...") |
57 | - | printf("Waiting for turtles to register...") |
57 | + | local turtleCount = 0 |
58 | - | local turtleCount = 0 |
58 | + | while true do |
59 | WaitForMessage("_TurtleReadyToMine") | |
60 | - | WaitForMessage("_TurtleRegistered") |
60 | + | turtleCount = turtleCount + 1 |
61 | - | turtleCount = turtleCount + 1 |
61 | + | print("Turtle ready to mine. Count is " .. tostring(turtleCount)) |
62 | - | printf("Turtle registered. Count is " .. tostring(turtleCount)) |
62 | + | if(turtleCount == desiredTurtleCount) then break end |
63 | - | if(turtleCount == desiredTurtleCount) then break end |
63 | + | |
64 | print("All turtles ready to mine") | |
65 | - | printf("All turtles registered") |
65 | + | |
66 | -- Begin managing mine operations | |
67 | - | printf("Sending reset Y signal") |
67 | + | print("Mining...") |
68 | - | SendMessage("_ResetY") |
68 | + | SendMessage("_Begin") |
69 | end | |
70 | - | -- Wait for all turtles to reset their y pos |
70 | + | |
71 | - | printf("Waiting for turtles to be ready to mine...") |
71 | + | |
72 | - | local turtleCount = 0 |
72 | + | |
73 | local emptyCount = 0 | |
74 | - | WaitForMessage("_TurtleReadyToMine") |
74 | + | |
75 | - | turtleCount = turtleCount + 1 |
75 | + | print("Starting mine cycle #" .. tostring(cycleCount)) |
76 | - | printf("Turtle ready to mine. Count is " .. tostring(turtleCount)) |
76 | + | if emptyCount == 64 then |
77 | - | if(turtleCount == desiredTurtleCount) then break end |
77 | + | SendMessage("_Empty") |
78 | emptyCount = 0 | |
79 | - | printf("All turtles ready to mine") |
79 | + | else |
80 | os.sleep(0.05) | |
81 | - | -- Begin managing mine operations |
81 | + | SendMessage("_StartNextCycle") |
82 | - | printf("Mining...") |
82 | + | |
83 | - | SendMessage("_Begin") |
83 | + | print("Waiting for turtles to be ready for next cycle...") |
84 | readyCount = 0 | |
85 | while true do | |
86 | WaitForMessage("_ReadyForNextCycle") | |
87 | - | printf("Starting mine cycle #" .. tostring(cycleCount)) |
87 | + | |
88 | - | SendMessage("_StartNextCycle") |
88 | + | print("A turtle is ready. Ready count is " .. tostring(readyCount)) |
89 | - | printf("Waiting for turtles to be ready for next cycle...") |
89 | + | if(readyCount == desiredTurtleCount) then |
90 | print("All turtles ready") | |
91 | break | |
92 | end | |
93 | end | |
94 | - | printf("A turtle is ready. Ready count is " .. tostring(readyCount)) |
94 | + | |
95 | - | if(readyCount == turtleCount) then |
95 | + | emptyCount = emptyCount + 1 |
96 | - | printf("All turtles ready") |
96 | + | print(">>") |
97 | print(">>") | |
98 | print(">>") | |
99 | end | |
100 | - | if(cycleCount == desiredCycleCount) then |
100 | + | |
101 | - | printf("All cycle complete") |
101 | + | |
102 | - | break |
102 | + | print("Goodbye >>") |
103 | read() |