1
0
mirror of https://github.com/mt-mods/pipeworks.git synced 2025-06-30 15:20:34 +02:00

Version MFF.

This commit is contained in:
sys4-fr
2018-09-08 14:42:39 +02:00
parent a1ed3acd7a
commit 85b55f57a4
193 changed files with 121 additions and 85 deletions

48
luaentity.lua Normal file → Executable file
View File

@ -29,7 +29,7 @@ local function read_entities()
end
local function write_entities()
for _, entity in pairs(luaentity.entities) do
for _, entity in pairs(luaentity.entities or {}) do
setmetatable(entity, nil)
for _, attached in pairs(entity._attached_entities) do
if attached.entity then
@ -53,31 +53,29 @@ end
local active_blocks = {} -- These only contain active blocks near players (i.e., not forceloaded ones)
local handle_active_blocks_step = 2
local handle_active_blocks_timer = 0
minetest.register_globalstep(function(dtime)
handle_active_blocks_timer = handle_active_blocks_timer + dtime
if handle_active_blocks_timer >= handle_active_blocks_step then
handle_active_blocks_timer = handle_active_blocks_timer - handle_active_blocks_step
local active_block_range = tonumber(minetest.setting_get("active_block_range")) or 2
local new_active_blocks = {}
for _, player in ipairs(minetest.get_connected_players()) do
local blockpos = get_blockpos(player:getpos())
local minp = vector.subtract(blockpos, active_block_range)
local maxp = vector.add(blockpos, active_block_range)
local function active_blocks_step()
local active_block_range = tonumber(minetest.setting_get("active_block_range")) or 2
local new_active_blocks = {}
for _, player in ipairs(minetest.get_connected_players()) do
local blockpos = get_blockpos(player:getpos())
local minp = vector.subtract(blockpos, active_block_range)
local maxp = vector.add(blockpos, active_block_range)
for x = minp.x, maxp.x do
for y = minp.y, maxp.y do
for z = minp.z, maxp.z do
local pos = {x = x, y = y, z = z}
new_active_blocks[minetest.hash_node_position(pos)] = pos
end
end
end
for x = minp.x, maxp.x do
for y = minp.y, maxp.y do
for z = minp.z, maxp.z do
local pos = {x = x, y = y, z = z}
new_active_blocks[minetest.hash_node_position(pos)] = pos
end
end
end
active_blocks = new_active_blocks
-- todo: callbacks on block load/unload
end
end)
active_blocks = new_active_blocks
-- todo: callbacks on block load/unload
minetest.after(handle_active_blocks_step, active_blocks_step)
end
minetest.after(0, active_blocks_step)
local function is_active(pos)
return active_blocks[minetest.hash_node_position(get_blockpos(pos))] ~= nil
@ -194,7 +192,7 @@ local entitydef_default = {
end
end,
getvelocity = function(self)
return vector.new(self._velocity)
return vector.new(self._velocity)
end,
setvelocity = function(self, velocity)
self._velocity = vector.new(velocity)
@ -272,7 +270,7 @@ function luaentity.add_entity(pos, name)
_acceleration = {x = 0, y = 0, z = 0},
_attached_entities = {},
}
local prototype = luaentity.registered_entities[name]
setmetatable(entity, prototype) -- Default to prototype for other methods
luaentity.entities[index] = entity