Check for falling float nodes in liquid transform (#12862)

This commit is contained in:
Jude Melton-Houghton 2022-10-18 18:03:05 -04:00 committed by GitHub
parent b38ffdec27
commit dafdb3edb4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 1 deletions

@ -533,6 +533,8 @@ void ServerMap::transformLiquids(std::map<v3s16, MapBlock*> &modified_blocks,
std::vector<std::pair<v3s16, MapNode> > changed_nodes; std::vector<std::pair<v3s16, MapNode> > changed_nodes;
std::vector<v3s16> check_for_falling;
u32 liquid_loop_max = g_settings->getS32("liquid_loop_max"); u32 liquid_loop_max = g_settings->getS32("liquid_loop_max");
u32 loop_max = liquid_loop_max; u32 loop_max = liquid_loop_max;
@ -595,6 +597,7 @@ void ServerMap::transformLiquids(std::map<v3s16, MapBlock*> &modified_blocks,
int num_neutrals = 0; int num_neutrals = 0;
bool flowing_down = false; bool flowing_down = false;
bool ignored_sources = false; bool ignored_sources = false;
bool floating_node_above = false;
for (u16 i = 0; i < 6; i++) { for (u16 i = 0; i < 6; i++) {
NeighborType nt = NEIGHBOR_SAME_LEVEL; NeighborType nt = NEIGHBOR_SAME_LEVEL;
switch (i) { switch (i) {
@ -610,7 +613,9 @@ void ServerMap::transformLiquids(std::map<v3s16, MapBlock*> &modified_blocks,
v3s16 npos = p0 + liquid_6dirs[i]; v3s16 npos = p0 + liquid_6dirs[i];
NodeNeighbor nb(getNode(npos), nt, npos); NodeNeighbor nb(getNode(npos), nt, npos);
const ContentFeatures &cfnb = m_nodedef->get(nb.n); const ContentFeatures &cfnb = m_nodedef->get(nb.n);
switch (m_nodedef->get(nb.n.getContent()).liquid_type) { if (nt == NEIGHBOR_UPPER && cfnb.floats)
floating_node_above = true;
switch (cfnb.liquid_type) {
case LIQUID_NONE: case LIQUID_NONE:
if (cfnb.floodable) { if (cfnb.floodable) {
airs[num_airs++] = nb; airs[num_airs++] = nb;
@ -752,6 +757,11 @@ void ServerMap::transformLiquids(std::map<v3s16, MapBlock*> &modified_blocks,
== flowing_down))) == flowing_down)))
continue; continue;
/*
check if there is a floating node above that needs to be updated.
*/
if (floating_node_above && new_node_content == CONTENT_AIR)
check_for_falling.push_back(p0);
/* /*
update the current node update the current node
@ -836,6 +846,11 @@ void ServerMap::transformLiquids(std::map<v3s16, MapBlock*> &modified_blocks,
m_transforming_liquid.push_back(iter); m_transforming_liquid.push_back(iter);
voxalgo::update_lighting_nodes(this, changed_nodes, modified_blocks); voxalgo::update_lighting_nodes(this, changed_nodes, modified_blocks);
for (const v3s16 &p : check_for_falling) {
env->getScriptIface()->check_for_falling(p);
}
env->getScriptIface()->on_liquid_transformed(changed_nodes); env->getScriptIface()->on_liquid_transformed(changed_nodes);
/* ---------------------------------------------------------------------- /* ----------------------------------------------------------------------

@ -1393,6 +1393,7 @@ content_t NodeDefManager::set(const std::string &name, const ContentFeatures &de
eraseIdFromGroups(id); eraseIdFromGroups(id);
m_content_features[id] = def; m_content_features[id] = def;
m_content_features[id].floats = itemgroup_get(def.groups, "float") != 0;
m_content_lighting_flag_cache[id] = def.getLightingFlags(); m_content_lighting_flag_cache[id] = def.getLightingFlags();
verbosestream << "NodeDefManager: registering content id \"" << id verbosestream << "NodeDefManager: registering content id \"" << id
<< "\": name=\"" << def.name << "\""<<std::endl; << "\": name=\"" << def.name << "\""<<std::endl;
@ -1606,6 +1607,7 @@ void NodeDefManager::deSerialize(std::istream &is, u16 protocol_version)
if (i >= m_content_features.size()) if (i >= m_content_features.size())
m_content_features.resize((u32)(i) + 1); m_content_features.resize((u32)(i) + 1);
m_content_features[i] = f; m_content_features[i] = f;
m_content_features[i].floats = itemgroup_get(f.groups, "float") != 0;
m_content_lighting_flag_cache[i] = f.getLightingFlags(); m_content_lighting_flag_cache[i] = f.getLightingFlags();
addNameIdMapping(i, f.name); addNameIdMapping(i, f.name);
TRACESTREAM(<< "NodeDef: deserialized " << f.name << std::endl); TRACESTREAM(<< "NodeDef: deserialized " << f.name << std::endl);

@ -322,6 +322,9 @@ struct ContentFeatures
bool has_on_destruct; bool has_on_destruct;
bool has_after_destruct; bool has_after_destruct;
// "float" group
bool floats;
/* /*
Actual data Actual data
*/ */

@ -257,6 +257,18 @@ void ScriptApiEnv::on_emerge_area_completion(
} }
} }
void ScriptApiEnv::check_for_falling(v3s16 p)
{
SCRIPTAPI_PRECHECKHEADER
int error_handler = PUSH_ERROR_HANDLER(L);
lua_getglobal(L, "core");
lua_getfield(L, -1, "check_for_falling");
luaL_checktype(L, -1, LUA_TFUNCTION);
push_v3s16(L, p);
PCALL_RES(lua_pcall(L, 1, 0, error_handler));
}
void ScriptApiEnv::on_liquid_transformed( void ScriptApiEnv::on_liquid_transformed(
const std::vector<std::pair<v3s16, MapNode>> &list) const std::vector<std::pair<v3s16, MapNode>> &list)
{ {

@ -43,6 +43,8 @@ public:
void on_emerge_area_completion(v3s16 blockpos, int action, void on_emerge_area_completion(v3s16 blockpos, int action,
ScriptCallbackState *state); ScriptCallbackState *state);
void check_for_falling(v3s16 p);
// Called after liquid transform changes // Called after liquid transform changes
void on_liquid_transformed(const std::vector<std::pair<v3s16, MapNode>> &list); void on_liquid_transformed(const std::vector<std::pair<v3s16, MapNode>> &list);