Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Forge distinguishes between "onLivingAttack" and "onPlayerAttack" while patchwork doesn't. #114

Open
kitlith opened this issue Jul 9, 2020 · 4 comments

Comments

@kitlith
Copy link
Contributor

kitlith commented Jul 9, 2020

YarnForge's ForgeHooks:

        public static boolean onLivingAttack(LivingEntity entity, DamageSource src, float amount) {
                return entity instanceof PlayerEntity || !MinecraftForge.EVENT_BUS.post(new LivingAttackEvent(entity, src, amount));
        }

        public static boolean onPlayerAttack(LivingEntity entity, DamageSource src, float amount) {
                return !MinecraftForge.EVENT_BUS.post(new LivingAttackEvent(entity, src, amount));
        }

Patchwork's EntityEvents:

	public static boolean onLivingAttack(LivingEntity entity, DamageSource src, float damage) {
		return MinecraftForge.EVENT_BUS.post(new LivingAttackEvent(entity, src, damage));
	}

The LivingEntity mixin ends up not checking if the entity is instanceof PlayerEntity while forge does. For all I know there's a reason for this, but it's not documented if there is a reason.

@obj-obj
Copy link

obj-obj commented Jul 27, 2020

Do you have an example of a mod that requires this event?

I think I fixed it, but I need to test somehow.

@kitlith
Copy link
Contributor Author

kitlith commented Jul 28, 2020

To be clear: The reason I opened this issue was because I saw it while implementing the god-classes module, which raised some questions that were not on scope for those PRs. It's my fault for not laying out those questions:

  1. Why does Forge do this?
  2. Is there a reason why Patchwork doesn't do this? (thus the issue)

If the first question has a reasonable answer, and the answer to the second question is "no", then fixing it certainly makes sense.

The god-classes module is unaffected either way as I simply added the instanceof check to the relevant method in ForgeHooks.

(this comment brought to you by: discussion of whether a fix for this issue is actually needed or not)

@obj-obj
Copy link

obj-obj commented Jul 30, 2020

After learning a bit about forge's event system and looking at it again, I don't actually think this issue actually does need to be fixed, as entity attacks just break when you try to, and it's already implemented in ForgeHooks anyway.

@kitlith
Copy link
Contributor Author

kitlith commented Jul 30, 2020

@obj-obj I know exactly why your attempt is breaking, I've even told you exactly why it's breaking on the PR. That is irrelevant to whether this issue should or should not be fixed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants