1
0
Fork 0

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:23:18 +01:00
parent 95cfa43483
commit 962500b189
1 changed files with 4 additions and 2 deletions

View File

@ -16,7 +16,8 @@ local spawn_children_on_die = function(child_mob, children_count, spawn_distance
if not eject_speed then if not eject_speed then
eject_speed = 1 eject_speed = 1
end end
local mother_stuck = minetest.registered_nodes[minetest.get_node(pos).name].walkable local mndef = minetest.registered_nodes[minetest.get_node(pos).name]
local mother_stuck = mndef and mndef.walkable
angle = math.random(0, math.pi*2) angle = math.random(0, math.pi*2)
local children = {} local children = {}
for i=1,children_count do for i=1,children_count do
@ -26,7 +27,8 @@ local spawn_children_on_die = function(child_mob, children_count, spawn_distance
-- If child would end up in a wall, use position of the "mother", unless -- If child would end up in a wall, use position of the "mother", unless
-- the "mother" was stuck as well -- the "mother" was stuck as well
local speed_penalty = 1 local speed_penalty = 1
if (not mother_stuck) and minetest.registered_nodes[minetest.get_node(newpos).name].walkable then local cndef = minetest.registered_nodes[minetest.get_node(newpos).name]
if (not mother_stuck) and cndef and cndef.walkable then
newpos = pos newpos = pos
speed_penalty = 0.5 speed_penalty = 0.5
end end