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
Conversation
(Unrelated: have you considered proposing as a core dev?) |
I looked through the issue. Is it actually a good idea to allow entities (items, objects) for non-existing blocks? Edit: Oh wait. This is not allowing that, this is about add_entity/add_item to return consistent information. |
Tested. On master, you simply get an (invalid?) object ref; With this PR, you get an "ERROR[Server]: ServerEnvironment::addActiveObjectRaw(): could not emerge block for storing id=5 statically (pos=(1000,1001,1000))" (?), but also an invalid object ref. I'm not sure that's what we want; what's the expected behavior here? Do we want adding the object to fail (loudly) - as opposed to adding the entity, such that it is there when the mapblock is generated - do we want a (somewhat weird) error message for that? |
FWIW Actual question is however: why doesn't this work right now?
This should logically not happen. Are you sure you tested right? |
Sorry, I should have written a |
It looks like active objects created in nongenerated areas are stored well. minetest/src/serverenvironment.cpp Line 1055 in cb689b5
Context: minetest/src/serverenvironment.cpp Lines 1053 to 1057 in cb689b5
|
This is probably source of the problem: Lines 531 to 535 in cb689b5
Because a nongenerated block is saved before it is activated and removed from active blocks. |
cb689b5
to
c20dbf8
Compare
So, the timestamp of the block is updated when object status data is saved to the block in |
I see a conceptual problem here: Everytime a block is loaded without running through e.g. following case: block is activated and saved once, clearobject called, block is loaded to add new static object, block is loaded for real afterwards -> new object deleted too However we can't just increase the timestamp to fix it because the delta is also used by other code. Anyway as the currently best fix I suggest not calling |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
works
Co-authored-by: sfan5 <sfan5@live.de>
Co-authored-by: sfan5 <sfan5@live.de>
Please can you amend |
I asked over on the issue what the expected behavior is, and here's Wuzzy's reply: #4759 (comment) - it seems not spawning the object is considered expected behavior by Wuzzy, and he makes a good point: We probably don't want active objects in unloaded areas. We could have a second variant of |
@appgurueu Something as is done in the last commit, can be? To test both modes, change line minetest/builtin/game/chat.lua Line 892 in ca0a57d
to local obj = core.add_entity(p, entityname, "", true) .
|
What's with all the unnecessary changes? This PR is only getting further from a mergeable state (IMO). All the modder wants to do is spawn an entity. Then we add a check that prevents spawning it. But in case the modder really wants to he can tell the engine to "actually do it anyway" with a new parameter. |
65323cb
to
ec75f94
Compare
Looks like adding two modes is controversial. Now add_entity will work for loaded, unloaded, and nongenerated blocks as well. |
btw this isn't as problematic as it sounds. Consider that objects can also teleport or move right into unloaded blocks. |
I've tested that this PR fixes the test case provided in #4759 (comment) by Wuzzy. It also correctly returns errors for entities outside the map boundaries. I extended the test code as follows: https://sprunge.us/MKuZU6?lua. When activating all entities two times by flying back and forth along the line generated by
The |
(Unrelated: Have no idea what responsibilities come with it.) |
Fix minetest.add_item and minetest.add_entity are unreliable #4759.
It disables saving Active objects to a blank map block, so the error is not masked.
Fix minetest.add_item and minetest.add_entity are unreliable #4759.
To do
This PR is a Ready for Review.
How to test
Try to spawn an entity with the command
/spawnentity
in not generated part of the map and teleport to that part.