1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-02 16:38:41 +00:00

ABM without_neighbors (#14116)

This commit is contained in:
sfence 2024-09-26 17:32:55 +02:00 committed by GitHub
parent c1ea49940b
commit d08d34d803
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 347 additions and 6 deletions

View file

@ -827,6 +827,7 @@ struct ActiveABM
{
ActiveBlockModifier *abm;
std::vector<content_t> required_neighbors;
std::vector<content_t> without_neighbors;
int chance;
s16 min_y, max_y;
};
@ -885,6 +886,10 @@ public:
ndef->getIds(s, aabm.required_neighbors);
SORT_AND_UNIQUE(aabm.required_neighbors);
for (const auto &s : abm->getWithoutNeighbors())
ndef->getIds(s, aabm.without_neighbors);
SORT_AND_UNIQUE(aabm.without_neighbors);
// Trigger contents
std::vector<content_t> ids;
for (const auto &s : abm->getTriggerContents())
@ -996,8 +1001,11 @@ public:
continue;
// Check neighbors
if (!aabm.required_neighbors.empty()) {
const bool check_required_neighbors = !aabm.required_neighbors.empty();
const bool check_without_neighbors = !aabm.without_neighbors.empty();
if (check_required_neighbors || check_without_neighbors) {
v3s16 p1;
bool have_required = false;
for(p1.X = p0.X-1; p1.X <= p0.X+1; p1.X++)
for(p1.Y = p0.Y-1; p1.Y <= p0.Y+1; p1.Y++)
for(p1.Z = p0.Z-1; p1.Z <= p0.Z+1; p1.Z++)
@ -1015,12 +1023,25 @@ public:
MapNode n = map->getNode(p1 + block->getPosRelative());
c = n.getContent();
}
if (CONTAINS(aabm.required_neighbors, c))
goto neighbor_found;
if (check_required_neighbors && !have_required) {
if (CONTAINS(aabm.required_neighbors, c)) {
if (!check_without_neighbors)
goto neighbor_found;
have_required = true;
}
}
if (check_without_neighbors) {
if (CONTAINS(aabm.without_neighbors, c))
goto neighbor_invalid;
}
}
if (have_required || !check_required_neighbors)
goto neighbor_found;
// No required neighbor found
neighbor_invalid:
continue;
}
neighbor_found:
abms_run++;