--- /dev/null
+-- Automatically detects deployers on startup.
+-- Keeps deployers stocked with exactly one
+-- menril sapling, sleeps for 2s between restocks.
+-- Warns if deployers are holding wrong item or
+-- if out of saplings.
+
+-- configuration
+local sapling_inventory = ""
+
+-- imports
+local inv = dofile("/lib/inventory.lua")
+
+-- program starts here
+local ds = {}
+do
+ for _,p in ipairs(peripheral.getNames()) do
+ if string.match(p, "^create:deployer") then
+ table.insert(ds, p)
+ end
+ end
+end
+
+local restock_deployers = function()
+ local skip = false
+ for _, d in pairs(ds) do
+ if skip then return skip end
+ local empty = { name = "integrateddynamics:menril_sapling", count = 0, maxCount = 64 }
+ local item = peripheral.call(d, "getItemDetail", 1) or empty
+ if item.name ~= "integrateddynamics:menril_sapling" then
+ print(string.sub(d, 17).." holding "..item.displayName)
+ end
+ if item.name == "integrateddynamics:menril_sapling" and item.count < 1 then
+ local found_all, index = inv.find(sapling_inventory, { ["integrateddynamics:menril_sapling"] = 1 })
+ if found_all then
+ for slot, amount in pairs(index["integrateddynamics:menril_sapling"].slots) do
+ peripheral.call(sapling_inventory, "pushItems", d, slot, amount)
+ end
+ else
+ skip = "out of saplings"
+ end
+-- if not found_all then
+-- print("low on saplings")
+-- end
+-- if not index["integrateddynamics:menril_sapling"] then
+-- log:warn("out of redstone")
+-- else
+ end
+ end
+ return skip
+end
+
+while true do
+ term.clear()
+ term.setCursorPos(1,1)
+ term.setTextColor(colors.gray)
+ print("restocking deployers")
+ print("warnings:")
+ term.setTextColor(colors.white)
+ local e = restock_deployers()
+ if e then print(e) end
+ sleep(2)
+end