From 1950c71f7252a231ab43c58958a2cf7085b738bf Mon Sep 17 00:00:00 2001 From: Mike Stump Date: Mon, 1 Jan 2024 14:53:23 -0800 Subject: [PATCH] More cmon support. --- modules/network/autocraft.lua | 17 ++++++++++++++--- modules/storage/cmonitor.lua | 28 ++++++++++++++-------------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/modules/network/autocraft.lua b/modules/network/autocraft.lua index dcd8e51..46c172f 100644 --- a/modules/network/autocraft.lua +++ b/modules/network/autocraft.lua @@ -122,9 +122,13 @@ local function build(net, cpos, inv, name, count, stack, sink, time) if dat.ostack:get_name() ~= name then -- invalidate it net.autocrafters[name][dat.apos] = nil - -- me.log("invalidating autocrafter", "error") + -- me.log("invalidating autocrafter for "..name, "error") return end + -- Consider looking up the recipe and finding the replacements that way. + if name == "technic:copper_coil" or name == "technic:control_logic_unit" then + second_output = ItemStack("basic_materials:empty_spool 999") + end else me.log("can't craft a "..name, "error") return @@ -182,6 +186,7 @@ local function build(net, cpos, inv, name, count, stack, sink, time) local grabbed = me.remove_item(net, inv, "main", istack) if grabbed then me.log("ac grabbed "..name, "error") + me.ac_status = me.ac_status .. "Grabbed "..count.." "..name..".\n" local slot = inv:get_size("ac")+1 inv:set_size("ac", slot) inv:set_stack("ac", slot, grabbed) @@ -200,12 +205,14 @@ local function build(net, cpos, inv, name, count, stack, sink, time) else -- Try and autocraft it me.log("AC: recursive crafting "..count.." "..istack:get_count(), "error") + me.ac_status = me.ac_status .. "Need to craft "..count.." "..name..".\n" local built, step_time = build(net, cpos, inv, name, count, istack, dat.isink, time) if built then hasit = true next_time = math.max(next_time, time + step_time) else me.log("can't craft "..istack:get_count().." "..istack:get_name(), "error") + me.ac_status = me.ac_status .. "Can't craft "..count.." "..name..".\n" end end replace = replace and hasit @@ -277,12 +284,14 @@ local function build(net, cpos, inv, name, count, stack, sink, time) if dst_stack:get_count() ~= stack:get_count() then me.log("wow, missing items that should have been crafted "..stack:get_name(), "error") -- me.log("saw "..dst_stack:get_count().." items instead of "..stack:get_count().." items", "error") + me.ac_status = me.ac_status .. "Missing "..(stack:get_count()-dst_stack:get_count()).." "..name..", only made "..dst_stack:get_count()..".\n" end if not dst_stack:is_empty() then me.log("TIMER: inserting "..dst_stack:get_count().." "..dst_stack:get_name(), "error") local leftovers = sink(dst_stack) if leftovers and not leftovers:is_empty() then me.log("autocrafter overflow, backpressuring", "error") + me.ac_status = me.ac_status .. "Backpressure of "..name..".\n" -- If any don't fit, back pressure on the crafter, we don't -- mean to do this, and want to chunk the crafting items smaller dat.rinv:add_item("dst", leftovers) @@ -299,6 +308,7 @@ local function build(net, cpos, inv, name, count, stack, sink, time) net:set_storage_space(true) if leftovers and not leftovers:is_empty() then me.log("autocrafter overflow, backpressuring", "error") + me.ac_status = me.ac_status .. "Backpressure of "..name..".\n" -- If any don't fit, back pressure on the crafter, we don't -- mean to do this, and want to chunk the crafting items smaller dat.rinv:add_item("dst", leftovers) @@ -308,9 +318,10 @@ local function build(net, cpos, inv, name, count, stack, sink, time) if second_output then local second = dat.rinv:remove_item("dst", second_output) if second and not second:is_empty() then - local leftovers = sink(second) + local leftovers = me.insert_item(second, net, inv, "main") if leftovers and not leftovers:is_empty() then me.log("autocrafter overflow, backpressuring", "error") + me.ac_status = me.ac_status .. "Backpressure of "..name..".\n" -- If any don't fit, back pressure on the crafter, we don't -- mean to do this, and want to chunk the crafting items smaller dat.rinv:add_item("dst", leftovers) @@ -412,7 +423,7 @@ function me.autocraft(autocrafterCache, cpos, net, linv, inv, count) me.ac_status = me.ac_status .. "Crafting "..count.." "..name.." in "..step_time.." seconds.\n" else me.log("can't craft "..stack:get_count().." "..stack:get_name(), "error") - me.ac_status = me.ac_status .. "Can't craft "..count.." "..name.."." + me.ac_status = me.ac_status .. "Can't craft "..count.." "..name..".\n" end return end diff --git a/modules/storage/cmonitor.lua b/modules/storage/cmonitor.lua index 4cbe0c9..ee6fe97 100644 --- a/modules/storage/cmonitor.lua +++ b/modules/storage/cmonitor.lua @@ -16,7 +16,7 @@ local function chest_formspec(pos, start_id, listname, page_max, q) if listname and (inv:get_size(listname) > 0 or net:get_item_capacity() > 0) then local ctrlinvname = net:get_inventory_name() list = "list[detached:"..ctrlinvname..";" - .."ac;0,0.3;8,4;" .. (start_id - 1) .. "]" + .. listname .. ";0,0.3;4,4;" .. (start_id - 1) .. "]" if minetest.get_modpath("i3") then list = list .. [[ list[current_player;main;0,8.5;9,4;] @@ -36,18 +36,18 @@ local function chest_formspec(pos, start_id, listname, page_max, q) ((net.pending and "running " .. #net.pending .. " steps\n") or "idle\n") status = status .. (me.ac_status or "") buttons = [[ - button[5.4,4.35;0.8,0.9;prev;<] - button[7.25,4.35;0.8,0.9;next;>] + button[0.8,5.1;0.8,0.9;prev;<] + button[2.65,5.1;0.8,0.9;next;>] tooltip[prev;Previous] tooltip[next;Next] field[0.29,4.6;2.2,1;filter;;]]..query..[[] button[2.1,4.5;0.8,0.5;search;?] button[2.75,4.5;1.6,0.5;refresh;Refresh] - button[4.35,4.5;0.8,0.5;clear;X] + button[0,5.28;0.8,0.5;clear;X] tooltip[search;Search] tooltip[refresh;Refresh] tooltip[clear;Reset] - textarea[0.29,5.7;10,10;;]] .. status .. ";]" + textarea[4.75,0;4.65,12.5;;]] .. status .. ";]" else list = "label[3,2;" .. minetest.colorize("blue", "Crafter is idle") .. "]" end @@ -55,7 +55,7 @@ local function chest_formspec(pos, start_id, listname, page_max, q) list = "label[3,2;" .. minetest.colorize("red", "No connected network!") .. "]" end if page_max then - page_number = "label[6.15,4.5;" .. math.floor((start_id / 32)) + 1 .. + page_number = "label[1.55,5.25;" .. math.floor((start_id / 16)) + 1 .. "/" .. page_max .."]" end @@ -84,7 +84,7 @@ local function update_chest(pos,_,ev) return end local inv = net:get_inventory() - local page_max = math.floor(inv:get_size("ac") / 32) + 1 + local page_max = math.floor(inv:get_size("ac") / 16) + 1 meta:set_string("inv_name", "ac") meta:set_string("formspec", chest_formspec(pos, 1, "ac", page_max)) @@ -205,22 +205,22 @@ me.register_node("cmonitor", { inv = own_inv assert(inv,"no own inv") end - local page_max = math.floor(inv:get_size(inv_name) / 32) + 1 + local page_max = math.floor(inv:get_size(inv_name) / 16) + 1 if inv_name == "none" then return end if fields.next then - if page + 32 > inv:get_size(inv_name) then + if page + 16 > inv:get_size(inv_name) then return end - meta:set_int("page", page + 32) - meta:set_string("formspec", chest_formspec(pos, page + 32, inv_name, page_max)) + meta:set_int("page", page + 16) + meta:set_string("formspec", chest_formspec(pos, page + 16, inv_name, page_max)) elseif fields.prev then - if page - 32 < 1 then + if page - 16 < 1 then return end - meta:set_int("page", page - 32) - meta:set_string("formspec", chest_formspec(pos, page - 32, inv_name, page_max)) + meta:set_int("page", page - 16) + meta:set_string("formspec", chest_formspec(pos, page - 16, inv_name, page_max)) elseif fields.search or fields.key_enter_field == "filter" then own_inv:set_size("search", 0) if fields.filter == "" then