feat(api/entity): add EntityEvent.Push when an entity is pushed #9678
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR is a continuation of the conversation from #9675.
Reason
The main reason I initially wanted to be able to modify the entity's push reaction was to prevent players from being pushed when in a specific GUI. In lower versions this was achievable by modifying the "pushthrough" variable on the Entity however, this was later removed by Mojang in favour of the "isPushable" method. In changing it to use this method they unfortunately removed the capability to prevent entities from being pushed outside of extending the entity and using your own class.
Details
Originally I added an event called when the
isPushable
method was called. However, when discussing the useful-ness I realized that perhaps adding functionality for modifying the push reaction would be more widely useful. There is only one other instance that this event doesn't cover which is the ItemFrame's push implementation as it eventually calls super anywayFrom ItemFrame.java:
The only other consideration I had when making this PR was that potentially someone would want the "cause" of the push. There is a method
LivingEntity#doPush
however, it is a protected method and only defers toEntity#push
. TL;DR: Currently I don't think it is pheasible to include the cause without creating a lot of changes in the Mojang code (which I assume is undesirable)