Fix duplicated book entities on the enchanting table (#155)
Because of a race condition, the check for whether to regenerate a book entity can happen while the entity is unloaded, resulting in multiple entities per enchanting server.
This commit is contained in:
parent
3b5b3f0c11
commit
4305841cf2
@ -186,11 +186,6 @@ function enchanting.destruct(pos)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function enchanting.timer(pos)
|
function enchanting.timer(pos)
|
||||||
local num = #minetest.get_objects_inside_radius(pos, 0.9)
|
|
||||||
if num == 0 then
|
|
||||||
minetest.add_entity({x = pos.x, y = pos.y + 0.85, z = pos.z}, "xdecor:book_open")
|
|
||||||
end
|
|
||||||
|
|
||||||
local minp = {x = pos.x - 2, y = pos.y, z = pos.z - 2}
|
local minp = {x = pos.x - 2, y = pos.y, z = pos.z - 2}
|
||||||
local maxp = {x = pos.x + 2, y = pos.y + 1, z = pos.z + 2}
|
local maxp = {x = pos.x + 2, y = pos.y + 1, z = pos.z + 2}
|
||||||
|
|
||||||
@ -249,14 +244,26 @@ minetest.register_entity("xdecor:book_open", {
|
|||||||
collisionbox = {0},
|
collisionbox = {0},
|
||||||
physical = false,
|
physical = false,
|
||||||
textures = {"xdecor_book_open.png"},
|
textures = {"xdecor_book_open.png"},
|
||||||
on_activate = function(self)
|
static_save = false,
|
||||||
local pos = self.object:get_pos()
|
})
|
||||||
local pos_under = {x = pos.x, y = pos.y - 1, z = pos.z}
|
|
||||||
|
|
||||||
if minetest.get_node(pos_under).name ~= "xdecor:enchantment_table" then
|
minetest.register_lbm({
|
||||||
self.object:remove()
|
label = "recreate book entity",
|
||||||
|
name = "xdecor:create_book_entity",
|
||||||
|
nodenames = {"xdecor:enchantment_table"},
|
||||||
|
run_at_every_load = true,
|
||||||
|
action = function(pos, node)
|
||||||
|
local objs = minetest.get_objects_inside_radius(pos, 0.9)
|
||||||
|
|
||||||
|
for _, obj in ipairs(objs) do
|
||||||
|
local e = obj:get_luaentity()
|
||||||
|
if e and e.name == "xdecor:book_open" then
|
||||||
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
minetest.add_entity({x = pos.x, y = pos.y + 0.85, z = pos.z}, "xdecor:book_open")
|
||||||
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
function enchanting:register_tools(mod, def)
|
function enchanting:register_tools(mod, def)
|
||||||
|
Loading…
Reference in New Issue
Block a user