Jump to content

[Solved][1.10.2] EntityInteract event seems to fire twice on each side


Recommended Posts

Posted

Hi, I've been away from modding for over a year and I'm stuck in China for a few weeks so had some down time to try porting my 1.8 mods to 1.10. It is mostly going well and now I'm working through the new bugs that have cropped up.

 

The issue I'm looking at now is that I have an interrupt handler that converts an ordinary cow into a custom cow if you right-click on it with a golden carrot. This worked fine in 1.8.9 and I didn't do much at all to convert to 1.10.2 but it is behaving differently -- if I interact it creates two of my custom cows for just one click.

 

So to debug I added some println statements to help trace the code. And it seems that the EntityInteract event is being called twice on each side. I see it print out that the interaction happened on the client twice and then on the server twice.

 

I checked on a few theories on why this is happening.

 

Theory 0) I thought maybe I wasn't handling fact that the event fires on both client and server, but my console output shows that I'm properly handling the server case by short-circuiting the execution.

 

Theory 1) I thought maybe the EntityInteract had been extended to have some sub-events, like a Start and End event, such that it is now called twice but I couldn't find any such thing.

 

Theory 2) I thought maybe I had some duplicate event handling somewhere due to cut and paste or something. But I only have one EventHandler class and searching and checking for duplicate methods doesn't come up with anything.

 

Theory 3) I thought maybe EventInteract was actually constructed twice now. So I traced the call hierarchy and found the following:

  1) The EntityInteract event is only constructed in the Forge Hook for onInteract()

  2) The onInteract() method is only called in one place: the EntityPlayer#interact()

  3) The interact() method is called in two places:

      a) PlayerControllerMP#interactWithEntity()

      b) NetHandlerPlayServer.processUseEntity()

 

Now that all makes sense because the interactWithEntity() is called on the client and in same code a CPacketUseEntity is sent, and the NetHandlerPlayServer handles the packet when received at the server. So that is the client and server side.

 

I can't figure out why all this is happening twice then! Any ideas?

 

Here is my EventHandling code:

 

  Reveal hidden contents

 

 

And here is the console output:

 

  Reveal hidden contents

 

 

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted
  On 8/31/2016 at 6:13 AM, jabelar said:

  Quote

Try using EntityInteractSpecific.

 

Okay, I'll try. But do you have a reason, or just guessing. It seems to have exactly the same call hierarchy as EntityInteract does.

I am just guessing as I do not know the exact call hierarchy of those events as I haven't messed around with them yet. Haven't really done much since 1.7.10 except the basics... I will try my best to help though.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Posted

I tried EntityInteractSpecific and it does exactly the same thing.

 

Weird.

 

I guess I might do the work to create a new mod that only handles these events to make sure there is nothing else in the mod causing this. But I have a lot of experience with modding and event handling so generally know how to debug these issues...  but I am a bit rusty so maybe I made a mistake somewhere.

 

Anyone else have any ideas? Especially anything that might have changed since 1.8?

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

This had me confused for a while too, until I realised that in 1.9+, the player now has two usable hands...

 

event.getHand()

will be your friend here.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.