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 12:11:59 +01:00
parent 88f7a150c7
commit 818cbb2f48
1 changed files with 3 additions and 2 deletions

View File

@ -432,7 +432,8 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o
-- Slow down or speed up -- Slow down or speed up
local acc = dir.y * -1.8 local acc = dir.y * -1.8
local friction = 0.4 local friction = 0.4
local speed_mod = minetest.registered_nodes[minetest.get_node(pos).name]._rail_acceleration local ndef = minetest.registered_nodes[minetest.get_node(pos).name]
local speed_mod = ndef and ndef._rail_acceleration
acc = acc - friction acc = acc - friction
@ -860,4 +861,4 @@ if has_mcl_wip then
mcl_wip.register_wip_item("mcl_minecarts:furnace_minecart") mcl_wip.register_wip_item("mcl_minecarts:furnace_minecart")
mcl_wip.register_wip_item("mcl_minecarts:command_block_minecart") mcl_wip.register_wip_item("mcl_minecarts:command_block_minecart")
mcl_wip.register_wip_item("mcl_minecarts:hopper_minecart") mcl_wip.register_wip_item("mcl_minecarts:hopper_minecart")
end end