Advertisement
Mine_Crafter

MiningTurtleMain

Apr 30th, 2025 (edited)
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.96 KB | None | 0 0
  1. local serverUrl = "ws://localhost:3000"
  2. local ws, err = http.websocket(serverUrl)
  3.  
  4. if not ws then
  5.   print("WebSocket connection failed:", err)
  6.   return
  7. end
  8.  
  9. local width = 5
  10. local height = 5
  11. local x, y = 1, 1
  12. local goingRight = true
  13.  
  14. for row = 1, height do
  15.   for col = 1, width do
  16.     local success, data = turtle.inspect()
  17.     local block = success and data.name or "minecraft:air"
  18.  
  19.     local msg = textutils.serializeJSON({
  20.       x = x,
  21.       y = y,
  22.       block = block
  23.     })
  24.  
  25.     ws.send(msg)
  26.  
  27.     if col < width then
  28.       turtle.dig()
  29.       turtle.forward()
  30.       x = x + (goingRight and 1 or -1)
  31.     end
  32.   end
  33.  
  34.   if row < height then
  35.     if goingRight then
  36.       turtle.turnRight()
  37.       turtle.dig()
  38.       turtle.forward()
  39.       turtle.turnRight()
  40.     else
  41.       turtle.turnLeft()
  42.       turtle.dig()
  43.       turtle.forward()
  44.       turtle.turnLeft()
  45.     end
  46.     y = y + 1
  47.     goingRight = not goingRight
  48.   end
  49. end
  50.  
  51. ws.close()
  52.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement