forceload and quarry bugfixes

This commit is contained in:
Joachim Stolberg 2018-12-31 21:00:19 +01:00
parent 1b0992734f
commit 958495acee
3 changed files with 35 additions and 5 deletions

@ -42,6 +42,24 @@ local function chat(player, text)
minetest.chat_send_player(player:get_player_name(), "[Tubelib] "..text)
end
local function get_node_lvm(pos)
local node = minetest.get_node_or_nil(pos)
if node then
return node
end
local vm = minetest.get_voxel_manip()
local MinEdge, MaxEdge = vm:read_from_map(pos, pos)
local data = vm:get_data()
local param2_data = vm:get_param2_data()
local area = VoxelArea:new({MinEdge = MinEdge, MaxEdge = MaxEdge})
local idx = area:index(pos.x, pos.y, pos.z)
node = {
name = minetest.get_name_from_content_id(data[idx]),
param2 = param2_data[idx]
}
return node
end
local function calc_area(pos)
local xpos = (math.floor(pos.x / 16) * 16)
local ypos = (math.floor(pos.y / 16) * 16)
@ -73,6 +91,10 @@ local function get_pos_list(player)
return minetest.deserialize(player:get_attribute("tubelib_forceload_blocks")) or {}
end
local function set_pos_list(player, lPos)
player:set_attribute("tubelib_forceload_blocks", minetest.serialize(lPos))
end
local function get_data(pos, player)
local pos1, pos2 = calc_area(pos)
local num = #minetest.deserialize(player:get_attribute("tubelib_forceload_blocks")) or 0
@ -175,9 +197,15 @@ if tubelib.max_num_forceload_blocks > 0 then
end
minetest.register_on_joinplayer(function(player)
local lPos = {}
for _,pos in ipairs(get_pos_list(player)) do
minetest.forceload_block(pos, true)
local node = get_node_lvm(pos)
if node.name == "tubelib:forceload" then
minetest.forceload_block(pos, true)
lPos[#lPos+1] = pos
end
end
set_pos_list(player, lPos)
end)
minetest.register_on_leaveplayer(function(player)

@ -363,7 +363,7 @@ function NodeStates:on_node_load(pos)
-- legacy node number/state/counter?
local number = meta:get_string("number")
if number ~= "" then
if number ~= "" and number ~= nil then
meta:set_string("tubelib_number", number)
meta:set_int("tubelib_state", tubelib.state(meta:get_int("running")))
if self.has_item_meter then

@ -459,9 +459,11 @@ tubelib.register_node("tubelib_addons1:quarry",
return "unsupported"
end
end,
on_node_load = function(pos)
State:on_node_load(pos)
end,
-- Function has some negative impact on the cycle time for the
-- cobble generator mode (5s on/5s off)
-- on_node_load = function(pos)
-- State:on_node_load(pos)
-- end,
on_node_repair = function(pos)
return State:on_node_repair(pos)
end,