Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Awake
- local Y = 64
- print("Mining client awake: Hello World!")
- -- Setup wireless
- local modem = peripheral.wrap("right")
- -- 5 Server -> Client
- -- 6 Client -> Server
- modem.open(11)
- modem.open(12)
- print("Channel 11 and 12 are open")
- -- Setup receiving wireless messages
- function WaitForMessage(messageCompare)
- while true do
- local a,b,c,d,e,f = os.pullEvent("modem_message")
- print("Message received: ")
- print(e)
- if(e == messageCompare) then
- print("Message accepted")
- break
- end
- end
- end
- -- Setup sending wireless messages
- function SendMessage(message)
- modem.transmit(12, 11, message)
- end
- -- Down shorthand
- function Down()
- while not turtle.down() do
- if turtle.detectDown() then turtle.digDown() end
- turtle.attackDown()
- end
- turtle.dig()
- end
- -- Up shorthand
- function Up()
- while not turtle.up() do
- if turtle.detectUp() then turtle.digUp() end
- turtle.attackUp()
- end
- turtle.dig()
- end
- -- Forward shorthand
- function Forward()
- while not turtle.forward() do
- if turtle.detect() then turtle.dig() end
- turtle.attack()
- end
- end
- -- Bedrock shorthand
- function IsBedrock()
- local success, data = turtle.inspectDown()
- if success then
- return data.name == "minecraft:bedrock"
- else
- return false
- end
- end
- -- Server handshake
- print("Waiting for server awake")
- WaitForMessage("_ServerAwake")
- print("Replying to server...")
- SendMessage("_TurtleRegistered")
- -- Reset position
- print("Waiting for signal to reset Y")
- WaitForMessage("_ResetY")
- print("Resetting to y " .. tostring(Y))
- turtle.select(1)
- turtle.dig()
- while not IsBedrock() do Down() end
- for i=0, Y do Up() end
- print("Letting server know ready...")
- SendMessage("_TurtleReadyToMine")
- print("Waiting to begin")
- WaitForMessage("_Begin")
- -- Mine Routine
- function Mine()
- Forward()
- Forward()
- turtle.dig()
- for i=0, Y do Down() end
- Forward()
- Forward()
- turtle.dig()
- for i=0, Y do Up() end
- turtle.select(1)
- while not turtle.place() do
- turtle.dig()
- turtle.attack()
- end
- for i = 16,1,-1 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.dig()
- end
- -- Mine loop
- while true do
- print("Waiting to start next cycle")
- WaitForMessage("_StartNextCycle")
- print("Starting next cycle...")
- Mine()
- print("Letting server know ready for next cycle...")
- SendMessage("_ReadyForNextCycle")
- print(">>")
- print(">>")
- print(">>")
- end
- print("Goodbye >>")
- read()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement