From e9bf509c85e2d4d612741d566910f06e4a397bf8 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sat, 31 Aug 2024 23:41:06 +0200 Subject: [PATCH] Add crash guards against unknown items (#4623) This adds defensive checks to guard against crashing when digging with an unknown item in hand. Reviewed-on: https://git.minetest.land/VoxeLibre/VoxeLibre/pulls/4623 Reviewed-by: the-real-herowl Co-authored-by: teknomunk Co-committed-by: teknomunk --- mods/HELP/mcl_tt/snippets_base.lua | 6 ++++++ mods/HELP/mcl_tt/snippets_mcl.lua | 8 ++++++++ 2 files changed, 14 insertions(+) diff --git a/mods/HELP/mcl_tt/snippets_base.lua b/mods/HELP/mcl_tt/snippets_base.lua index f20f3dfe2..0468c50ac 100644 --- a/mods/HELP/mcl_tt/snippets_base.lua +++ b/mods/HELP/mcl_tt/snippets_base.lua @@ -37,6 +37,8 @@ end -- Digging capabilities of tool tt.register_snippet(function(itemstring, toolcaps, itemstack) local def = minetest.registered_items[itemstring] + if not def then return end + if not toolcaps then return end @@ -165,6 +167,8 @@ end)]] -- Food tt.register_snippet(function(itemstring) local def = minetest.registered_items[itemstring] + if not def then return end + local desc if def._tt_food then desc = S("Food item") @@ -179,6 +183,8 @@ end) -- Node info tt.register_snippet(function(itemstring) local def = minetest.registered_items[itemstring] + if not def then return end + local desc = "" -- Health-related node facts diff --git a/mods/HELP/mcl_tt/snippets_mcl.lua b/mods/HELP/mcl_tt/snippets_mcl.lua index 639422295..a964b96a3 100644 --- a/mods/HELP/mcl_tt/snippets_mcl.lua +++ b/mods/HELP/mcl_tt/snippets_mcl.lua @@ -64,6 +64,8 @@ end) tt.register_snippet(function(itemstring) local def = minetest.registered_items[itemstring] + if not def then return end + local s = "" if def.groups.eatable and def.groups.eatable > 0 then s = s .. S("Hunger points: +@1", def.groups.eatable) @@ -89,6 +91,8 @@ end) tt.register_snippet(function(itemstring) local def = minetest.registered_items[itemstring] + if not def then return end + if def.groups.place_flowerlike == 1 then return S("Grows on grass blocks or dirt") elseif def.groups.place_flowerlike == 2 then @@ -98,6 +102,8 @@ end) tt.register_snippet(function(itemstring) local def = minetest.registered_items[itemstring] + if not def then return end + if def.groups.flammable then return S("Flammable") end @@ -127,6 +133,8 @@ end) tt.register_snippet(function(itemstring, _, itemstack) if not itemstack then return end local def = itemstack:get_definition() + if not def then return end + if def.groups._mcl_potion ~= 1 then return end local s = ""