emagiannu

[AutomaticEssentiaRefilling] essentia

Mar 14th, 2014
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.32 KB | None | 0 0
  1. rednet.open("left")
  2. recvID = 68
  3.  
  4. local jars = peripheral.getNames()
  5. local essentia = {}
  6. local  jarSize = 64  --Max number of essentia per jar(always <= 64)
  7.  
  8. function fillTable()
  9.   for i,j in pairs(jars) do
  10.      if peripheral.getType(j) == "tt_aspectContainer" then
  11.        asp = peripheral.call(j, "getAspects")
  12.        countasp = peripheral.call(j, "getAspectCount", asp)
  13.        if asp ~= nil then essentia[asp] = math.floor(countasp) end
  14.        --print(countasp)
  15.        --print(asp..":"..countasp)
  16.        
  17.      end
  18.   end
  19. end
  20.  
  21. function scanBeans()
  22.   rednet.send(recvID, "scan")
  23.   print("Scanning beans...")
  24.   local message
  25.   while message ~= "scanned" do
  26.     id,message = rednet.receive()
  27.   end
  28.   print("Bean Scan complete.")
  29.  
  30. end
  31.  
  32. function scanJars()
  33.   for i, j in pairs(essentia) do
  34.     print(i .. ": " .. j)
  35.     if j < jarSize and i~=nil then
  36.       refillJar(i, (jarSize - j))
  37.     end
  38.   end
  39. end
  40.  
  41. function refillJar(asp, amo) --aspect, amount
  42.   t = {asp, amo}
  43.   local msg = textutils.serialize(t)
  44.   rednet.send(recvID, msg)
  45.   print("Waiting to add " .. amo .. " to " .. asp .. ".")
  46.   message = ""
  47.   while message ~= "refilled" do
  48.     id,message = rednet.receive()
  49.   end
  50.   print("Added " .. amo .. " to " .. asp .. ".")
  51. end
  52.  
  53. fillTable()
  54. scanBeans()
  55. sleep(2)
  56. scanJars()
  57.  
  58. rednet.close("left")
Advertisement
Add Comment
Please, Sign In to add comment