Add check for unknown nodes.

* Check if node has a definition table before attempting to evaluate its
  attributes.
* Define local variable to cache multiple accesses to `registered_nodes[]`
  and improve readability.
This commit is contained in:
kabou 2022-03-09 02:05:38 +01:00
parent b9c2c3bd0a
commit 4a1b93bbfa

View File

@ -478,7 +478,8 @@ mobs:register_mob("mobs_mc:enderman", {
-- Selected node needs to have 3 nodes of free space above
for u=1, 3 do
local node = minetest.get_node({x=nodepos.x, y=nodepos.y+u, z=nodepos.z})
if minetest.registered_nodes[node.name].walkable then
local ndef = minetest.registered_nodes[node.name]
if ndef and ndef.walkable then
node_ok = false
break
end
@ -512,7 +513,8 @@ mobs:register_mob("mobs_mc:enderman", {
node_ok = true
for u=1, 3 do
local node = minetest.get_node({x=nodepos.x, y=nodepos.y+u, z=nodepos.z})
if minetest.registered_nodes[node.name].walkable then
local ndef = minetest.registered_nodes[node.name]
if ndef and ndef.walkable then
node_ok = false
break
end