Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- fluids
- --pastebin get 0bvF2EWk fluids.lua
- local fluids = {}
- function fluids.wrap(name)
- local tank = {}
- local wrapper = peripheral.wrap(name)
- tank.name = name
- function tank.list()
- return wrapper.tanks()
- end
- function tank.contains(fluid)
- for _,f in pairs(tank.list()) do
- if fluid == f.name then return true, f.amount end
- end
- end
- function tank.push(to,fluid,amount)
- if to.name ~= nil then to = to.name end
- local moved = wrapper.pushFluid(to,amount,fluid)
- return moved == amount, amount
- end
- function tank.pull(from,fluid,amount)
- if from.name ~= nil then from = from.name end
- local moved = wrapper.pullFluid(from,amount,fluid)
- return moved == amount, amount
- end
- return tank
- end
- function fluids.isTank(name)
- local types = {peripheral.getType(name)}
- for _,t in pairs(types) do
- if t == "fluid_storage" then return true end
- end
- return false
- end
- function fluids.list()
- local ret = {}
- for _,peripheral in pairs(peripheral.getNames()) do
- if fluids.isTank(peripheral) then
- ret[peripheral]=fluids.wrap(peripheral)
- end
- end
- return ret
- end
- return fluids
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement