fix errors, add refab

This commit is contained in:
sfokin 2025-03-29 07:20:28 +03:00
parent 4d893a32a7
commit d309587782
3 changed files with 101 additions and 1 deletions

8
debug.lua Normal file
View File

@ -0,0 +1,8 @@
if event.type == "program" then
mem.events = {}
end
if event.type == "digiline" then
table.insert(mem.events, event)
end

View File

@ -80,7 +80,7 @@ if event.type == "program" then
mem={}
mem.buttonState = 0
mem.outputCount = 0
if mem.totalProcessed == nill then
if mem.totalProcessed == nil then
mem.totalProcessed = 0
end

92
fabric_refab.lua Normal file
View File

@ -0,0 +1,92 @@
if event.type == "program" then
mem = {}
mem.events = {}
mem.orderSize = 5
mem.outputSize = 22
mem.inputName = "Tacit:ironrefab"
mem.itemName = "default:iron_lump"
mem.orderName = "ironrefab"
mem.outputCount = 0
mem.injectCount = 0
mem.state = "checkchest"
interrupt(1)
end
if event.type == "interrupt" then
-- if port.a == 0 then
-- mem.state = "idle"
-- end
-- if mem.state == "idle" and mem.outputCount == 0 then
-- interrupt(10)
-- end
port.a = not port.a
if mem.state == "checkchest" then
digiline_send("chest",{command="get_list"})
end
if mem.state == "ordering" then
local order = {
name=mem.orderName,
destination=mem.inputName,
item=mem.itemName,
stacksize=99,
count=mem.orderSize,
}
digiline_send("drawercontroller", order)
mem.state = "waitorder"
end
if mem.state == "inject" then
digiline_send("injector", {name=mem.itemName, count = 99, tags=mem.itemName})
mem.state = "waitoutput"
end
interrupt(1)
end
if event.type == "digiline" then
if event.channel == "chest" then
if event.msg.event and event.msg.event == "inject" then
mem.injectCount = mem.injectCount + 1
if mem.injectCount == mem.orderSize then
mem.injectCount = 0
mem.state = "inject"
end
end
if not event.msg.event then
local emptyCount = 0
local stacks = 0
for k,v in pairs(event.msg) do
if v == "" then emptyCount = emptyCount + 1 end
if v ~= "" then stacks = stacks + 1 end
end
if stacks == 0 then
mem.state = "ordering"
else
mem.state = "inject"
end
end
end
if event.channel == "detector" then
mem.outputCount = mem.outputCount + 1
if mem.outputCount == mem.outputSize then
mem.outputCount = 0
mem.state = "checkchest"
end
end
if event.type == "off" then
mem.state = "idle"
end
if event.type == "on" then
mem.state = "checkchest"
end
end