--- /dev/null
+-- very temporary coal feeder.
+
+-- local config = dofile=("temporary-coal-feeder.config")
+local deployers = {}
+local barrels = {}
+
+local refill_when = function(amt) return amt < 2 end
+local refill_amt = 2
+
+-- for peripherals, mactch deployers and barrels
+
+for _,p in pairs(peripheral.getNames()) do
+ local deployer = string.match(p, "^create\:deployer_%d+$")
+ local barrel = string.match(p, "^sophisticatedstorage\:limited_barrel_%d+$")
+ if deployer then
+ deployers[deployer] = peripheral.wrap(deployer)
+ else if barrel then
+ barrels[barrel] = peripheral.wrap(barrel)
+ end
+end
+
+local locate_coal = function()
+ local t = {}
+ for addr,barrel in pairs(barrels) do
+ local item = barrel.getItemDetail(1)
+ t[addr] = item.count()
+ end
+end
+
+local feed = function(stock)
+ local stock = stock
+ for deployer_addr,deployer in pairs(deployers) do
+ if refill_when(d.getItemDetail(1).count) then
+ local f = function() return false, "No coal available" end
+ for barrel_addr,count in pairs(stock) do
+ if count >= refill_amt then
+ stock[barrel_addr] = count - refill_amt
+ f = function() deployer.pullItems(barrel_addr, 1, refill_amt, 1) end
+ break
+ end
+ end
+ local ok, e = f()
+ if not ok then
+ print("Could not feed "..deployer_addr.."\n"..e)
+ end
+ end
+ end
+end
+
+while true do
+ feed(locate_coal())
+ os.sleep(60)
+end