SHOW:
|
|
- or go back to the newest paste.
| 1 | -- Awake | |
| 2 | - | local Y = 52 |
| 2 | + | |
| 3 | ||
| 4 | -- Setup wireless | |
| 5 | local modem = peripheral.wrap("right")
| |
| 6 | -- 5 Server -> Client | |
| 7 | -- 6 Client -> Server | |
| 8 | modem.open(111) | |
| 9 | - | modem.open(11) |
| 9 | + | modem.open(112) |
| 10 | - | modem.open(12) |
| 10 | + | print("Channel 111 and 112 are open")
|
| 11 | - | 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 | -- Setup sending wireless messages | |
| 26 | function SendMessage(message) | |
| 27 | modem.transmit(112, 111, message) | |
| 28 | - | modem.transmit(12, 11, message) |
| 28 | + | |
| 29 | ||
| 30 | -- Down shortdown | |
| 31 | function Down() | |
| 32 | while not turtle.down() do | |
| 33 | if turtle.detectDown() then turtle.digDown() end | |
| 34 | turtle.attackDown() | |
| 35 | end | |
| 36 | turtle.dig() | |
| 37 | end | |
| 38 | ||
| 39 | -- Up shorthand | |
| 40 | function Up() | |
| 41 | while not turtle.up() do | |
| 42 | if turtle.detectUp() then turtle.digUp() end | |
| 43 | turtle.attackUp() | |
| 44 | end | |
| 45 | turtle.dig() | |
| 46 | end | |
| 47 | ||
| 48 | -- Forward shorthand | |
| 49 | function Forward() | |
| 50 | while not turtle.forward() do | |
| 51 | if turtle.detect() then turtle.dig() end | |
| 52 | turtle.attack() | |
| 53 | end | |
| 54 | end | |
| 55 | ||
| 56 | -- Bedrock shorthand | |
| 57 | function IsBedrock() | |
| 58 | local success, data = turtle.inspectDown() | |
| 59 | if success then | |
| 60 | return data.name == "minecraft:bedrock" | |
| 61 | else | |
| 62 | return false | |
| 63 | end | |
| 64 | end | |
| 65 | ||
| 66 | -- Server handshake | |
| 67 | print("Waiting for server awake")
| |
| 68 | WaitForMessage("_ServerAwake")
| |
| 69 | print("Replying to server...")
| |
| 70 | SendMessage("_TurtleRegistered")
| |
| 71 | ||
| 72 | -- Reset position | |
| 73 | print("Waiting for signal to reset Y")
| |
| 74 | WaitForMessage("_ResetY")
| |
| 75 | print("Picking up chest in case it's not in me")
| |
| 76 | - | print("Resetting to y 55")
|
| 76 | + | |
| 77 | turtle.dig() | |
| 78 | ||
| 79 | - | while not IsBedrock() do Down() end |
| 79 | + | |
| 80 | - | for i=0, Y do Up() end |
| 80 | + | |
| 81 | ||
| 82 | print("Waiting to begin")
| |
| 83 | WaitForMessage("_Begin")
| |
| 84 | ||
| 85 | -- Mine Routine | |
| 86 | function Mine() | |
| 87 | Forward() | |
| 88 | end | |
| 89 | ||
| 90 | function Drop() | |
| 91 | if turtle.getItemCount(16) > 0 then | |
| 92 | turtle.select(1) | |
| 93 | - | for i=0, Y do Down() end |
| 93 | + | while not turtle.place() do |
| 94 | turtle.dig() | |
| 95 | turtle.attack() | |
| 96 | end | |
| 97 | - | for i=0, Y do Up() end |
| 97 | + | for i = 16,1,-1 do |
| 98 | - | turtle.select(1) |
| 98 | + | turtle.select(i) |
| 99 | - | while not turtle.place() do |
| 99 | + | turtle.drop() |
| 100 | - | turtle.dig() |
| 100 | + | end |
| 101 | - | turtle.attack() |
| 101 | + | turtle.dig() |
| 102 | end | |
| 103 | - | for i = 16,1,-1 do |
| 103 | + | |
| 104 | - | turtle.select(i) |
| 104 | + | |
| 105 | - | turtle.drop() |
| 105 | + | |
| 106 | while true do | |
| 107 | print("Waiting to start next cycle")
| |
| 108 | WaitForMessage("_StartNextCycle")
| |
| 109 | print("Starting next cycle (mine)...")
| |
| 110 | Mine() | |
| 111 | print("Letting server know ready for next cycle...")
| |
| 112 | SendMessage("_ReadyForNextCycle")
| |
| 113 | ||
| 114 | - | print("Starting next cycle...")
|
| 114 | + | |
| 115 | print(">>")
| |
| 116 | print(">>")
| |
| 117 | ||
| 118 | print("Waiting to start next cycle")
| |
| 119 | WaitForMessage("_StartNextCycle")
| |
| 120 | print("Starting next cycle (drop)...")
| |
| 121 | Drop() | |
| 122 | print("Letting server know ready for next cycle...")
| |
| 123 | SendMessage("_ReadyForNextCycle")
| |
| 124 | ||
| 125 | print(">>")
| |
| 126 | print(">>")
| |
| 127 | print(">>")
| |
| 128 | end | |
| 129 | ||
| 130 | print("Goodbye >>")
| |
| 131 | read() |