Fix active object adding to not generated block (#14311)

This commit is contained in:
sfence 2024-02-04 21:24:08 +01:00 committed by GitHub
parent c9e10e1dd9
commit 83f779c52d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 9 deletions

@ -5948,8 +5948,11 @@ Environment access
* `minetest.add_entity(pos, name, [staticdata])`: Spawn Lua-defined entity at
position.
* Returns `ObjectRef`, or `nil` if failed
* Entities with `static_save = true` can be added also
to unloaded and non-generated blocks.
* `minetest.add_item(pos, item)`: Spawn item
* Returns `ObjectRef`, or `nil` if failed
* Items can be added also to unloaded and non-generated blocks.
* `minetest.get_player_by_name(name)`: Get an `ObjectRef` to a player
* `minetest.get_objects_inside_radius(pos, radius)`: returns a list of
ObjectRefs.

@ -1044,7 +1044,8 @@ void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime)
<<stamp<<", game time: "<<m_game_time<<std::endl;*/
// Remove stored static objects if clearObjects was called since block's timestamp
if (stamp == BLOCK_TIMESTAMP_UNDEFINED || stamp < m_last_clear_objects_time) {
// Note that non-generated blocks may still have stored static objects
if (stamp != BLOCK_TIMESTAMP_UNDEFINED && stamp < m_last_clear_objects_time) {
block->m_static_objects.clearStored();
// do not set changed flag to avoid unnecessary mapblock writes
}
@ -1892,11 +1893,6 @@ u16 ServerEnvironment::addActiveObjectRaw(std::unique_ptr<ServerActiveObject> ob
return 0;
}
// Register reference in scripting api (must be done before post-init)
m_script->addObjectReference(object);
// Post-initialize object
object->addedToEnvironment(dtime_s);
// Add static data to block
if (object->isStaticAllowed()) {
// Add static object to active static list of the block
@ -1915,12 +1911,20 @@ u16 ServerEnvironment::addActiveObjectRaw(std::unique_ptr<ServerActiveObject> ob
MOD_REASON_ADD_ACTIVE_OBJECT_RAW);
} else {
v3s16 p = floatToInt(objectpos, BS);
errorstream<<"ServerEnvironment::addActiveObjectRaw(): "
<<"could not emerge block for storing id="<<object->getId()
<<" statically (pos="<<p<<")"<<std::endl;
errorstream << "ServerEnvironment::addActiveObjectRaw(): "
<< "could not emerge block " << p << " for storing id="
<< object->getId() << " statically" << std::endl;
// clean in case of error
m_ao_manager.removeObject(object->getId());
return 0;
}
}
// Register reference in scripting api (must be done before post-init)
m_script->addObjectReference(object);
// Post-initialize object
object->addedToEnvironment(dtime_s);
return object->getId();
}