Make crafting button logic use table.count

This commit is contained in:
cora 2024-03-19 22:00:44 +01:00
parent 4a15625de7
commit 20de2b3641
2 changed files with 3 additions and 3 deletions

View File

@ -603,7 +603,7 @@ local function get_recipe_fs(data, iY, player)
local pinv = player:get_inventory()
if mcl_inventory.get_recipe_groups(pinv, recipe) and
( mcl_crafting_table.has_crafting_table(player) or
( recipe.width <= pinv:get_width("craft") and #recipe.items <= pinv:get_size("craft"))) then
( recipe.width <= pinv:get_width("craft") and table.count(recipe.items, function(_,v) return not ItemStack(v):is_empty() end) <= pinv:get_size("craft"))) then
fs[#fs + 1] = string.format("image_button[%f,%f;%f,%f;%s;%s_inv;%s]",
8.5,
7.2,
@ -925,7 +925,7 @@ local function on_receive_fields(player, fields)
if not mcl_inventory.get_recipe_groups(pinv, data.recipes[data.rnum]) then return end
if mcl_crafting_table.has_crafting_table(player) then
mcl_crafting_table.show_crafting_form(player)
elseif data.recipes[data.rnum].width <= pinv:get_width("craft") and #data.recipes[data.rnum].items <= pinv:get_size("craft") then
elseif data.recipes[data.rnum].width <= pinv:get_width("craft") and table.count(data.recipes[data.rnum].items, function(_,v) return not ItemStack(v):is_empty() end) <= pinv:get_size("craft") then
minetest.show_formspec(name, "", player:get_inventory_formspec())
else
return

View File

@ -64,7 +64,7 @@ end
function mcl_inventory.get_recipe_groups(pinv, craft)
local grid_width = pinv:get_width("craft")
if craft.width > grid_width or pinv:get_size("craft") < #craft.items then
if craft.width > grid_width or pinv:get_size("craft") < table.count(craft.items, function(_,v) return not ItemStack(v):is_empty() end) then
return false
end
local r = { "", "", "", "", "", "", "", "", "" }