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.
master
Gabriel Pérez-Cerezo 2021-06-30 23:46:00 +02:00
parent 9b0ec771d7
commit 30f4e342fd
2 changed files with 58 additions and 9 deletions

View File

@ -56,3 +56,8 @@ advtrains_dtime_limit (DTime Limit for slow-down) float 0.2 0 5
# Time interval in seconds in which advtrains stores its save data to disk # Time interval in seconds in which advtrains stores its save data to disk
# Nevertheless, advtrains saves all data when shutting down the server. # Nevertheless, advtrains saves all data when shutting down the server.
advtrains_save_interval (Save Interval) int 60 20 3600 advtrains_save_interval (Save Interval) int 60 20 3600
# Enable forgiving collision mode
# If enabled, trains only collide with nodes with "normal" drawtype.
advtrains_forgiving_collision (Forgiving Collision mode) bool false

View File

@ -1368,17 +1368,61 @@ function advtrains.invalidate_path(id)
end end
--not blocking trains group --not blocking trains group
function advtrains.train_collides(node)
if node and minetest.registered_nodes[node.name] then if minetest.settings:get_bool("advtrains_forgiving_collision") then
local ndef = minetest.registered_nodes[node.name] function advtrains.train_collides(node)
-- if the node is drawtype normal (that is a full cube) then it does collide if node and minetest.registered_nodes[node.name] then
if ndef.drawtype == "normal" then local ndef = minetest.registered_nodes[node.name]
-- except if it is not_blocking_trains -- if the node is drawtype normal (that is a full cube) then it does collide
if ndef.groups.not_blocking_trains and ndef.groups.not_blocking_trains ~= 0 then if ndef.drawtype == "normal" then
return false -- 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
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 return true
end end
end
return false
end 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 end