From 517a8fcc2e707933d2466b8d39d47d405534df36 Mon Sep 17 00:00:00 2001 From: AndrejIT Date: Sat, 23 Aug 2014 11:16:42 +0300 Subject: [PATCH 1/3] Fast fixes Fix for "unknown item", use most common blocks instead. Fix for crash on search. Crash on inventory not fixed. --- craft_guide/api_craft_guide.lua | 86 +++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 31 deletions(-) diff --git a/craft_guide/api_craft_guide.lua b/craft_guide/api_craft_guide.lua index 59f6b49..12ef4ab 100644 --- a/craft_guide/api_craft_guide.lua +++ b/craft_guide/api_craft_guide.lua @@ -15,6 +15,30 @@ CRAFT GUIDE API -- expose object to other modules craft_guide = {} +-- fast fix to "unknown items". not even reading code, just find and replace. +craft_guide.set_stack=function(inv, listname, index, stack) + if type(stack)=="string" then + if stack=="group:wood" then + stack="default:wood" + elseif stack=="group:stone" then + stack="default:cobble" + elseif stack=="group:sand" then + stack="default:sand" + elseif stack=="group:stick" then + stack="default:stick" + elseif stack=="group:wool" then + stack="default:wool" + elseif stack=="group:dye,basecolor_black" then + stack="default:cobble" + elseif stack=="group:mesecon_conductor_craftable" then + stack="mesecons:wire_00000000_off" + elseif stack=="" then + stack="" + end + end + inv:set_stack(listname, index, stack) +end + -- define api variables craft_guide.crafts = {} @@ -196,13 +220,13 @@ end craft_guide.update_recipe = function(meta, player, stack, alternate) local inv = meta:get_inventory() for i=0,inv:get_size("build"),1 do - inv:set_stack("build", i, nil) + craft_guide.set_stack(inv, "build", i, nil) end - inv:set_stack("cook", 1, nil) - inv:set_stack("fuel", 1, nil) + craft_guide.set_stack(inv, "cook", 1, nil) + craft_guide.set_stack(inv, "fuel", 1, nil) if stack==nil then return end - inv:set_stack("output", 1, stack:get_name()) + craft_guide.set_stack(inv, "output", 1, stack:get_name()) alternate = tonumber(alternate) or 1 craft_guide.log(player:get_player_name().." requests recipe "..alternate.." for "..stack:get_name()) @@ -223,94 +247,94 @@ craft_guide.update_recipe = function(meta, player, stack, alternate) --minetest.chat_send_player(player:get_player_name(), "recipe for "..stack:get_name()..": "..dump(craft)) local itemstack = ItemStack(craft.output) - inv:set_stack("output", 1, itemstack) + craft_guide.set_stack(inv, "output", 1, itemstack) -- cook if craft.type == "cooking" then - inv:set_stack("cook", 1, craft.recipe) + craft_guide.set_stack(inv, "cook", 1, craft.recipe) meta:set_string("formspec",craft_guide.get_craft_guide_formspec(meta)) return end -- fuel if craft.type == "fuel" then - inv:set_stack("fuel", 1, craft.recipe) + craft_guide.set_stack(inv, "fuel", 1, craft.recipe) meta:set_string("formspec",craft_guide.get_craft_guide_formspec(meta)) return end -- build (shaped or shapeless) if craft.recipe[1] then if (type(craft.recipe[1]) == "string") then - inv:set_stack("build", 1, craft.recipe[1]) + craft_guide.set_stack(inv, "build", 1, craft.recipe[1]) else if craft.recipe[1][1] then - inv:set_stack("build", 1, craft.recipe[1][1]) + craft_guide.set_stack(inv, "build", 1, craft.recipe[1][1]) end if craft.recipe[1][2] then - inv:set_stack("build", 2, craft.recipe[1][2]) + craft_guide.set_stack(inv, "build", 2, craft.recipe[1][2]) end if craft.recipe[1][3] then - inv:set_stack("build", 3, craft.recipe[1][3]) + craft_guide.set_stack(inv, "build", 3, craft.recipe[1][3]) end end end if craft.recipe[2] then if (type(craft.recipe[2]) == "string") then - inv:set_stack("build", 2, craft.recipe[2]) + craft_guide.set_stack(inv, "build", 2, craft.recipe[2]) else if craft.recipe[2][1] then - inv:set_stack("build", 4, craft.recipe[2][1]) + craft_guide.set_stack(inv, "build", 4, craft.recipe[2][1]) end if craft.recipe[2][2] then - inv:set_stack("build", 5, craft.recipe[2][2]) + craft_guide.set_stack(inv, "build", 5, craft.recipe[2][2]) end if craft.recipe[2][3] then - inv:set_stack("build", 6, craft.recipe[2][3]) + craft_guide.set_stack(inv, "build", 6, craft.recipe[2][3]) end end end if craft.recipe[3] then if (type(craft.recipe[3]) == "string") then - inv:set_stack("build", 3, craft.recipe[3]) + craft_guide.set_stack(inv, "build", 3, craft.recipe[3]) else if craft.recipe[3][1] then - inv:set_stack("build", 7, craft.recipe[3][1]) + craft_guide.set_stack(inv, "build", 7, craft.recipe[3][1]) end if craft.recipe[3][2] then - inv:set_stack("build", 8, craft.recipe[3][2]) + craft_guide.set_stack(inv, "build", 8, craft.recipe[3][2]) end if craft.recipe[3][3] then - inv:set_stack("build", 9, craft.recipe[3][3]) + craft_guide.set_stack(inv, "build", 9, craft.recipe[3][3]) end end end if craft.recipe[4] then if (type(craft.recipe[4]) == "string") then - inv:set_stack("build", 4, craft.recipe[4]) + craft_guide.set_stack(inv, "build", 4, craft.recipe[4]) end end if craft.recipe[5] then if (type(craft.recipe[5]) == "string") then - inv:set_stack("build", 5, craft.recipe[5]) + craft_guide.set_stack(inv, "build", 5, craft.recipe[5]) end end if craft.recipe[6] then if (type(craft.recipe[6]) == "string") then - inv:set_stack("build", 6, craft.recipe[6]) + craft_guide.set_stack(inv, "build", 6, craft.recipe[6]) end end if craft.recipe[7] then if (type(craft.recipe[7]) == "string") then - inv:set_stack("build", 7, craft.recipe[7]) + craft_guide.set_stack(inv, "build", 7, craft.recipe[7]) end end if craft.recipe[8] then if (type(craft.recipe[8]) == "string") then - inv:set_stack("build", 8, craft.recipe[8]) + craft_guide.set_stack(inv, "build", 8, craft.recipe[8]) end end if craft.recipe[9] then if (type(craft.recipe[9]) == "string") then - inv:set_stack("build", 9, craft.recipe[9]) + craft_guide.set_stack(inv, "build", 9, craft.recipe[9]) end end meta:set_string("formspec",craft_guide.get_craft_guide_formspec(meta)) @@ -329,7 +353,7 @@ craft_guide.create_inventory = function(inv, search) --and (not def.groups.not_in_creative_inventory or def.groups.not_in_creative_inventory == 0) and def.description and def.description ~= "" then if search then - if string.find(def.name, search) or string.find(def.description, search) then + if string.find(def.name, search, 1, true) or string.find(def.description, search, 1, true) then table.insert(craft_guide_list, name) end else @@ -341,7 +365,7 @@ craft_guide.create_inventory = function(inv, search) table.sort(craft_guide_list) for i=0,inv:get_size("main"),1 do - inv:set_stack("main", i, nil) + craft_guide.set_stack(inv, "main", i, nil) end inv:set_size("main", #craft_guide_list) for _,itemstring in ipairs(craft_guide_list) do @@ -355,16 +379,16 @@ craft_guide.allow_metadata_inventory_move = function(pos, from_list, from_index, local meta = minetest.env:get_meta(pos) local inv = meta:get_inventory() if to_list == "bin" and from_list == "output" then - inv:set_stack(from_list,from_index,nil) + craft_guide.set_stack(inv, from_list,from_index,nil) craft_guide.update_recipe(meta, player, inv:get_stack(from_list, from_index)) end if to_list == "bin" and from_list == "bookmark" then - inv:set_stack(from_list,from_index,nil) + craft_guide.set_stack(inv, from_list,from_index,nil) end if to_list == "bookmark" then - inv:set_stack(to_list, to_index, inv:get_stack(from_list, from_index):get_name()) + craft_guide.set_stack(inv, to_list, to_index, inv:get_stack(from_list, from_index):get_name()) if from_list == "output" then - inv:set_stack(from_list,from_index,nil) + craft_guide.set_stack(inv, from_list,from_index,nil) end end if to_list == "output" or from_list == "output" then From ce5706cdb0bf56d60626be237975b9ebb9e31a5c Mon Sep 17 00:00:00 2001 From: AndrejIT Date: Sat, 23 Aug 2014 23:10:16 +0300 Subject: [PATCH 2/3] trying to fix crash Try to fix server crash --- craft_guide/api_craft_guide.lua | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/craft_guide/api_craft_guide.lua b/craft_guide/api_craft_guide.lua index 12ef4ab..a88e614 100644 --- a/craft_guide/api_craft_guide.lua +++ b/craft_guide/api_craft_guide.lua @@ -226,6 +226,10 @@ craft_guide.update_recipe = function(meta, player, stack, alternate) craft_guide.set_stack(inv, "fuel", 1, nil) if stack==nil then return end + if stack:get_name()=="" then + craft_guide.log("Request for item with empty name :|") + return + end craft_guide.set_stack(inv, "output", 1, stack:get_name()) alternate = tonumber(alternate) or 1 @@ -243,7 +247,7 @@ craft_guide.update_recipe = function(meta, player, stack, alternate) local craft = crafts[alternate] -- show me the unknown items - craft_guide.log(dump(craft)) + -- craft_guide.log(dump(craft)) --minetest.chat_send_player(player:get_player_name(), "recipe for "..stack:get_name()..": "..dump(craft)) local itemstack = ItemStack(craft.output) From 45d0fd3d89eba20216732d86914211114934a3dd Mon Sep 17 00:00:00 2001 From: AndrejIT Date: Sun, 14 Sep 2014 22:43:33 +0300 Subject: [PATCH 3/3] crash partially fixed now crash happens much less --- craft_guide/api_craft_guide.lua | 34 ++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/craft_guide/api_craft_guide.lua b/craft_guide/api_craft_guide.lua index a88e614..c2c172b 100644 --- a/craft_guide/api_craft_guide.lua +++ b/craft_guide/api_craft_guide.lua @@ -168,6 +168,11 @@ craft_guide.on_receive_fields = function(pos, formname, fields, player) if fields.craft_guide_search_button then page = 1 end + if player and player:is_player() then + minetest.log('action', 'CraftGuide formspec by player '..player:get_player_name()) + else + minetest.log('action', 'CraftGuide formspec without player') + end -- change page if fields.craft_guide_prev then @@ -226,6 +231,9 @@ craft_guide.update_recipe = function(meta, player, stack, alternate) craft_guide.set_stack(inv, "fuel", 1, nil) if stack==nil then return end + if type(stack)=="string" then + craft_guide.log("Request for item by string name :| - "..stack) + end if stack:get_name()=="" then craft_guide.log("Request for item with empty name :|") return @@ -380,26 +388,22 @@ end -- allow_metadata_inventory_move craft_guide.allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player) + local meta = minetest.env:get_meta(pos) local inv = meta:get_inventory() - if to_list == "bin" and from_list == "output" then + if from_list == "output" and to_list == "bin" then + craft_guide.update_recipe(meta, player, inv:get_stack(from_list, from_index)) craft_guide.set_stack(inv, from_list,from_index,nil) + elseif from_list == "output" or to_list == "output" then craft_guide.update_recipe(meta, player, inv:get_stack(from_list, from_index)) - end - if to_list == "bin" and from_list == "bookmark" then - craft_guide.set_stack(inv, from_list,from_index,nil) - end - if to_list == "bookmark" then - craft_guide.set_stack(inv, to_list, to_index, inv:get_stack(from_list, from_index):get_name()) - if from_list == "output" then - craft_guide.set_stack(inv, from_list,from_index,nil) - end - end - if to_list == "output" or from_list == "output" then - craft_guide.update_recipe(meta, player, inv:get_stack(from_list, from_index)) - end - if from_list == "bookmarks" and to_list == "bookmarks" then + elseif from_list == "bookmarks" and to_list == "bookmarks" then return count + elseif from_list == "bookmark" and to_list == "bin" then + craft_guide.set_stack(inv, from_list,from_index,nil) + elseif to_list == "bookmark" then + if inv:get_size("from_list") > from_index then + craft_guide.set_stack(inv, to_list, to_index, inv:get_stack(from_list, from_index):get_name()) + end end return 0 end