-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
feat(entity/api): add EntityEvent.IsPushable and implementation #9675
Conversation
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.
A test mod would go great with this. Please make one. 😊
A test mod as in a Forge test case? Or just an example mod where the event is used? If the former, I wasn't really sure how to emulate two entities pushing eachother in the world using the test framework |
Just a test mod that listens for the new event and cancels it on a specific mob. Something just to demonstrate that the event works. |
I added the test and here is a GIF of with and without it enabled (Removed the embeded gifs as they looked terrible) |
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.
Please include the license header at the top of this file.
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
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.
Resolved in 97a32f0.
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.
Looks good! I appreciate the minimally-invasive changes.
About your comment on the Warden: I think it would be good to keep this implementation as-is. This event seems like it would be useful to exclusively cancel the motion of entity cramming and pushing, rather than to enable it. Although I can leave additional thoughts to @LexManos.
Hmm perhaps to make it less exclusive, and further it's useful-ness, I could change it to a "Push" event where it includes the push motion and then allows for modifying how far an entity is pushed, and as such the equivalent to preventing them from being pushed would just be setting that motion to all 0s. Something like this perhaps: (From Entity.java:) public void push(double p_20286_, double p_20287_, double p_20288_) {
var result = ForgeHooks.onPush(this, p_20286_, p_20287_, p_20288_);
this.setDeltaMovement(this.getDeltaMovement().add(result.x(), result.y(), result.z());
this.hasImpulse = true;
} Thus allowing for more creativity as potentially it could be used for increasing the push reaction under given circumstances |
If you think that would be better, you can make a successor PR and close this one. |
Description
This PR adds the EntityEvent.IsPushable class so that you can prevent entities from being pushed in any given situation, with the main intention being to prevent this interaction with vanilla entities.
Reason
The main use-case I have for making this is for preventing players from being pushed. In lower versions there was a variable in the Entity class mapped to "pushthrough" which was used in Mojang's code for determining how much an Entity would be pushed by. However, in modern versions Mojang removed this and replaced this with the "isPushable" method. Unfortuantely this means that you cannot prevent players from being pushed anymore, and in my specific instance it means that when a player is in a GUI and gets pushed into a nether portal the nether portal GUI effect begins to cause graphical errors. They could also be pushed into other damage sources whilst in this GUI which is something I'd like to prevent without putting them in spectator mode.
Details
I added the event to each of the overrides of the isPushable method such that it would fire consistently for all entities, with the exception of those entities that have a super call. I did this as I assumed it would be much more useful to others if it covered more than just the Player entity.
I did not include the event call in classes such as the Warden where they have a super call, as I figured that if they wanted to prevent the warden from being pushed they could set it to return false and the logical and would end up returning false and as such the event won't fire twice. However, now I am considering that perhaps it is returning false and they want it to return true? Is this something that should be changed?
Code from Warden.java: