mirror of
https://github.com/luanti-org/luanti.git
synced 2025-10-13 08:35:20 +02:00
Add callback on_mapblocks_changed
This commit is contained in:
@@ -381,6 +381,18 @@ void ActiveBlockList::update(std::vector<PlayerSAO*> &active_players,
|
||||
m_list = std::move(newlist);
|
||||
}
|
||||
|
||||
/*
|
||||
OnMapblocksChangedReceiver
|
||||
*/
|
||||
|
||||
void OnMapblocksChangedReceiver::onMapEditEvent(const MapEditEvent &event)
|
||||
{
|
||||
assert(receiving);
|
||||
for (const v3s16 &p : event.modified_blocks) {
|
||||
modified_blocks.insert(p);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
ServerEnvironment
|
||||
*/
|
||||
@@ -476,6 +488,11 @@ void ServerEnvironment::init()
|
||||
|
||||
m_player_database = openPlayerDatabase(player_backend_name, m_path_world, conf);
|
||||
m_auth_database = openAuthDatabase(auth_backend_name, m_path_world, conf);
|
||||
|
||||
if (m_map && m_script->has_on_mapblocks_changed()) {
|
||||
m_map->addEventReceiver(&m_on_mapblocks_changed_receiver);
|
||||
m_on_mapblocks_changed_receiver.receiving = true;
|
||||
}
|
||||
}
|
||||
|
||||
ServerEnvironment::~ServerEnvironment()
|
||||
@@ -1570,6 +1587,14 @@ void ServerEnvironment::step(float dtime)
|
||||
// Send outdated detached inventories
|
||||
m_server->sendDetachedInventories(PEER_ID_INEXISTENT, true);
|
||||
|
||||
// Notify mods of modified mapblocks
|
||||
if (m_on_mapblocks_changed_receiver.receiving &&
|
||||
!m_on_mapblocks_changed_receiver.modified_blocks.empty()) {
|
||||
std::unordered_set<v3s16> modified_blocks;
|
||||
std::swap(modified_blocks, m_on_mapblocks_changed_receiver.modified_blocks);
|
||||
m_script->on_mapblocks_changed(modified_blocks);
|
||||
}
|
||||
|
||||
const auto end_time = porting::getTimeUs();
|
||||
m_step_time_counter->increment(end_time - start_time);
|
||||
}
|
||||
|
Reference in New Issue
Block a user