Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local function split(s, delimiter)
- result = {}
- for token in string.gmatch(s, "%a+") do
- table.insert(result, token)
- end
- return result
- end
- local function move(direction, distance)
- if direction == "forward" then
- turtle.forward(distance)
- elseif direction == "back" then
- turtle.back(distance)
- elseif direction == "left" then
- turtle.turnLeft(distance)
- elseif direction == "right" then
- turtle.turnRight(distance)
- elseif direction == "up" then
- turtle.up(distance)
- elseif direction == "down" then
- turtle.down(distance)
- end
- end
- local function mine(distance)
- local fuel = turtle.getFuelLevel()
- if distance*2 > fuel then
- rednet.send(385, "No fuel", "ABORT")
- end
- for i = 1, distance do
- turtle.digDown()
- turtle.down()
- end
- turtle.up(distance)
- end
- local function rx()
- while true do
- local id, msg = rednet.receive()
- if id == 385 and msg == "ABORT" then
- error("Administratively down.")
- else
- msg = split(msg, " ")
- if msg[1] == "move" then
- move(msg[2], msg[3])
- elseif msg[1] == "mine" then
- mine(msg[2])
- end
- end
- end
- end
- rx()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement