Fix crash in rp_crafting

This commit is contained in:
Wuzzy 2024-04-16 18:40:49 +02:00
parent 574104a811
commit a84d08d7a7

View File

@ -23,6 +23,7 @@ crafting.registered_crafts = {}
-- User table of last selected row etc. -- User table of last selected row etc.
local userdata = {} local userdata = {}
local userdata_init = { mode = MODE_CRAFTABLE }
-- Crafting can only take a limited number of itemstacks as -- Crafting can only take a limited number of itemstacks as
-- input for sanity/interface reasons -- input for sanity/interface reasons
@ -318,6 +319,9 @@ form = form .. "container_end[]"
form = form .. "tablecolumns[text,align=left,width=2;text,align=left,width=40]" form = form .. "tablecolumns[text,align=left,width=2;text,align=left,width=40]"
function crafting.get_formspec(name) function crafting.get_formspec(name)
if not userdata[name] then
userdata[name] = table.copy(userdata_init)
end
local selected_craft_id = (userdata[name] and userdata[name].craft_id) or 1 local selected_craft_id = (userdata[name] and userdata[name].craft_id) or 1
if userdata[name] and userdata[name].old_craft_id then if userdata[name] and userdata[name].old_craft_id then
@ -349,9 +353,9 @@ function crafting.get_formspec(name)
-- In the craft guide, the list of craftable items is cached for -- In the craft guide, the list of craftable items is cached for
-- the player so it doesn't have to be recalculated that often. -- the player so it doesn't have to be recalculated that often.
local craftable_cache = userdata[name].craftable_cache local craftable_cache = userdata[name] and userdata[name].craftable_cache
local cache_update_required local cache_update_required
if userdata[name].mode == MODE_GUIDE and craftable_cache == nil then if userdata[name] and userdata[name].mode == MODE_GUIDE and craftable_cache == nil then
cache_update_required = true cache_update_required = true
craftable_cache = {} craftable_cache = {}
userdata[name].craftable_cache = craftable_cache userdata[name].craftable_cache = craftable_cache
@ -749,7 +753,9 @@ local function on_joinplayer(player)
local inv = player:get_inventory() local inv = player:get_inventory()
userdata[name] = {mode = MODE_CRAFTABLE} if not userdata then
userdata[name] = table.copy(userdata_init)
end
if inv:get_size("craft_in") ~= 4 then if inv:get_size("craft_in") ~= 4 then
inv:set_size("craft_in", 4) inv:set_size("craft_in", 4)