From: Olav Bakke Svendsen Date: Wed, 11 Oct 2023 21:16:32 +0000 (+0200) Subject: Added temporary coal feeder X-Git-Tag: stable-steam~38 X-Git-Url: http://git.olavbs.no/?a=commitdiff_plain;h=163bd556bcd35cea696a4726e837e0b8e4cd639d;p=cc.git Added temporary coal feeder --- diff --git a/steam/temporary-coal-feeder.lua b/steam/temporary-coal-feeder.lua new file mode 100644 index 0000000..ba1b7bf --- /dev/null +++ b/steam/temporary-coal-feeder.lua @@ -0,0 +1,53 @@ +-- 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