Fix more book entity spawn/despawn bugs
This commit is contained in:
parent
e154919b34
commit
4be2f2f76d
2 changed files with 29 additions and 8 deletions
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
Reference in a new issue