crafting: fix crash on lookup unknown item
This commit is contained in:
parent
93ee3be696
commit
2c45a5bc11
49
crafting.lua
49
crafting.lua
@ -10,6 +10,12 @@ local function update_preview(state)
|
||||
local player = state.location.rootState.location.player
|
||||
local listentry = state.param.crafting_recipes_preivew_listentry
|
||||
local selected = state.param.crafting_recipes_preivew_selected
|
||||
local itemdef = listentry.itemdef
|
||||
local inf_state = state:get("inf_area"):getContainerState()
|
||||
|
||||
-- recipe to display and prepare them. Check for paging buttons needed
|
||||
local recipe
|
||||
if listentry.recipes then
|
||||
if not listentry.recipes[selected] then
|
||||
selected = 1
|
||||
end
|
||||
@ -25,9 +31,7 @@ local function update_preview(state)
|
||||
state:get("preview_next"):setVisible(false)
|
||||
end
|
||||
|
||||
-- create the recipe preview, set right items for groups
|
||||
local itemdef = listentry.itemdef
|
||||
local recipe
|
||||
-- set right items for groups in recipe
|
||||
if listentry.recipes[selected] then
|
||||
recipe = table.copy(listentry.recipes[selected])
|
||||
recipe.items = table.copy(recipe.items)
|
||||
@ -51,24 +55,12 @@ local function update_preview(state)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- update info area
|
||||
local inf_state = state:get("inf_area"):getContainerState()
|
||||
if itemdef then
|
||||
inf_state:get("info1"):setText(itemdef.description)
|
||||
inf_state:get("info2"):setText("("..itemdef.name..")")
|
||||
if itemdef._doc_items_longdesc then
|
||||
inf_state:get("info3"):setText(itemdef._doc_items_longdesc)
|
||||
else
|
||||
inf_state:get("info3"):setText("")
|
||||
end
|
||||
else
|
||||
inf_state:get("info1"):setText("")
|
||||
inf_state:get("info2"):setText("")
|
||||
inf_state:get("info3"):setText("")
|
||||
inf_state:get("cr_type"):setText("")
|
||||
state:get("preview_prev"):setVisible(false)
|
||||
state:get("preview_next"):setVisible(false)
|
||||
end
|
||||
|
||||
-- display the recipe result or selected item
|
||||
if recipe then
|
||||
if recipe.type ~="normal" then
|
||||
inf_state:get("cr_type"):setText(recipe.type)
|
||||
@ -88,6 +80,23 @@ local function update_preview(state)
|
||||
end
|
||||
state:get("craft_preview"):setCraft(nil)
|
||||
end
|
||||
|
||||
|
||||
-- update info area
|
||||
if itemdef then
|
||||
inf_state:get("info1"):setText(itemdef.description)
|
||||
inf_state:get("info2"):setText("("..itemdef.name..")")
|
||||
if itemdef._doc_items_longdesc then
|
||||
inf_state:get("info3"):setText(itemdef._doc_items_longdesc)
|
||||
else
|
||||
inf_state:get("info3"):setText("")
|
||||
end
|
||||
else
|
||||
inf_state:get("info1"):setText("")
|
||||
inf_state:get("info2"):setText("")
|
||||
inf_state:get("info3"):setText("")
|
||||
inf_state:get("cr_type"):setText("")
|
||||
end
|
||||
end
|
||||
|
||||
-----------------------------------------------------
|
||||
@ -202,9 +211,11 @@ local function create_lookup_inv(state, name)
|
||||
state.param.crafting_recipes_preivew_selected = 1
|
||||
state.param.crafting_recipes_preivew_listentry = {
|
||||
itemdef = minetest.registered_items[lookup_item],
|
||||
recipes = cache.citems[lookup_item].in_output_recipe,
|
||||
item = lookup_item
|
||||
}
|
||||
if cache.citems[lookup_item] then
|
||||
state.param.crafting_recipes_preivew_listentry.recipes = cache.citems[lookup_item].in_output_recipe
|
||||
end
|
||||
update_preview(state)
|
||||
if state:get("inf_area"):getVisible() == false then
|
||||
state:get("groups_btn"):submit()
|
||||
|
Loading…
x
Reference in New Issue
Block a user