1
0
mirror of https://github.com/osmarks/random-stuff synced 2024-11-08 13:39:53 +00:00
random-stuff/computercraft/furnace_controller.lua

50 lines
1.2 KiB
Lua
Raw Normal View History

2023-11-13 19:37:05 +00:00
local inchest = peripheral.wrap "quark:variant_chest_0"
local outchest = peripheral.wrap "quark:variant_chest_1"
local furns = {peripheral.find "mana-and-artifice:runeforge_tile_entity"}
local function find_next()
for k, v in pairs(inchest.list()) do return k end
end
--[[
local smelt = {
"minecraft:stone",
"minecraft:baked_potato"
}
local sset = {}
for k, v in pairs(smelt) do sset[v] = true end
]]
local last_inputs = {}
local function commit()
local f = fs.open("state", "w")
f.write(textutils.serialise(last_inputs))
f.close()
end
if fs.exists "state" then
local f = fs.open("state", "r")
last_inputs = textutils.unserialise(f.readAll())
f.close()
end
while true do
for _, furn in pairs(furns) do
local nxt = find_next()
if nxt then
local idet = inchest.getItemDetail(nxt)
if inchest.pushItems(peripheral.getName(furn), nxt, 1, 1) then
last_inputs[peripheral.getName(furn)] = idet.name
print("insert", idet.displayName)
commit()
end
end
local det = furn.getItemDetail(1)
if det and det.name ~= last_inputs[peripheral.getName(furn)] then
print("extract", det.displayName)
outchest.pullItems(peripheral.getName(furn), 1, 1)
end
end
sleep(1)
end