Advertisement
Robear9992

fluids

Aug 2nd, 2022 (edited)
1,321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.13 KB | None | 0 0
  1. -- fluids
  2. --pastebin get 0bvF2EWk fluids.lua
  3.  
  4. local fluids = {}
  5.  
  6.  
  7. function fluids.wrap(name)
  8.     local tank = {}
  9.     local wrapper = peripheral.wrap(name)
  10.     tank.name = name
  11.  
  12.     function tank.list()
  13.         return wrapper.tanks()
  14.     end
  15.    
  16.     function tank.contains(fluid)
  17.         for _,f in pairs(tank.list()) do
  18.             if fluid == f.name then return true, f.amount end
  19.         end
  20.     end
  21.    
  22.     function tank.push(to,fluid,amount)
  23.         if to.name ~= nil then to = to.name end
  24.         local moved = wrapper.pushFluid(to,amount,fluid)
  25.         return moved == amount, amount
  26.     end
  27.    
  28.     function tank.pull(from,fluid,amount)
  29.         if from.name ~= nil then from = from.name end
  30.         local moved = wrapper.pullFluid(from,amount,fluid)
  31.         return moved == amount, amount
  32.     end
  33.     return tank
  34. end
  35.  
  36. function fluids.isTank(name)
  37.     local types = {peripheral.getType(name)}
  38.     for _,t in pairs(types) do
  39.         if t == "fluid_storage" then return true end
  40.     end
  41.     return false
  42. end
  43.  
  44. function fluids.list()
  45.     local ret = {}
  46.     for _,peripheral in pairs(peripheral.getNames()) do
  47.         if fluids.isTank(peripheral) then
  48.             ret[peripheral]=fluids.wrap(peripheral)
  49.         end
  50.     end
  51.     return ret
  52. end
  53.  
  54. return fluids
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement