SHOW:
|
|
- or go back to the newest paste.
1 | - | --pastebin get 2mvkUaWL startup |
1 | + | --pastebin get VHJ4gRX2 startup |
2 | ||
3 | -- Awake | |
4 | print("Tunnel Client Alive: Hello World!") | |
5 | ||
6 | -- Setup wireless | |
7 | local modem = peripheral.wrap("right") | |
8 | -- 210 Server -> Client | |
9 | -- 220 Client -> Server | |
10 | modem.open(210) | |
11 | modem.open(220) | |
12 | print("Channel 210 and 220 are open") | |
13 | ||
14 | -- Setup receiving wireless messages | |
15 | function WaitForMessage(messageCompare) | |
16 | while true do | |
17 | local a,b,c,d,e,f = os.pullEvent("modem_message") | |
18 | print("Message received: ") | |
19 | print(e) | |
20 | if(e == messageCompare) then | |
21 | print("Message accepted") | |
22 | break | |
23 | elseif (e == "_Empty") then | |
24 | return true | |
25 | end | |
26 | end | |
27 | return false | |
28 | end | |
29 | ||
30 | -- Setup sending wireless messages | |
31 | function SendMessage(message) | |
32 | modem.transmit(220, 210, message) | |
33 | end | |
34 | ||
35 | -- Forward shorthand | |
36 | function Forward() | |
37 | while not turtle.forward() do | |
38 | if turtle.detect() then turtle.dig() end | |
39 | turtle.attack() | |
40 | end | |
41 | end | |
42 | ||
43 | --Empty shorthand | |
44 | function Empty() | |
45 | turtle.dig() | |
46 | turtle.select(1) | |
47 | while not turtle.place() do | |
48 | turtle.dig() | |
49 | turtle.attack() | |
50 | end | |
51 | for i = 16,1,-1 do | |
52 | turtle.select(i) | |
53 | turtle.drop() | |
54 | end | |
55 | turtle.dig() | |
56 | end | |
57 | ||
58 | -- Server handshake | |
59 | print("Waiting for server awake") | |
60 | WaitForMessage("_ServerAwake") | |
61 | print("Replying to server...") | |
62 | SendMessage("_TurtleRegistered") | |
63 | ||
64 | print("Ensuring ender chest is inside me...") | |
65 | turtle.select(1) | |
66 | turtle.dig() | |
67 | ||
68 | print("Letting server know ready...") | |
69 | SendMessage("_TurtleReadyToMine") | |
70 | ||
71 | print("Waiting to begin") | |
72 | WaitForMessage("_Begin") | |
73 | ||
74 | -- Mine loop | |
75 | while true do | |
76 | print("Waiting to start next cycle") | |
77 | empty = WaitForMessage("_StartNextCycle") | |
78 | ||
79 | if empty then Empty() end | |
80 | ||
81 | print("Starting next cycle...") | |
82 | Forward() | |
83 | turtle.digDown() | |
84 | turtle.digUp() | |
85 | print("Letting server know ready for next cycle...") | |
86 | SendMessage("_ReadyForNextCycle") | |
87 | print(">>") | |
88 | print(">>") | |
89 | print(">>") | |
90 | end | |
91 | ||
92 | print("Goodbye >>") | |
93 | read() |