Advertisement
mini_froakie1

remote_control_turtle_mining

Jul 7th, 2024 (edited)
408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.58 KB | Gaming | 0 0
  1. local item = turtle.getItemDetail() or error("put modem in current slot.")
  2. local mainChannel = 21
  3. local fuelNames = {"minecraft:coal"}
  4.  
  5. function refuel(i, fuel)
  6.     local name = turtle.getItemDetail(i).name
  7.     if fuel == name then
  8.         turtle.select(i)
  9.         turtle.refuel()
  10.         turtle.select(1)
  11.     else
  12.         error("not fuel")
  13.     end
  14. end
  15.  
  16. if item.name == "computercraft:peripheral" and item.damage == 1 then
  17.     turtle.equipLeft()
  18.     local modem = peripheral.wrap("left")
  19.     modem.open(mainChannel)
  20.     local event, side, channel, replyChannel, message, distance
  21.     local moved, reason
  22.     while true do
  23.         moved = true
  24.         event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  25.         message = tostring(message)
  26.         if message == "w" then
  27.             moved, reason = turtle.forward()
  28.         elseif message == "s" then
  29.             moved, reason = turtle.back()
  30.         elseif message == "a" then
  31.             moved, reason = turtle.turnLeft()
  32.         elseif message == "d" then
  33.             moved, reason = turtle.turnRight()
  34.         elseif message == "r" then
  35.             for i = 1, 16 do
  36.                 for _, fuel in pairs(fuelNames) do
  37.                     if pcall(refuel, i, fuel) then break end
  38.                 end
  39.             end
  40.         end
  41.         if moved == false then
  42.             modem.transmit(mainChannel, mainChannel, "Didn't move: " .. reason)
  43.         else
  44.             modem.transmit(mainChannel, mainChannel, "Moved")
  45.         end
  46.     end
  47. else
  48.     error("put modem in current slot.")
  49. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement