Advertisement
Archer2o2x

storage

Apr 30th, 2024
875
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.19 KB | None | 0 0
  1. local function transfer(self, destination, name, count)
  2.  
  3.     if not count then count = 64 end
  4.  
  5.     local countLeft = count
  6.  
  7.     for slot, item in pairs(self.peripheral.list()) do
  8.  
  9.         if item.name == name then
  10.  
  11.             countLeft = countLeft - self.peripheral.pushItems(destination, slot, countLeft)
  12.  
  13.             if countLeft < 1 then break end
  14.  
  15.         end
  16.  
  17.     end
  18.  
  19. end
  20.  
  21. local function list(self)
  22.  
  23.     local results = {}
  24.  
  25.     for slot, item in pairs(self.peripheral.list()) do
  26.        
  27.         if results[item.name] ~= nil then
  28.  
  29.             results[item.name] = results[item.name] + item.count
  30.  
  31.         else
  32.  
  33.             results[item.name] = item.count
  34.  
  35.         end
  36.  
  37.     end
  38.  
  39.     return results
  40.  
  41. end
  42.  
  43. local function amount(self, name)
  44.  
  45.     local results = 0
  46.  
  47.     for slot, item in pairs(self.peripheral.list()) do
  48.        
  49.         if item.name == name then
  50.  
  51.             results = results + item.count
  52.  
  53.         end
  54.  
  55.     end
  56.  
  57.     return results
  58.  
  59. end
  60.  
  61. local function make(peripheral)
  62.  
  63.     return {
  64.  
  65.         peripheral = peripheral,
  66.         transfer = transfer,
  67.         list = list,
  68.         amount = amount
  69.  
  70.     }
  71.  
  72. end
  73.  
  74. return { make = make }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement