Epuuc

Minecraft CC Tree Sensor

Nov 21st, 2020 (edited)
2,233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.63 KB | None | 0 0
  1. --not my code
  2. function split(pString, pPattern)
  3.    local Table = {}  -- NOTE: use {n = 0} in Lua-5.0
  4.    local fpat = "(.-)" .. pPattern
  5.    local last_end = 1
  6.    local s, e, cap = pString:find(fpat, 1)
  7.    while s do
  8.           if s ~= 1 or cap ~= "" then
  9.          table.insert(Table,cap)
  10.           end
  11.           last_end = e+1
  12.           s, e, cap = pString:find(fpat, last_end)
  13.    end
  14.    if last_end <= #pString then
  15.           cap = pString:sub(last_end)
  16.           table.insert(Table, cap)
  17.    end
  18.    return Table
  19. end
  20. --not my code
  21. --now my code VVV
  22.  
  23. local function figureoutwhoiam()
  24.     local cpulabel = os.getComputerLabel()
  25.     local id = split(cpulabel,"_")[3]
  26.     local x = split(id,"-")[2]
  27.     local z = split(id,"-")[1]
  28.     print("I am:",id.."!")
  29.     return {x,z,id}
  30. end
  31.  
  32. local allowed = true
  33. local modem = peripheral.wrap("left")
  34. if not modem then turtle.equipLeft() turtle.equipLeft() end
  35. modem.open(40)
  36.  
  37. local iam = figureoutwhoiam()
  38.  
  39. coroutine.wrap(function()
  40.     print("Reload Function Waiting")
  41.     while true do
  42.         local event,side,freq,rpfreq,msg,distance = os.pullEvent("modem_message")
  43.         print("Modem Message Received:","ID:",freq)
  44.         if freq == 30+10*iam[2] and msg.Reason ~= nil and msg.Reason == "Reload" then
  45.             print("Reloading")
  46.             allowed = false
  47.             break
  48.         end
  49.     end
  50. end)
  51.  
  52. while allowed do
  53.     if turtle.detect() then
  54.         local suc,data = turtle.inspect()
  55.         if suc and data.name == "minecraft:log" then
  56.             print("Tree Detected")
  57.             modem.transmit(30+10*iam[2],30+10*iam[2],{Reason="TreeGrew",Pos=iam[1]})
  58.             repeat sleep(0.1) until not turtle.detect()
  59.             print("Tree No Longer Detected")
  60.         end
  61.     end
  62. end
  63. shell.run("reload")
Add Comment
Please, Sign In to add comment