aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authororwell96 <mono96.mml@gmail.com>2016-10-29 21:07:51 +0200
committerorwell96 <mono96.mml@gmail.com>2016-10-29 21:07:51 +0200
commitbe37a649f7ea83007ee15effed0a474fb8d00f59 (patch)
treef2e880cbefaed4ed6615d884794a9c30e222a39c
parentcddc92d1debd0f804d9325fbe039d42b69af6ef8 (diff)
downloadadvtrains-be37a649f7ea83007ee15effed0a474fb8d00f59.tar.gz
advtrains-be37a649f7ea83007ee15effed0a474fb8d00f59.tar.bz2
advtrains-be37a649f7ea83007ee15effed0a474fb8d00f59.zip
fix unloaded map chunk travelling
-rw-r--r--advtrains.zipbin1326007 -> 1326055 bytes
-rw-r--r--trainlogic.lua11
2 files changed, 6 insertions, 5 deletions
diff --git a/advtrains.zip b/advtrains.zip
index b1e88d5..38995c6 100644
--- a/advtrains.zip
+++ b/advtrains.zip
Binary files differ
diff --git a/trainlogic.lua b/trainlogic.lua
index 0291e8f..f16e1e2 100644
--- a/trainlogic.lua
+++ b/trainlogic.lua
@@ -246,11 +246,12 @@ function advtrains.train_step(id, train, dtime)
--check for any trainpart entities if they have been unloaded. do this only if train is near a player, to not spawn entities into unloaded areas
train.check_trainpartload=(train.check_trainpartload or 0)-dtime
local node_range=(math.max((minetest.setting_get("active_block_range") or 0),1)*16)
- if train.check_trainpartload<=0 and posfront and posback then
- --print(minetest.pos_to_string(posfront))
+ if train.check_trainpartload<=0 then
+ local ori_pos=advtrains.get_real_index_position(path, train.index) --not much to calculate
+
local should_check=false
for _,p in ipairs(minetest.get_connected_players()) do
- should_check=should_check or ((vector.distance(posfront, p:getpos())<node_range) and (vector.distance(posback, p:getpos())<node_range))
+ should_check=should_check or ((vector.distance(ori_pos, p:getpos())<node_range))
end
if should_check then
--it is better to iterate luaentites only once
@@ -274,7 +275,7 @@ function advtrains.train_step(id, train, dtime)
elseif advtrains.wagon_save[w_id] then
--print(w_id.." not loaded, but save available")
--spawn a new and initialize it with the properties from wagon_save
- local le=minetest.env:add_entity(posfront, advtrains.wagon_save[w_id].entity_name):get_luaentity()
+ local le=minetest.env:add_entity(ori_pos, advtrains.wagon_save[w_id].entity_name):get_luaentity()
for k,v in pairs(advtrains.wagon_save[w_id]) do
le[k]=v
end
@@ -287,7 +288,7 @@ function advtrains.train_step(id, train, dtime)
end
end
end
- train.check_trainpartload=10
+ train.check_trainpartload=2
end