mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-01 17:38:41 +00:00
Use "core" namespace internally
This commit is contained in:
parent
1cd512913e
commit
c4359ff65c
45 changed files with 812 additions and 843 deletions
|
@ -1,8 +1,8 @@
|
|||
-- Prevent anyone else accessing those functions
|
||||
local forceload_block = minetest.forceload_block
|
||||
local forceload_free_block = minetest.forceload_free_block
|
||||
minetest.forceload_block = nil
|
||||
minetest.forceload_free_block = nil
|
||||
local forceload_block = core.forceload_block
|
||||
local forceload_free_block = core.forceload_free_block
|
||||
core.forceload_block = nil
|
||||
core.forceload_free_block = nil
|
||||
|
||||
local blocks_forceloaded
|
||||
local total_forceloaded = 0
|
||||
|
@ -15,14 +15,14 @@ local function get_blockpos(pos)
|
|||
z = math.floor(pos.z/BLOCKSIZE)}
|
||||
end
|
||||
|
||||
function minetest.forceload_block(pos)
|
||||
function core.forceload_block(pos)
|
||||
local blockpos = get_blockpos(pos)
|
||||
local hash = minetest.hash_node_position(blockpos)
|
||||
local hash = core.hash_node_position(blockpos)
|
||||
if blocks_forceloaded[hash] ~= nil then
|
||||
blocks_forceloaded[hash] = blocks_forceloaded[hash] + 1
|
||||
return true
|
||||
else
|
||||
if total_forceloaded >= (tonumber(minetest.setting_get("max_forceloaded_blocks")) or 16) then
|
||||
if total_forceloaded >= (tonumber(core.setting_get("max_forceloaded_blocks")) or 16) then
|
||||
return false
|
||||
end
|
||||
total_forceloaded = total_forceloaded+1
|
||||
|
@ -32,9 +32,9 @@ function minetest.forceload_block(pos)
|
|||
end
|
||||
end
|
||||
|
||||
function minetest.forceload_free_block(pos)
|
||||
function core.forceload_free_block(pos)
|
||||
local blockpos = get_blockpos(pos)
|
||||
local hash = minetest.hash_node_position(blockpos)
|
||||
local hash = core.hash_node_position(blockpos)
|
||||
if blocks_forceloaded[hash] == nil then return end
|
||||
if blocks_forceloaded[hash] > 1 then
|
||||
blocks_forceloaded[hash] = blocks_forceloaded[hash] - 1
|
||||
|
@ -46,19 +46,19 @@ function minetest.forceload_free_block(pos)
|
|||
end
|
||||
|
||||
-- Keep the forceloaded areas after restart
|
||||
local wpath = minetest.get_worldpath()
|
||||
local wpath = core.get_worldpath()
|
||||
local function read_file(filename)
|
||||
local f = io.open(filename, "r")
|
||||
if f==nil then return {} end
|
||||
local t = f:read("*all")
|
||||
f:close()
|
||||
if t=="" or t==nil then return {} end
|
||||
return minetest.deserialize(t)
|
||||
return core.deserialize(t)
|
||||
end
|
||||
|
||||
local function write_file(filename, table)
|
||||
local f = io.open(filename, "w")
|
||||
f:write(minetest.serialize(table))
|
||||
f:write(core.serialize(table))
|
||||
f:close()
|
||||
end
|
||||
|
||||
|
@ -67,13 +67,13 @@ for _, __ in pairs(blocks_forceloaded) do
|
|||
total_forceloaded = total_forceloaded + 1
|
||||
end
|
||||
|
||||
minetest.after(5, function()
|
||||
core.after(5, function()
|
||||
for hash, _ in pairs(blocks_forceloaded) do
|
||||
local blockpos = minetest.get_position_from_hash(hash)
|
||||
local blockpos = core.get_position_from_hash(hash)
|
||||
forceload_block(blockpos)
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_shutdown(function()
|
||||
core.register_on_shutdown(function()
|
||||
write_file(wpath.."/force_loaded.txt", blocks_forceloaded)
|
||||
end)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue