From 4be2f2f76dee702e00e88efb4327942b77e0f20e Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 14 Dec 2020 18:53:34 +0100 Subject: [PATCH] Fix more book entity spawn/despawn bugs --- mods/ITEMS/mcl_enchanting/engine.lua | 26 ++++++++++++++++++++------ mods/ITEMS/mcl_enchanting/init.lua | 11 +++++++++-- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/mods/ITEMS/mcl_enchanting/engine.lua b/mods/ITEMS/mcl_enchanting/engine.lua index ecf0c2152..3f06d99c5 100644 --- a/mods/ITEMS/mcl_enchanting/engine.lua +++ b/mods/ITEMS/mcl_enchanting/engine.lua @@ -575,17 +575,31 @@ function mcl_enchanting.look_at(self, pos2) end function mcl_enchanting.check_book(pos) + local has_enchanting_table = minetest.get_node(pos).name == "mcl_enchanting:table" local obj_pos = vector.add(pos, mcl_enchanting.book_offset) - for _, obj in pairs(minetest.get_objects_inside_radius(obj_pos, 0.1)) do - local luaentity = obj:get_luaentity() - if luaentity and luaentity.name == "mcl_enchanting:book" then - if minetest.get_node(pos).name ~= "mcl_enchanting:table" then + if not has_enchanting_table then + for _, obj in pairs(minetest.get_objects_inside_radius(obj_pos, 0.2)) do + local luaentity = obj:get_luaentity() + if luaentity and luaentity.name == "mcl_enchanting:book" then obj:remove() + return + end + end + else + for _, obj in pairs(minetest.get_objects_inside_radius(obj_pos, 0.2)) do + local luaentity = obj:get_luaentity() + if luaentity and luaentity.name == "mcl_enchanting:book" then + return + end + end + local obj = minetest.add_entity(obj_pos, "mcl_enchanting:book") + if obj then + local lua = obj:get_luaentity() + if lua then + lua._table_pos = table.copy(pos) end - return end end - minetest.add_entity(obj_pos, "mcl_enchanting:book") end function mcl_enchanting.get_bookshelves(pos) diff --git a/mods/ITEMS/mcl_enchanting/init.lua b/mods/ITEMS/mcl_enchanting/init.lua index eeef90100..6049069ad 100644 --- a/mods/ITEMS/mcl_enchanting/init.lua +++ b/mods/ITEMS/mcl_enchanting/init.lua @@ -148,6 +148,7 @@ minetest.register_entity("mcl_enchanting:book", { mesh = "mcl_enchanting_book.b3d", visual_size = {x = 12.5, y = 12.5}, collisionbox = {0, 0, 0}, + pointable = false, physical = false, textures = {"mcl_enchanting_book_entity.png"}, }, @@ -167,7 +168,9 @@ minetest.register_entity("mcl_enchanting:book", { end self.object:set_armor_groups({immortal = 1}) mcl_enchanting.set_book_animation(self, "close") - mcl_enchanting.check_book(vector.subtract(self.object:get_pos(), mcl_enchanting.book_offset)) + if self._table_pos then + mcl_enchanting.check_book(self._table_pos) + end end, on_step = function(self, dtime) local old_player_near = self._player_near @@ -231,7 +234,11 @@ minetest.register_node("mcl_enchanting:table", { end end end, - on_destruct = function(pos) + after_dig_node = function(pos, oldnode, oldmetadata, digger) + local dname = (digger and digger:get_player_name()) or "" + if minetest.is_creative_enabled(dname) then + return + end local itemstack = ItemStack("mcl_enchanting:table") local meta = minetest.get_meta(pos) local itemmeta = itemstack:get_meta()