ServerEntityEvents.ALLOW_FRESH_LOAD and AFTER_FRESH_LOAD event#5206
ServerEntityEvents.ALLOW_FRESH_LOAD and AFTER_FRESH_LOAD event#5206bleudev wants to merge 9 commits intoFabricMC:26.1from
Conversation
|
What is the difference between this and ServerEntityEvents.ENTITY_LOAD? |
The entity load event is called when an entity is loaded upon creation, as well as when the server starts once the entity has been added. My event is called only when an entity is added to the server. |
|
Could you use data attachments to keep track of if its the first time the entity was added to the world? E.g store a marker to indicate that your mod has done what it needs to the entity? |
|
I'm personally happier with this than having to needlessly keep track of things myself - I've had to mixin in order to do this instead of having an equivalent event to the one on NeoForge. It'd save on unnecessary calls to mod logic by only running when needed instead of every time the entity is loaded/unloaded. |
|
At the very least please fix the build issues, and explain the documentation what its for, why it differs from the other and when its fired. |
|
Would it maybe make more sense to run the event before entity is actually added to world rather than after? I think for cases where you want to modify it in some way it would be probably cleaner (and maybe allow canceling that within the event). Maybe rename would be good, since just "adding" an entity feels little bit unspecific, maybe calling it "ON_FRESHLY_ADDED" would be better (since it's more descriptive). Probably would make sense to document it too that it's called when ServerLevel#addFreshEntity runs |
|
Could this be expanded to cover all entities? I'm thinking something like Then |
Great idea, I thought about it before. But parameters (similar to chuck load event) - i think no. It will be unnecessary breaking change |
What do you mean? Sorry for my misunderstanding) |
Maybe i will do something like |
|
Done some recommendations. Can anyone review? |
|
I can't check build issues, workflow awaiting approval |
I still think it would be better to add to ENTITY_LOAD instead of a new AFTER_FRESH_LOAD event. Yes it's a breaking change but if #5112 was considered fine I don't see why this would be unacceptable. |
Maybe you're right. Probably, we can do breaking changes cause it's snapshots. But I'm waiting for @modmuss50. What he will say about it? |
|
I've fixed all issues from checkStyleMain task. Can anyone approve workflow again? |
Add two simple server-side events which calls before/after a living entity was added to level (spawned). It is useful for developers who wants do something before/after entity spawn.
Sample: