Advertisement
hornedcommando

Minecraft ComputerCraft Turtle Listener Above and Beyond

Nov 22nd, 2024 (edited)
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.07 KB | Gaming | 0 0
  1. ---
  2. ---Desc: A Program for a turtle which makes it listen for a "craft" message and causes
  3. ---it to run turtle.craft() when it gets the message
  4. ---pairs with Modem Crafter, pastebin: gx4XjreV
  5. ---
  6.  
  7. --By: hornedcommando
  8.  
  9.  
  10. -- Function to find the side with the modem
  11. local function findModemSide()
  12.     for _, side in ipairs(peripheral.getNames()) do
  13.         if peripheral.getType(side) == "modem" then
  14.             print("Found modem on side: " .. side)
  15.             return side
  16.         end
  17.     end
  18.     error("No modem found")
  19. end
  20.  
  21. -- Open the modem
  22. local modemSide = findModemSide()
  23. rednet.open(modemSide)
  24.  
  25. while true do
  26.     -- Receive command from the computer
  27.     local senderId, message = rednet.receive()
  28.  
  29.     -- If the received message is "craft", execute turtle.craft()
  30.     if message == "craft" then
  31.         turtle.craft()
  32.         -- Send confirmation back to the sender
  33.         rednet.send(senderId, "Crafting complete!")
  34.     else
  35.         -- Send a message back if the command is not recognized
  36.         rednet.send(senderId, "Unknown command")
  37.     end
  38. end
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement