Reliably reset crafting grid when no crafting table is near

This commit is contained in:
cora 2024-03-19 12:41:11 +01:00
parent 637d924ccd
commit 9996c75de5
2 changed files with 14 additions and 0 deletions

View File

@ -438,6 +438,7 @@ local function get_tooltip(item, groups, cooktime, burntime)
end
local function get_recipe_fs(data, iY, player)
mcl_inventory.reset_craft_grid(player)
local fs = {}
local recipe = data.recipes[data.rnum]
local width = recipe.width
@ -618,6 +619,7 @@ local function get_recipe_fs(data, iY, player)
end
local function make_formspec(name)
mcl_inventory.reset_craft_grid(minetest.get_player_by_name(name))
local data = player_data[name]
local iY = data.iX - 5
local ipp = data.iX * iY

View File

@ -166,6 +166,18 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
end)
function mcl_inventory.reset_craft_grid(player)
local inv = player:get_inventory()
if inv:get_size("craft") > 4 and not mcl_crafting_table.has_crafting_table(player) then
return_fields(player, "craft")
inv:set_width("craft", 2)
inv:set_size("craft", 4)
end
end
minetest.register_craft_predict(function(itemstack, player, old_craft_grid, inv)
mcl_inventory.reset_craft_grid(player)
end)
function mcl_inventory.update_inventory_formspec(player)
set_inventory(player)