From e6d99b8b188fb476b9f981f8a6fc21cccd0fa4d2 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 14 Dec 2020 19:15:40 +0100 Subject: [PATCH] Respawn enchantbook ent when rightclick table --- mods/ITEMS/mcl_enchanting/init.lua | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_enchanting/init.lua b/mods/ITEMS/mcl_enchanting/init.lua index 08e8f86572..315cadc895 100644 --- a/mods/ITEMS/mcl_enchanting/init.lua +++ b/mods/ITEMS/mcl_enchanting/init.lua @@ -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)