Advertisement
Guest User

fillAspectJars

a guest
Jul 7th, 2014
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.33 KB | None | 0 0
  1. lp = peripheral.wrap("left")
  2. local jars = {}
  3. local beans = {}
  4. local beancounts = {}
  5.  
  6. pnames = peripheral.getNames()
  7. for k,v in ipairs(pnames) do
  8.    if peripheral.getType(v) == "tilejar" then
  9.       aspects = peripheral.call(v, "getAspects")
  10.       if aspects then
  11.          aspect = string.lower(aspects[1]["name"])
  12.          print("got aspect jar: ", aspect)
  13.          jars[aspect] = aspects[1]["quantity"]
  14.       end
  15.    end
  16. end
  17.  
  18. local data = lp.getAvailableItems()
  19. for k,v in pairs(data) do
  20.    item = v.getValue1()
  21.    if item.getName() == "Mana Bean" then
  22.       tag = item.getTagCompound()
  23.       aspect = tag["value"]["Aspects"]["value"][1]["value"]["key"]["value"]
  24.       beans[aspect] = item
  25.       beancounts[aspect] = v.getValue2()
  26.       print("system has ", beancounts[aspect], " ", aspect)
  27.    end      
  28. end
  29.  
  30. local n = 0
  31. for k,v in pairs(jars) do
  32.    print(k, v)
  33.    if beans[k] then
  34.       if v < 64 then
  35.          count = 64 - v
  36.          if count > beancounts[k] then
  37.             count = beancounts[k]
  38.          end
  39.          
  40.          print("requesting ", count, " of ", k, ": ",beans[k])
  41.          result = lp.makeRequest(beans[k], count)
  42.          if result == "DONE" then
  43.             -- print(result)
  44.             n = n + 1
  45.          end
  46.       end
  47.    end
  48.    
  49.    if n == 5 then
  50.       break
  51.    end
  52. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement