forked from Mirrorlandia_minetest/minetest
Fix active object adding to not generated block (#14311)
This commit is contained in:
parent
c9e10e1dd9
commit
83f779c52d
@ -5948,8 +5948,11 @@ Environment access
|
|||||||
* `minetest.add_entity(pos, name, [staticdata])`: Spawn Lua-defined entity at
|
* `minetest.add_entity(pos, name, [staticdata])`: Spawn Lua-defined entity at
|
||||||
position.
|
position.
|
||||||
* Returns `ObjectRef`, or `nil` if failed
|
* 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
|
* `minetest.add_item(pos, item)`: Spawn item
|
||||||
* Returns `ObjectRef`, or `nil` if failed
|
* 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_player_by_name(name)`: Get an `ObjectRef` to a player
|
||||||
* `minetest.get_objects_inside_radius(pos, radius)`: returns a list of
|
* `minetest.get_objects_inside_radius(pos, radius)`: returns a list of
|
||||||
ObjectRefs.
|
ObjectRefs.
|
||||||
|
@ -1044,7 +1044,8 @@ void ServerEnvironment::activateBlock(MapBlock *block, u32 additional_dtime)
|
|||||||
<<stamp<<", game time: "<<m_game_time<<std::endl;*/
|
<<stamp<<", game time: "<<m_game_time<<std::endl;*/
|
||||||
|
|
||||||
// Remove stored static objects if clearObjects was called since block's timestamp
|
// 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();
|
block->m_static_objects.clearStored();
|
||||||
// do not set changed flag to avoid unnecessary mapblock writes
|
// do not set changed flag to avoid unnecessary mapblock writes
|
||||||
}
|
}
|
||||||
@ -1892,11 +1893,6 @@ u16 ServerEnvironment::addActiveObjectRaw(std::unique_ptr<ServerActiveObject> ob
|
|||||||
return 0;
|
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
|
// Add static data to block
|
||||||
if (object->isStaticAllowed()) {
|
if (object->isStaticAllowed()) {
|
||||||
// Add static object to active static list of the block
|
// 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);
|
MOD_REASON_ADD_ACTIVE_OBJECT_RAW);
|
||||||
} else {
|
} else {
|
||||||
v3s16 p = floatToInt(objectpos, BS);
|
v3s16 p = floatToInt(objectpos, BS);
|
||||||
errorstream<<"ServerEnvironment::addActiveObjectRaw(): "
|
errorstream << "ServerEnvironment::addActiveObjectRaw(): "
|
||||||
<<"could not emerge block for storing id="<<object->getId()
|
<< "could not emerge block " << p << " for storing id="
|
||||||
<<" statically (pos="<<p<<")"<<std::endl;
|
<< 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();
|
return object->getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user