aboutsummaryrefslogtreecommitdiff
path: root/advtrains/trainlogic.lua
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2021-02-03 09:30:44 +0100
committerorwell96 <orwell@bleipb.de>2021-02-03 09:30:44 +0100
commit8ae405f00f7073bca8cb621612ab11bc730228a3 (patch)
tree8eb6d7b055df6cf2be0887cf7b3b85532e47ead2 /advtrains/trainlogic.lua
parentd8d1d27ccb622dfc8e80eb5eb44e6020a1655389 (diff)
downloadadvtrains-8ae405f00f7073bca8cb621612ab11bc730228a3.tar.gz
advtrains-8ae405f00f7073bca8cb621612ab11bc730228a3.tar.bz2
advtrains-8ae405f00f7073bca8cb621612ab11bc730228a3.zip
Discard get_node_or_nil() for area-loaded check and use either a distance-based approach or minetest.is_block_active() if available
See also https://github.com/minetest/minetest/pull/10897
Diffstat (limited to 'advtrains/trainlogic.lua')
-rw-r--r--advtrains/trainlogic.lua15
1 files changed, 4 insertions, 11 deletions
diff --git a/advtrains/trainlogic.lua b/advtrains/trainlogic.lua
index cc34b4f..76bbb7a 100644
--- a/advtrains/trainlogic.lua
+++ b/advtrains/trainlogic.lua
@@ -527,7 +527,7 @@ function advtrains.train_step_c(id, train, dtime)
local collpos = advtrains.path_get(train, atround(collindex))
if collpos then
local rcollpos=advtrains.round_vector_floor_y(collpos)
- local is_loaded_area = minetest.get_node_or_nil(rcollpos) ~= nil
+ local is_loaded_area = advtrains.is_node_loaded(rcollpos)
for x=-train.extent_h,train.extent_h do
for z=-train.extent_h,train.extent_h do
local testpos=vector.add(rcollpos, {x=x, y=0, z=z})
@@ -870,14 +870,7 @@ function advtrains.spawn_wagons(train_id)
local index = advtrains.path_get_index_by_offset(train, train.index, -data.pos_in_train)
local pos = advtrains.path_get(train, atfloor(index))
- local spawn = false
- for _,p in pairs(minetest.get_connected_players()) do
- if vector.distance(p:get_pos(),pos)<=ablkrng then
- spawn = true
- end
- end
-
- if spawn then
+ if advtrains.position_in_range(pos, ablkrng) then
--atdebug("wagon",w_id,"spawning")
local wt = advtrains.get_wagon_prototype(data)
local wagon = minetest.add_entity(pos, wt):get_luaentity()
@@ -1032,7 +1025,7 @@ function advtrains.train_check_couples(train)
if not train.cpl_front then
-- recheck front couple
local front_trains, pos = advtrains.occ.get_occupations(train, atround(train.index) + CPL_CHK_DST)
- if minetest.get_node_or_nil(pos) then -- if the position is loaded...
+ if advtrains.is_node_loaded(pos) then -- if the position is loaded...
for tid, idx in pairs(front_trains) do
local other_train = advtrains.trains[tid]
if not advtrains.train_ensure_init(tid, other_train) then
@@ -1062,7 +1055,7 @@ function advtrains.train_check_couples(train)
if not train.cpl_back then
-- recheck back couple
local back_trains, pos = advtrains.occ.get_occupations(train, atround(train.end_index) - CPL_CHK_DST)
- if minetest.get_node_or_nil(pos) then -- if the position is loaded...
+ if advtrains.is_node_loaded(pos) then -- if the position is loaded...
for tid, idx in pairs(back_trains) do
local other_train = advtrains.trains[tid]
if not advtrains.train_ensure_init(tid, other_train) then