mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-22 10:31:06 +01:00
Fix invisible chests
Pass chest entity initialization data to on_activate as staticdata so initialization is atomic, preventing premature deletion of chest entity by concurrent server steps.
This commit is contained in:
parent
709b73295c
commit
d0d9600709
1 changed files with 18 additions and 8 deletions
|
@ -75,11 +75,14 @@ minetest.register_entity("mcl_chests:chest", {
|
||||||
self.node_name = node_name
|
self.node_name = node_name
|
||||||
self.sound_prefix = sound_prefix
|
self.sound_prefix = sound_prefix
|
||||||
self.animation_type = animation_type
|
self.animation_type = animation_type
|
||||||
self.object:set_properties({
|
local obj = self.object
|
||||||
|
obj:set_armor_groups({ immortal = 1 })
|
||||||
|
obj:set_properties({
|
||||||
textures = textures,
|
textures = textures,
|
||||||
mesh = mesh_prefix .. (double and "_double" or "") .. ".b3d",
|
mesh = mesh_prefix .. (double and "_double" or "") .. ".b3d",
|
||||||
})
|
})
|
||||||
self:set_yaw(dir)
|
self:set_yaw(dir)
|
||||||
|
self.players = {}
|
||||||
end,
|
end,
|
||||||
|
|
||||||
reinitialize = function(self, node_name)
|
reinitialize = function(self, node_name)
|
||||||
|
@ -102,9 +105,12 @@ minetest.register_entity("mcl_chests:chest", {
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_activate = function(self)
|
on_activate = function(self, initialization_data)
|
||||||
self.object:set_armor_groups({ immortal = 1 })
|
if initialization_data:find("^return") then
|
||||||
self.players = {}
|
self:initialize(unpack(minetest.deserialize(initialization_data)))
|
||||||
|
else
|
||||||
|
minetest.log("warning", debug.traceback("[mcl_chests] on_activate called without initialization_data"))
|
||||||
|
end
|
||||||
end,
|
end,
|
||||||
|
|
||||||
on_step = function(self, dtime)
|
on_step = function(self, dtime)
|
||||||
|
@ -140,10 +146,14 @@ end
|
||||||
local function create_entity(pos, node_name, textures, param2, double, sound_prefix, mesh_prefix, animation_type, dir,
|
local function create_entity(pos, node_name, textures, param2, double, sound_prefix, mesh_prefix, animation_type, dir,
|
||||||
entity_pos)
|
entity_pos)
|
||||||
dir, entity_pos = get_entity_info(pos, param2, double, dir, entity_pos)
|
dir, entity_pos = get_entity_info(pos, param2, double, dir, entity_pos)
|
||||||
local obj = minetest.add_entity(entity_pos, "mcl_chests:chest")
|
local initialization_data = minetest.serialize({pos, node_name, textures, dir, double, sound_prefix,
|
||||||
local luaentity = obj:get_luaentity()
|
mesh_prefix, animation_type})
|
||||||
luaentity:initialize(pos, node_name, textures, dir, double, sound_prefix, mesh_prefix, animation_type)
|
local obj = minetest.add_entity(entity_pos, "mcl_chests:chest", initialization_data)
|
||||||
return luaentity
|
if obj and obj:get_pos() then
|
||||||
|
return obj:get_luaentity()
|
||||||
|
else
|
||||||
|
minetest.log("warning", "[mcl_chests] Failed to create entity at " .. (entity_pos and minetest.pos_to_string(entity_pos, 1) or "nil"))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
mcl_chests.create_entity = create_entity
|
mcl_chests.create_entity = create_entity
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue