Epuuc

Minecraft CC Tree Computer

Nov 22nd, 2020 (edited)
995
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 modem = peripheral.find("modem")
  24.  
  25. local treesgrown = {}
  26. local turtledocked = peripheral.isPresent("left")
  27.  
  28. local function parseName()
  29.     return split(os.getComputerLabel(),"_")[3]
  30. end
  31. local id = parseName()
  32. local function activateTurtle(pos,bypass)
  33.     if not turtledocked and not bypass then return end
  34.     turtledocked = false
  35.    
  36.     modem.transmit(tonumber(id)+200,tonumber(id)+200,pos)
  37.  
  38.     print("Turtle has departed.")
  39. end
  40.  
  41. modem.open(40)
  42. term.clear()
  43. term.setCursorPos(1,1)
  44. print("Listening for Tree Events.")
  45. while true do
  46.     local e,side,channel,repchannel,msg,distance = os.pullEvent()
  47.     if e == "modem_message" then
  48.         print("MSG RECEIVED C:",channel,"R:",msg.Reason,"P:",msg.Pos)
  49.         if channel == id*10+30 and msg.Reason == "TreeGrew" then
  50.             if turtledocked and #treesgrown == 0 then
  51.                 activateTurtle(msg.Pos)
  52.             else
  53.                 table.insert(treesgrown,msg.Pos)
  54.             end
  55.         end
  56.     elseif e == "peripheral" then
  57.         if peripheral.isPresent("left") then
  58.             print("Turtle has Docked.")
  59.             if #treesgrown > 0 then
  60.                 print(#treesgrown,"trees currently grown")
  61.                 print(treesgrown[1])
  62.                 activateTurtle(treesgrown[1],true)
  63.                 table.remove(treesgrown,1)
  64.             else
  65.                 turtledocked = true
  66.             end
  67.         end
  68.     end
  69. end
RAW Paste Data