-- run on a cheep computer to auto_import from a chest local saved_chest_file = "auto_chest.txt" local default_chest = 89 local redstone_threshold = 7 local modem = peripheral.find("modem") local sides = {"top", "bottom", "right", "left", "front", "back"} local function loadChest() if not fs.exists(saved_chest_file) then return default_chest end local file = fs.open(saved_chest_file, "r") local data = file.readAll() file.close() assert(data) local res = tonumber(data) assert(res) return res end local chest = loadChest() local function saveChest() local file = fs.open(saved_chest_file, "w") file.writeLine(tostring(chest)) file.close() end local function maxRedstone() local max = 0 for _,side in pairs(sides) do local res = redstone.getAnalogInput(side) if res > max then max = res end end return max end local function checkAndSend() local redstone_level = maxRedstone() -- print("redstone level = " .. redstone_level) if redstone_level >= redstone_threshold then print("sending import command...") modem.transmit(1, 1, "import " .. chest) end end local function main(args) if #args == 1 then local res = tonumber(args[1]) assert(res) chest = res saveChest() end print("running auto_import for chest number " .. chest) checkAndSend() while true do os.pullEvent("redstone") checkAndSend() end end local args = {...} main(args)