Skip to content

Commit b074683

Browse files
lhofhanslZeno-
authored andcommittedJan 8, 2017
Get neighbor from same map block if possible in ABMHandler (#4998)
1 parent 8f9611b commit b074683

File tree

1 file changed

+15
-6
lines changed

1 file changed

+15
-6
lines changed
 

‎src/environment.cpp

+15-6
Original file line numberDiff line numberDiff line change
@@ -902,14 +902,23 @@ class ABMHandler
902902
if(!i->required_neighbors.empty())
903903
{
904904
v3s16 p1;
905-
for(p1.X = p.X-1; p1.X <= p.X+1; p1.X++)
906-
for(p1.Y = p.Y-1; p1.Y <= p.Y+1; p1.Y++)
907-
for(p1.Z = p.Z-1; p1.Z <= p.Z+1; p1.Z++)
905+
for(p1.X = p0.X-1; p1.X <= p0.X+1; p1.X++)
906+
for(p1.Y = p0.Y-1; p1.Y <= p0.Y+1; p1.Y++)
907+
for(p1.Z = p0.Z-1; p1.Z <= p0.Z+1; p1.Z++)
908908
{
909-
if(p1 == p)
909+
if(p1 == p0)
910910
continue;
911-
MapNode n = map->getNodeNoEx(p1);
912-
content_t c = n.getContent();
911+
content_t c;
912+
if (block->isValidPosition(p1)) {
913+
// if the neighbor is found on the same map block
914+
// get it straight from there
915+
const MapNode &n = block->getNodeUnsafe(p1);
916+
c = n.getContent();
917+
} else {
918+
// otherwise consult the map
919+
MapNode n = map->getNodeNoEx(p1 + block->getPosRelative());
920+
c = n.getContent();
921+
}
913922
std::set<content_t>::const_iterator k;
914923
k = i->required_neighbors.find(c);
915924
if(k != i->required_neighbors.end()){

0 commit comments

Comments
 (0)
Please sign in to comment.