Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.16.5] Detect Animal Eat Grass


Recommended Posts

Hello,

I've been searching through events for hours and would like some guidance.

I want to know when a block changes from grass to dirt and it was caused by an animal eating the grass, and I want to know what animal type it was that did it.

 

Is there an event for that?

 

I know it won't be an exact event. I was thinking a world block state change and the entity that changed it or something.

 

Thank you

Edited by whatzhisface
Link to post
Share on other sites

There is no easy way to detect this, but you can employ some hacks™.

  1. Subscribe to EntityMobGriefingEvent.
  2. Check if the entity is a MobEntity. If not, abort.
  3. Get the entity is running an EatGrassGoal by searching through MobEntity#goalSelector.getRunningGoals (PrioritizedGoal#getGoal gets you the actual goal). If you don't find anything, abort.
  4. Get the grass eating goal's timer: EatGrassGoal#getEatingGrassTimer. It must be 4 for the entity to by eating grass, so if its not, abort.

Once this is done (and you didn't abort at any step) you can be pretty sure that the event was caused by an entity eating grass. Of course it's not guaranteed, because there is no way to check if the entity is currently in the process of updating its EatGrassGoal or if the griefing event happened somewhere else in the entity's tick code and it just so happened to also eat grass in that same tick. However that is pretty unlikely.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
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.



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.