Respawn enchantbook ent when rightclick table

This commit is contained in:
Wuzzy 2020-12-14 19:15:40 +01:00
parent 73cb6b7a22
commit e6d99b8b18

@ -142,7 +142,20 @@ minetest.register_craftitem("mcl_enchanting:book_enchanted", {
stack_max = 1,
})
local spawn_book_entity = function(pos)
local spawn_book_entity = function(pos, respawn)
if respawn then
-- Check if we already have a book
local objs = minetest.get_objects_inside_radius(pos, 1)
for o=1, #objs do
local obj = objs[o]
local lua = obj:get_luaentity()
if lua and lua.name == "mcl_enchanting:book" then
if lua._table_pos and vector.equals(pos, lua._table_pos) then
return
end
end
end
end
local obj = minetest.add_entity(vector.add(pos, mcl_enchanting.book_offset), "mcl_enchanting:book")
if obj then
local lua = obj:get_luaentity()
@ -221,6 +234,8 @@ minetest.register_node("mcl_enchanting:table", {
player_meta:set_int("mcl_enchanting:num_bookshelves", num_bookshelves)
player_meta:set_string("mcl_enchanting:table_name", table_name)
mcl_enchanting.show_enchanting_formspec(clicker)
-- Respawn book entity just in case it got lost
spawn_book_entity(pos, true)
end,
on_construct = function(pos)
spawn_book_entity(pos)