Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure blocks stay force-loaded so long as anyone online is force-loading them #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion tubelib/forceload.lua
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,29 @@ minetest.register_on_joinplayer(function(player)
end)

minetest.register_on_leaveplayer(function(player)
local all_players = minetest.get_connected_players()
local all_other_forceloads = {}
for _,other_player in ipairs(all_players) do
if other_player ~= player then
for _,other_pos in ipairs(get_pos_list(other_player)) do
local other_corner = calc_area(other_pos)
table.insert(all_other_forceloads, other_corner)
end
end
end
local function loaded_by_another(pos)
local corner = calc_area(pos)
for _,other_corner in ipairs(all_other_forceloads) do
if vector.equals(corner, other_corner) then
return true
end
end
return false
end
for _,pos in ipairs(get_pos_list(player)) do
minetest.forceload_free_block(pos, true)
if not loaded_by_another(pos) then
minetest.forceload_free_block(pos, true)
end
end
end)

Expand Down