Skip to content
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

Initial implementation of Entity Interaction Events #183

Draft
wants to merge 21 commits into
base: 1.19
Choose a base branch
from

Conversation

Quplet
Copy link

@Quplet Quplet commented Aug 22, 2022

Adds an interaction module containing (as of now) the basic Player interaction events similar to Fabric's implementation, and a LivingEntityAttack event.

TODO:

  • Separate cancellable callbacks into BEFORE and AFTER events
    • LivingEntityAttackEvents
    • AttackBlockEvents (Player)
    • AttackEntityEvents (Player)
    • UseBlockEvents (Player)
    • UseEntityEvents (Player)
    • UseItemEvents (Player)
  • Add more LivingEntity events (like EnderManPickUpBlock event)

@Quplet Quplet requested a review from a team August 22, 2022 19:54
@LambdAurora LambdAurora changed the title Initial implimentation of Enitity Interaction Events Initial implimentation of Entity Interaction Events Aug 22, 2022
@LambdAurora LambdAurora changed the title Initial implimentation of Entity Interaction Events Initial implementation of Entity Interaction Events Aug 22, 2022
@LambdAurora LambdAurora added documentation enhancement New feature or request new: module A pull request which adds a new module library: entity Related to the entity library. t: new api This adds a new API. s: waiting for test This pull request is waiting to be tested, the PR cannot be put in FCP until it has been tested. labels Aug 22, 2022
Copy link

@0xJoeMama 0xJoeMama left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some generic nitpicks and ideas.

* <li>{@link ActionResult#FAIL} cancels further processing and does not send a packet to the server.</li>
* </ul>
*/
public interface AttackBlockCallback {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this is based on the QM name, but I don't like calling it "attacking" a block, because it's really the beginning of a player breaking (destroying) a block.

Would this maybe make more sense if it was part of BreakBlockEvents?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they have different purposes... its kinda hard to describe. The action of left clicking vs the event of breaking.
Break block events to me are designed to be acted upon the block's breaking more than the player's action while this is more the player's action than the block breaking, if that makes any sense.

I'm fine with moving it over tho if people agree it fits better with the block breaking events.

@TheGlitch76 TheGlitch76 removed documentation enhancement New feature or request labels Aug 28, 2022
@EnnuiL EnnuiL marked this pull request as draft August 30, 2022 01:21
Copy link
Contributor

@Platymemo Platymemo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this! Just some nitpicks.

Also, an alternative for the DamageContext is to have a separate MODIFY_DAMAGE event that fires if the before event is not canceled. That way all the events are cohesive.

* An encapsulation of several arguments relevant to a damage context with a
* mutable damage value and cancellation that is shared across all listeners.
*/
public class DamageContext {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Annotating members with @Nullable and @NotNull would be really helpful!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imo, nothing in it should ever be null. Should I just annotate everything with @notNull?

* @param source the {@link DamageSource} of the attack
* @param damage the damage that was dealt
*/
void afterDamage(LivingEntity attacker, ItemStack stack, LivingEntity target, DamageSource source, float damage);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there should be two DamageContexts. A MutableDamageContext for the before event, and an ImmutableDamageContext (names very much up for debate) for the after event. Then these interfaces can even be merged into one.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So two more classes extending a abstract DamageContext? I think that can work.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The separation of the Before and After functional interfaces I believe are more for clarification purposes however. The documentation could become a bit confusing if they are merged.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming back to this, I think a separate MODIFY_DAMAGE event would be better. That way you have the ability to cancel it, modify it, or react to it in clear, separate events.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this would create a lot of duplicate code on the user's part. I think logic that determines cancellation or modifying damage would align a lot of the time and I'd rather not force users to duplicate code to perform these tasks.

* <p>
* Is hooked before the spectator check, so make sure to check the player's game mode!
* <ul>
* <li>{@link ActionResult#SUCCESS} cancels further processing and, on the client, sends a packet to the server.</li>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

linking the class of the packet would be useful! (also in all the other places that have similar docs)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Easy enough to do, but I'm not so sure why that would be helpful. All the packet really does is tell the logical server to process the event on their side.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just lets devs jump around the codebase a little easier, in case they want to look at how the interaction is processed

return damage;
}

@Inject(method = "damage", at = @At(value = "HEAD", shift = At.Shift.AFTER), cancellable = true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd say give this method priority so other @Injects at HEAD get run after this and it can cancel before other mods do funky things.

* @param source the {@link DamageSource} of the attack
* @param damage the damage that was dealt
*/
void afterDamage(LivingEntity attacker, ItemStack stack, LivingEntity target, DamageSource source, float damage);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming back to this, I think a separate MODIFY_DAMAGE event would be better. That way you have the ability to cancel it, modify it, or react to it in clear, separate events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
library: entity Related to the entity library. new: module A pull request which adds a new module s: waiting for test This pull request is waiting to be tested, the PR cannot be put in FCP until it has been tested. t: new api This adds a new API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants