Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix active object adding to not generated block #14311

Merged
merged 7 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/lua_api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/nongenerated blocks.
sfence marked this conversation as resolved.
Show resolved Hide resolved
* `minetest.add_item(pos, item)`: Spawn item
* Returns `ObjectRef`, or `nil` if failed
* Items can be added also to unloaded/nongenerated 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.
Expand Down
13 changes: 8 additions & 5 deletions src/serverenvironment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1901,6 +1901,11 @@ 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
Expand All @@ -1922,16 +1927,14 @@ u16 ServerEnvironment::addActiveObjectRaw(std::unique_ptr<ServerActiveObject> ob
errorstream << "ServerEnvironment::addActiveObjectRaw(): "
sfence marked this conversation as resolved.
Show resolved Hide resolved
<< "could not emerge block " << p << " for storing id="
<< object->getId() << " statically" << std::endl;
// clean in case of error
object->removingFromEnvironment();
m_script->removeObjectReference(object);
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);
sfence marked this conversation as resolved.
Show resolved Hide resolved

return object->getId();
}

Expand Down