From 30f4e342fdc6bd74c72bcbb649d4e1ccf974bcab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gabriel=20P=C3=A9rez-Cerezo?= Date: Wed, 30 Jun 2021 23:46:00 +0200 Subject: Make the collision mode configurable If the advtrains_forgiving_collision setting is set to true, then the train only collides with nodes that do not have normal drawtype. Otherwise the old behavior is restored. This change is being made because there were users and mods relying on the old behavior, such as the railroad_paraphernalia mod's track blocker. --- advtrains/trainlogic.lua | 62 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 53 insertions(+), 9 deletions(-) (limited to 'advtrains/trainlogic.lua') diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua index 7093929..0f2a66e 100644 --- a/advtrains/trainlogic.lua +++ b/advtrains/trainlogic.lua @@ -1368,17 +1368,61 @@ function advtrains.invalidate_path(id) end --not blocking trains group -function advtrains.train_collides(node) - if node and minetest.registered_nodes[node.name] then - local ndef = minetest.registered_nodes[node.name] - -- if the node is drawtype normal (that is a full cube) then it does collide - if ndef.drawtype == "normal" then - -- except if it is not_blocking_trains - if ndef.groups.not_blocking_trains and ndef.groups.not_blocking_trains ~= 0 then - return false + +if minetest.settings:get_bool("advtrains_forgiving_collision") then + function advtrains.train_collides(node) + if node and minetest.registered_nodes[node.name] then + local ndef = minetest.registered_nodes[node.name] + -- if the node is drawtype normal (that is a full cube) then it does collide + if ndef.drawtype == "normal" then + -- except if it is not_blocking_trains + if ndef.groups.not_blocking_trains and ndef.groups.not_blocking_trains ~= 0 then + return false + end + return true end + end + return false + end +else + function advtrains.train_collides(node) + if node and minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].walkable then + if not minetest.registered_nodes[node.name].groups.not_blocking_trains then return true end + end + return false end - return false + + local nonblocknodes={ + "default:fence_wood", + "default:fence_acacia_wood", + "default:fence_aspen_wood", + "default:fence_pine_wood", + "default:fence_junglewood", + "default:torch", + "bones:bones", + + "default:sign_wall", + "signs:sign_wall", + "signs:sign_wall_blue", + "signs:sign_wall_brown", + "signs:sign_wall_orange", + "signs:sign_wall_green", + "signs:sign_yard", + "signs:sign_wall_white_black", + "signs:sign_wall_red", + "signs:sign_wall_white_red", + "signs:sign_wall_yellow", + "signs:sign_post", + "signs:sign_hanging", + + } + minetest.after(0, function() + for _,name in ipairs(nonblocknodes) do + if minetest.registered_nodes[name] then + minetest.registered_nodes[name].groups.not_blocking_trains=1 + end + end + end) end -- cgit v1.2.3