SHOW:
|
|
- or go back to the newest paste.
| 1 | -- Awake | |
| 2 | print("Mining client awake: Hello World!")
| |
| 3 | ||
| 4 | -- Setup wireless | |
| 5 | - | local modemSide = "left" |
| 5 | + | local modem = peripheral.wrap("right")
|
| 6 | - | local modem = peripheral.wrap(modemSide) |
| 6 | + | |
| 7 | -- 6 Client -> Server | |
| 8 | modem.open(5) | |
| 9 | modem.open(6) | |
| 10 | print("Channel 5 and 6 are open")
| |
| 11 | ||
| 12 | -- Setup receiving wireless messages | |
| 13 | function WaitForMessage(messageCompare) | |
| 14 | while true do | |
| 15 | - | print("A")
|
| 15 | + | local a,b,c,d,e,f = os.pullEvent("modem_message")
|
| 16 | print("Message received: ")
| |
| 17 | - | print("B")
|
| 17 | + | print(e) |
| 18 | - | local |
| 18 | + | if(e == messageCompare) then |
| 19 | - | event, |
| 19 | + | print("Message accepted")
|
| 20 | - | eventModemSide, |
| 20 | + | |
| 21 | - | senderChannel, |
| 21 | + | |
| 22 | - | replyChannel, |
| 22 | + | |
| 23 | - | message, |
| 23 | + | |
| 24 | - | senderDistance = |
| 24 | + | |
| 25 | - | os.pullEvent("modem_message")
|
| 25 | + | |
| 26 | - | os.sleep(1) |
| 26 | + | |
| 27 | - | print("C")
|
| 27 | + | |
| 28 | - | print("Message received: " + message)
|
| 28 | + | |
| 29 | - | if(message == messageCompare) then |
| 29 | + | |
| 30 | - | print("D")
|
| 30 | + | |
| 31 | print("Waiting for server awake")
| |
| 32 | WaitForMessage("_ServerAwake")
| |
| 33 | print("Replying to server...")
| |
| 34 | SendMessage("_TurtleRegistered")
| |
| 35 | print("Waiting to begin")
| |
| 36 | WaitForMessage("_Begin")
| |
| 37 | ||
| 38 | function Down() | |
| 39 | while not turtle.down() do | |
| 40 | if turtle.detectDown() then turtle.digDown() end | |
| 41 | turtle.attackDown() | |
| 42 | end | |
| 43 | - | local a,b,c,d,e,f = os.pullEvent("modem_message")
|
| 43 | + | turtle.dig() |
| 44 | - | --WaitForMessage("_ServerAwake")
|
| 44 | + | |
| 45 | - | --os.sleep(1) |
| 45 | + | |
| 46 | function Up() | |
| 47 | while not turtle.up() do | |
| 48 | if turtle.detectUp() then turtle.digUp() end | |
| 49 | turtle.attackUp() | |
| 50 | end | |
| 51 | turtle.dig() | |
| 52 | end | |
| 53 | - | print("Mining...")
|
| 53 | + | |
| 54 | - | os.sleep(1) |
| 54 | + | function Forward() |
| 55 | - | print("Mine")
|
| 55 | + | while not turtle.forward() do |
| 56 | - | os.sleep(1) |
| 56 | + | if turtle.detect() then turtle.dig() end |
| 57 | - | print("Mine")
|
| 57 | + | turtle.attack() |
| 58 | - | os.sleep(1) |
| 58 | + | end |
| 59 | - | print("Mine")
|
| 59 | + | |
| 60 | - | os.sleep(1) |
| 60 | + | |
| 61 | - | print("Mine")
|
| 61 | + | |
| 62 | - | os.sleep(1) |
| 62 | + | |
| 63 | - | print("Done mining")
|
| 63 | + | local Y = 52 |
| 64 | Forward() | |
| 65 | Forward() | |
| 66 | turtle.dig() | |
| 67 | for i=0, Y do Down() end | |
| 68 | Forward() | |
| 69 | Forward() | |
| 70 | turtle.dig() | |
| 71 | for i=0, Y do Up() end | |
| 72 | turtle.select(1) | |
| 73 | while not turtle.place() do | |
| 74 | turtle.dig() | |
| 75 | turtle.attack() | |
| 76 | end | |
| 77 | for i = 16,1,-1 do | |
| 78 | turtle.select(i) | |
| 79 | turtle.drop() | |
| 80 | end | |
| 81 | turtle.dig() | |
| 82 | end | |
| 83 | ||
| 84 | -- Mine loop | |
| 85 | while true do | |
| 86 | print("Waiting to start next cycle")
| |
| 87 | WaitForMessage("_StartNextCycle")
| |
| 88 | print("Starting next cycle...")
| |
| 89 | Mine() | |
| 90 | print("Letting server know ready for next cycle...")
| |
| 91 | SendMessage("_ReadyForNextCycle")
| |
| 92 | print(">>")
| |
| 93 | print(">>")
| |
| 94 | print(">>")
| |
| 95 | end | |
| 96 | ||
| 97 | print("Goodbye >>")
| |
| 98 | read() |