mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-05 15:51: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.sound_prefix = sound_prefix
|
||||
self.animation_type = animation_type
|
||||
self.object:set_properties({
|
||||
local obj = self.object
|
||||
obj:set_armor_groups({ immortal = 1 })
|
||||
obj:set_properties({
|
||||
textures = textures,
|
||||
mesh = mesh_prefix .. (double and "_double" or "") .. ".b3d",
|
||||
})
|
||||
self:set_yaw(dir)
|
||||
self.players = {}
|
||||
end,
|
||||
|
||||
reinitialize = function(self, node_name)
|
||||
|
@ -102,9 +105,12 @@ minetest.register_entity("mcl_chests:chest", {
|
|||
return true
|
||||
end,
|
||||
|
||||
on_activate = function(self)
|
||||
self.object:set_armor_groups({ immortal = 1 })
|
||||
self.players = {}
|
||||
on_activate = function(self, initialization_data)
|
||||
if initialization_data:find("^return") then
|
||||
self:initialize(unpack(minetest.deserialize(initialization_data)))
|
||||
else
|
||||
minetest.log("warning", debug.traceback("[mcl_chests] on_activate called without initialization_data"))
|
||||
end
|
||||
end,
|
||||
|
||||
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,
|
||||
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 luaentity = obj:get_luaentity()
|
||||
luaentity:initialize(pos, node_name, textures, dir, double, sound_prefix, mesh_prefix, animation_type)
|
||||
return luaentity
|
||||
local initialization_data = minetest.serialize({pos, node_name, textures, dir, double, sound_prefix,
|
||||
mesh_prefix, animation_type})
|
||||
local obj = minetest.add_entity(entity_pos, "mcl_chests:chest", initialization_data)
|
||||
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
|
||||
mcl_chests.create_entity = create_entity
|
||||
|
||||
|
|
Loading…
Reference in a new issue