1
0
Fork 0

Fix ServerActiveObject stuff

mutilcraft-mt53
Perttu Ahola 2012-09-09 14:18:14 +03:00
parent c4f400acd0
commit 1cc1b93e65
1 changed files with 18 additions and 5 deletions

View File

@ -743,18 +743,24 @@ neighbor_found:
u32 active_object_count = block->m_static_objects.m_active.size(); u32 active_object_count = block->m_static_objects.m_active.size();
// Find out how many objects this and all the neighbors contain // Find out how many objects this and all the neighbors contain
u32 active_object_count_wider = 0; u32 active_object_count_wider = 0;
u32 wider_unknown_count = 0;
for(s16 x=-1; x<=1; x++) for(s16 x=-1; x<=1; x++)
for(s16 y=-1; y<=1; y++) for(s16 y=-1; y<=1; y++)
for(s16 z=-1; z<=1; z++) for(s16 z=-1; z<=1; z++)
{ {
MapBlock *block2 = map->getBlockNoCreateNoEx( MapBlock *block2 = map->getBlockNoCreateNoEx(
block->getPos() + v3s16(x,y,z)); block->getPos() + v3s16(x,y,z));
if(block2==NULL) if(block2==NULL){
wider_unknown_count = 0;
continue; continue;
}
active_object_count_wider += active_object_count_wider +=
block2->m_static_objects.m_active.size() block2->m_static_objects.m_active.size()
+ block2->m_static_objects.m_stored.size(); + block2->m_static_objects.m_stored.size();
} }
// Extrapolate
u32 wider_known_count = 3*3*3 - wider_unknown_count;
active_object_count_wider += wider_unknown_count * active_object_count_wider / wider_known_count;
// Call all the trigger variations // Call all the trigger variations
i->abm->trigger(m_env, p, n); i->abm->trigger(m_env, p, n);
@ -1465,9 +1471,10 @@ u16 ServerEnvironment::addActiveObjectRaw(ServerActiveObject *object,
"addActiveObjectRaw"); "addActiveObjectRaw");
} }
else{ else{
v3s16 p = floatToInt(objectpos, BS);
errorstream<<"ServerEnvironment::addActiveObjectRaw(): " errorstream<<"ServerEnvironment::addActiveObjectRaw(): "
<<"could not find block for storing id="<<object->getId() <<"could not find block for storing id="<<object->getId()
<<" statically"<<std::endl; <<" statically (pos="<<PP(p)<<")"<<std::endl;
} }
} }
@ -1756,7 +1763,12 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
// Add to the block where the object is located in // Add to the block where the object is located in
v3s16 blockpos = getNodeBlockPos(floatToInt(objectpos, BS)); v3s16 blockpos = getNodeBlockPos(floatToInt(objectpos, BS));
// Get or generate the block // Get or generate the block
MapBlock *block = m_map->emergeBlock(blockpos); MapBlock *block = NULL;
try{
block = m_map->emergeBlock(blockpos);
} catch(InvalidPositionException &e){
// Handled via NULL pointer
}
if(block) if(block)
{ {
@ -1793,9 +1805,10 @@ void ServerEnvironment::deactivateFarObjects(bool force_delete)
} }
else{ else{
if(!force_delete){ if(!force_delete){
v3s16 p = floatToInt(objectpos, BS);
errorstream<<"ServerEnv: Could not find or generate " errorstream<<"ServerEnv: Could not find or generate "
<<"a block for storing id="<<obj->getId() <<"a block for storing id="<<obj->getId()
<<" statically"<<std::endl; <<" statically (pos="<<PP(p)<<")"<<std::endl;
continue; continue;
} }
} }