Advertisement
AstolfoFate

quarryclient

Oct 11th, 2021
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.31 KB | None | 0 0
  1. local function split(s, delimiter)
  2.     result = {}
  3.     for token in string.gmatch(s, "%a+") do
  4.       table.insert(result, token)
  5.     end
  6.     return result
  7.   end
  8.  
  9. local function move(direction, distance)
  10.     if direction == "forward" then
  11.         turtle.forward(distance)
  12.     elseif direction == "back" then
  13.         turtle.back(distance)
  14.     elseif direction == "left" then
  15.         turtle.turnLeft(distance)
  16.     elseif direction == "right" then
  17.         turtle.turnRight(distance)
  18.     elseif direction == "up" then
  19.         turtle.up(distance)
  20.     elseif direction == "down" then
  21.         turtle.down(distance)
  22.     end
  23. end
  24.  
  25.  
  26. local function mine(distance)
  27.     local fuel = turtle.getFuelLevel()
  28.     if distance*2 > fuel then
  29.         rednet.send(385, "No fuel", "ABORT")
  30.     end
  31.     for i = 1, distance do
  32.         turtle.digDown()
  33.         turtle.down()
  34.     end
  35.     turtle.up(distance)
  36. end
  37.  
  38.  
  39. local function rx()
  40.     while true do
  41.         local id, msg = rednet.receive()
  42.         if id == 385 and msg == "ABORT" then
  43.             error("Administratively down.")
  44.         else
  45.             msg = split(msg, " ")
  46.             if msg[1] == "move" then
  47.                 move(msg[2], msg[3])
  48.             elseif msg[1] == "mine" then
  49.                 mine(msg[2])
  50.             end
  51.         end
  52.     end
  53. end
  54.  
  55. rx()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement