diff --git a/basic_machines/chest.lua b/basic_machines/chest.lua index 4230e89..d62849f 100644 --- a/basic_machines/chest.lua +++ b/basic_machines/chest.lua @@ -304,10 +304,10 @@ techage.register_node({"techage:chest_ta4"}, { local meta = minetest.get_meta(pos) local inv = meta:get_inventory() local mem = techage.get_mem(pos) - if not mem.filter or not mem.filter["unconfigured"] then - mem.filter = mConf.item_filter(pos, 50) - end - mem.chest_configured = mem.chest_configured or #mem.filter["unconfigured"] < 50 + + mem.filter = mem.filter or mConf.item_filter(pos, 50) + mem.chest_configured = mem.chest_configured or + not mem.filter["unconfigured"] or #mem.filter["unconfigured"] < 50 if inv:is_empty("main") then return nil @@ -337,10 +337,10 @@ techage.register_node({"techage:chest_ta4"}, { local meta = minetest.get_meta(pos) local inv = meta:get_inventory() local mem = techage.get_mem(pos) - if not mem.filter or not mem.filter["unconfigured"] then - mem.filter = mConf.item_filter(pos, 50) - end - mem.chest_configured = mem.chest_configured or #mem.filter["unconfigured"] < 50 + + mem.filter = mem.filter or mConf.item_filter(pos, 50) + mem.chest_configured = mem.chest_configured or + not mem.filter["unconfigured"] or #mem.filter["unconfigured"] < 50 if mem.chest_configured then local name = item:get_name() @@ -354,10 +354,10 @@ techage.register_node({"techage:chest_ta4"}, { local meta = minetest.get_meta(pos) local inv = meta:get_inventory() local mem = techage.get_mem(pos) - if not mem.filter or not mem.filter["unconfigured"] then - mem.filter = mConf.item_filter(pos, 50) - end - mem.chest_configured = mem.chest_configured or #mem.filter["unconfigured"] < 50 + + mem.filter = mem.filter or mConf.item_filter(pos, 50) + mem.chest_configured = mem.chest_configured or + not mem.filter["unconfigured"] or #mem.filter["unconfigured"] < 50 if mem.chest_configured then local name = item:get_name() diff --git a/basic_machines/distributor.lua b/basic_machines/distributor.lua index ef06421..e4b2cee 100644 --- a/basic_machines/distributor.lua +++ b/basic_machines/distributor.lua @@ -219,7 +219,7 @@ local function push_item(pos, filter, itemstack, num_items, nvm) local idx = 1 local num_pushed = 0 local num_ports = #filter - local randidx = permIdx[num_ports][math.random(1, #permIdx[num_ports])] + local randidx = permIdx[num_ports][math.random(1, #(permIdx[num_ports] or {0}))] local amount = math.floor(math.max((num_items + 1) / num_ports, 1)) local num_of_trials = 0 while num_pushed < num_items and num_of_trials <= 8 do diff --git a/basis/conf_inv.lua b/basis/conf_inv.lua index 8b1badb..2963daf 100644 --- a/basis/conf_inv.lua +++ b/basis/conf_inv.lua @@ -25,7 +25,7 @@ function inv_lib.preassigned_stacks(pos, xsize, ysize) local item_name = inv:get_stack("conf", idx):get_name() if item_name ~= "" then local x = (idx - 1) % xsize - local y = math.floor(idx / xsize) + local y = math.floor((idx - 1) / xsize) tbl[#tbl+1] = "item_image["..x..","..y..";1,1;"..item_name.."]" end end @@ -76,7 +76,7 @@ function inv_lib.allow_conf_inv_move(pos, from_list, from_index, to_list, to_ind end function inv_lib.put_items(pos, inv, listname, item, stacks, idx) - for _, i in ipairs(stacks) do + for _, i in ipairs(stacks or {}) do if not idx or idx == i then local stack = inv:get_stack(listname, i) if stack:item_fits(item) then