Don't save book entity statically to save space
This commit is contained in:
parent
4be2f2f76d
commit
73cb6b7a22
|
@ -574,34 +574,6 @@ function mcl_enchanting.look_at(self, pos2)
|
||||||
self.object:set_yaw(yaw + math.pi)
|
self.object:set_yaw(yaw + math.pi)
|
||||||
end
|
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)
|
|
||||||
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
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function mcl_enchanting.get_bookshelves(pos)
|
function mcl_enchanting.get_bookshelves(pos)
|
||||||
local absolute, relative = {}, {}
|
local absolute, relative = {}, {}
|
||||||
for i, rp in ipairs(mcl_enchanting.bookshelf_positions) do
|
for i, rp in ipairs(mcl_enchanting.bookshelf_positions) do
|
||||||
|
|
|
@ -142,6 +142,16 @@ minetest.register_craftitem("mcl_enchanting:book_enchanted", {
|
||||||
stack_max = 1,
|
stack_max = 1,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
local spawn_book_entity = function(pos)
|
||||||
|
local obj = minetest.add_entity(vector.add(pos, mcl_enchanting.book_offset), "mcl_enchanting:book")
|
||||||
|
if obj then
|
||||||
|
local lua = obj:get_luaentity()
|
||||||
|
if lua then
|
||||||
|
lua._table_pos = table.copy(pos)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_entity("mcl_enchanting:book", {
|
minetest.register_entity("mcl_enchanting:book", {
|
||||||
initial_properties = {
|
initial_properties = {
|
||||||
visual = "mesh",
|
visual = "mesh",
|
||||||
|
@ -151,26 +161,13 @@ minetest.register_entity("mcl_enchanting:book", {
|
||||||
pointable = false,
|
pointable = false,
|
||||||
physical = false,
|
physical = false,
|
||||||
textures = {"mcl_enchanting_book_entity.png"},
|
textures = {"mcl_enchanting_book_entity.png"},
|
||||||
|
static_save = false,
|
||||||
},
|
},
|
||||||
_player_near = false,
|
_player_near = false,
|
||||||
_table_pos = nil,
|
_table_pos = nil,
|
||||||
get_staticdata = function(self)
|
|
||||||
local pstr = ""
|
|
||||||
if self._table_pos then
|
|
||||||
pstr = minetest.serialize(self._table_pos)
|
|
||||||
end
|
|
||||||
return pstr
|
|
||||||
end,
|
|
||||||
on_activate = function(self, staticdata)
|
on_activate = function(self, staticdata)
|
||||||
if staticdata ~= "" then
|
|
||||||
local data = minetest.deserialize(staticdata)
|
|
||||||
self._table_pos = data
|
|
||||||
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")
|
||||||
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
|
||||||
|
@ -226,13 +223,7 @@ minetest.register_node("mcl_enchanting:table", {
|
||||||
mcl_enchanting.show_enchanting_formspec(clicker)
|
mcl_enchanting.show_enchanting_formspec(clicker)
|
||||||
end,
|
end,
|
||||||
on_construct = function(pos)
|
on_construct = function(pos)
|
||||||
local obj = minetest.add_entity(vector.add(pos, mcl_enchanting.book_offset), "mcl_enchanting:book")
|
spawn_book_entity(pos)
|
||||||
if obj then
|
|
||||||
local lua = obj:get_luaentity()
|
|
||||||
if lua then
|
|
||||||
lua._table_pos = table.copy(pos)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end,
|
end,
|
||||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||||
local dname = (digger and digger:get_player_name()) or ""
|
local dname = (digger and digger:get_player_name()) or ""
|
||||||
|
@ -284,7 +275,6 @@ minetest.register_abm({
|
||||||
chance = 1,
|
chance = 1,
|
||||||
nodenames = "mcl_enchanting:table",
|
nodenames = "mcl_enchanting:table",
|
||||||
action = function(pos)
|
action = function(pos)
|
||||||
mcl_enchanting.check_book(pos)
|
|
||||||
local absolute, relative = mcl_enchanting.get_bookshelves(pos)
|
local absolute, relative = mcl_enchanting.get_bookshelves(pos)
|
||||||
for i, ap in ipairs(absolute) do
|
for i, ap in ipairs(absolute) do
|
||||||
if math.random(10) == 1 then
|
if math.random(10) == 1 then
|
||||||
|
@ -303,6 +293,17 @@ minetest.register_abm({
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
minetest.register_lbm({
|
||||||
|
label = "(Re-)spawn book entity above enchanting table",
|
||||||
|
name = "mcl_enchanting:spawn_book_entity",
|
||||||
|
nodenames = {"mcl_enchanting:table"},
|
||||||
|
run_at_every_load = true,
|
||||||
|
action = function(pos)
|
||||||
|
spawn_book_entity(pos)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
minetest.register_on_mods_loaded(mcl_enchanting.initialize)
|
minetest.register_on_mods_loaded(mcl_enchanting.initialize)
|
||||||
minetest.register_on_joinplayer(mcl_enchanting.initialize_player)
|
minetest.register_on_joinplayer(mcl_enchanting.initialize_player)
|
||||||
minetest.register_on_player_receive_fields(mcl_enchanting.handle_formspec_fields)
|
minetest.register_on_player_receive_fields(mcl_enchanting.handle_formspec_fields)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user