1
0
Fork 0

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: VoxeLibre/VoxeLibre#4623
Reviewed-by: the-real-herowl <the-real-herowl@noreply.git.minetest.land>
Co-authored-by: teknomunk <teknomunk@protonmail.com>
Co-committed-by: teknomunk <teknomunk@protonmail.com>
This commit is contained in:
teknomunk 2024-08-31 23:41:06 +02:00 committed by the-real-herowl
parent 444c491e14
commit e9bf509c85
2 changed files with 14 additions and 0 deletions

View File

@ -37,6 +37,8 @@ end
-- Digging capabilities of tool -- Digging capabilities of tool
tt.register_snippet(function(itemstring, toolcaps, itemstack) tt.register_snippet(function(itemstring, toolcaps, itemstack)
local def = minetest.registered_items[itemstring] local def = minetest.registered_items[itemstring]
if not def then return end
if not toolcaps then if not toolcaps then
return return
end end
@ -165,6 +167,8 @@ end)]]
-- Food -- Food
tt.register_snippet(function(itemstring) tt.register_snippet(function(itemstring)
local def = minetest.registered_items[itemstring] local def = minetest.registered_items[itemstring]
if not def then return end
local desc local desc
if def._tt_food then if def._tt_food then
desc = S("Food item") desc = S("Food item")
@ -179,6 +183,8 @@ end)
-- Node info -- Node info
tt.register_snippet(function(itemstring) tt.register_snippet(function(itemstring)
local def = minetest.registered_items[itemstring] local def = minetest.registered_items[itemstring]
if not def then return end
local desc = "" local desc = ""
-- Health-related node facts -- Health-related node facts

View File

@ -64,6 +64,8 @@ end)
tt.register_snippet(function(itemstring) tt.register_snippet(function(itemstring)
local def = minetest.registered_items[itemstring] local def = minetest.registered_items[itemstring]
if not def then return end
local s = "" local s = ""
if def.groups.eatable and def.groups.eatable > 0 then if def.groups.eatable and def.groups.eatable > 0 then
s = s .. S("Hunger points: +@1", def.groups.eatable) s = s .. S("Hunger points: +@1", def.groups.eatable)
@ -89,6 +91,8 @@ end)
tt.register_snippet(function(itemstring) tt.register_snippet(function(itemstring)
local def = minetest.registered_items[itemstring] local def = minetest.registered_items[itemstring]
if not def then return end
if def.groups.place_flowerlike == 1 then if def.groups.place_flowerlike == 1 then
return S("Grows on grass blocks or dirt") return S("Grows on grass blocks or dirt")
elseif def.groups.place_flowerlike == 2 then elseif def.groups.place_flowerlike == 2 then
@ -98,6 +102,8 @@ end)
tt.register_snippet(function(itemstring) tt.register_snippet(function(itemstring)
local def = minetest.registered_items[itemstring] local def = minetest.registered_items[itemstring]
if not def then return end
if def.groups.flammable then if def.groups.flammable then
return S("Flammable") return S("Flammable")
end end
@ -127,6 +133,8 @@ end)
tt.register_snippet(function(itemstring, _, itemstack) tt.register_snippet(function(itemstring, _, itemstack)
if not itemstack then return end if not itemstack then return end
local def = itemstack:get_definition() local def = itemstack:get_definition()
if not def then return end
if def.groups._mcl_potion ~= 1 then return end if def.groups._mcl_potion ~= 1 then return end
local s = "" local s = ""