Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Add removal reason to EntityRemoveFromWorldEvent

Open TonytheMacaroni opened this issue 1 year ago • 4 comments
trafficstars

Adds a removal reason to EntityRemoveFromWorldEvent. The RemovalReason enum mirrors the NMS Entity.RemovalReason, except that the methods shouldDestroy/shouldSave are renamed to willDestroy/willSave. Due to the chunk system rewrite, unloaded entities are not set as removed with RemovalReason.UNLOAD_TO_CHUNK, so currently if the removal reason is not set and the entity is inaccessible, it'll default to RemovalReason.UNLOAD_TO_CHUNK as the removal reason.

TonytheMacaroni avatar Jan 08 '24 17:01 TonytheMacaroni

Given upstream has merged into an entity remove from world event, can you expand this PR to include the new reasons?

Would be fixing #10280

lynxplay avatar Mar 16 '24 19:03 lynxplay

Yes please!

prototype464 avatar Mar 19 '24 21:03 prototype464

Updated the PR to include the causes upstream added. Also moved the primary event call to CraftEventFactory#callEntityRemoveEvent, as using ServerLevel.EntityCallbacks#onTrackingEnd didn't provide the additional cause context, and that method isn't called on entity unload. The previous event call there was made to use a new INACCESSIBLE cause, for when the chunk an entity is in is made inaccessible (but prior to fully unloading).

TonytheMacaroni avatar Jul 16 '24 18:07 TonytheMacaroni