Clem105

Storage management piloute

Oct 8th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.59 KB | None | 0 0
  1. modem = peripheral.wrap("back")
  2. modem.open(57)
  3. local chests = {
  4. "InventoryInterface_17","InventoryInterface_18","InventoryInterface_19",
  5. "InventoryInterface_20","InventoryInterface_21","InventoryInterface_22",
  6. "InventoryInterface_24","InventoryInterface_25","InventoryInterface_26",
  7. "InventoryInterface_27","InventoryInterface_28"
  8. }
  9. Storage = peripheral.wrap("InventoryInterface_34")
  10. local data = {}
  11. local s = false
  12. for i = 1,#chests do
  13.   data[i] = peripheral.wrap(chests[i])
  14. end
  15.  
  16. --WOW
  17. function getStorage()
  18.     local tab = {}
  19.     for m = 1,#data do
  20.      for i=1, data[m].getInventorySize() do
  21.         slot = data[m].getItemInSlot(i)
  22.         if slot["name"] then
  23.             tab[slot.name:gsub("minecraft:","")..":"..slot.metadata] = (tab[slot.name:gsub("minecraft:","")..":"..slot.metadata] or 0) + slot.stackSize
  24.         end
  25.     end
  26.     end
  27.     return(tab)
  28. end
  29.  
  30.  while true do
  31.     event,_,_,_,msg = os.pullEvent("modem_message")
  32.     if msg == "Request" then
  33.         modem.transmit(57,1,textutils.serialize(getStorage()))
  34.     else
  35.         u = 1
  36.         t = textutils.unserialize(msg)
  37.         count = t[2]
  38.         for m = 1,#data do
  39.             for i=1, data[m].getInventorySize() do
  40.                 slot = data[m].getItemInSlot(i)
  41.                 if slot["name"] then
  42.                     if (slot["name"]:gsub("minecraft:","")..":"..slot.metadata) == t[1] then
  43.                         count = count - slot.stackSize
  44.                         print(count)
  45.                         if count >= 0 then
  46.                             data[m].transferToII(Storage.uuid(),i,u,(slot.stackSize))
  47.                             u = u+1
  48.                         else
  49.                             data[m].transferToII(Storage.uuid(),i,u,(count +slot.stackSize))
  50.                             break
  51.                         end
  52.                     end
  53.                 end
  54.             end
  55.         end
  56.     end
  57. end
Advertisement
Add Comment
Please, Sign In to add comment