From 233e253a5d371102018dfab9c530e0dbad5f8b43 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sat, 6 Apr 2024 07:33:47 +0000 Subject: [PATCH] Harden against unknown nodes --- mods/ENTITIES/mcl_minecarts/carts.lua | 37 +++++++++++------------ mods/ENTITIES/mcl_minecarts/functions.lua | 4 +-- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/mods/ENTITIES/mcl_minecarts/carts.lua b/mods/ENTITIES/mcl_minecarts/carts.lua index 8b6c1f767..f72a33830 100644 --- a/mods/ENTITIES/mcl_minecarts/carts.lua +++ b/mods/ENTITIES/mcl_minecarts/carts.lua @@ -56,15 +56,16 @@ local function handle_cart_enter_exit(self, pos, next_dir, event) local check_pos = pos + dir * check[1] + right * check[2] + up * check[3] local node = minetest.get_node(check_pos) local node_def = minetest.registered_nodes[node.name] + if node_def then + -- node-specific hook + local hook_name = "_mcl_minecarts_"..event..check[4] + local hook = node_def[hook_name] + if hook then hook(check_pos, self, next_dir, pos) end - -- node-specific hook - local hook_name = "_mcl_minecarts_"..event..check[4] - local hook = node_def[hook_name] - if hook then hook(check_pos, self, next_dir, pos) end - - -- global minecart hook - hook = mcl_minecarts[event..check[4]] - if hook then hook(check_pos, self, next_dir, node_def) end + -- global minecart hook + hook = mcl_minecarts[event..check[4]] + if hook then hook(check_pos, self, next_dir, node_def) end + end end -- Handle cart-specific behaviors @@ -85,9 +86,11 @@ local function handle_cart_node_watches(self, dtime) for _,node_pos in ipairs(watches) do local node = minetest.get_node(node_pos) local node_def = minetest.registered_nodes[node.name] - local hook = node_def._mcl_minecarts_node_on_step - if hook and hook(node_pos, self, dtime) then - new_watches[#new_watches+1] = node_pos + if node_def then + local hook = node_def._mcl_minecarts_node_on_step + if hook and hook(node_pos, self, dtime) then + new_watches[#new_watches+1] = node_pos + end end end @@ -197,10 +200,8 @@ local function calculate_acceleration(self, staticdata) acceleration = 0.6 elseif staticdata.velocity >= ( node_def._max_acceleration_velocity or max_vel ) then -- Standard friction - else - if node_def._rail_acceleration then - acceleration = node_def._rail_acceleration * 4 - end + elseif node_def and node_def._rail_acceleration then + acceleration = node_def._rail_acceleration * 4 end -- Factor in gravity after everything else @@ -860,11 +861,9 @@ function mcl_minecarts.place_minecart(itemstack, pointed_thing, placer) end local function dropper_place_minecart(dropitem, pos) - local node = minetest.get_node(pos) - local nodedef = minetest.registered_nodes[node.name] - -- Don't try to place the minecart if pos isn't a rail - if (nodedef.groups.rail or 0) == 0 then return false end + local node = minetest.get_node(pos) + if minetest.get_item_group(node.name, "rail") == 0 then return false end mcl_minecarts.place_minecart(dropitem, { above = pos, diff --git a/mods/ENTITIES/mcl_minecarts/functions.lua b/mods/ENTITIES/mcl_minecarts/functions.lua index a991793be..0b0d664ce 100644 --- a/mods/ENTITIES/mcl_minecarts/functions.lua +++ b/mods/ENTITIES/mcl_minecarts/functions.lua @@ -207,8 +207,8 @@ local function update_rail_connections(pos, opt) local node = minetest.get_node(pos) local nodedef = minetest.registered_nodes[node.name] - if not nodedef._mcl_minecarts then - minetest.log("warning", "attemting to rail connect "..node.name) + if not nodedef or not nodedef._mcl_minecarts then + minetest.log("warning", "attemting to rail connect to "..node.name) return end