mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-19 09:31:07 +01:00
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
|
end
|
||||||
|
|
||||||
function mcl_enchanting.check_book(pos)
|
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)
|
local obj_pos = vector.add(pos, mcl_enchanting.book_offset)
|
||||||
for _, obj in pairs(minetest.get_objects_inside_radius(obj_pos, 0.1)) do
|
if not has_enchanting_table then
|
||||||
local luaentity = obj:get_luaentity()
|
for _, obj in pairs(minetest.get_objects_inside_radius(obj_pos, 0.2)) do
|
||||||
if luaentity and luaentity.name == "mcl_enchanting:book" then
|
local luaentity = obj:get_luaentity()
|
||||||
if minetest.get_node(pos).name ~= "mcl_enchanting:table" then
|
if luaentity and luaentity.name == "mcl_enchanting:book" then
|
||||||
obj:remove()
|
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
|
end
|
||||||
return
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
minetest.add_entity(obj_pos, "mcl_enchanting:book")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function mcl_enchanting.get_bookshelves(pos)
|
function mcl_enchanting.get_bookshelves(pos)
|
||||||
|
|
|
@ -148,6 +148,7 @@ minetest.register_entity("mcl_enchanting:book", {
|
||||||
mesh = "mcl_enchanting_book.b3d",
|
mesh = "mcl_enchanting_book.b3d",
|
||||||
visual_size = {x = 12.5, y = 12.5},
|
visual_size = {x = 12.5, y = 12.5},
|
||||||
collisionbox = {0, 0, 0},
|
collisionbox = {0, 0, 0},
|
||||||
|
pointable = false,
|
||||||
physical = false,
|
physical = false,
|
||||||
textures = {"mcl_enchanting_book_entity.png"},
|
textures = {"mcl_enchanting_book_entity.png"},
|
||||||
},
|
},
|
||||||
|
@ -167,7 +168,9 @@ minetest.register_entity("mcl_enchanting:book", {
|
||||||
end
|
end
|
||||||
self.object:set_armor_groups({immortal = 1})
|
self.object:set_armor_groups({immortal = 1})
|
||||||
mcl_enchanting.set_book_animation(self, "close")
|
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,
|
end,
|
||||||
on_step = function(self, dtime)
|
on_step = function(self, dtime)
|
||||||
local old_player_near = self._player_near
|
local old_player_near = self._player_near
|
||||||
|
@ -231,7 +234,11 @@ minetest.register_node("mcl_enchanting:table", {
|
||||||
end
|
end
|
||||||
end
|
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 itemstack = ItemStack("mcl_enchanting:table")
|
||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local itemmeta = itemstack:get_meta()
|
local itemmeta = itemstack:get_meta()
|
||||||
|
|
Loading…
Reference in a new issue